Menu

Expand
Rate this page:

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 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, check out this guide on sending WhatsApp notifications with message 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.

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:

To configure templates, open Frontline console and set Templates Callback URL configuration option to a url that will respond back with templates JSON.

Template Callback URL.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 meant to help to determine how to process a request
Worker string The app user identity

Frontline will send a request with 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.

Request params:

Parameter name Type Description
CustomerId string Customer Id provided by the server
ConversationSid string SID of a conversation

Response format:

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

JSON response example:

[
  {
    "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:

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more