Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this pageProducts used

Rich Messaging Features in the Twilio API for WhatsApp


Twilio supports the latest WhatsApp-specific features to make it easier for your customers to engage with you.


Rich outbound messages with Content Template Builder

WhatsApp's latest rich features are supported using Twilio's Content Template Builder.

These features include:

  • Formatting message text
  • Messages including location information
  • Card messages with images, text, and/or buttons
  • List messages
  • Call-to-action messages
  • Messages with quick reply buttons

Rich Inbound Features in Webhooks

Twilio supports the latest inbound metadata made available by WhatsApp. This includes the end user's profile name, click to WhatsApp ad parameters, and much more.

See our request to your webhook URL for all of the supported inbound parameters for rich messages.


Formatting in WhatsApp Messages

WhatsApp allows text, emojis, and some formatting in messages. To format all or part of a message, use these formatting symbols:

FormattingSymbolExample
BoldAsterisk (**)Your total is $10.50.
ItalicUnderscore (_)Welcome to WhatsApp!
Strike-throughTilde (~)This is better best!
Code / Pre-formattedThree backticks (```)print 'Hello World';

Send a formatted WhatsApp message

Use symbols to format your WhatsApp messaage

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
_21
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21
const authToken = process.env.TWILIO_AUTH_TOKEN;
_21
const client = twilio(accountSid, authToken);
_21
_21
async function createMessage() {
_21
const message = await client.messages.create({
_21
body: "🎶I am _not_ ~pushing~ throwing away my *shot*!",
_21
from: "whatsapp:+15005550006",
_21
messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
to: "whatsapp:+14155552345",
_21
});
_21
_21
console.log(message.body);
_21
}
_21
_21
createMessage();

Output

_28
{
_28
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"api_version": "2010-04-01",
_28
"body": "🎶I am _not_ ~pushing~ throwing away my *shot*!",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "whatsapp:+15005550006",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp:+14155552345",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}

WhatsApp message displaying italics, strikethrough, and bolding.

Location Messages with WhatsApp

The Twilio API for WhatsApp supports sending and receiving GPS location data in messages to and from WhatsApp users.

(warning)

Warning

Facebook does not support location messaging in WhatsApp Message Templates at this time. Twilio Conversations also does not support location messaging functionality at this time. To send and receive location messages with WhatsApp, you'll need to use session messages leveraging the API or Twilio's helper libraries.

Send outbound location messages

Sending outbound location messages over WhatsApp is similar to sending a text-based message, with the addition of the PersistentAction parameter in your Twilio API requests. Outbound location messages must include the following information:

  • Body={name}
  • PersistentAction=geo:{latitude},{longitude} OR
  • PersistentAction=geo:{latitude},{longitude}|{label}
NameTypeRequiredDescription
nameStringYes (for outbound messages)The name of the location being sent.(Location must exist in Google maps for the hyperlink to work on Mac/Windows WhatsApp client)
latitudeNumberYesLatitude of the location being sent
longitudeNumberYesLongitude of the location being sent
labelStringNoOptional free-form text to display under the location name

Send a WhatsApp message with location information

Use the persistent_action parameter

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
_21
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21
const authToken = process.env.TWILIO_AUTH_TOKEN;
_21
const client = twilio(accountSid, authToken);
_21
_21
async function createMessage() {
_21
const message = await client.messages.create({
_21
body: "This is one of the Twilio office locations",
_21
messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
persistentAction: ["geo:37.787890,-122.391664|375 Beale St"],
_21
to: "whatsapp:+15005550006",
_21
});
_21
_21
console.log(message.body);
_21
}
_21
_21
createMessage();

Output

_28
{
_28
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"api_version": "2010-04-01",
_28
"body": "This is one of the Twilio office locations",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "+14155552345",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp:+15005550006",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}

Your user should receive a message that looks like this:

WhatsApp message containing location information, it shows a map for 375 Beale St in San Francisco.

Receive inbound location messages

You can also receive inbound location messages with the Twilio API for WhatsApp.

Locations do not appear in the Twilio Console at this time. However, your web application will receive the location data in the POST request that Twilio sends. This data will be included in the HTTP POST request for the incoming message that we send to your webhook.

You will be able to access the following parameters in the POST request values Twilio sends to your application when you receive a WhatsApp location message:

  • Latitude
  • Longitude
  • Address
  • Label

Location Message Types

There are two types of location that users can send with WhatsApp: Current Location and Live Location. Live Location is not currently supported by the WhatsApp Business API.

Current Location is a static type of content, similar to a timestamp. This means the location information you receive from a user indicates where the user was in that particular moment in time when they triggered the "send location" action.

Below is a sample payload containing location information. Please note that the Body={name} parameter is not required for inbound messages.


_10
Latitude=37.7879277&Longitude=-122.3937508&Address=375+Beale+St%2C+San+Francisco%2C+CA+94105&SmsMessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&NumMedia=0&SmsSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&Label=Twilio+Inc&Body=&To=whatsapp%3A%2B14155238886&NumSegments=1&MessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&AccountSid=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&From=whatsapp%3A%2B12345678900&ApiVersion=2010-04-01

What are QR codes?

A QR ("Quick Response") code is a type of barcode that you can use to open up a new WhatsApp conversation. Your end uses can scan your business' QR code, and the WhatsApp business profile will automatically load, with a pre-filled message that your business can define.

Here's an example of a QR Code:

sample_whatsapp_qr_code.

What's Next?

Ready to send feature-rich messages to your end users over WhatsApp? Check out some of these resources to get started (or keep) building:


Rate this page: