# Variables

## How to use variables

Let's explore what variables are and how to use them effectively when building chatbots in MaviBot.

{% hint style="danger" %}
**Please be aware of the following system limits for variables and constants within a single project:**

**Template Variables:**

* **Maximum quantity:** 100 variables
* **Maximum name length:** 100 characters

**Project constants:**

* **Maximum quantity:** 50 constants
* **Maximum name length:** 100 characters
* **Maximum value length:** 5,000 characters
  {% endhint %}

A variable is a named storage location for data, identified by a unique text label.

<div data-with-frame="true"><figure><img src="/files/BGn8ix4sHcgSLQYV6x6S" alt=""><figcaption></figcaption></figure></div>

&#x20;                                          *Fig. 1: A variable named `total`, storing a payment amount*.

MaviBot provides several types of variables:

1. [Built-in variables ](#built-in-variables)
2. [System variables](#system-variables)&#x20;
3. User-defined variables — these are the ones you create yourself within the project.

**To declare a variable** means to assign a value to a named container. In other words, a statement like ***a=0*** is the declaration of the variable ***a***. We’ve just told (declared to) the builder that we’ll store a number in the variable ***a***, and for now, that value is ***0***.

**To assign a value to a variable** carries the same meaning.

The expressions **"assign a variable the value of a function"** or **"set a variable equal to a function"** are also commonly used. The principle is the same: instead of assigning a specific value, you assign the result of a function. For example: **s\_id = tg\_send\_message(platform\_id, "Hello!")** In this case, the result of the function will be stored in the variable.

**To reset a variable** means to assign it the value **0**.

[**Functions and methods**](/chatbot/functions/variables.md#functions-for-working-with-variables)  are predefined sets of commands that are configured in advance by MaviBot. Most functions require parameters - values that the function or method can understand. Once the bot receives the necessary parameters, it executes a specific command.

**`tg_send_message(platform_id, "Hello!")` —** this function sends the message "Hello!" in Telegram.

<div data-with-frame="true"><figure><img src="/files/kRb0ie4sAHdc1dfyVk4H" alt=""><figcaption></figcaption></figure></div>

<p align="center"><em>Fig. 2. Example of a variable named text1 assigned to a function.</em></p>

### <mark style="color:red;">**RULES FOR WORKING WITH VARIABLES:**</mark>

1. A variable name can only start with **a letter**; it cannot begin with a number.

   **Age1 - ✅ correct**  &#x20;

   1Age - ❌ <mark style="color:red;">incorrect</mark>

   **age1 -** **✅ correct**   <mark style="color:blue;">- recommended option</mark> <br>
2. A variable cannot contain spaces or special characters, except for the underscore (\_).

   **Name\_Surname - ✅ correct** &#x20;

   Name Surname - ❌ <mark style="color:red;">incorrect</mark>

   **nameSurname** **- ✅ correct**   <mark style="color:blue;">- recommended option</mark><br>

   Reserved words from programming languages cannot be used as variable names, for example: print, true, false, count, sum, and so on.<br>
3. <mark style="color:$primary;">It is</mark> <mark style="color:red;">**strictly prohibited**</mark> <mark style="color:$primary;">to use</mark> the names of built-in and system variables for user-defined variables. You can find the list of such variables here. <mark style="color:red;">**ссылка**</mark>
4. <mark style="color:blue;">**We recommend:**</mark>
   * Use Latin (English) names for variables.
   * Use short but meaningful variable names, for example: totalSum, pay\_name, <mark style="color:red;">**ns**</mark>, name\_client, etc.

### How to get the value of a variable

Place the variable name inside curly braces **#{}**. You can reference its value in the message text field this way. However, in the "Calculator" field, you should refer to the variable’s value simply by its name, without any additional syntax.

{% hint style="danger" %}
The **#{}** construction allows you to retrieve the value of a variable. It is used in the "Message text" field to insert the variable's value into the text.
{% endhint %}

Example:

<div data-with-frame="true"><figure><img src="/files/2A0xZP36h4klEzjmH98t" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="success" %}
The system supports nested variables, where the value of one variable is part of the name of another variable. For example: **#{q#{test#{i}}}**
{% endhint %}

In the "Calculator" field, refer to variables by their names without using the #{} notation.&#x20;For example, if we have two variables: price (sum) and quantity (num).

`num = 10`

`sum = 1500`

<div data-with-frame="true"><figure><img src="/files/r8o0VzvNd0AOW40qedTX" alt=""><figcaption></figcaption></figure></div>

### How to display the total sum&#xD;

Enter the following in the calculator:

`total_sum = sum1 * num2` **✅ correct**

<div data-with-frame="true"><figure><img src="/files/z88PpXPeHSWwDdRzjPB1" alt=""><figcaption></figcaption></figure></div>

**How&#x20;*****not*****&#x20;to do it:**

`total_sum = #{sum1} * #{num2}` - ❌ <mark style="color:red;">incorrect</mark>

### How to delete a variable from the bot

To delete (clear) a variable, enter one of the following in the "Calculator" field:\
YourVariableName =\
or\
YourVariableName = ""

After the equals sign, either leave a space or use double (or single) quotation marks.

{% hint style="warning" %} <mark style="color:red;">**Please note!**</mark> It’s important to use the correct prefix to indicate where the variable belongs.

For project-level variables (stored in the project settings), use the prefix **project:**\
Example:&#x20;*project.YourVariableName =*&#x20;or&#x20;*project.YourVariableName = ""*

For client-level variables, use the prefix **client**:\
Example:&#x20;*client.YourVariableName =* or&#x20;*client.YourVariableName = ""*

For deal-level variables, no prefix is needed.
{% endhint %}

## Built-in variables

Here is the list of built-in variables:

**#{none}** - ignore the message

**#{api\_key}** - API token used in Salebot API calls

**#{attachment\_url}** - contains the link to the attachment

**#{attachments}** - a JSON array of attachment URLs from the user's message

**#{avatar}** - link to the user's avatar (shown in the "Clients" section)

**#{client\_id}** - client ID in the constructor, also used in API requests

**#{client\_type}** - the type of messenger the client came from (values described \[here])

**#{current\_date}** - current date in dd.mm.yyyy format, based on the project's time zone

**#{current\_time}** - current time in hh:mm format, based on the project's time zone

**#{custom\_answer}** - the response received from the server specified in the "Server response URL" field

**#{message\_from\_outside}** - type of incoming message. Possible values:\
\&#xNAN;*regular message = 0*\
*message sent via API = 1*\
*callback notification (yellow background in the dialog) = 3*\
*telephony notification (light blue background in the dialog) = 5* \
*This variable is generated with every incoming message but does not appear in the client card.*\
*You can use it in the "Variable for comparison" field to set up conditions for block triggers and connections.*

**#{date\_of\_creation}** - date when user was added to the bot or messaged it for the first time

**#{full\_name}** - full name of the user (first and last name)

**#{group}** - bot the client is linked to (shown as "Linked to bot" in client card)

**#{main\_client\_id}** - ID of the main client among a group of linked client cards

**#{message\_id}** - current conversation state ID with the client (defaults to NONE)

**#{messenger}** - name of the messenger the client came from

\#{name} - first name of the user

\#{next\_day} - tomorrow’s date in dd.mm.yyyy format (useful for scheduling messages)

**#{order\_id}** - order identifier (client ID and internal order ID separated by a hyphen)

**#{order}** - contents of the order submitted by the user

**#{platform\_id}** - client ID in the messaging platform

**#{question}** - message sent by the user

**#{timestamp}** - current timestamp including milliseconds

**#{time\_of\_creation}** - time when the user was added to the bot or messaged it for the first time

**#{wa\_bot}** - WhatsApp number the user messaged (useful for passing to CRM fields and distributing leads among managers)

**#{weekday}** - day of the week as a number (Monday = 1, Tuesday = 2, etc.)

#### **client\_type values**

<table><thead><tr><th width="195.3359375">Value</th><th width="211.8125">Messenger</th></tr></thead><tbody><tr><td>1  </td><td>for Telegram </td></tr><tr><td>2  </td><td>for Viber</td></tr><tr><td>3  </td><td>for Facebook</td></tr><tr><td>5  </td><td>for online chat</td></tr><tr><td>10</td><td>for Instagram</td></tr><tr><td>14 </td><td>e-mail </td></tr><tr><td>16</td><td>Telegram Business Account </td></tr><tr><td>21</td><td>Telegram account</td></tr><tr><td>22</td><td>TikTok</td></tr></tbody></table>

## System variables

The system automatically generates various runtime variables during a bot's operation You can use these variables while building your bot. Here is a list of those that might be useful to you.

{% hint style="info" %}
You can find additional system variables in the documentation. They are located within the sections relevant to their use.
{% endhint %}

**phone** - phone number

**notSubscribed** - if the variable equals 1, the client has unsubscribed from messages and will not receive any messages

**clientBlocked** - client is blocked, and the bot does not operate for them

**story\_url** - identifier of the Instagram story the client replied to

**viewed\_page** - page from which the user is writing in the online chat

**wa\_bot** - phone number of the WhatsApp bot

{% hint style="info" %}
To learn which variables can be created during payment, refer to the integration guides for payment services in the "[Payment system](/payment.md)" section.
{% endhint %}

## Custom variables

Custom variables are divided into:

* Project variables (also called common variables)
* [Client variables](#custom-variables)&#x20;
* [Deal variables](#key-deal-variables) (also called regular variables)
* [Constants](#how-to-set-constant-variables)&#x20;

Each type of variable will be explained below.

{% hint style="info" %}
Please avoid using the same names for different types of variables to prevent confusion when the Builder displays or uses a value other than what you expected.
{% endhint %}

{% hint style="info" %}
When assigning a value to a variable, it is important to specify its type by using the appropriate prefix:

**client.** (for client variables) and **project.** (for project variables). No prefix is used for deal variables.

The prefix is omitted when retrieving a variable’s value.

Example:&#x20;Let's imagine you want to create a project variable called like to serve as a counter for likes from your clients.

**project.like = 0 - declaration, done once**

In the block where you need to count likes, write:&#x20;**project.like = like + 1**
{% endhint %}

{% hint style="info" %}
Variable priority order:&#x20;deal variables have the highest priority, followed by client variables, then project variables.
{% endhint %}

#### **Messenger ID (platform\_id)**

**Messenger ID (platform\_id)** is the identifier of the user/chat/channel within the messenger. To find it, open the conversation with the desired client in the "Clients" section. On the right side of the chat window, navigate to the "**About client** - **System variables"** tab or the "**All"** tab.

The **`platform_id`** is a permanent, system-generated variable representing the user's unique messenger ID.

* **Persistence:** This ID remains constant for a user. Even if you delete their record from the builder, their `platform_id` will be the same upon re-registration.
* **Origin:** The ID is assigned by the messenger platform (e.g., Telegram, WhatsApp) when the user first interacts with the bot.

The following example shows how the `platform_id` appears in a client card.

<div data-with-frame="true"><figure><img src="/files/U2m8sFMoua1reUu1w4Uo" alt="" width="563"><figcaption></figcaption></figure></div>

The platform\_id variable exists for regular users as well as for communities, channels, and chats.

To obtain the **platform\_id** (messenger ID) of a Telegram channel where the bot is an administrator, simply send a message to the channel from your personal account. This will automatically create a dialog between the bot and the channel.

You can copy the channel’s **platform\_id** value in the "About client" section.

In Telegram, the messenger ID for channels always starts with a minus sign (-). When using functions, make sure to include the entire value, including the minus sign.&#x20;

## How to use variables

Variables can be used in triggers, orders, user responses, blocks, and more. Let’s look at a concrete example while creating a funnel for a real estate agency.

So, let’s create a Start block:

<div data-with-frame="true"><figure><img src="/files/M5zUGTuEP5SWVmRrNxCR" alt=""><figcaption></figcaption></figure></div>

**Step 1: Create the "Thank you" block**

Create a new block with a message thanking the user for their input.

**Step 2: Configure the transition**

On the connection leading to this block, configure the following trigger:

1. Enable the **"User inputs data"** toggle.
2. In the **"Input data"** field, enter the variable name: **`name`**.

<div data-with-frame="true"><figure><img src="/files/AHtIGKjuJe5My2NhWust" alt=""><figcaption></figcaption></figure></div>

The user's input is stored in the **`Name`** variable. This value can be reused in any subsequent block by invoking the variable with the `#{Name}` syntax, such as: `Welcome, #{Name}!`.

<div data-with-frame="true"><figure><img src="/files/U74Whe87gDfUvbhAwB6j" alt=""><figcaption></figcaption></figure></div>

The bot will work as follows:

<div data-with-frame="true"><figure><img src="/files/kaqVKH6pqllyV20IIdh2" alt="" width="563"><figcaption></figcaption></figure></div>

Now let’s make the task a bit more complex.&#x20;

In this same block, we’ll ask the user whether he's interested in primary (new) or secondary (resale) housing:

<div data-with-frame="true"><figure><img src="/files/FeDAMyUVM4Sfc5NpAAjN" alt=""><figcaption></figcaption></figure></div>

Next, create connections from the "Primary housing" and "Secondary housing" buttons in the "Chat" block.

<div data-with-frame="true"><figure><img src="/files/kT47UUpON4ivjjNTfuq7" alt=""><figcaption></figcaption></figure></div>

Now let’s look at the second way to use variables within blocks.

Select the right block and enter the following text in the "Calculator" field:&#x20;**client\_interest = Primary housing**. In the left block, enter:&#x20;**client\_interest = Secondary housing**.

<div data-with-frame="true"><figure><img src="/files/QOHOgl92FpYAa304S4z4" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/ToGaJfbVoFpnlRJdBuEy" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
A variable is assigned to the user when they transition to any of these blocks. We can use it later when creating an order.
{% endhint %}

Next, we’ll ask the client about their budget for purchasing real estate in these blocks, and create two more blocks with arrows leading to them based on the client’s response triggers.

<div data-with-frame="true"><figure><img src="/files/PcMEX9FOl9KQWavxMihw" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/omFkN3JHElpjcOGjPdSU" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/zl6QmsaTfoPiPmEUpVa5" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/oJfJjvtpEZzM06ZFCwEZ" alt=""><figcaption></figcaption></figure></div>

From the block **"What is your budget?"**, create a connection and set a trigger condition to segment users based on their input.

1. In the connection's settings, enable the checkbox for **"User enters data"**.
2. Assign a variable name (e.g., `budget`) to store the client's response.
3. In the **"Variable"** field, use the built-in variable `#{question}` (which contains the user's last message) to create a condition.
   * **Example:** `#{question} <= 1000000`

<div data-with-frame="true"><figure><img src="/files/npzvri0oEc64s0DeHiWs" alt=""><figcaption></figcaption></figure></div>

{% hint style="warning" %}
For all connections to **"Leads"** blocks, activate **"User enters data"** and define the variable.
{% endhint %}

You can also define an additional variable directly in the **"Leads"** block to provide more comprehensive deal information.

<div data-with-frame="true"><figure><img src="/files/zIqxCueufkQN8HcmJMZx" alt=""><figcaption></figcaption></figure></div>

Now change the type of the last two blocks to "Leads" and see the results:

Let’s test the flow in action:

<div data-with-frame="true"><figure><img src="/files/EHTzjVw2r6KJX8L9Ra6w" alt="" width="375"><figcaption></figcaption></figure></div>

You can review the created deal and the client's stored data by going to the **"Clients"** section and opening the relevant conversation. The deal variables will be visible there.

<div data-with-frame="true"><figure><img src="/files/teDjM0hiXcSIARChJbUo" alt=""><figcaption></figcaption></figure></div>

Now you know how to use variables in at least three different ways:

1. Assign variable names to user input data (e.g., “Name”, “Budget”)
2. Assign a variable value when transitioning to a block (e.g., client\_interest = Primary housing)

## How to view variables

To view a client's variables, navigate to the **"Clients"** section and open their client card.

<div data-with-frame="true"><figure><img src="/files/4g0ZmFnc1kMjlMfAsb80" alt=""><figcaption></figcaption></figure></div>

Variables are displayed in a list format within the client card:

* Each variable occupies its own line.
* The **variable name** is shown on the left.
* Its corresponding **value** is displayed on the right.

**To modify a variable:**

Hover over its line in the list to reveal an action button. Clicking this button allows you to:

* Edit the variable's name.
* Edit the variable's value.
* Delete the variable entirely.

<div data-with-frame="true"><figure><img src="/files/zRMIrcgnSnf2k9zUOReI" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/zSrmwtr8Nzh644LtMt4U" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
System variables cannot be edited!
{% endhint %}

## How to set client variables

{% hint style="info" %}
Client variables are not deleted, reset, or lost when using the "End of data collection" block (red block).
{% endhint %}

A client variable can be set in two ways: explicitly and implicitly.\
An explicit way to define a variable is to set it in the "Calculator" field of one of the funnel blocks.&#x20;

Example: `client.age = 28` or `client.age = 28:`

<div data-with-frame="true"><figure><img src="/files/cm7SueQdS4DDhZZch2G5" alt="" width="563"><figcaption></figcaption></figure></div>

The implicit way is to set a variable in the data input field of the arrow.

Example:

Let’s create a block where we ask for the client’s name, and also create a block below:

<div data-with-frame="true"><figure><img src="/files/GKPs4p2TSv1mXFGXhhOl" alt="" width="563"><figcaption></figcaption></figure></div>

Next, navigate to the connection settings and enable the "User enters data" option.

<div data-with-frame="true"><figure><img src="/files/kUwgEbecLl6qJCasg5EK" alt="" width="563"><figcaption></figcaption></figure></div>

Use the `client.` prefix when naming your variable (e.g., `client.name`) to store the user's input. This variable can then be referenced in later messages as `#{client.name}`.

<div data-with-frame="true"><figure><img src="/files/dWbjTtRwWcSVC3em6Zgq" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="success" %}
Client variables are used exactly like regular variables in the builder, but without the **client** prefix.
{% endhint %}

## How to set project variables

{% hint style="info" %}
Global variables are not deleted, reset, or lost when using the "Leads" block (red block).
{% endhint %}

Global variables are accessible to all users of the bot. They are ideal for controlling bot behavior or facilitating interactions between different users.

**Use case example:**\
One user can post an item in a marketplace channel by setting a variable (e.g., `project.latest_listing`), and all other users can see it and respond.

#### **Syntax for assignment**

To create or update a global variable, use the `project.` prefix in the Calculator:

**Examples:**

* `project.product_shop = 28`
* `project.age = 28`

<div data-with-frame="true"><figure><img src="/files/Ls8vc0zq79RT3MHuTYdC" alt=""><figcaption></figcaption></figure></div>

They can be used without any prefix.

Let's see how the data is displayed in the table.

<div data-with-frame="true"><figure><img src="/files/vlJafH7do0mxcHJFeCB7" alt=""><figcaption></figcaption></figure></div>

Now, execute the "Start" block in test mode.

<div data-with-frame="true"><figure><img src="/files/1Qi3MpP2TtRQmeDFMsh9" alt="" width="375"><figcaption></figcaption></figure></div>

We can see the data that was written to the variable from the table in the message sent by the bot. Because we referenced the variable in the message using the `#{}` syntax, the data stored in it was displayed in the bot chat.

{% hint style="info" %}
More details on how to work with the function get\_records\_from\_table() are explained in the article "[AI assistant with MaviBot table](/chatbot/ai/tables.md)".
{% endhint %}

The `project.` prefix allowed the function to write the table data directly to the project's global variables, accessible in the **"Variables"** section.

<div data-with-frame="true"><figure><img src="/files/tjYGLPSoshqH0Q54nXiJ" alt=""><figcaption></figcaption></figure></div>

You can edit project variables in the project settings.

### Example: using project variables

Create a system that assigns a sequential number to each new client who enters the bot.

**Implementation:**

1. Navigate to your **Project settings**.
2. Create a new project variable (e.g., `project.client_counter`).

<div data-with-frame="true"><figure><img src="/files/d6VJ4ezt5FsT3BKde6aQ" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/cHjQR4yLgZGaQIIhx2UP" alt=""><figcaption></figcaption></figure></div>

3. Set its initial value (e.g., `0`) which means **"No clients in the bot"**:

<div data-with-frame="true"><figure><img src="/files/ykyzjUbYCgXGvGewxyX5" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/IMOYneazA4XLz0RHF6fg" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/KUswTcKU5XF03wxOdxhT" alt="" width="563"><figcaption></figcaption></figure></div>

In the bot's start block, add logic that:

1. Increments the project variable's value by 1.
2. Assigns the new value to a client-specific variable for the current user.

<div data-with-frame="true"><figure><img src="/files/xP3rVfSgAH2noxLXdywH" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Don’t forget to set a restriction so that the counter cannot be incremented for the same client twice.
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/qDQ5oQYhjyDwSbT7dy7q" alt="" width="563"><figcaption></figcaption></figure></div>

## How to set constant variables

Constants are fixed values that remain unchanged (or rarely change) throughout a project's lifecycle.

**Key difference from global variables:**

Unlike global variables, constants are **client-specific**. If a constant's value is modified, the change applies only to that individual client's session.

**Common use cases:**

Constants are ideal for storing static data such as:

* Product prices and customer discounts
* Integration tokens and API keys
* Seller or support contact information
* Any other fixed configuration values

### Example: using constant variables

For example, a client's discount could be 10% by default, but change to 25% upon entering a promo code.

In "Project settings" → "Constants", enter: Discount : 10

<div data-with-frame="true"><figure><img src="/files/Ewhub2RhPh48LEAyP6dS" alt=""><figcaption></figcaption></figure></div>

To enter a promo code, add a "Trigger" block, where we assign the variable **discount** the value of 25.

<div data-with-frame="true"><figure><img src="/files/KVfFNLRD7gFDepvNtq4p" alt=""><figcaption></figcaption></figure></div>

Display the variable that shows the discount amount in the green block:

<div data-with-frame="true"><figure><img src="/files/LBJyc8KapB4Br69ydyas" alt=""><figcaption></figcaption></figure></div>

**Step 1: Configure the automatic transition**\
Create a connection with a **zero-second timer** from the gray block. This ensures the discount is applied immediately and the client proceeds to the message in the start block.

**Step 2: Test the flow**\
Now, write a message to the bot to trigger and test the entire sequence.

<div data-with-frame="true"><figure><img src="/files/H0OPphyRg4QrR48pH3Ih" alt="" width="563"><figcaption></figcaption></figure></div>

The standard discount is 10% without a promo code. However, entering a valid promo code changes the situation.

<div data-with-frame="true"><figure><img src="/files/TkBViCyuT2p96iVkXNCE" alt="" width="563"><figcaption></figcaption></figure></div>

Thus, after entering the promo code, the variable "discount" for this client became 25. <br>

This happened because an assignment like discount = 25 set the value for the deal variable, rather than changing the value of the constant with the same name.

## Key deal variables

**name** - deal name. The term **Name** is used for the international version of the project.

**description** - tdeal description. **Description** is used in the international version of the project

**budget** - deal amount (number).

To edit variables using the API request /set\_order\_vars, you must use the names from t[his guide exactly as shown](#how-to-set-client-variables), including case sensitivity and the project version.

## Limits

{% hint style="warning" %}
Maximum variable name length: 500 characters

Maximum variable value length: 100,000 characters

Maximum number of variables per client or deal: 1,000 characters.
{% endhint %}

## How to work with variables correctly

### *When should you enclose a variable's value in quotation marks?*

*For example, <mark style="color:yellow;">**client\_id = 1202020202**</mark> or <mark style="color:green;">**client\_id = '1202020202'**</mark>?*

Both syntax options are functionally correct. Using quotation marks around a value only affects its visual highlighting in the calculator editor.

However, following consistent coding conventions improves readability and maintainability:

* **Omit quotes** for **numeric** values (e.g., `discount = 25`).
* **Use quotes** for **string** values (e.g., `status = "active"`).

<div data-with-frame="true"><figure><img src="/files/CQw5UIeoZ0yHRGN3yMTY" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/rfoRoZtCrMb30uIAQUBT" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/uJiOKpxyvj2cWWQopLNb" alt=""><figcaption></figcaption></figure></div>

*What is the correct syntax for passing identifiers such as Client ID, Site ID, Block ID, or Certificate ID to functions—should they be enclosed in quotation marks?*

<div data-with-frame="true"><figure><img src="/files/PyZjejJZNYyuKO2mt53a" alt="" width="563"><figcaption></figcaption></figure></div>

An ID should not be enclosed in quotation marks when passed to a method or function:

<div data-with-frame="true"><figure><img src="/files/iSgzzIVd6i566lMuapww" alt=""><figcaption></figcaption></figure></div>

### Which should be used: double quotes or single quotes?

There is no difference between using single or double quotation marks, but we recommend using double quotes. This way, for example, when inserting a variable inside a string, the variable will be highlighted in a different color, making it easier to notice.

<div data-with-frame="true"><figure><img src="/files/FP3RDPyf6nc71WN69WUX" alt=""><figcaption></figcaption></figure></div>

### How should spaces be placed?&#x20;

Does it work the same if there is a space between the variable and the equals sign (for example, *<mark style="color:blue;">ans="yes"</mark>, <mark style="color:purple;">ans = "yes"</mark>, <mark style="color:orange;">ans= "yes"</mark>, <mark style="color:red;">ans ="yes"</mark>?*

<div data-with-frame="true"><figure><img src="/files/aDua6C30aeqXa15LgVdy" alt=""><figcaption></figcaption></figure></div>

Spacing does not affect the operation of methods, variables, or functions. However, it is recommended to use spaces in the code to improve readability.

### How to write comments in the calculator correctly

{% hint style="success" %}
**For more details on how to write comments in the Calculator, please see** [**this article**](/chatbot/functions/calculator.md)**.**
{% endhint %}

## How to compare variables

You can control the chatbot's flow by comparing variable values. This allows you to create conditional logic, such as verifying a user's age for legal compliance or routing interactions based on the user's messenger platform.

{% hint style="info" %}
Here’s how to split the funnel [by different messengers or by different accounts of the same messenger explained here.](/faq/faq.md#how-can-i-split-a-funnel-by-messengers)
{% endhint %}

#### **Supported operators:**

"**+**": addition \
"**-**"': substraction \
"**\***" *multiplication* \
"**/**": *division*\
"**%**'"*: remainder of division* \
"**^**" "**\*\***": exponentiation \
"**and**" "**AND**" "**&&**": logical AND \
"**or**" "**OR**" "**||**": logical OR

Comparison operators:\
"**==**" — equal to\
"**!=**" — not equal to\
"**>**" — greater than\
"**<**" — less than \
"**>=**" — greater than or equal to\
"**<=**" — less than or equal to

{% hint style="warning" %}
**IMPORTANT!** \
To check that **the built-in variable tag** (the bot launch tag) is not present in the client’s card, use the following comparison method:\
\
`tag == "NONE"`
{% endhint %}

Variables should be compared in the condition within the "Variable" field (both in the connection settings and in the block settings):

**Example of variable comparison in the "Variable" field of a trigger block.**

<div data-with-frame="true"><figure><img src="/files/j3Evnv2DmzaHqpc0VsjC" alt=""><figcaption></figcaption></figure></div>

**Example of variable comparison in the "Variable" field of a block connection.**

<div data-with-frame="true"><figure><img src="/files/IRjIH4Kp5NXPi7ZcCwXk" alt=""><figcaption></figcaption></figure></div>

#### **How variables and triggers work together**

For a connection to be activated, **both triggers must be met**:

1. The condition in the **"Trigger"** field.
2. The comparison logic in the **"Variable"** field.

#### **Understanding the "Variable" field**

If you enter only a variable name (e.g., `client_type`) in the **"Variable"** field without an expression, the system checks for the *existence* or *truthiness* of the variable's value. It does **not** compare it to the user's raw input.

**Example:**\
The configuration below checks if the client is from WhatsApp by verifying that the `client_type` variable equals `6` (where `6` represents WhatsApp).

`client_type == 6`

<div data-with-frame="true"><figure><img src="/files/l2VFUqoJvEVnO4GuAEQe" alt="" width="563"><figcaption></figcaption></figure></div>

The example below works identically:

<div data-with-frame="true"><figure><img src="/files/EfKxYgk8qKwa5J3zu1bU" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
Please note! \
You cannot specify multiple values for variable comparison in the "Trigger" field.

<img src="/files/KijMlDTXTdpQPXoOSOn2" alt="" data-size="original">

This is incorrect!

If you need to compare multiple variables, specify their values in the "Variable" field.

These options are correct.

<img src="/files/83HbjgSXIrwjE8XdF7RT" alt="" data-size="original">
{% endhint %}

{% hint style="info" %}
client\_type == 3 transition if the variable value equals **3**\
attachments != None transition if the variable contains any value\
attachments == None transition if the variable is not set\
product\_quantity >= 100 transition if the product quantity is greater than or equal to **100**\
product\_quantity <= 100 transition if the product quantity is less than or equal to **100**\
name == "John" transition if the variable name equals John

To check if a variable is empty or not, use the expressions:\
\&#xNAN;**"#{value}" == ""**  \
**"#{value}" != ""** <br>

(where **value** is the variable name).

The result of the comparison operation returns a boolean value: **True** or **False**.
{% endhint %}

{% hint style="warning" %}
Maximum expression length: 1000 characters
{% endhint %}

{% hint style="warning" %}
The default value will be returned as a result when attempting to compare values of different types.

"==" - False                       "<" - False\
"!=" - True                          ">=" - False \
">" - False                          "<=" - False
{% endhint %}

{% hint style="warning" %}
**IMPORTANT!** \
To check that **the built-in variable tag** (the bot launch tag) is not present in the client’s card, use the following comparison method:\
\
`tag == "NONE"`
{% endhint %}

**Example:** a bot that checks a user's age (`age`).

* If `age < 18`, it sends a message for minors.
* If `age >= 18`, it sends a message for adults.

<div data-with-frame="true"><figure><img src="/files/iokjX2He3zEvrmMEN9vl" alt=""><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/bgolPDtJiVJNpaTT0oGi" alt=""><figcaption></figcaption></figure></div>

Note that the flow includes a block without a trigger, with timed connections leading from it.&#x20;

This block is intentionally designed to demonstrate how to build flows where the bot reacts not to user actions, but to calculation results. At the first step, the answer is saved to a variable, and then the comparison takes place. The delay on the arrows is set to 0 for an instant response.

The comparison **"Age >= 18"** can also be expressed as **"greater than or equal to 18."**

<div data-with-frame="true"><figure><img src="/files/Cpt4C72URfwgod7NFPDu" alt=""><figcaption></figcaption></figure></div>

{% hint style="danger" %}
Please note the errors in the triggers:

<img src="/files/jjRQeZVYi9BQkIlzi42Q" alt="" data-size="original">

<img src="/files/7blpRJ9EoTKRdM1439iA" alt="" data-size="original">

<img src="/files/0X3LZTIsECJAteljwgJv" alt="" data-size="original">

**A number cannot be simultaneously greater than, less than, and equal to 18!**

These triggers are meaningless. Every number is either less than 18, greater than 18, or equal to 18.
{% endhint %}

{% hint style="warning" %} <mark style="color:red;">**Important!**</mark>&#x20;

Logical triggers with variables must be written in the <mark style="color:red;">**"Variable"**</mark> field, not in the "Trigger" field!
{% endhint %}

For example, in the image below, the block will be triggered if <mark style="color:green;">**the variable phone is filled**</mark> (i.e., not equal to **None**):

<div data-with-frame="true"><figure><img src="/files/5aqgxZHaj5YMf5MjeliJ" alt="" width="563"><figcaption></figcaption></figure></div>

The next example shows how to combine operators:

<div data-with-frame="true"><figure><img src="/files/fOxVFCxuo329APXOibF9" alt=""><figcaption></figcaption></figure></div>

If the client has an age variable with a value between 18 and 99, the block will be triggered. If the variable is missing, or the age is less than 18 or greater than 99, the block will not activate.

{% hint style="warning" %}
Note!&#x20;

If you compare a variable to a value in quotation marks, make sure there are no spaces between the quotes and the value; otherwise, the block may fail to trigger or behave incorrectly!

<mark style="color:green;">**Correct**</mark> (no space <mark style="color:red;">**before the quotation mark**</mark> or <mark style="color:red;">**after the value my\_new\_bot**</mark>):

<img src="/files/bjz4Px8MVyTPfZck7dIQ" alt="" data-size="original">

<mark style="color:red;">**Incorrect**</mark> (with a space before the quotation mark):

<img src="/files/Col6gQdfy380NtNsaKwz" alt="" data-size="original">
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/chatbot/functions/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
