# Templated Messages

A **message template** is a message format that you can use to message users once they have opted-in and given your application permission to send messages. This is either a formal, repeated message such as a conversation opener, or it can be a reusable template approved by WhatsApp.

The Frontline app has built-in support for templated messages. For more information on WhatsApp templates, see [Message templates](/docs/whatsapp/key-concepts#message-templates) and [sending WhatsApp notifications with message templates](/docs/whatsapp/tutorial/send-whatsapp-notification-messages-templates).

## Using WhatsApp templates with Twilio Frontline

WhatsApp has a limitation in which you can only send approved templates until a user responds back to a message. When a user sends you a message, a 24 hour session will then open and within that session, you can send any message you'd like without using templates. If a session expires you will have to start a new session with a templated message.\
**Note**: To make a template visible in the WhatsApp channel, when there is no active 24 hour session, you need to add `whatsAppApproved: true` flag on each approved template.

![Twilio to WhatsApp message flow showing template approval and session timeout.](https://docs-resources.prod.twilio.com/b2bf611a2656f5be4a1be7c2f3da05651299f86de1d13d5561a4521081520b76.png)

### How do templated messages work?

Templated messages can be defined as a string with placeholders.

Template example: `Hello, this is \{\{Author}}. Just to confirm I am on my way to your office.`

The templated messages are provided by the customer's backend. When the application requests templates through **templates\_callback\_url**, it passes customer, worker and conversation identifiers. The templates are rendered based on those attributes. As a result, the server responds with already processed templates as plain texts, populated with data.

Populated template example: `Hello, this is Jane. Just to confirm I am on my way to your office.`

The diagram below shows the flow of fetching the templated messages list:

![Diagram showing Twilio Frontline sending templates to customer and receiving POST templates\_callback\_url.](https://docs-resources.prod.twilio.com/6265c5f2274b6bca457128b2418b767e29ae5b6301d40911159ee85039f4467a.jpg)

To configure templates, [open Frontline console](https://www.twilio.com/console/frontline) and set **Templates Callback URL** configuration option to a URL that will respond back with templates JSON.

![Configure callbacks with CRM, Outgoing Conversations, and Templates URLs.](https://docs-resources.prod.twilio.com/0ea83ef281892f12aa17f04be6fbfa7fb5d9bcc36a440ad6cab7cfc31afd4733.png)

### Responding to Templates Callback

When the Frontline application makes a `POST` HTTP request to your server, it includes information about the action that triggered the callback to your web application. Each action has its own `Location` type. The Location will be sent with the rest of the parameters in the request body in `application/x-www-urlencoded` format.

In addition to the location-specific parameters, each request also contains the following parameters and information:

| **Parameter name** | **Type** | **Description**                                                                                                                |
| ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| Location           | string   | A single callback URL might be used for different purposes. This parameter is meant to help determine how to process a request |
| Worker             | string   | The app user identity                                                                                                          |

> \[!NOTE]
>
> Frontline will send a request with **`Content-Type`** header of `application/x-www-urlencoded` and will expect a response with **`Content-Type`** header of `application/json` and a body based on the `Location` parameter.

### Get Templates by Customer Id

You can retrieve a list of templates for each customer by making a `POST` request to the `GetTemplatesByCustomerId` endpoint.

**Note:** `ChannelType` and `WhatsAppSessionState` parameters are only available in requests made from Frontline's mobile app versions 1.11.0 and above.

**Request parameters:**

| **Parameter name**   | **Type** | **Description**                                                                  |
| -------------------- | -------- | -------------------------------------------------------------------------------- |
| CustomerId           | string   | Customer ID provided by the server                                               |
| ConversationSid      | string   | SID of a conversation                                                            |
| ChannelType          | string   | Indicates the channel used to send a template. Values: `sms`, `whatsapp`, `chat` |
| WhatsAppSessionState | string   | Only sent when the channel is `whatsapp`. Values: `open`, `closed`               |

**Response format:**

| **Type**                                                                            | **Description**                               |
| ----------------------------------------------------------------------------------- | --------------------------------------------- |
| Array\<[TemplateCategory](/docs/frontline/data-transfer-objects#template-category)> | List of categories, containing the templates. |

**JSON response example:**

```json
[
  {
    "display_name": "Category Name",
    "templates": [
      { "content": "Template Content 1" },
      { "content": "Just to confirm I am on my way to your office. Jane." }
    ]
  }
]
```

**In App example**:

![Templates screen showing 'Template Content 1' and message 'Just to confirm I am on my way to your office. Jane.'.](https://docs-resources.prod.twilio.com/4ef057793ecbd91abb062fb99da5ec8968d20822c9d46a3b11e8401305141266.png)
