Template Messages
You can send a
template message
with a WhatsApp Flow. Only published Flows can be sent this way. We introduced a new button type called FLOW. Use this type to specify the Flow to be sent with the template message.
First you need to
create a template
. Here is an example request:
curl -i -X POST \
https://graph.facebook.com/v16.0/<waba-id>/message_templates \
-H 'Authorization: Bearer TOKEN' \
-H 'Content-Type: application/json' \
-d'
{
"name": "example_template_name",
"language": "en_US",
"category": "MARKETING",
"components": [
{
"type": "body",
"text": "This is a flows as template demo"
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "FLOW",
"text": "Open flow!",
"flow_id": "<flow-id>",
"navigate_screen": "Flows Json screen name",
"flow_action": "navigate"
}
]
}
]
}'
Parameter
| Description
| buttons
| |
?
flow_id
string
|
The unique ID of a Flow.
|
?
nagivate_screen
string
|
Required if
flow_action
is
navigate
.
The unique ID of the Screen in the Flow.
|
?
flow_action
string
|
Either
navigate
or
data_exchange
.
(Default value:
navigate
)
|
You are able to send messages in
these languages
.
Sample Response
{
"id": "<template-id>",
"status": "PENDING",
"category": "MARKETING"
}
Ensure that your template passes all required reviews so that
status
is
APPROVED
instead of
PENDING
.
Now you can send a template message with a Flow using the following request:
curl -X POST \
'https://graph.facebook.com/v16.0/FROM_PHONE_NUMBER_ID/messages' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "PHONE_NUMBER",
"type": "template",
"template": {
"name": "TEMPLATE_NAME",
"language": {
"code": "LANGUAGE_AND_LOCALE_CODE"
},
"components": [
{
"type": "button",
"sub_type": "flow",
"index": "0",
"parameters": [
{
"type": "action",
"action": {
"flow_token": "FLOW_TOKEN", //optional, default is "unused"
"flow_action_data": {
...
} // optional, json object with the data payload for the first screen
}
}
]
}
]
}
}'
Sample Response
{
"messaging_product": "whatsapp",
"contacts": [
{
"input": "<phone-number>",
"wa_id": "<phone-number>"
}
],
"messages": [
{
"id": "<message-id>"
}
]
}