JSON API

JSON API

See here
The JSON API plugin enables you to integrate your backend into your chat bots on Smax bot.
It allows you to
  • Generate dynamic content
  • Get and set user attributes
  • Redirect users to another block in the bot
  • Create postbacks
You can use GET and POST requests - the max. timeout is always 10 seconds. There are four options to enter data that will be sent with your request:
1. URL — This field supports user attributes, they will be URL-encoded with your request
2. Full JSON profile (POST requests only) — This will send all the user attributes of the user to your backend
3. JSON Body (POST requests only) — This is a customizable field and will be validated as JSON.
4. URL Encoded (POST requests only) — The data will be encoded before sending your request.
In your responses, you can
  • combine several messages in one answer by sending several dictionaries in the messages array.
  • use any content type header.
  • send an empty response to not show the user any dynamic content.

Response Reference

Sending text
Use this response to send text messages.
1
{
2
"messages": [
3
{"text": "Welcome to the Smax Rockets!"},
4
{"text": "What are you up to?"}
5
]
6
}
Copied!
Sending images
Use this response to send image files. Messenger supports JPG, PNG and GIF images. If you are having issues with GIF rendering, please try to reduce the file size.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "image",
6
"payload": {
7
"url": "https://rockets.chatfuel.com/assets/welcome.png"
8
}
9
}
10
}
11
]
12
}
Copied!
You can also directly use Facebook Posts with media instead of uploading it manually:
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "template",
6
"payload": {
7
"template_type": "media",
8
"elements": [
9
{
10
"media_type": "image",
11
"url": "https://www.facebook.com/chatfuelrockets/photos/1087668107975064",
12
"buttons": [
13
{
14
"title": "Go to Chatfuel!",
15
"type": "web_url",
16
"url": "https://chatfuel.com/"
17
}
18
]
19
}
20
]
21
}
22
},
23
"quick_replies": [
24
{
25
"title": "That's cool!",
26
"payload": "string"
27
}
28
]
29
}
30
]
31
}
Copied!
Sending video
Use this response to send video files. Messenger supports MP4 videos, which are up to 25MB in size.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "video",
6
"payload": {
7
"url": "https://rockets.chatfuel.com/assets/video.mp4"
8
}
9
}
10
}
11
]
12
}
Copied!
You can also directly use Facebook Posts with media instead of uploading it manually:
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "template",
6
"payload": {
7
"template_type": "media",
8
"elements": [
9
{
10
"media_type": "video",
11
"url": "https://www.facebook.com/chatfuelrockets/videos/252894858962779/",
12
"buttons": [
13
{
14
"title": "Go to Chatfuel!",
15
"type": "web_url",
16
"url": "https://chatfuel.com/"
17
}
18
]
19
}
20
]
21
}
22
},
23
"quick_replies": [
24
{
25
"title": "That's cool!",
26
"payload": "string"
27
}
28
]
29
}
30
]
31
}
Copied!
Sending audio
Use this response to send audio files. Messenger supports MP3, OGG, WAV audios, which are up to 25MB in size.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "audio",
6
"payload": {
7
"url": "https://rockets.chatfuel.com/assets/hello.mp3"
8
}
9
}
10
}
11
]
12
}
Copied!
Sending files
Use this response to send any other files, which are no larger than 25 MB.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "file",
6
"payload": {
7
"url": "https://rockets.chatfuel.com/assets/ticket.pdf"
8
}
9
}
10
}
11
]
12
}
Copied!
Sending galleries
Use this response to send a horizontal scrollable gallery. Each item is composed of an image attachment, short description and buttons to request input from the user. Note: messenger_extensions should only be added if you are using Messenger Extensions.
1
{
2
"messages": [
3
{
4
"attachment":{
5
"type":"template",
6
"payload":{
7
"template_type":"generic",
8
"image_aspect_ratio": "square",
9
"elements":[
10
{
11
"title":"Chatfuel Rockets Jersey",
12
"image_url":"https://rockets.chatfuel.com/assets/shirt.jpg",
13
"subtitle":"Size: M",
14
"buttons":[
15
{
16
"type":"web_url",
17
"url":"https://rockets.chatfuel.com/store",
18
"title":"View Item"
19
}
20
]
21
},
22
{
23
"title":"Chatfuel Rockets Jersey",
24
"image_url":"https://rockets.chatfuel.com/assets/shirt.jpg",
25
"subtitle":"Size: L",
26
"default_action": {
27
"type": "web_url",
28
"url": "https://rockets.chatfuel.com/store",
29
"messenger_extensions": true
30
},
31
"buttons":[
32
{
33
"type":"web_url",
34
"url":"https://rockets.chatfuel.com/store",
35
"title":"View Item"
36
}
37
]
38
}
39
]
40
}
41
}
42
}
43
]
44
}
Copied!
Sending receipts
Use this response to send an order confirmation. It may include an order summary, payment details, and shipping information.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "template",
6
"payload": {
7
"template_type": "receipt",
8
"recipient_name": "Mark Zuckerberg",
9
"order_number": "12345678901",
10
"currency": "USD",
11
"payment_method": "Visa 2345",
12
"order_url": "https://rockets.chatfuel.com/store?order_id=12345678901",
13
"timestamp": "1428444666",
14
"address": {
15
"street_1": "1 Hacker Way",
16
"street_2": "",
17
"city": "Menlo Park",
18
"postal_code": "94025",
19
"state": "CA",
20
"country": "US"
21
},
22
"summary": {
23
"subtotal": 105,
24
"shipping_cost": 4.95,
25
"total_tax": 9,
26
"total_cost": 118.95
27
},
28
"adjustments": [
29
{
30
"name": "CF Rockets Superstar",
31
"amount": -25
32
}
33
],
34
"elements": [
35
{
36
"title": "Chatfuel Rockets Jersey",
37
"subtitle": "Size: M",
38
"quantity": 1,
39
"price": 65,
40
"currency": "USD",
41
"image_url": "http://rockets.chatfuel.com/assets/shirt.jpg"
42
},
43
{
44
"title": "Chatfuel Rockets Jersey",
45
"subtitle": "Size: L",
46
"quantity": 1,
47
"price": 65,
48
"currency": "USD",
49
"image_url": "http://rockets.chatfuel.com/assets/shirt.jpg"
50
}
51
]
52
}
53
}
54
}
55
]
56
}
Copied!
Buttons
Use this JSON to add buttons to your responses. You can set buttons to link to a block in the dashboard, open a website, or send another request to your backend. Buttons are limited to 3 items per message.
1
{
2
"messages": [
3
{
4
"attachment": {
5
"type": "template",
6
"payload": {
7
"template_type": "button",
8
"text": "Hello!",
9
"buttons": [
10
{
11
"type": "show_block",
12
"block_names": ["name of block"],
13
"title": "Show Block"
14
},
15
{
16
"type": "web_url",
17
"url": "https://rockets.chatfuel.com",
18
"title": "Visit Website"
19
},
20
{
21
"url": "https://rockets.chatfuel.com/api/welcome",
22
"type":"json_url",
23
"title":"Postback"
24
}
25
]
26
}
27
}
28
}
29
]
30
}
Copied!
You can also use the Call button, this button dials a phone number when tapped.
1
{
2
"messages":[
3
{
4
"attachment":{
5
"type":"template",
6
"payload":{
7
"template_type":"generic",
8
"elements":[
9
{
10
"title":"Get in touch",
11
"image_url":"https://rockets.chatfuel.com/assets/contact.jpg",
12
"subtitle":"Feel free to hit us up!",
13
"buttons":[
14
{
15
"type":"phone_number",
16
"phone_number":"+19268881413",
17
"title":"Call"
18
}
19
]
20
}
21
]
22
}
23
}
24
}
25
]
26
}
Copied!
Quick replies
Use this JSON to add quick replies to your responses. Quick replies are limited to 11 items per message.
1
{
2
"messages": [
3
{
4
"text": "Did you enjoy the last game of the CF Rockets?",
5
"quick_replies": [
6
{
7
"title":"Loved it!",
8
"block_names": ["Block 1", "Block 2"]
9
},
10
{
11
"title":"Not really...",
12
"url": "https://rockets.chatfuel.com/api/sad-match",
13
"type":"json_url"
14
},
15
{
16
"title": "More...",
17
"payload": "string"
18
}
19
]
20
}
21
]
22
}
Copied!
Setting user attributes
You can set user attributes by having the field set_attributes as bellow
1
{
2
"set_attributes":
3
{
4
"some attribute": "some value",
5
"another attribute": "another value"
6
},
7
"messages":[
8
. . .
9
]
10
}
Copied!
Redirect to blocks
You can redirect a user to a block or to a sequence of blocks — no user action is needed.
1
{
2
"redirect_to_blocks": ["Welcome Message", "Default Answer"]
3
}
Copied!
Do keep in mind that for other functionalities or compiling functions to work altogether is out of Chatfuel's scope of support and we suggest to get help from an expert.
Last modified 4mo ago