Send WhatsApp template messages with buttons

Conversations API provides the ability to our customer to send WhatsApp template messages with buttons. Please keep in mind that, in order to send any template message, first you must have your template pre-approved by Facebook. You can manage your templates using the WhatsApp Template Manager.

Starting simple: template message with buttons

Let's assume you have the following template message approved by Facebook in your WhatsApp Template Manager.

Template with buttons

In order to send a WhatsApp message using this template, you must perform the following HTTP request to Conversations API.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey <your-access-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"content": {
"hsm": {
"namespace": "20a32cd4_f095_b0r0_d255_35677259aaxd",
"language": {
"code": "en"
},
"templateName": "buttons_test"
}
},
"to": "+9999999999",
"type": "hsm",
"from": "0181d0bb76c54g9aae4309s822d35ba5"
}'
  • content.hsm.namespace can be found in the WhatsApp templates Manager of your Facebook Business account, or, in case you don't have access to it, please contact our support team
  • content.hsm.language.code is the language which the template message should be sent
  • content.hsm.templateName is the template name
  • to is the phone number of the recipient
  • type must be hsm because this is a template message
  • from must be your WhatsApp channel ID

Send a message with buttons and variables

The value of template messages is in the fact that you can use variables to customise them. Let's now assume now you have the following template message approved by Facebook in your WhatsApp Template Manager.

Template with buttons and variables

In order to send a template message using this template, you must perform the following HTTP request to Conversations API.

curl -X "POST" "https://conversations.messagebird.com/v1/send" \
-H 'Authorization: AccessKey <access-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"content": {
"hsm": {
"language": {
"code": "en"
},
"namespace": "20a32cd4_f095_b0r0_d255_35677259aaxd",
"params": [
{
"default": "Robert"
}
],
"templateName": "issue_resolution_confirmation"
}
},
"to": "+9999999999",
"type": "hsm",
"from": "0181d0bb76c54g9aae4309s822d35ba5"
}'

As you can see, the only different is that, as this template needs variables, we must provide a list of params. The number of items in params must match the number of variables in the template, otherwise your template message will be rejected.

Other button types

Currently, there are two supported button types: quick reply and call to action.

  • Quick replies: enables customers to easily reply using pre-defined answer, as the examples demonstrated previously
  • Call to actions: enables customers to easily trigger pre-defined actions

There are two types of call to action buttons: call to a phone number and visit website.

  • Call to a phone: enables customers to easily call to a pre-defined phone number
  • Visit website: enables customer to visit a pre-defined website
Notification icon

Unfortunately is not possible yet to use variables in the pre-defined quick reply and actions (phone number and website).

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings