commit 4b50ae32f65d5dc16ae70d142d2bed6dce36ec63
parent 3dc4ce909e1996521602a7666933670d639285bd
Author: MTRNord <mtrnord1@gmail.com>
Date: Thu, 18 Jan 2024 13:49:56 +0100
Use correct version
Diffstat:
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
@@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Rasa Train and Test GitHub Action
- uses: RasaHQ/rasa-train-test-gha@v2
+ uses: RasaHQ/rasa-train-test-gha@2.2.0
with:
requirements_file: requirements.txt
data_validate: true
diff --git a/addons/channel.py b/addons/channel.py
@@ -0,0 +1,54 @@
+import inspect
+from sanic import Blueprint, response
+from sanic.request import Request
+from sanic.response import HTTPResponse
+from typing import Text, Callable, Awaitable
+
+from rasa.core.channels.channel import (
+ InputChannel,
+ CollectingOutputChannel,
+ UserMessage,
+)
+
+
+class Matrix(InputChannel):
+ def name(self) -> Text:
+ """Name of your custom channel."""
+ return "matrix"
+
+ def blueprint(
+ self, on_new_message: Callable[[UserMessage], Awaitable[None]]
+ ) -> Blueprint:
+ custom_webhook = Blueprint(
+ "custom_webhook_{}".format(type(self).__name__),
+ inspect.getmodule(self).__name__,
+ )
+
+ @custom_webhook.route("/", methods=["GET"])
+ async def health(request: Request) -> HTTPResponse:
+ return response.json({"status": "ok"})
+
+ @custom_webhook.route("/webhook", methods=["POST"])
+ async def receive(request: Request) -> HTTPResponse:
+ sender_id = request.json.get("sender") # method to get sender_id
+ text = request.json.get("text") # method to fetch text
+ input_channel = self.name() # method to fetch input channel
+ metadata = self.get_metadata(request) # method to get metadata
+
+ collector = CollectingOutputChannel()
+
+ # include exception handling
+
+ await on_new_message(
+ UserMessage(
+ text,
+ collector,
+ sender_id,
+ input_channel=input_channel,
+ metadata=metadata,
+ )
+ )
+
+ return response.json(collector.messages)
+
+ return custom_webhook