ChatApps: usage samples

๐Ÿ‘

Please see ChatApps Send API for the full API reference.

If you want to send a text message, your request will look like this:

{
    "user": {
        "msisdn": "+65000000"
    },
    "clientMessageId": "1234_id",
    "type": "text",
    "content": {
        "text": "Hello World!",
        "sms": {
            "encoding": "AUTO",
            "source": "SENDERID"
        }
    }
}

If you want to send an image with a text (optional) and a fallback text (optional), your request will look like this:

{
    "user": {
        "msisdn": "+650000000"
    },
    "clientMessageId": "1234_id",
    "type": "image",
    "content": {
        "text": "Welcome to Singapore!",
        "url": "https://example.com/media/image.jpg",
        "fallbackText": "We tried to send an image - but Welcome to Singapore",
        "sms": {
            "encoding": "AUTO",
            "source": "SENDERID"
        }
    }
}

If you want to send a WeChat message, you need to specify the WeChatId of the user. As there are no delivery receipts on WeChat, there will be no fallbacks, hence the msisdn is not required. Your request will look like this:

{
    "user": {
        "weChatUserId": "wsknf_12324k4n2n22"
    },
    "clientMessageId": "1234_id",
    "type": "image",
    "content": {
        "text": "Welcome to Singapore!",
        "url": "https://example.com/media/image.jpg",
        "fallbackText": "We tried to send an image - but Welcome to Singapore",
        "sms": {
            "encoding": "AUTO",
            "source": "SENDERID"
        }
    }
}

If you want to send a Viber rich message, with a text, an image and a button, your request will look like this:

{
  "user": {
    "msisdn": "+650000000"
  },
  "type": "buttons",
    "content": {
        "text": "Welcome to Singapore!",
        "url": "https://example.com/media/image.jpg",
        "button": {
            "caption": "Check the documentation",
            "action": "https://developer.8x8.com/"
        }
    }
}

If you want to send a template message only on WhatsApp, your request will look like this (this template has two parameters). This would be a valid request for a template with static buttons too:

{
    "user": {
        "msisdn": "+65000000"
    },
    "clientMessageId": "1234_id",
    "type": "template",
    "content": {
    "template": {
      "language": "en",
      "name": "template_name_1",
      "components": [
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "Mr. John"
            },
						{
              "type": "text",
              "text": "http://example.com"
            }
          ]
        }
      ]  
    }
  }
}

If you want to send a rich template message only on WhatsApp, your request will look like this (this template has an image header and two parameters):

{
    "user": {
        "msisdn": "+65000000"
    },
    "clientMessageId": "1234_id",
    "type": "template",
    "content": {
    "template": {
      "language": "en",
      "name": "template_name_1",
      "components": [
				{
          "type": "header",
          "parameters": [
            {
              "type": "image",
              "url": "https://example.com/media/image.jpg"
            }
          ]
        },
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "Mr. John"
            },
						{
              "type": "text",
              "text": "http://example.com"
            }
          ]
        }
      ]  
    }
  }
}

If you want to send a rich template message only on WhatsApp, your request will look like this (this template has a location header and two parameters):

{
    "user": {
        "msisdn": "+65000000"
    },
    "clientMessageId": "1234_id",
    "type": "template",
    "content": {
    "template": {
      "language": "en",
      "name": "template_name_1",
      "components": [
				{
          "type": "header",
          "parameters": [
            {
              "type": "location",
                    "location":{
                    "latitude": "1.3521",
                    "longitude": "103.8198"
              }
            }
          ]
        },
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "Mr. John"
            },
						{
              "type": "text",
              "text": "http://example.com"
            }
          ]
        }
      ]  
    }
  }
}

If you want to send a template message with one dynamic call to action button, only on WhatsApp, your request will look like this (this template has no body parameters and only the second button is dynamic):

{
     "user": {
          "msisdn": "+65000000"
     },
     "type": "Template",
     "content": {
          "template": {
               "name": "test_template_new2_copy1",
               "language": "en_US",
               "components": [
                    {
                         "type": "button",
                         "parameters": [
                              {
                                   "type": "text",
                                   "text": "landing-page.php",
                                   "payload": "landing-page"
                              }
                         ],
                         "index": 1,
                         "subType": "Url"
                    }
               ]
          }
     }
}

If you want to send an interactive message with a reply button, only on WhatsApp, your request will look like this (this message has multiple reply buttons):

{
    "user": {
        "msisdn": "+65000000"
    },
    "type": "interactive",
    "content": {
        "interactive": {
            "action": {
                "buttons": [
                    {
                        "type": "reply",
                        "reply": {
                            "title": "Option 1",
                            "id": "option-1"
                        }
                    },
                    {
                        "type": "reply",
                        "reply": {
                            "title": "Option 2",
                            "id": "option-2"
                        }
                    },
                    {
                        "type": "reply",
                        "reply": {
                            "title": "Option 3",
                            "id": "option-3"
                        }
                    }
                ]
            },
            "body": {
                "text": "Body"
            },
            "footer": {
                "text": "Footer"
            },
            "header": {
                "type": "text",
                "text": "Header"
            },
            "type": "button"
        }
    }
}

If you want to send an interactive message with a list of menu options, only on WhatsApp, your request will look like this (this message has two menu options with send button):

{
    "user": {
        "msisdn": "+65000000"
    },
    "type": "interactive",
    "content": {
        "interactive": {
            "action": {
                "button": "Send",
                "sections": [
                    {
                        "rows": [
                            {
                                "id": "row-1",
                                "title": "Title 1",
                                "description": "Description 1"
                            },
                            {
                                "id": "row-2",
                                "title": "Title 2",
                                "description": "Description 2"
                            }
                        ],
                        "title": "Section title"
                    }
                ]
            },
            "body": {
                "text": "Body content"
            },
            "footer": {
                "text": "Footer content"
            },
            "header": {
                "type": "text",
                "text": "Header"
            },
            "type": "list"
        }
    }
}

If you want to send an interactive message with a single product item from the business's inventory, only on WhatsApp, your request will look like this (this message has a link to a product from the inventory):

{
    "user": {
        "msisdn": "+65000000"
    },
    "type": "interactive",
    "content": {
        "interactive": {
            "action": {
                "catalog_id": "<id>",
                "product_retailer_id": "<id>"
            },
            "body": {
                "text": "Body content"
            },
            "footer": {
                "text": "Footer content"
            },
            "type": "product"
        }
    }
}

If you want to send an interactive message with a list of product items from the business's inventory, only on WhatsApp, your request will look like this (this message has a link to a product list from the inventory):

{
    "user": {
        "msisdn": "+65000000"
    },
    "type": "interactive",
    "content": {
        "interactive": {
            "action": {
                "catalog_id": "<id>",
                "product_retailer_id": "<id>",
                "sections": [
                    {
                        "product_items": [
                            {
                                "product_retailer_id": "<id>"
                            },
                            {
                                "product_retailer_id": "<id>"
                            }
                        ],
                        "title": "Section title"
                    }
                ]
            },
            "body": {
                "text": "Body content"
            },
            "footer": {
                "text": "Footer content"
            },
            "header": {
                "type": "text",
                "text": "Header"
            },
            "type": "product_list"
        }
    }
}