# Template messages Sending a message outside of a 24-hour [customer service window](https://community.sinch.com/t5/WhatsApp/What-is-a-Customer-Care-Session/ta-p/6858) requires an approved template. Templates are generally constructed by Sinch based on your organization's needs. If you used the [embedded signup process](https://community.sinch.com/t5/WhatsApp/How-do-I-use-the-WhatsApp-embedded-signup-process-on-the-Sinch/ta-p/9335), you'll also have access to a set of [default templates](https://community.sinch.com/t5/WhatsApp/Does-WhatsApp-provide-default-templates-when-onboarding-using/ta-p/9306). Note the following: - [Approved WhatsApp templates](https://community.sinch.com/t5/WhatsApp/What-is-a-message-template-and-why-are-they-necessary/ta-p/6857) are not the same as [omni-channel](/docs/conversation/api-reference/template) templates that you can use with the rest of the Conversation API. WhatsApp templates need to be [approved by WhatsApp](https://community.sinch.com/t5/WhatsApp/Why-was-my-WhatsApp-message-template-rejected/ta-p/11997), and are not used on other Conversation API channels. - All marketing, utility, or authentication conversations on the WhatsApp channel must start with an “Opt-In” by the user. This can be collected through any third party channel. For example in an SMS message, a web form, or email. Businesses must also provide a method by which customers may opt-out of receiving future messages from your organization. - When using the WhatsApp channel, you may receive a `RECIPIENT_NOT_REACHABLE` [error code](/docs/conversation/callbacks/#error-codes) if you send a [marketing template message](https://community.sinch.com/t5/WhatsApp/What-are-WhatsApp-marketing-templates-used-for/ta-p/11801) to a recipient, and the recipient is part of the current WhatsApp [marketing message experiment](https://developers.facebook.com/docs/whatsapp/on-premises/guides/experiments?content_id=86oue5PtwEgcBJl). When sending a template message, you need to specify the template name, language code, and the set of parameters defined in the template. Conversation API provides the capability to send channel-specific templates that use a key-value dictionary to specify the template parameters. Each key in the dictionary corresponds to a property of a template parameter as they're defined in WhatsApp public documentation for [templates](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates). The format of the keys in the parameter dictionary is of the following form: ```json [carousel_card_index][][] ``` where: - **** must be set to one of `header`, `body`, `button` or `carousel`. - **** is a 0-based index of the carousel card in the template. There can be, at most, ten cards included in the template. The **** key is present and required only for the carousel component. - **** must be set to one of `header`, `body` or `button`. The **** key is present and required only for carousel component. - **** is a 0-based index of the button in the template. There can be, at most, ten buttons. The **** key is present and required only for button components. - **** is present and required only for button components. It's set to either `quick_reply`, `url`, or `flow`. - **** is a 1-based index of the parameter for the given component. - **** is a property of the parameter. It can be one of `text`, `payload`, `document.`, `image.`, or `video.*` ## Character limitations When creating and populating templates, consider the following limitations: - When creating a template, the template content field (i.e., the text body) can include up to 1024 characters. - When sending a populated template that only includes a `body` component with text, the total number of characters that may be included (after parameters have been populated) in that `body` component is 32768. If any other components are included (for example, if a `header` is included), the `body` component may include up to 1024 characters after parameters have been populated. - When creating or sending a template that includes a `header` with text, up to 60 characters may be included in the `header` field (both before and after parameter population). - When calculating the number of characters included in a message in which the parameter placeholders have been populated, note that all regular characters and all formatting characters count against the total (regardless of how they are displayed in the message once it is received on a mobile device). # Template types - [Text Template](#text-template) - [Media Template](#media-template) - [Document](#document) - [Video](#video) - [Image](#image) - [Location Template](#location-template) - [Interactive Template](#interactive-template) - [Quick reply example](#quick-reply-example) - [Call-to-action example](#call-to-action-example) - [Authentication Template](#authentication-template) - [Carousel Template](#carousel-template) - [Flow Template](#flow-template) ## Text Template Below is an example of sending a text-only template with three body parameters and no header. The template name is `text_template` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "text_template", "language_code": "en", "parameters": { "body[1]text": "Value of first parameter", "body[2]text": "Value of second parameter", "body[3]text": "Value of third parameter" } } } } } } ``` Below is an example of sending the same template with the `fr` language code. It also specifies a text header parameter: ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "text_template", "language_code": "fr", "parameters": { "header[1]text": "Value of header parameter", "body[1]text": "Value of first parameter", "body[2]text": "Value of second parameter", "body[3]text": "Value of third parameter" } } } } } } ``` Templates with text-only bodies can include up to 32768 characters. ## Media Template The WhatsApp channel allows you to send the following media types in the template header: - [Document](#document) - [Video](#video) - [Image](#image) ### Document The parameter fields for sending a document are: | Parameter field key | Description | Required? | | --- | --- | --- | | header[1]document.link | The URL of the document | Yes | | header[1]document.provider.name | Provider to use when downloading the file | No | | header[1]document.filename | The filename of the document | No | Below is an example of sending a template with a document header and a single body parameter. The template name is `document_template` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "document_template", "language_code": "en", "parameters": { "header[1]document.link": "https://example.com/document.pdf", "header[1]document.filename": "document.pdf", "body[1]text": "Value of first parameter" } } } } } } ``` ### Video The parameter fields for sending a video are: | Parameter field key | Description | Required? | | --- | --- | --- | | header[1]video.link | The URL of the video | Yes | | header[1]video.provider.name | Provider to use when downloading the file | No | Below is an example of sending a template with a video header and a single body parameter. The template name is `video_template` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "video_template", "language_code": "en", "parameters": { "header[1]video.link": "https://example.com/video.mp4", "body[1]text": "Value of first parameter" } } } } } } ``` ### Image The parameter fields for sending an image are: | Parameter field key | Description | Required? | | --- | --- | --- | | header[1]image.link | The URL of the image | Yes | | header[1]image.provider.name | Provider to use when downloading the file | No | Below is an example of sending a template with an image header and a single body parameter. The template name is `image_template` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "image_template", "language_code": "en", "parameters": { "header[1]image.link": "https://example.com/image.jpg", "body[1]text": "Value of first parameter" } } } } } } ``` ## Location Template If a business wishes to share location information with a user, the business can include that location information in the header of a message template. The parameter fields for sending a location in the header are: | Parameter field key | Description | Required? | | --- | --- | --- | | header[1]location.longitude | Longitude of the location | Yes | | header[1]location.latitude | Latitude of the location | Yes | | header[1]location.name | Name of the location | No | | header[1]location.address | Address of the location | No | Below is an example of sending a template with a location header and a single body parameter. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "location_template", "language_code": "en", "parameters": { "header[1]location.latitude": "59.33273659725326", "header[1]location.longitude": "18.018601842853027", "header[1]location.name": "Sinch Office", "header[1]location.address": "Lindhagensgatan 74, 112 18 Stockholm, Sweden", "body[1]text": "Value of first parameter" } } } } } } ``` ## Interactive Template Interactive templates allow you to send messages that include interactive buttons. WhatsApp offers two types of predefined buttons: - **Quick reply** - Presents a button with predefined text which, when clicked, then returns a callback with a defined payload. - **Call-to-action** - Presents a clickable action in WhatsApp to either call a phone number or to visit a website. Opt-outs: A business can manage and record marketing opt-outs using quick reply buttons. These buttons can be attached to both text and media templates. However, you are only allowed to register templates that have, at most, **ten** buttons. The parameter fields used to configure the buttons in the template are: | Parameter field key | Description | Required? | | --- | --- | --- | | button[n]url[1]text | Dynamic URL suffix for the URL button | Yes, if button at index *n* is a URL button | | button[m]quick_reply[1]payload | Postback payload to be returned | Yes, if button at index *m* is a quick_reply button | where **n** and **m** are indices of the buttons in the template. Note the following: - When using `quick_reply` buttons with other buttons, `quick_reply` buttons must be grouped together in the template. Use the index feature to designate the order in which the buttons appear and ensure that `quick_reply` buttons are grouped together in the template. - When adding a `quick_reply` button, the `payload` field must be set, even when empty. For example, you can set the `quick_reply` button at index `0` to be empty by adding the following entry in the parameter dictionary: ```json "button[0]quick_reply[1]payload": "" ``` ### Quick reply example Opt-outs: A business can manage and record marketing opt-outs using quick reply buttons. Below is an example of sending a template with three quick reply buttons. The template also has one header and one body parameter. The template name is `interactive_template_quick_reply` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "interactive_template_quick_reply", "language_code": "en", "parameters": { "header[1]text": "Value of header parameter", "body[1]text": "Value of first parameter", "button[0]quick_reply[1]payload": "button0clicked", "button[1]quick_reply[1]payload": "button1clicked", "button[2]quick_reply[1]payload": "button2clicked" } } } } } } ``` #### Quick reply response example When a recipient presses a quick reply button, the sender/business receives an MO contact message. The contact message will contain the `choice_response_message` with a `postback_data` field. That field is populated with the payload of the quick reply button that was pressed (this content is specified when sending the original template message): ```json { "app_id": "01FDEHES4Y3FRK0Q3RDV3T12VN", "accepted_time": "2023-12-18T09:23:47.444Z", "event_time": "2023-12-18T09:23:47.444Z", "project_id": "c36f3d3d-1513-4edd-ae42-11995557ff61", "message": { "id": "01E6NKBV63YG6K01ENEW7S1N80", "direction": "TO_APP", "contact_message": { "choice_response_message": { "message_id": "01HHY3SZJ0RN5FWWM3XRSPMXS7", "postback_data": "button0clicked" }, "reply_to": { "message_id": "01HHY3SZJ0RN5FWWM3XRSPMXS7" } }, "conversation_id": "01E6K4A8PGZ6MV0GD3C7M901MZ", "contact_id": "01E6K4A8N3NANZ05VM0FS80EHD", "metadata": "", "accept_time": "2023-12-18T09:23:47.444Z" } } ``` ### Call-to-action example Below is an example of sending a template with two URL buttons (call-to-action). The template also has one header and one body parameter. The template name is `interactive_template_call_to_action` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "interactive_template_call_to_action", "language_code": "en", "parameters": { "header[1]text": "Value of header parameter", "body[1]text": "Value of first parameter", "button[0]url[1]text": "Value for URL suffix button 1", "button[1]url[1]text": "Value for URL suffix button 2" } } } } } } ``` ## Authentication Template If a business wants to send codes to verify a transaction or login attempt, an authentication template can be used. The parameter fields for sending a code via authentication template are: | Parameter field key | Description | Required? | | --- | --- | --- | | body[1]text | Code to verify a transaction or login | Yes | | button[0]url[1]text | Code to verify a transaction or login | Yes | Below is an example of the `message` payload when sending an authentication template: ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "authentication_template", "language_code": "en", "parameters": { "body[1]text": "123456", "button[0]url[1]text": "123456" } } } } } } ``` Depending on the definition of the template, this message will be displayed with a one-tap autofill button or a copy code button. Note that, when sending this type of message, the above structure must be followed exactly. Additionally, the values used to populate the `body[1]text` field and the `button[0]url[1]` field must match. Below is an example of how an authentication template message might appear on a user's handset: ![Authentication Message](/assets/whatsapp_authentication_message.f076172ba14e41ee29cc4b441e60cf80e71121561d6217325f8b444d19a1f1bc.3a8dbadf.png) Note: In the above image, the text reads ** is your verification code.** The message can also be configured to read ** is your verification code. For your security, do not share this code.** (if you opt to include a security warning during template configuration) or ** is your verification code. This code expires in minutes.** (if you opt to define an expiry time during template configuration). ## Carousel Template Below is an example of sending a carousel template with two body parameters for the first card, one body parameter for the second card, and an image header parameter for each card. The template name is `carousel_template` and the language code is `en`. This template message is sent using a Conversation API `POST` to the `messages:send` endpoint. ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "carousel_template", "language_code": "en", "parameters": { "carousel[0]header[1]image.link": "https://example.com/image1.jpg", "carousel[0]body[1]text": "Value of first parameter (first card)", "carousel[0]body[2]text": "Value of second parameter (first card)", "carousel[1]header[1]image.link": "https://example.com/image2.jpg", "carousel[1]body[1]text": "Value of first parameter (second card)" } } } } } } ``` ## Flow Template The prerequisites for sending a Flow template message and the parameters used when sending a Flow template message are described below. ### Prerequisites Before sending a template with a Flow button, you must have the following set up: - At least one Flow created and published in Meta's system. For more details about creating Flows, see Sinch's [Managing Flows](/docs/conversation/channel-support/whatsapp/whatsapp-flows#managing-flows) documentation. You may also review the [WhatsApp Flows](https://developers.facebook.com/docs/whatsapp/flows) section of Meta's documentation. - At least one message template with the specific **Flow ID** and **Button with `FLOW` type** created and approved by WhatsApp. For more details about creating Message Templates, the [Create a template in project](/docs/provisioning-api/api-reference/provisioning-api/whatsapp-templates/templatescontroller_createtemplate_v1) documentation in the [WhatsApp Templates](/docs/provisioning-api/api-reference/provisioning-api/whatsapp-templates) section of the Provisioning API API reference guide. ### Parameters Supported parameter fields for a button with `FLOW` type in Message Templates are: | Parameter field key | Description | Required? | | --- | --- | --- | | button[n]flow[1]action.type | **Required**. The only supported value is `action`. | Yes | | button[n]flow[1]action.token | Optional. Default value is "unused". | No | | button[n]flow[1]action.data | Optional. A JSON object with the data payload for the first screen of the Flow. | No | ### Example request ```json { "message": { "template_message": { "channel_template": { "WHATSAPP": { "template_id": "flow_template", "language_code": "en", "parameters": { "button[1]flow[1]action.type": "action" } } } } } } ```