【问题标题】:Generating a card with button is shown successfully in Dialogflow but not in Facebook Messenger生成带有按钮的卡片在 Dialogflow 中成功显示,但在 Facebook Messenger 中未成功显示
【发布时间】:2020-07-30 22:06:09
【问题描述】:

我有以下在 Dialogflow 平台上运行成功的履行消息:

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 中的输出如下:

但是,在 Facebook Messenger 中从未实现相同的预期结果:

我在 SO 上发现了类似的问题:

但是,他们都没有解决我的问题。可能是因为我错过了什么。

【问题讨论】:

    标签: python facebook dialogflow-es dialogflow-es-fulfillment


    【解决方案1】:

    我在阅读 Facebook for Developers 文档后找到了解决方案。

    请注意,此解决方案适用于 Facebook 聊天机器人和 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 图像,另一个用于您的按钮。

    【讨论】:

      猜你喜欢
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 2016-11-03
      • 1970-01-01
      相关资源
      最近更新 更多