header.phone_number boris@borisbot.com
Variable is a store of data that can be assigned a specific value (text or number). The system remembers the value that was stored in the variable, and then it can be used in the bot.

We create a greeting message and ask a person his name.

When a user has entered a text, we receive data with a certain value and can use it. So, we create a block where we address a person by name, using the variable %first_name% 👇
%first_name% is a variable to which a bot assigned the value entered by a user. At the same time, variable value is displayed in the dialogue with the person – name 👇

Types of variables

Variables are divided into types depending on the assigned value: temporary, global, functions.

Temporary variables are needed to assign a value to data within one script.

The variable is called %answer% and its value corresponds to the block number in the script: %answer_1%, %answer_2%, %answer_3%

For example, a person takes a test, and we want to record the answers in a table. To do this, you need to save variables in accordance with the blocks in which a user selected an option or entered text using free form.
Global variables are needed to assign a value to data that will be saved to the designer database and can be used within the bot.

For example, if a person entered his phone number and the bot saved it into the global variable %phone%, then the value of this variable remains in the system and can be used not only within one script, but anywhere in the bot.
List of built-in global variables

%username% – username in the messenger
%first_name% – username on the platform
%last_name% – user’s last name
%city% – user’s city
%email% – user’s email
%phone% – user’s phone
%photo% – user’s photo on the platform
%show_cart% – cart contents
%last_purchase% – last purchase
%utm_source% – the value of traffic source utm tag
%utm_medium% – the value of ad utm tag 
%utm_campaign% – the value of the utm tag of the name of the advertising company
%utm_content% – the value of the utm tag of the content of the advertising company
%utm_term% – value of the utm tag of the keyword
%ref% – parameter for the referral program
%respondent_id% – individual user number
%roistat_visit% – user visit identifier
%score% – points
%cart_products% – cart of products
%department% – division
%interests% – interests
%scope% – field of activity
%current_date% – date
%current_time% – time

Functions are needed to assign function value to data – the result of executing a function is written into the variable. For example, the sum of several values (sum function). It is used to perform mathematical operations.
List of functions

=sum(1,2,3); – allows to calculate and obtain the sum of values
=calc(1*2/3); – allows to calculate values and get calculation results based on addition, subtraction, multiplication, division
=random(1,2); – allows to get a random value in a range
=random_string(1,2); – allows to get the value of a random string in a range
=date_modify(+1 day, %current_date%, Y-m-d); – allows to get the date value in the present, future and past
=date(%current_date%, Y-m-d); – allows to convert the date to the required format

How to insert a variable

Any variable is inserted into a block field in the script. A list of all variables can be obtained by clicking on the Cross icon in the text field of the block.

A variable can be copied by hovering over and clicking on the variable name next to the block number.

How to save and create a global variable

Some global variables are associated with blocks that save entered values into the designer database.

Username block – %first_name% variable 
Phone block – %phone% variable 
Email block – %email% variable

To use another built-in global variable in different scripts and integrations, you can store it in a specific block. When a user enters a value into the block, it is saved in the designer's database (just like with Username, Phone, Email blocks).

For example, we want to save user responses to the database about what they are interested in. To do this, save the built-in variable – %interests% 👇
In addition to the built-in global variables, you can create your own. For example, you want to save user responses to the database about what languages they speak. To do this, create and add a variable – %language% 👇

❗️Do not use the same names for different variables.

How to view variables in the designer database

Variables can be viewed in the Client card in the Segments or Dialogues section. The values of global variables are also stored in the users table (Respondents type).

Where to use variables + examples of ready-made bots

Use variables to store data, perform mathematical operations, send requests, display information to a user, route scripts, and integrate a bot with other platforms.

We have selected several free templates* with different variables. You can use the template in your project or just look at how the variables are structured.

*Template is a ready-made bot script that you can copy into your project. All templates are placed on the template marketplace.