Manage Variables

Variables

Variables or properties or entities are data storage entities. Variables are a way to store data or the user input in a format to reuse that detail in the chatbot conversation or to store the information.

Variables are helpful when you need to personalize the conversation by saving the user name in a variable for using it during the conversation or if you want to store user details and pass them on to external systems or generate reports.

You can save user details or inputs in a variable for getting user insights as well.

Types of Variables

Generally, these are of the below kinds:

  1. System - These are generally global contexts, not under the direct control of a brand. For eg, the current date, and time. These variables are provided by Bot Studio and can not be modified. They are available for read only use.
System VariableUseExample
event_typeStores the event type. Events can be user inputs(user_input), marketing campaign(marketing_campaign), click to chat ad(click_to_chat_advertise) events.user_input
channelStores the channel on which user is interacting with the botwhatsapp
user_channel_idStores the unique channel id of the user interacting with the bot. If the channel is whatsapp, user_channel_id contains the country code + Ten digit user number91XXXXXXXXXX
user_inputStores the last user input receivedIf user selects a button "next" on reply node, user_input contains "next"
timeStampEpochStores the Epoch timezone format1648796400
payloadStringContains entire payload of user's conversation{"source":"channel","sender":"91XXXXXXXXXX","channel":"whatsapp","isGroup":false,"isFromDocker":false,"destination":917669715082,"botname":"LXNkW5hNhNMVG55amn2PvjMG","proxy":false,"contextobj":{"channeltype":"whatsapp","contexttype":"p2p","contextid":"91XXXXXXXXXX","botname":"LXNkW5hNhNMVG55amn2PvjMG","preventReply":false,"senderName":"****","cc":"91","dc":"XXXXXXXXXX"},"senderobj":{"channeltype":"whatsapp","channelid":"91XXXXXXXXXX","display":"****"},"messageobj":{"refmsgid":"5db41b09-4df4-42ae-8e27-5273b15b1edc","metadata":{"flowId":"68B31B92D79E2AC-000000000000478B"},"type":"text","text":"Next","from":"91XXXXXXXXXX","timestamp":1689155106659,"raw":{"id":"ABEGkYgAYEg4Ago6TIBLpqKKmiqU","source":"91XXXXXXXXXX","payload":{"title":"Next","id":"5db41b09-4df4-42ae-8e27-5273b15b1edc","reply":"Next 1","postbackText":"Next"},"sender":{"phone":"91XXXXXXXXXX","name":"****","country_code":"91","dial_code":"XXXXXXXXXX"},"context":{"id":"gBEGkYgAYEg4AgmW62X91r_RXEM","gsId":"5bcc56ba-5605-47ea-ade5-545aac70fc5b"},"type":"button_reply"},"id":"ABEGkYgAYEg4Ago6TIBLpqKKmiqU","postbackText":"Next"},"isFromSendMessage":false,"disableForwarding":false,"disablePreview":false,"event_type":"user_input","context":{"channeltype":"whatsapp","contexttype":"p2p","contextid":"91XXXXXXXXXX","botname":"LXNkW5hNhNMVG55amn2PvjMG","preventReply":false,"senderName":"****","cc":"91","dc":"XXXXXXXXXX"},"message":"Next","postbackText":"Next"}
user_nameContains user nameJane Doe
  1. Global Session - These are brand-level variables. They are defined by the brand and have the same value across all end users. For example, counter, brand name, etc.
  2. Local Session - These variables are global for a customer/end user. For example, customer name, email address, etc.
    1. Local or Session-based - These are session-based variables, whose scope can restrict to a particular session. For eg, after the 24-hour session on WhatsApp, the local variables can restart again
    2. Event-based - These are external variables whose scope is customer based but can be true for a segment of customers. For example, the channel of the message received from the customer, customer message, type of events, autoresponders, etc. These can be viewed or used but should not be edited.

Variable Management Elements

  1. Name (Unique identifier)
  2. Data Type (the kind of data it can store, for eg, text, number)
  3. Dummy Value (Some initial value for eg, 0 for a number or another constant)

Data Types

There are three data types that can be stored:

  1. Number
  2. String
  3. JSON

How to use a variable

Below are the steps to use variables in the chatbot journey building:

  1. Open the Variable Management screen. (you can open the Variable Management screen by clicking on Manage Variables)
  2. Give a name to the variable, eg - user_phone, user_email
  3. Select the data type from the dropdown on the manage variable screen.
  4. Provide a default value (it is optional) and click save.

Limitations

  1. Any special character can’t be added to the variable name except _ and -
  2. Duplicate name variables can’t be added.
  3. System Variable and Session Variable Naming can’t be the same.

How to use

Variables can be added by clicking on Manage Variable Button on the Journey Builder screen. Any Variable added can't be deleted, only the default value can be edited for a variable. To add a variable, a Name, and Data type are to be added and then click on the save button.

Variable Management Screen

📘

NOTE:

If the 'Default Value' is not provided by the user, then the platform sets the following default values as shown:

  1. String: empty string ""
  2. Number: 0
  3. JSON : empty Object {}