Chatfuel

Plugins

JSON API

Use this plugin to create various integrations with your server – generate dynamic content or send data. You can apply user attributes in either the URL or the USER ATTRIBUTES field. With POST request type, user attributes will be sent in a standard way. With GET request, they will be added to the URL as GET parameters.

To add an attribute to the URL field just type {{ in the URL field.

Chatfuel makes a simple GET or POST query to your API, then renders the response straight to the user and/or set user attributes. You can use any content type header for this.

If you are looking for an easy and fast way to setup your own endpoint for JSON plugin, check out this short tutorial.

Also check out our Broadcasting API. It allows to send a custom message to one of the users on a given trigger

Here are examples of JSON format to be used:

Here is how you can send two text messages:

{
 "messages": [
   {"text": "Welcome to our store!"},
   {"text": "How can I help you?"}
 ]
}

Send an image:

{
  "messages": [
    {
      "attachment": {
        "type": "image",
        "payload": {
          "url": "https://petersapparel.parseapp.com/img/item101-thumb.png"
        }
      }
    }
  ]
}

Send a video*:

{
  "messages": [
    {
      "attachment": {
        "type": "video",
        "payload": {
          "url": "https://petersapparel.parseapp.com/img/item101-video.mp4"
        }
      }
    }
  ]
}

* video should be in MP4 format and no larger than 20MB.

Send an audio*:

{
  "messages": [
    {
      "attachment": {
        "type": "audio",
        "payload": {
          "url": "https://archive.org/download/Dictaphones_Lament/TychoDictaphones_Lament.mp3"
        }
      }
    }
  ]
}

* audio should be in MP3, OGG, WAW format and no larger than 10MB.

Send a text card with two buttons, one of which points to a block, another one to a URL:

{
  "messages": [
    {
      "attachment": {
        "type": "template",
        "payload": {
          "template_type": "button",
          "text": "Hello!",
          "buttons": [
            {
              "type": "show_block",
              "block_name": "some block name",
              "title": "Show the block!"
            },
            {
              "type": "web_url",
              "url": "https://petersapparel.parseapp.com/buy_item?item_id=100",
              "title": "Buy Item"
            }
          ]
        }
      }
    }
  ]
}

Send a gallery:

{
 "messages": [
    {
      "attachment":{
        "type":"template",
        "payload":{
          "template_type":"generic",
          "elements":[
            {
              "title":"Classic White T-Shirt",
              "image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
              "subtitle":"Soft white cotton t-shirt is back in style",
              "buttons":[
                {
                  "type":"web_url",
                  "url":"https://petersapparel.parseapp.com/view_item?item_id=100",
                  "title":"View Item"
                },
                {
                  "type":"web_url",
                  "url":"https://petersapparel.parseapp.com/buy_item?item_id=100",
                  "title":"Buy Item"
                }
              ]
            },
            {
              "title":"Classic Grey T-Shirt",
              "image_url":"http://petersapparel.parseapp.com/img/item101-thumb.png",
              "subtitle":"Soft gray cotton t-shirt is back in style",
              "buttons":[
                {
                  "type":"web_url",
                  "url":"https://petersapparel.parseapp.com/view_item?item_id=101",
                  "title":"View Item"
                },
                {
                  "type":"web_url",
                  "url":"https://petersapparel.parseapp.com/buy_item?item_id=101",
                  "title":"Buy Item"
                }
              ]
            }
          ]
        }
      }
    }
  ]
}

Keep in mind that you can combine several messages in one answer by sending several dictionaries in the messages array.

Link to a block

You can also link to a block in your bot’s structure by using this syntax in the buttons array:

{
  "type": "show_block",
  "block_name": "Finish",
  "title": "Finish Shopping"
},
{
  "type": "show_block",
  "block_names": ["Block1", "Block2"],
  "title": "Finish Shopping"
}

You can use either block_name to link to one block or block_names to link to several blocks.

Quick Reply

{
  "messages": [
    {
      "text":  "testRedirectInQuickReply",
      "quick_replies": [
        {
          "title":"go",
          "block_names":["Block1", "Block2"]
        }
      ]
    }
  ]
}

Postback

New request to your JSON API can be done after clicking on a button (both Quick Reply and regular buttons are supported).

{
  "messages": [
    {
      "attachment": {
        "payload":{
          "template_type": "button",
          "text": "test JSON with postback",
          "buttons": [
            {
              "url": "http://pastebin.com/raw/bYwUN7un",
              "type":"json_plugin_url",
              "title":"go"
            }
          ]
        },
        "type": "template"
      }
    }
  ]
}

Set user attributes

Also, we enabled setting user attributes in JSON by clicking a button (not only Quick Reply, but all other buttons too). Here is what code for a button should look like *:

{
  "set_attributes": 
    {
      "some attribute": "some value",
      "another attribute": "another value"
    },
  "block_names": ["BlockWithUserAttributes"],
  "type": "show_block",
  "title": "go"
}

* Please note that setting attributes works only for show_block and json_plugin_url button types because we need to be able to receive postbacks from Facebook.

You can now also set user attributes in our JSON plugin without or prior to showing anything to the user — it comes in handy when you have advanced logic of user segmentation on your backend. After that, you can use these new, advanced segments in the Broadcasting tab.

{
  "set_attributes":
    {
      "some attribute": "some value",
      "another attribute": "another value"
    },
  "messages":[
    . . .
  ]
}

Share and Call buttons *

{
  "messages":[
    {
      "attachment":{
        "type":"template",
        "payload":{
          "template_type":"generic",
          "elements":[
            {
              "title":"Classic White T-Shirt",
              "image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
              "subtitle":"Soft white cotton t-shirt is back in style",
              "buttons":[
                {
                  "type":"phone_number",
                  "phone_number":"+79268881413",
                  "title":"Call"
                },
                {
                  "type":"element_share"
                }
              ]
            }
          ]
        }
      }
    }
  ]
}

* Please note that the share button works only in gallery cards due to Facebook API constraints.

Airline templates

For airline templates our JSON format is very similar to Facebook’s. Here is four possible airline templates’ code:

The JSON plugin currently does not support more than 10 messages per request or subscribing users to any results.