Sending Custom JSON Payload from actions(workaround for utter_custom_message)

@erohmensing

It means for custom utterance to work with the websocket chat the data: line MUST be present in the template layout or else it will crash. The documentation sample stops at “custom:” which does not actually work. Same as @Mgo2 found out.

  utter_test_custom_output:
    - custom:
        data:
          attachment:
            type: "video"
            payload:
              title: "Sample video output from domain template"
              src: "link to my video"

Gotcha. This is specific to the websocket then, in order to use the custom responses I would say it’s pretty reasonable to expect someone to be familiar with the relevant API. I suppose it could be made clearer that everything under custom: should be a complete payload that would be accepted by the channel (e.g. apparently for websocket it all needs to be wrapped in data), but that’s not the case for everything.

1 Like

@erohmensing Yes, this is for websocket channel. And this the specific of the socket.io library that is being used. It would be very useful to update this documentation page https://rasa.com/docs/rasa/core/domains/#custom-output-payloads as the sample there is channel specific to Slack only. And mentioned no hints of websocket, so it took sometime to debug through both the back end and front end frameworks (mr.bot) to understand what the socket.io requires. Keep in mind, documentation for websocket does point to Mr. bot Chat UI, so when people want to use rasa with a chat ui, they will a lot of time end up with mr. bot chat ui and if they need a custom action, there is nothing to guide them but the slack example, which does not work for websockets :slight_smile:

Right, but the socket documentation shows relatively clearly that everything is wrapped in data to do anything custom rasa-webchat/README.md at master · mrbot-ai/rasa-webchat · GitHub

@erohmensing “Relatively” yes. This is how we figured out that the data: part is needed. But took a bit of bumping. It would he helpful to have a Mr.Bot example alongside Slacks. While it seems it’s not Rasa’s concern of what goes below the custom line, Rasa is typically not used headless and websocket channel from Mr.Bot is a popular one and referred to from the documentation, especially a yml in the domain utterance to help connect the dots easier vs mr.bots jason. But thanks, whoever comes across this page will probably find this useful :smiley:

Excellent work, Do you have any idea how could we change the class RestInput(InputChannel): so that our output format will change. what I’m looking to change(the rest input channel) or create a new channel that will store all the info that I’ll send from my custom UI. Just like I’m sending

data: JSON.stringify({ “message”: message, “sender”: “senderid”, “input_channel” : “mycustom” “another_variable” : “some_text” })

What I’m trying to achieve is to change the data format[after detecting channel which rest] for my custom UI so that my same assistant would run on messenger, telegram and the custom UI [for which i’m changing the format].

[

{

“recipient_id”:“default”, “custom”:{

“buttons”:[

{

“payload”:"/contactinfo", “title”:“info”

}, {

“payload”:"/carddetails", “title”:“Details of Card”

}, {

“payload”:"/mymsg", “title”:“Msg from us”

}, {

“payload”:"/info", “title”:“Information”

}, {

“payload”:"/maplink", “title”:“Here is the Map”

}, {

“payload”:"/findoutmore", “title”:“Find Out More”

}, {

“payload”:"/contact_me", “title”:“Contact me”

}

], “text”:“Hey, How do do you do”

}

}

]

Firstly I tried to change the payload directly in domain.yml which will only be rendered in the custom UI and other channels ultimately fails to render it.

hi @anuragchaudhary, you can use metadata for that or the other way which you are trying to achieve is by do the following way:

You can edit the recieve method of the channels.py file to accept the parameters that you are trying to send from your custom UI:

Thanks, Jitesh

1 Like

Hi, @jitesh do you have any idea about the event handling I’m trying to send an object as in the form of an event so that the rasa could get this data event and store the object details in tracker_store. Any views on this?

var json = {
            "event":"WEB_FORM",
            "message": message,
            "sender": "username",
            "custom": { 
                "name":"username",
                "phone":"1234",
                "email":"9891@abc.com"
                }

        };

Hi @anuragchaudhary, can you just tell me I mean what are you trying to achieve by adding event in the tracker store, I mean it will help me to get a clear picture.:sweat_smile:

The current scenario is when we talk with an assistant, it directly send the msg to NLU after storing the text in the tracker then as per the predicted intent the reply is generated and sent to the user. I’m showing a form on the custom UI the user fills it and send it to me. Now on my end I just have to store that in my tracker. So after searching a lot, I came across events. Is there any other way to achieve it

@anuragchaudhary, I will suggest you something but I don’t know it will help you or not, so what you can do is like once the user has filled the web ui form and user has clicked submit button what you can do is you can call the below api which will store this data in tracker, now you can send the data to rasa without passing it to nlu you can use the below api:

https://rasa.com/docs/rasa/api/http-api/#operation/addConversationMessage

Let me know if this helps you. :blush:

How about the format message of the facebook? I’ve tried with your second option and it work with rasa-webchat but facebook messenger is not.

look into fb messenger payload

Any idea how can i do this inside a form - say a particular slot which needs to be filled and i need to send the data to a custom frontend

dispatcher.utter_message(json2html.convert(json = )) will display the JSON data in Rasa response

Hi guys, I have to send a Json from custom action but I don’t want to see it in the chat’s output. I need it for obtaining a link for an interaction, but I don’t need to visualize it in the chat. What function can I use for this? Can you give me a little example?

Hi @shivangpatel , how can we use the above solution to make rasa chatbot buttons work in ms teams? I have deployed rasa IT helpdesk bot in teams, its buttons are visible but on clicking it gives an error “Something went wrong. Please try again.” Please suggest a solution to make them work. Thank you.