Send a Quick-reply Template with Dynamic Button Payload
POST Method
Kaleyra allows you to send a WhatsApp message with a dynamic payload in a quick-reply button using the approved templates. When the end customer clicks on the quick-reply button with dynamic payload, a callback is triggered based on your configured payload.
Limitation:You can only add a maximum of three dynamic payloads to the Quick Reply buttons.
Pre-requisites
The following are the prerequisites:
- Before you get started, sign up for a Kaleyra.io account for free and Create an API Key. To view the API Key and the SID, see View API Key and SID.
- A prerequisite for using Kaleyra WhatsApp APIs is to have an active WhatsApp plan on kaleyra.io.
- To set up a WhatsApp account on kaleyra.io, see Manual Signup and Embedded Signup.
Base URL
https://api.kaleyra.io/v1/<SID>
API request to Send a WhatsApp Template with Dynamic Payload in Quick Reply Buttons
To send a WhatsApp message using a template with dynamic payload in quick reply buttons, use the /messages
endpoint.
Request Format
The following is the request format to send a WhatsApp message using a template with a dynamic payload in quick reply buttons:
curl --location 'https://api.kaleyra.io/v1/<SID>/messages' \
--header 'api-key: {{api-key}}' \
--header 'Content-Type: {{content_type}}' \
--form 'to="{{to}}"' \
--form 'type="{{type}}"' \
--form 'from="{{from}}"' \
--form 'template_name="{{template_name}}"' \
--form 'language":"{{template_language}}"',\
--form 'channel="{{channel}}"' \
--form 'payload1="{{payload1}}"' \
--form 'callback_url="{{callback_url}}"' \
--form 'media=@"{{media}}"' \
--form 'payload2="{{payload2}}"' \
--form 'payload3="{{payload3}}"' \
--form 'params="\"{{param1}}\",\"{{param2}}\""'
Sample Request
The following is the sample request to send a WhatsApp message using a template with a dynamic payload in quick reply buttons:
curl --location 'https://api.kaleyra.io/v1/HXXXXXXX071US/messages' \
--header 'api-key: Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3' \
--header 'Content-Type: application/json ' \
--form 'to="+916xxxxxxxx"' \
--form 'type="mediatemplate"' \
--form 'from="+918xxxxxxxxx"' \
--form 'template_name="quick_reply_confirm"' \
--form 'language":"en_us"',\
--form 'channel="whatsapp"' \
--form 'payload1="cart_checkout"' \
--form 'callback_url="https://webhook.site/3xxxxxx8-exxd-4xx6-axxd-daxxxxxxxxb1"' \
--form 'media=@"image.png"' \
--form 'payload2="partial_checkout"' \
--form 'payload3="add_to_wishlist"' \
--form 'params="\"param1\",\"param\""'
Parameters and Data Types
Following is the list of parameters and data types supported:
Parameter | Data Type | Description | Example | Mandatory |
---|---|---|---|---|
| String | Account SID (Security Identifier). | HXXXXXXX071US | Yes |
| String | API key generated from Kaleyra.io account. | Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3 | Yes |
| String | The format in which the data is sent. | application/x-www-form-urlencoded | Yes |
| String | A valid WhatsApp number of the recipient. Ensure that the country code is prefixed to the number. (E164 format). Note: You can add multiple recipients, separate each number using the comma (,) delimiter. | +916xxxxxxxx | Yes |
| String | It can be one of the following:
| mediatemplate | Yes |
| String | The number registered with WhatsApp business from which the message is to be sent. Ensure that the country code is prefixed to the number. (E164 format). | +918xxxxxxxxx | Yes |
| String | Template name. | quick_reply_confirm | Yes |
| String | The language in which you want to create the template. | en_us | Yes |
| String | Channel on which message must be sent. | Yes | |
| String | Holds the dynamic variable text that needs to be attached to the first Quick Reply button. | cart_checkout | Yes |
| String | The URL that kaleyra.io should send information to when your number receives a response. This URL can be accessed publicly. | Click here for an example. | No |
| String | The location of the media file that will be embedded in the message. Ensure you upload only the formats supported. Refer to | image.png | |
| Sring | Holds the dynamic variable text that needs to be attached to the second Quick Reply button. | partial_checkout | No |
| String | Holds the dynamic variable text that needs to be attached to the third Quick Reply button. | add_to_wishlist | No |
| String | Define the parameter type for payload in the quick-reply button. | payload | Yes |
Sample Success Response
The following success message appears with the response:
{
"id": "ccxxxxe-9xxd-4xx5-bxx4-11xxxxxxxx32",
"type": "text",
"body": "Hi, your order has been shipped",
"createdDateTime": "2020-01-29 06:22:21+00:00",
"totalCount": 1,
"data": [
{
"message_id": "ccxxxxe-9xxd-4xx5-bxx4-11xxxxxxxx32:0",
"recipient": "1202XXXXXXX"
}
],
"error": {}
}
Sample error response
The following is a sample error response.
{
"code": "RBC201",
"message": "Incorrect SID or API key.",
"data": \[],
"error": {
"error": "Incorrect SID or API key."
}
}
Error Codes
For information related to the WhatsApp error code, see WhatsApp Error Codes.
Note:For more information about creating a template to send a message with dynamic payload in quick-reply button, see Create a WhatsApp Template with Dynamic Payload.
Updated about 14 hours ago