生成带有按钮的卡片在 Dialogflow 中成功显示,但在 Facebook Messenger 中未成功显示

Generating a card with button is shown successfully in Dialogflow but not in Facebook Messenger

我有以下实现消息,在 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 上发现了类似的问题:

但是,none 解决了我的问题。可能是因为我错过了什么。

我在阅读 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 图像,另一个用于您的按钮。