Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat-bot Support for Webhooks (MS Bot Framework-based MS Teams Chat-bot) #2

Merged
merged 42 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5a03af0
added a webhook polling class
MinuraPunchihewa Oct 2, 2024
f27ad42
extended chat bot message with optional kwargs
MinuraPunchihewa Oct 2, 2024
8640ed2
extended the chat bot task to support webhooks
MinuraPunchihewa Oct 2, 2024
d55ec66
created an API endpoint for the webhook to call
MinuraPunchihewa Oct 2, 2024
89c8265
updated the MS Teams handler to support webhook polling
MinuraPunchihewa Oct 2, 2024
e538751
Merge branch 'main' into feature/webhook_based_chatbot
MinuraPunchihewa Oct 2, 2024
82614a0
made a couple of formatting changes
MinuraPunchihewa Oct 2, 2024
cb5728d
moved the common initialization code from run() to __init__()
MinuraPunchihewa Oct 3, 2024
a7de713
moved more common code to init()
MinuraPunchihewa Oct 3, 2024
7dc6c21
added a on_webhook() func to task and polling
MinuraPunchihewa Oct 5, 2024
4228830
added the webhook_token col to the ChatBots model
MinuraPunchihewa Oct 7, 2024
37e0f4e
created the Alembic revision for the change to the database model
MinuraPunchihewa Oct 7, 2024
45dd6e1
added the API namespace for webhooks
MinuraPunchihewa Oct 7, 2024
43004c6
added the route for handling messages via webhooks
MinuraPunchihewa Oct 7, 2024
db2790e
passed the request from the endpoint to the controller
MinuraPunchihewa Oct 7, 2024
c0c5cdf
added an on_webhook() method to ChatBotController
MinuraPunchihewa Oct 7, 2024
67b10aa
removed the on_webhook() method from WebhookPolling
MinuraPunchihewa Oct 7, 2024
77878d9
added on_webhook method to ChatBotTask and updated o_message to take …
MinuraPunchihewa Oct 7, 2024
dc8121a
updated polling call on_message with chat ID instead of memory
MinuraPunchihewa Oct 7, 2024
ea2ab9a
removed the request attr from ChatBotMessage
MinuraPunchihewa Oct 7, 2024
eb10ca5
added an on_webhook() to the MS Teams handler
MinuraPunchihewa Oct 7, 2024
275553a
added a method to get chatbot by ID and added the webhook token to up…
MinuraPunchihewa Oct 8, 2024
bde34a1
added a run() method to WebhookPolling
MinuraPunchihewa Oct 8, 2024
f875f6b
registered the new webhooks namespace
MinuraPunchihewa Oct 8, 2024
6539e78
fixed bugs in WebhookPolling
MinuraPunchihewa Oct 8, 2024
c8eeb87
updated the MS Teams handler with the new implementation
MinuraPunchihewa Oct 8, 2024
896afc0
updated controller to return webhook_token when getting chatbots
MinuraPunchihewa Oct 8, 2024
fdec233
added the webhook_token col to internal chatbots table
MinuraPunchihewa Oct 8, 2024
8920979
removed the ChatBotMessagesResource
MinuraPunchihewa Oct 8, 2024
b0a54b9
increased the token length
MinuraPunchihewa Oct 8, 2024
a108482
cleaned up the logic for getting a chatbot
MinuraPunchihewa Oct 8, 2024
7556ad9
improved the on_webhook() method in ChatBotController
MinuraPunchihewa Oct 8, 2024
d72ac04
re-introduced chat_memory as a param to on_message
MinuraPunchihewa Oct 8, 2024
7e53726
fixed lint issues
MinuraPunchihewa Oct 8, 2024
a999898
added a simple mechanism to persist chatbot memory
MinuraPunchihewa Oct 8, 2024
e7c6360
fixed lint issues
MinuraPunchihewa Oct 8, 2024
21e3336
removed unused code in the MS Teams handler
MinuraPunchihewa Oct 8, 2024
03bd314
removed unnecessary files
MinuraPunchihewa Oct 8, 2024
1fcee24
updated the dependencies
MinuraPunchihewa Oct 8, 2024
7f5c3e5
updated the script for checking requirements with new dependencies
MinuraPunchihewa Oct 8, 2024
40cf370
removed the unnecessary settings file
MinuraPunchihewa Oct 8, 2024
19cda2e
Merge branch 'feature/webhook_based_chatbot' of https://github.com/mi…
rahul-dange-talentica Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mindsdb/api/executor/datahub/datanodes/mindsdb_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class ChatbotsTable(MdbTable):
"PARAMS",
"IS_RUNNING",
"LAST_ERROR",
"WEBHOOK_TOKEN",
]

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions mindsdb/api/http/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from mindsdb.api.http.namespaces.tree import ns_conf as tree_ns
from mindsdb.api.http.namespaces.views import ns_conf as views_ns
from mindsdb.api.http.namespaces.util import ns_conf as utils_ns
from mindsdb.api.http.namespaces.webhooks import ns_conf as webhooks_ns
from mindsdb.interfaces.database.integrations import integration_controller
from mindsdb.interfaces.database.database import DatabaseController
from mindsdb.interfaces.file.file_controller import FileController
Expand Down Expand Up @@ -246,6 +247,7 @@ def root_index(path):
api.add_namespace(ns)
api.add_namespace(default_ns)
api.add_namespace(auth_ns)
api.add_namespace(webhooks_ns)

@api.errorhandler(Exception)
def handle_exception(e):
Expand Down
3 changes: 3 additions & 0 deletions mindsdb/api/http/namespaces/configs/webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from flask_restx import Namespace

ns_conf = Namespace('webhooks', description='API to receive messages from bots')
29 changes: 29 additions & 0 deletions mindsdb/api/http/namespaces/webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from flask import request
from flask_restx import Resource

from mindsdb.api.http.namespaces.configs.webhooks import ns_conf
from mindsdb.interfaces.chatbot.chatbot_controller import ChatBotController
from mindsdb.metrics.metrics import api_endpoint_metrics


# Stores the memory of the various chat-bots mapped by their webhook tokens.
# This is required because each time a new request is made, a new instance of the ChatBotTask is created.
# This causes the memory to be lost.
chat_bot_memory = {}


@ns_conf.route('/chatbots/<webhook_token>')
class ChatbotWebhooks(Resource):
@ns_conf.doc('chatbots_webhook')
@api_endpoint_metrics('POST', '/webhooks/chatbots/<webhook_token>')
def post(self, webhook_token: str) -> None:
"""
This endpoint is used to receive messages posted by bots from different platforms.

Args:
webhook_token (str): The token of the webhook. It is used to uniquely identify the webhook.
"""
request_data = request.json

chat_bot_controller = ChatBotController()
return chat_bot_controller.on_webhook(webhook_token, request_data, chat_bot_memory)

This file was deleted.

Loading
Loading