In the bot builder, a variable is a container for data related to a conversation, such as a customer's name or a store order ID. During a conversation, a messaging bot can use variables to send personalized messages, display dynamic information, or change the conversation's flow.
A bot can include up to 50 unique variables across all answers. Each unique variable can be used in an answer as many times as needed.
About variable names and values
In the bot builder, each variable has a name and value. When configuring a step in an answer, the name acts as a placeholder for the value. When the bot runs the answer, it replaces the variable's name with the variable's value. For example, you can use a variable named Email as a placeholder for the customer's email address.
Handling empty variables
A variable is empty if it has no value. Messaging bots skip empty variables during a conversation.
For example, a Send message step include a bot message of "Your package's shipping status is shipping_status." If the shipping_status variable is empty during a conversation, the bot sends "Your package's shipping status is ."
Handling missing variables
In the Make API call step, if one of the saved variables is missing from the response, the step's Fail branch is triggered. See Using the Make API call step in bot builder.
About variable types
Customer variables store information provided by a customer during an Ask for details step. For example, the step may ask a customer to provide their name and email address.
When inserting a variable in a step using the Add a variable icon () , customer variables appear under Responses from customer.
External service variables
External service variables store data received from an external system during a Make API call step. For example, the step can make a REST API request to a shipping provider to fetch the current status of a package.
Admins create external service variables when configuring the Make API call step. As part of the configuration, the admin can set a custom name for each variable.
When inserting a variable in a step using the Add a variable icon () , external service variables appear under Responses from external service.
Messaging metadata variables
Messaging metadata variables contain information about a customer's identity and authentication status. Messaging metadata variables get their values from the signed JSON Web Tokens (JWTs) used for messaging authentication.
Messaging metadata variables aren't enabled by default and are only available for the Web Widget and mobile SDK channels. For more information about enabling and using messaging metadata variables, see Using authentication metadata in a bot answer.
If enabled, messaging metadata variables appear under Messaging metadata when inserting a variable in a step using the Add a variable icon () ,
Using variables in an answer
You can use up to 50 variables across a single flow.
Customizing bot messages
Sending data to external systems
When making a REST API call to an external system using the Make API call step, admins can add insert variables into the path and query string of the step's Endpoint URL field. For more information, see Using the Make API call step in the bot builder.
Branching an answer's flow
The Branch by condition step lets an admin branch the flow of an answer based on the value of one or more variables. For more information, see Understanding branching conditions.