Skip to main content

How to use contact attributes and variables in Wati chatbots

Summary

When building a chatbot in Wati, you can collect information from contacts and use it later in the conversation or save it to their contact profile. This guide explains the difference between variables and contact attributes, and shows how to use them together in chatbots to collect, evaluate, and save contact information.

Instructions

Variables vs. contact attributes

Variables and contact attributes both store information, but they serve different purposes.

Variables temporarily store information while a chatbot is running. For example, you can use a variable to hold a contact's answer to a question and use that answer in a later step of the same chatbot.

Contact attributes permanently store information on a contact's profile. The information remains available after the chatbot ends and can be used for contact segmentation, campaigns, and personalization.

A simple way to think about it:

  • Variable: Stores information temporarily during a chatbot conversation.

  • Contact attribute: Saves information permanently to the contact's profile.

In many chatbot flows, you use both together: first save a contact's answer in a variable, then use an Update Attribute node to save that value as a contact attribute.

Sync a contact's WhatsApp phone number to Google Sheets

If your chatbot is running on WhatsApp, you can use the {{phone}} contact attribute to capture the contact's phone number without asking them to enter it manually.

The {{phone}} attribute is available when:

  • The conversation is happening on WhatsApp.

  • The contact has not hidden their phone number by using a WhatsApp username.

You can then use this attribute when sending contact data to a Google Sheet.

Add a fallback when the phone number isn't available

The {{phone}} attribute may not be available for every contact. To make sure your workflow still collects the phone number, add a condition to check whether the attribute exists.

  • Add a Condition node to check whether {{phone}} exists.

  • If {{phone}} exists, continue the chatbot flow and use it when syncing the contact's details to Google Sheets.

  • If {{phone}} does not exist, ask the contact to share their phone number.

  • Save the number they provide to a contact attribute using an Update Attribute node.

  • Continue the flow and use the updated attribute when sending the contact's details to Google Sheets.

This fallback helps ensure that your Google Sheet receives a phone number even when the {{phone}} attribute is not available automatically.

Collect a chatbot answer and save it as a contact attribute

Follow these steps to collect an answer from a contact and save it to their profile:

Step 1: Save the answer to a variable

In a List node, where you present options to the contact, find the Save Answers in a variable field.

Enter a variable name that starts with @.

Example: @travel_country

The @ prefix is required for chatbot variables.

When the contact selects an option, Wati stores their answer in the variable for use later in the chatbot.

Step 2: Save the variable as a contact attribute

Add an Update Attribute node after the List node.

Configure the fields as follows:

Field

Value

Attribute type

Custom Attribute

Attribute name

travel_country_attribute

Value

@travel_country

The Attribute name is the contact attribute where the information will be stored. The Value uses the variable containing the contact's answer.

For example, if the contact selects Spain, Wati saves Spain to the travel_country_attribute contact attribute.

You can then use this information from the contact's profile and for use cases such as segmentation and campaigns.

Update contact attributes based on a condition

You can also use variables with Condition nodes to evaluate information collected from a contact and then save the result to their profile.

Example: Verify an internal staff ID

Suppose you want to identify contacts whose staff ID starts with INT-.

Step 1: Ask for the staff ID

Add a Question node that asks the contact to enter their staff ID.

Save their answer in a variable:

@idnumber

For example, if the contact enters INT-1111, the variable contains that value for the rest of the chatbot conversation.

Step 2: Check the answer with a condition

Add a Condition node and check whether the variable starts with INT-.

Condition: @idnumber starts with INT-

Note: In Wati's chatbot Condition node, you can use the following operators: Equal to, Not equal to, Contains, Does not contain, Starts with, Does not start with, Greater than, and Less than.

This creates separate paths for contacts whose ID matches the condition and those whose ID does not.

Step 3: Save the result to contact attributes

On the branch where the condition is true, add an Update Attribute node.

Configure the attributes as follows:

Attribute

Value

{{internalstaff}}

yes

{{idnumber}}

@idnumber

This saves 2 pieces of information to the contact:

  • internalstaff is set to yes.

  • idnumber stores the actual staff ID entered by the contact.

Step 4: Use the variable in a message

You can also use the variable directly in a chatbot message.

For example:

Thank you. We've noted your ID is @idnumber. You can proceed to the next step.

Wati replaces @idnumber with the value entered by the contact.

Quick reference

Variables

Contact attributes

How long do they last?

During the chatbot session

Remain on the contact's profile

What are they used for?

Temporarily storing information within a chatbot flow

Storing contact information for use across Wati

How do you get the value?

Capture information during the chatbot flow

Use existing contact information or save information collected in the chatbot

Format

@variablename

{{attributename}}

Require @ prefix?

Yes

No

Tips to remember

  • Start chatbot variable names with @, such as @travel_country.

  • Use Update Attribute to save a variable's value as a contact attribute.

  • Use variables when you need information temporarily within the chatbot flow.

  • Use contact attributes when you need to keep information on the contact's profile after the chatbot ends.

  • On WhatsApp, use {{phone}} to access the contact's phone number when it is available.

  • Add a fallback to check whether {{phone}} exists. If it isn't available, ask the contact to share their number and save it to a contact attribute.

  • Saved contact attributes can be used for use cases such as segmentation and campaigns.

Frequently Asked Questions (FAQs)

Variables and contact attributes

1. What is the difference between variables and contact attributes in Wati?

Variables temporarily store information while a chatbot is running. Contact attributes permanently store information on a contact's profile and remain available after the chatbot ends.

2. When should I use a chatbot variable?

Use a chatbot variable when you need to temporarily store information and use it later in the same chatbot conversation.

3. When should I use a contact attribute?

Use a contact attribute when you need to keep information on a contact's profile after the chatbot ends. Contact attributes can be used for segmentation, campaigns, and personalization.

4. How do I save a chatbot variable as a contact attribute?

Use an Update Attribute node to save the value stored in a chatbot variable to a contact attribute.

WhatsApp phone numbers

5. When can I use {{phone}} to get a contact's WhatsApp phone number?

You can use {{phone}} when the conversation is happening on WhatsApp and the contact has not hidden their phone number by using a WhatsApp username.

6. What should I do if {{phone}} is not available?

Add a condition to check whether {{phone}} exists. If it is not available, ask the contact to share their phone number and save the number to a contact attribute.

Using variables in chatbot flows

7. How are chatbot answers stored in variables?

A chatbot can save a contact's answer in a variable, such as @travel_country. The @ prefix is required for chatbot variables, and the stored value can be used later in the same chatbot conversation.

Did this answer your question?