Coverage for mindsdb / api / http / namespaces / webhooks.py: 79%
14 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1from flask import request
2from flask_restx import Resource
4from mindsdb.api.http.namespaces.configs.webhooks import ns_conf
5from mindsdb.interfaces.chatbot.chatbot_controller import ChatBotController
6from mindsdb.metrics.metrics import api_endpoint_metrics
9# Stores the memory of the various chat-bots mapped by their webhook tokens.
10# This is required because each time a new request is made, a new instance of the ChatBotTask is created.
11# This causes the memory to be lost.
12chat_bot_memory = {}
15@ns_conf.route('/chatbots/<webhook_token>')
16class ChatbotWebhooks(Resource):
17 @ns_conf.doc('chatbots_webhook')
18 @api_endpoint_metrics('POST', '/webhooks/chatbots/<webhook_token>')
19 def post(self, webhook_token: str) -> None:
20 """
21 This endpoint is used to receive messages posted by bots from different platforms.
23 Args:
24 webhook_token (str): The token of the webhook. It is used to uniquely identify the webhook.
25 """
26 request_data = request.json
28 chat_bot_controller = ChatBotController()
29 return chat_bot_controller.on_webhook(webhook_token, request_data, chat_bot_memory)