# Custom payloads for custom web chat widget

**URL:** <https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643>\
**Category:** Rasa Open Source\
**Created:** [November 30, 2021, 6:24pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643 "2021-11-30T18:24:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca5](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/luca5/32/18414_2.png) [@luca5](https://forum.rasa.com/u/luca5)\
**Post date:** [November 30, 2021, 6:24pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/1 "2021-11-30T18:24:29Z")

</div>

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:

```auto
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:

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

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [November 30, 2021, 8:38pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/2 "2021-11-30T20:38:17Z")

</div>

Welcome to the forum, Lucas! 🙂

You’re really close to your goal, what you should do is use [Channel-Specific Response Variations](https://rasa.com/docs/rasa/responses#channel-specific-response-variations) with your [Custom Output Payload](https://rasa.com/docs/rasa/responses#custom-output-payloads):

```auto
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."

```

---

<div class="post-metadata">

**Author:** ![luca5](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/luca5/32/18414_2.png) [@luca5](https://forum.rasa.com/u/luca5)\
**Post date:** [December 1, 2021, 11:50am UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/3 "2021-12-01T11:50:38Z")

</div>

Thanks Chris! This is very helpful.

I assume a channel specific response variation requires the use of a [custom channel connector](https://rasa.com/docs/rasa/connectors/custom-connectors) 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](https://forum.rasa.com/uploads/short-url/mGxdoy6df6qEmrU8qghYBJ3OTwL.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:

```auto
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:

```auto
- 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?

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 1, 2021, 12:13pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/4 "2021-12-01T12:13:54Z")

</div>

Sorry, I should’ve mentioned the following earlier:

> [@luca5](#):
>
> I assume a channel specific response variation requires the use of a [custom channel connector](https://rasa.com/docs/rasa/connectors/custom-connectors) too

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` 🙂

---

<div class="post-metadata">

**Author:** ![luca5](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/luca5/32/18414_2.png) [@luca5](https://forum.rasa.com/u/luca5)\
**Post date:** [December 1, 2021, 12:26pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/5 "2021-12-01T12:26:17Z")

</div>

> 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]](http://forum.rasa.com/t/channel-specific-utterances-not-working-using-rest-channel-and-set-the-input-channel-in-post-request/31648). (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](https://github.com/RasaHQ/rasa/issues/7384))

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](https://github.com/RasaHQ/rasa/issues/8228). I was missing an output class for my channel.

For those interested, here’s my final custom connector [chatwidgets.py](https://forum.rasa.com/uploads/short-url/wJxnfwKQB9xBzUNcNHfyW2WoGMe.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!

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 1, 2021, 12:34pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/6 "2021-12-01T12:34:05Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![luca5](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/luca5/32/18414_2.png) [@luca5](https://forum.rasa.com/u/luca5)\
**Post date:** [December 1, 2021, 1:37pm UTC](https://forum.rasa.com/t/custom-payloads-for-custom-web-chat-widget/49643/7 "2021-12-01T13:37:30Z")

</div>

> [@luca5](#):
>
> > 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.

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]](http://forum.rasa.com/t/channel-specific-utterances-not-working-using-rest-channel-and-set-the-input-channel-in-post-request/31648)
