Custom payloads for custom web chat widget

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).

Welcome to the forum, Lucas! :slight_smile:

You’re really close to your goal, what you should do is use Channel-Specific Response Variations with your Custom Output Payload:

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."
1 Like

Thanks Chris! This is very helpful.

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:
    - story: channel specific response path
      steps:
      - intent: channel_response
      - action: utter_channel_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.

Hopefully it’ll work by using rest :slight_smile:

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.

I did try that, but that always returned the non-channels specific responses. But that makes sense, because my widget does not include any metadata about the fact that it wants to receive the ‘chatwidgets_com’ responses. But even if my widget would include it as metadata, it seems to be ignored currently, I found out after reading this topic Channel specific utterances not working [using rest channel and set the input_channel in post request]. (There’s a feature request for it here: Channel-specific responses for REST channel with using input_channel in post request · Issue #7384 · RasaHQ/rasa · GitHub)

That being said, I managed to get it to work using my custom channel after finding this issue on github: Custom Channels Not Responding with Channel-Specific Responses · Issue #8228 · RasaHQ/rasa · GitHub. I was missing an output class for my channel.

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.

Thanks very much for your help Chris!

1 Like

Ah, I see, good job finding the error and glad you solved it :slight_smile:

Please mark the message that helped you as solution (could be even your message) to mark the thread as solved :slight_smile:

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.

For completeness, I did a quick test but it turns out when using the rest connector, the value for channel should be ‘connector’ as mentioned in this topic I linked to earlier Channel specific utterances not working [using rest channel and set the input_channel in post request]

1 Like