You can use utter_custom_json()
to send your defined json you will get result in custom key as response from bot
You can use utter_custom_json()
to send your defined json you will get result in custom key as response from bot
Hi…
Can you tell me how to send facebook’s generic template payload from custom action.py. I tried but nothing showing on messenger app.
please suggest me. What I am missing.
msg = {
"attachment": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Test Element !",
"image_url": "https://loremflickr.com/320/240",
"subtitle": "This is a dummy text...",
"default_action": {
"type": "web_url",
"url": "tithal.life",
"webview_height_ratio": "tall"
},
"buttons": [
{
"type": "web_url",
"url": "tithal.life",
"title": "tithal.life"
},
{
"type": "web_url",
"url": "tithal.life",
"title": "shivang patel"
}
]
}
]
}
}
dispatcher.utter_custom_json(msg)
how are you handling the response at your end you get response in custom key.
@cr33dx I just figured out, after some inspecting and comparison with quick_replies
Answer is check below… If any have issue like this problems…
Facebook’s example demo for generic template :
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Welcome!",
"image_url":"https://petersfancybrownhats.com/company_image.png",
"subtitle":"We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://petersfancybrownhats.com/view?item=103",
"webview_height_ratio": "tall",
},
"buttons":[
{
"type":"web_url",
"url":"https://petersfancybrownhats.com",
"title":"View Website"
},{
"type":"postback",
"title":"Start Chatting",
"payload":"DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
And this way, You can use above example in our custom action file :
gt = {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Welcome! 1",
"image_url": "https://picsum.photos/200",
"subtitle": "We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://tithal.life",
"webview_height_ratio": "tall",
},
"buttons": [
{
"type": "web_url",
"url": "https://tithal.life",
"title": "View Website"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
]
},
{
"title": "Welcome! 2",
"image_url": "https://picsum.photos/200",
"subtitle": "We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://tithal.life",
"webview_height_ratio": "tall",
},
"buttons": [
{
"type": "web_url",
"url": "https://tithal.life",
"title": "View Website"
},
{
"type": "postback",
"title": "Start Chatting",
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
dispatcher.utter_custom_json(gt)
Compare both code and anyone can figure it out.
Thanks
Is there a way to send custom facebook response as generic template from domain.yml?
I can send pure text by this but using a template I get:
line 227, in send_custom_json
recipient_id = json_message.pop("sender", {}).pop("id", None) or recipient_id
using:
utter_goodbye:
- custom:
- attachment:
type: “template”
payload:
template_type: “generic”
elements:
- title: “test123”