简体   繁体   English

如何在 Dialogflow 中创建 Facebook 轮播作为“自定义有效负载”

[英]How to create a Facebook Carousel in Dialogflow as “Custom Payload”

I would like to create a Mockup Facebook Bot with Dialogflow without using a webhook.我想在不使用 webhook 的情况下使用 Dialogflow 创建 Mockup Facebook Bot。

It's possible to define channel specific answers in Dialogflow.可以在 Dialogflow 中定义特定于渠道的答案。 There you can chooses between pre defined response types or a custom payload.在那里,您可以在预定义的响应类型或自定义负载之间进行选择。 The custom payload for a simple button works, but when I try to create a caroussel nothing happens.简单按钮的自定义有效负载有效,但是当我尝试创建轮播时,没有任何反应。

https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic#carousel https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic#carousel

Where can I find out what is supported by Dialogflow and what isn't?我在哪里可以找到 Dialogflow 支持的内容和不支持的内容? How can I build the caroussel card by using custom payloads?如何使用自定义有效负载构建轮播卡?

{
  "facebook": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "generic",
        "elements": [
          {
            "title": "Welcome!",
            "image_url": "https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png",
            "subtitle": "We have the right hat for everyone.",
            "default_action": {
              "type": "web_url",
              "url": "https://commons.wikimedia.org/wiki/File:Example.png",
              "messenger_extensions": false,
              "webview_height_ratio": "tall",
              "fallback_url": "https://website.com/"
            },
            "buttons": [
              {
                "type": "web_url",
                "url": "https://commons.wikimedia.org/wiki/File:Example.png",
                "title": "View Website"
              },
              {
                "type": "postback",
                "title": "Start Chatting",
                "payload": "DEVELOPER_DEFINED_PAYLOAD"
              }
            ]
          }
        ]
      }
    }
  }
}

If you remove messenger_extensions and fallback_url from your JSON it should work fine.如果您从 JSON 中删除messenger_extensionsfallback_url它应该可以正常工作。

By using the custom payload in dialogflow, everything is supported as long as you send the correct corresponding channel json通过在 dialogflow 中使用自定义有效载荷,只要您发送正确的对应通道 json,一切都将得到支持

Here is a working tested example of a carousel ( multiple elements )这是一个旋转木马的工作测试示例(多个元素)

{
 "facebook":{
  "attachment":{
     "type":"template",
     "payload":{
        "template_type":"generic",
        "elements":[
           {
              "title":"Welcome!",
              "image_url":"https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png",
              "subtitle":"We have the right hat for everyone.",
              "default_action":{
                 "type":"web_url",
                 "url":"https://www.google.com/",
                 "webview_height_ratio":"tall"
              },
              "buttons":[
                 {
                    "type":"web_url",
                    "url":"https://www.google.com/",
                    "title":"View Website"
                 },
                 {
                    "type":"postback",
                    "title":"Start Chatting",
                    "payload":"DEVELOPER_DEFINED_PAYLOAD"
                 }
              ]
           },
               {
              "title":"Welcome!",
              "image_url":"https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png",
              "subtitle":"We have the right hat for everyone.",
              "default_action":{
                 "type":"web_url",
                 "url":"https://www.google.com/",
                 "webview_height_ratio":"tall"
              },
              "buttons":[
                 {
                    "type":"web_url",
                    "url":"https://www.google.com/",
                    "title":"View Website"
                 },
                 {
                    "type":"postback",
                    "title":"Start Chatting",
                    "payload":"DEVELOPER_DEFINED_PAYLOAD"
                 }
              ]
           },
               {
              "title":"Welcome!",
              "image_url":"https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png",
              "subtitle":"We have the right hat for everyone.",
              "default_action":{
                 "type":"web_url",
                 "url":"https://www.google.com/",
                 "webview_height_ratio":"tall"
              },
              "buttons":[
                 {
                    "type":"web_url",
                    "url":"https://www.google.com/",
                    "title":"View Website"
                 },
                 {
                    "type":"postback",
                    "title":"Start Chatting",
                    "payload":"DEVELOPER_DEFINED_PAYLOAD"
                 }
              ]
           }
        ]
     }
  }
 }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM