How to use template message variables on your WhatsApp messages

You can use the Wassenger template variable syntax to display dynamic information in your messages based on a set of pre-defined variables that are linked to the current user sending the message, or the target chat, contact, metadata and date.

Wassenger
5 min readAug 28, 2024

--

Template variables can be used in quick replies, automatic replies and messages sent through the API or web chat.

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

You can display dynamic information in messages based on the following entities:

  • whatsapp: connected WhatsApp number sending the message
  • user: current user sending the message
  • chat: target chat that will receive the message
  • contact: target contact that will receive the message
  • date: the current date when the message is delivered

➡️ Here is more information about the specific accepted variables.

➡️ Find a real example sending template variables using the API

How it works

The template variable syntax can be used in any text message with double braces {{ for opening and }} to close the expression:

Dear {{ contact.name }},
We will be in touch shortly with more information.
Your query has been registered on {{ date.humanize.full }}.
Your support agent is {{ chat.agent.name }}.
Thank you!

The previous message with template variables will be sent to the user like this:

Dear Michael,
We will be in touch shortly with more information.
Your query has been registered on Monday, August 26, 2024 11:01 AM.
Your support agent is Noah.
Thank you!

Using a default value

Dear {{ contact.name | customer }},
How can I help you today?

In case the variable contact.name is empty for the target contact, customer will be used as the default value. Therefore the message sent to the user will look like this:

Dear customer,
How can I help you today?

You can also chain multiple default values like this:

Dear {{ contact.name | contact.surname | customer }}

In this case, if contact.name is empty, it will default to contact.surname. Then, if contact.surnname is empty, it will default to customer.

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Supported variables

Here is the list of the supported variables in the template syntax:

Campaign variables

When sending messages from a Campaign, you can use the following template variables based on the imported contacts data via CSV / Excel spreadsheet file upload. Each template variable will point to the pre-selected imported column in the CSV / Excel document.

Accepted campaign template variables

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Examples

Simple template variable

Dear {{ contact.name }},
How can I help you today?

Multiple template variables

Dear {{ contact.name }},
We will send you more information to your email: {{ contact.email }}
If you need further information, you can call us: {{ whatsapp.number }}
Thank you!

Use contact’s metadata in template variables

Hello {{ metadata.crm_name }}
We will send you an email to: {{ metadata.crm_email }}

Template variable with a default value

Dear {{ contact.name | customer }},
Thank you!

Template variable with multiple default values

Dear {{ contact.name | contact.surname | customer }},
Thanks for contacting us, we will answer your query shortly.
Thank you!

Live API Sample

You can now play, debug and live test the API directly from your browser, explore and try more API examples and get in one click ready-to-use code snippets available in 15+ different programming languages 😎

Try our API-Live tester now

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Questions (FAQ)

Where can I use template variables?

You can use template variables in quick replies, automatic replies and messages sent via API.

Can I send the contact’s metadata in template variables?

Yes, you can! Simply use the following syntax:

Hello {{ metadata.crm_name }}

Where crm_name represents the metadata key crm_name in the contact's metadata.

You can create or update the contact’s metadata from the web chat or API.

Can I set a default value if the variable value is empty?

Yes, you can use the following syntax to define a default value:

Dear {{ contact.name | customer }}!

In this case, assuming the target contact has no name defined, the value displayed in the message sent will be customer. Example:

Dear customer!

What happens if the variable is empty and there is no default value?

In that case, the template variable expression will be removed from the message.

For example, given the following message template where contact.name is empty:

Hello {{ contact.name }},
We are happy to have you onboard!

The resulting message will be sent like this:

Hello,
We are happy to have you onboard!

However, in cases like this it might be better to use the default syntax:

Hello {{ contact.name | there }},
We are happy to have you onboard!

Here is how it will be sent to the user:

Hello there,
We are happy to have you onboard!

Can I use multiple possible default values?

Yes! You can chain multiple default expressions.

In case you want to replace a given value with multiple alternative default values, you can use the following syntax:

Dear {{ contact.name | contact.surname | contact.phone | customer }}

In this case, it contact.name is empty, it will default to contact.surname. Then, if contact.surname is empty, it will default to contact.phone. Finally, if contact.phone is empty, it will default to customer a raw string.

--

--

Wassenger
Wassenger

Written by Wassenger

WhatsApp API + Team Chat + CRM + AI Assistant Solution for smart Businesses and Teams. Automate and work more productively with your clients on WhatsApp!

No responses yet