I am developing a web-based chat widget that supports multiple bot platforms, including Rasa. The widget uses the rest api to communicate with Rasa and it supports various rich responses, like (adaptive) cards, carousels, video, audio etc. The yaml/json for those responses should be added to the response’s ‘custom’ key.
What I am wondering is this: should I require that the custom payloads that are specific to my widget, are added to ‘custom’ section using a specific key? For example:
utter_video:
- text: "Here's message with a video."
custom:
chatwidgets_com:
type: video
videoUrl: https://example.com/video.mp4
Or can I just let them be added right below the custom key, like this:
utter_video:
- text: "Here's message with a video."
custom:
type: video
videoUrl: https://example.com/video.mp4
I am worried that the last approach might result in custom payload conflicts with other frontends that also use the rest channel.
I hope my question makes sense (English is not my native language).
utter_video:
- text: "Here's a message with a video for the widget."
channel: chatwidgets_com
custom:
type: video
videoUrl: https://example.com/video.mp4
- text: "Here's a message with a video for another widget that uses another format."
channel: otherwidget
custom:
mime: "video/mp4"
location: "https://example.com/video.mp4"
display: "true"
- text: "Here's a message without video for other channels."
I assume a channel specific response variation requires the use of a custom channel connector too, and I am trying to get it to work, but for some reason, my custom connector always returns the non-channel specific response.
This is what I have done:
Created a custom connector chatwidgets.py (5.6 KB) with a name method that returns ‘chatwidgets_com’. I’ve added a print statements for the input channel (line 115) and the json response (line 147).
In credentials.yml I’ve added my custom connector like this: chatwidgets.ChatWidgetsInput:
In domain.yml I’ve added an utterance for my channel, and a non-channel specific fallback:
utter_channel_response:
- text: "This is a message for the chatwidgets channel."
channel: "chatwidgets_com"
- text: "This is a message for all other channels."
In stories.yml I’ve added a story that allows me to test my response:
And I setup my widget to connect to my custom channel: https://[mydomain]/webhooks/chatwidgets_com/webhook
It seems to correctly connect to my custom connector, because I see the print statements in the console. However, when I enter /channel_response as an input, the answer I get is ‘This is a message for all other channels.’ where I would have expected ‘This is a message for the chatwidgets channel.’
The print statements in the console show this:
input channel: chatwidgets_com
collector.messages: [{“recipient_id”: “c17e063d-2d89-4707-a26f-048a6f6cb768”, “text”: “This is a message for all other channels.”}]
I must be doing something wrong. How do I tell Rasa to return the channel specific response when one is available?
Sorry, I should’ve mentioned the following earlier:
You’re completely right, but I don’t think you need it in this case, since you’re using the REST channel. So please try just using rest for the channel name.
You correctly implemented the custom connector though, as far as I can tell. So I don’t know what the error is.
You’re completely right, but I don’t think you need it in this case, since you’re using the REST channel. So please try just using rest for the channel name.
For those interested, here’s my final custom connector chatwidgets.py (5.8 KB). The extra output class is specified at line 173 and it is instantiated at line 126.
Sorry, after re-reading your comment I noticed I misread it. I did not test by using the value rest for the channel when using the default rest connector.