Search code examples
dialogflow-esfacebook-messengerfacebook-messenger-botdialogflow-es-fulfillment

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.

It's possible to define channel specific answers in 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

Where can I find out what is supported by Dialogflow and what isn't? 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"
              }
            ]
          }
        ]
      }
    }
  }
}

Solution

  • If you remove messenger_extensions and fallback_url from your JSON it should work fine.

    By using the custom payload in dialogflow, everything is supported as long as you send the correct corresponding channel 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"
                     }
                  ]
               }
            ]
         }
      }
     }
     }