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:

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

sid

String

Account SID (Security Identifier).

HXXXXXXX071US

Yes

api-key

String

API key generated from Kaleyra.io account.

Axxxxxxxxxxxxxxxxxxxxxxxxxxxx3

Yes

content-type

String

The format in which the data is sent.

application/x-www-form-urlencoded

Yes

to

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

type

String

It can be one of the following:

  • text
  • template
  • mediatemplate
  • location
  • contacts
  • list
  • reply
  • singleproduct
  • multiproduct
  • button
  • *Note**: In case of quick-reply use "button".

mediatemplate

Yes

from

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

template_name

String

Template name.

quick_reply_confirm

Yes

language

String

The language in which you want to create the template.

en_us

Yes

channel

String

Channel on which message must be sent.
Only allowed value is “whatsapp”.

whatsapp

Yes

payload1

String

Holds the dynamic variable text that needs to be attached to the first Quick Reply button.

cart_checkout

Yes

callback_url

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

media

String

The location of the media file that will be embedded in the message.

Ensure you upload only the formats supported. Refer to
Messaging on WhatsApp Business for more details.

image.png

payload2

Sring

Holds the dynamic variable text that needs to be attached to the second Quick Reply button.

partial_checkout

No

payload3

String

Holds the dynamic variable text that needs to be attached to the third Quick Reply button.

add_to_wishlist

No

parameter_type

String

Define the parameter type for payload in the quick-reply button.
For dynamic payload to be used with Quick Reply button, use “payload”.

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.