Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

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 and sending WhatsApp notifications with message templates.


Using WhatsApp templates with Twilio Frontline

using-whatsapp-templates-with-twilio-frontline page anchor

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.

How do templated messages work?

how-do-templated-messages-work page anchor

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.

To configure templates, open Frontline console(link takes you to an external page) 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.

Responding to Templates Callback

responding-to-templates-callback page anchor

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 nameTypeDescription
LocationstringA single callback URL might be used for different purposes. This parameter is meant to help determine how to process a request
WorkerstringThe app user identity
(information)

Info

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

get-templates-by-customer-id page anchor

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 nameTypeDescription
CustomerIdstringCustomer ID provided by the server
ConversationSidstringSID of a conversation
ChannelTypestringIndicates the channel used to send a template. Values: sms, whatsapp, chat
WhatsAppSessionStatestringOnly sent when the channel is whatsapp. Values: open, closed

Response format:

TypeDescription
Array<TemplateCategory>List of categories, containing the templates.

JSON response example:

1
[
2
{
3
"display_name": "Category Name",
4
"templates": [
5
{ "content": "Template Content 1" },
6
{ "content": "Just to confirm I am on my way to your office. Jane." }
7
]
8
}
9
]

In App example:

Templates screen showing 'Template Content 1' and message 'Just to confirm I am on my way to your office. Jane.'.