在Dialogflow中成功显示带有按钮的卡片,但在Facebook Messenger中未成功显示 [英] Generating a card with button is shown successfully in Dialogflow but not in Facebook Messenger
问题描述
我收到以下在Dialogflow平台上成功运行的履行消息:
I have the following fulfillment message which is run success on Dialogflow platform:
return {"fulfillmentMessages": [
{
"platform": "FACEBOOK",
"text": {
"text": ['Great news! Grab a bowl of Pop-Corn and enjoy one of the two films!\n\n(Type "Thank you" to continue!)']
}
},
{
"platform": "FACEBOOK",
"card": {
"buttons": [
{
"text": "Thank you"
}
]
}
}
]
}
这是Dialogflow中的输出:
Output is this in Dialogflow:
但是,相同预期的结果永远不会在Facebook Messenger中完成:
However, the same expected result is never accomplished in Facebook Messenger:
我在因此:
- question 1
- question 2
但是,没有一个人解决了我的问题。
However, none of them solved my issue. Probably because I miss something.
推荐答案
在阅读了Facebook for Developers文档后,我找到了解决方案。
I found a solution after reading the Facebook for Developers documentation.
请注意,此解决方案适用于Facebook chatbot和Facebook Messenger
def thanks(req):
your_welcome_gif=[ "https://media3.giphy.com/media/KCw6QUxe9zBO6QNrFe/giphy.gif",
"https://media1.giphy.com/media/H21d4avBXs8B9X0NLj/giphy.gif",
"https://media1.tenor.com/images/15bafc0b414757acab81650a6ff21963/tenor.gif?itemid=11238673"]
greeding = req.get('queryResult').get('parameters').get('greeding')
if greeding == 'Thank you' or greeding == 'thank you' or greeding == 'Thanks' or greeding == 'thanks' or greeding == 'Nice' or greeding == 'nice':
return {"fulfillmentMessages": [
{
'payload': {
"facebook": {
"attachment": {
"type": "image",
"payload":{
"url":random.choice(your_welcome_gif)
}
}
}
}
},
{
'payload': {
"facebook": {
"attachment": {
"type": "template",
"payload": {
"template_type": "button",
"text": "You're welcome :) \nWould you like to choose another movie?",
"buttons": [
{
"type": "postback",
"title":"Yes",
"payload":"Yes"
},
{
"type": "postback",
"title":"No",
"payload":"No"
}
]
}
}
}
}
}
]}
解决方案是创建两个自定义有效负载,一个用于GIF图像,另一个用于按钮。
The solution is to create two custom payloads, one for the GIF image and the other for your buttons.
这篇关于在Dialogflow中成功显示带有按钮的卡片,但在Facebook Messenger中未成功显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!