So when we do dispatch.utter_message(text="Hello");
It sends {text:"Hello"}
But i wanted to send one more parameter, like {text:“Hello”, param:“data”} when doing dispatch.utter_message()
How can I do that ?
Thanks
So when we do dispatch.utter_message(text="Hello");
It sends {text:"Hello"}
But i wanted to send one more parameter, like {text:“Hello”, param:“data”} when doing dispatch.utter_message()
How can I do that ?
Thanks
You can just use python built-in string format or rasa text format:
dispatcher.utter_message(template="utter_template", ph="jack")
The result will be my name is Jack. Rasa replace placeholder variable ph, you could define more than one placeholders.
utter_template:
- text: my name is {ph}
Thanks :), But I wanted to “receive” data on client side, Like
dispatcher.utter_message(text=“Hello”, id=“2”) should send an object {text:“hello”, id:“2”}
Hi, json message is still not there
Thank you for your reply. Actually what I was looking for is ability to pass more arbitary fields to the front end along with the text attribute So e.g.
instead of dispatcher.utter_message(text=“Hello”)
I wanted to send something like below all the way to frontend dispatcher.utter_message(text=“Hello”, field1=“imp_val_1”, field2=“imp_val_2”) and I want my web frontend to get all the 3 fields, viz., text, field1 and field2
So template does not solve my problem.
I did find something of interest, which was dispatcher.utter_message( json_message = {text: “Hello”, field1: “imp_val_1”, field2: “imp_val_2”})
However using this, what I receive on frontend is a blank message, so basically the response from RASA received by my web front end is blank
Can you help me understand, this issue
dispatcher.utter_message(json_message={…}) is not sending anything on my socketio channel , to my frontend, can someone help me?
Can you share the code that sends and receives the message?
class ActionMiniStatement(Action):
"""Executes after restart of a session"""
def name(self) -> Text:
"""Unique identifier of the action"""
return "action_mini_statement"
async def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[EventType]:
"""Executes the custom action"""
transactions = profile_db.get_mini_statement(tracker.sender_id)
dispatcher.utter_message(text="Here are your five recent transactions 😊")
statement=''
for k in transactions:
statement = statement+(f'{date.fromisoformat(str(k.timestamp)[0:10]).strftime("%b %d, %Y")} **₹{k.amount}** to A/C: **XX{k.to_account_number[len(k.to_account_number)-4:len(k.to_account_number)]}** \n. . . . . . . . . . . . . . . . . . . \n')
dispatcher.utter_message(text = 'Hello', json_message = {'id': 2})
return []
Following is the screenshot of bwoser console which shows that it doesnt sends json_message at all, as you can see it only sends text, have tried multiple times
Weird. Try adding buttons just to see what happens:
utter_message(text = 'Hello', buttons = [
{"payload": "/affirm", "title": "Yes"},
{"payload": "/deny", "title": "No"},
])
Yea sure, buttons are working, even the carousels and other payloads like attachments and generic templates
How are you sending carousels?
This is how i am sending, only json_message is never sent
You can join this meet if u want,
Show me the format of the attachment message
please, and how the front-end app receives it (by code and in the console)
it receives
socket.on(“bot_uttered”, data=>{
})
On front end which works but only in case of json_message its null
How is it being sent in the action?
message = {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Health Insurance",
"image_url": "https://www.healthcareitnews.com/sites/hitn/files/Global%20healthcare_2.jpg",
"buttons": [
{
"title": "Apply",
"url": "https://www.icicibank.com/Personal-Banking/insurance/health-insurance/index.page?ITM=nli_cms_GI_health_insurance_more_menu_navigation",
"type": "web_url"
},
{
"title": "Learn more",
"url": "https://www.icicibank.com/Personal-Banking/insurance/health-insurance/index.page?ITM=nli_cms_GI_health_insurance_more_menu_navigation",
"type": "web_url"
}
]
}
]
}
}
Okay, then just send {'id': 2}
in attachment
i was actually doing that, but i thought of finding a better way
I remember using attachment
as well, I never used json_message
. They’re the way to go
If you want send a messaje with websocket as json used attachment message
dispatcher.utter_message(text = “Hi”, attachment = { “payload”:“location”})
and with rest send messaje used json_message dispatcher.utter_message(“Hi”,json_message={“payload”:“location”})