Create and access bot variables in UI

Three types of variables can be used in our flow:

  1. Bot variables (customisable)
  2. System variables (exposed on platform)
  3. Profile variables (Partially customisable)

Bot variables#

How to create a bot variable#

You can create bot variables using below option from UI. Variables are nothing but a way to store data that can vary/is not fixed.

Storing in a variable#

For storing something in a variable, you get an option in each prompt and in action nodes where needed to store. Additionally, you can also use variables action node for this purpose.

How to access a bot variable#

You can access a bor variable inside any node using this notation {{variables.variable_name}} or clicking on variables icon. So for the variable you just created above, you can access using {{variables.category}}

Advanced example - accessing variable fields and index in JSON object, array type stored in a variable#

Above was very simple, but often, in this example in API action node, the response you store is not a simple string or value.

Consider following response from a weather API

{
"coord": {
"lon": 77.2167,
"lat": 28.6667
},
"weather": [
{
"id": 761,
"main": "Dust",
"description": "dust",
"icon": "50d"
}
],
"base": "stations",
"main": {
"temp": 32.54,
"feels_like": 30.55,
"temp_min": 32,
"temp_max": 33,
"pressure": 1002,
"humidity": 21
},
"visibility": 3500,
"wind": {
"speed": 3.09,
"deg": 260,
"gust": 8.23
},
"clouds": {
"all": 0
},
"dt": 1617278187,
"sys": {
"type": 1,
"id": 9161,
"country": "IN",
"sunrise": 1617237667,
"sunset": 1617282517
},
"timezone": 19800,
"id": 1273294,
"name": "Delhi",
"cod": 200
}
  • To access any fields of this you can simply do {{variables.variable_name.field_name}} and this can go upto fields of fields.

For example: to access temp in above, {{variables.API_var.main.temp}} can be used.

  • You can also access array values using keys. To access weather description in above, you can see it's inside an array [ ] and is the first [0th index] value of array. {{variables.API_var.weather.0.description}} will be used.

System variables#

Following system variables have been exposed on the platform for quick use: -

{{{var_name}}} notation is used to access system variables.

VariableUse
{{{source}}}Returns channel source like yellowmessenger , whatsapp
{{{sender}}}Returns sender ID
{{{pageUrl}}}Returns current page URL
{{{sessionMessageLogUrl}}}Returns current chat's transcript URL
{{{profile}}}Returns business profile object , to access individual fields , use like {{{profile.name}}}
{{{date}}}Returns date object with current date and time in detected timezone. Following can be detected - {{{date.day}}}, {{{date.month}}}, {{{date.year}}} , {{{date.date}}} , {{{date.timestamp}}}, {{{date.hour}}}, {{{date.minute}}}.