+55 (21) 960104492
Log In Free trial
Select region

The "Condition" block

In the script editor, you can teach the bot to perform actions based on a condition. For example: "If the client does not have a phone number, ask the client to send a phone number" or "If the client's message contains an employee ID, assign a specific operator".

A block is used to test a variable for a condition. Which variable and what the condition is, you set yourself. 

To learn what variables are and how they work, see the article "Variables in the Script Editor".

How to configure the block

This block has a lot of settings: operators, variable selection, conditions, values, regular expressions. It is easy to understand all of them if you go step by step.

Selecting the "AND"/"OR" operator

First, we need to select the "AND" or "OR" operator. On it depends on what principle the conditions will be checked. 

"AND"

A block with the "AND" operator has 2 outputs: "True" — true and "False" — false. True will be true only when all the conditions are satisfied. If at least one condition you set does not work, the result will be "False".

For example, you want the following action to be performed only if a client writes to Telegram Bot, it's Friday and a responsible employee is assigned to this client. Only if all the conditions are satisfied, the bot will send the message.

"OR"

"OR” also has "True" and "False" outputs. "True" will be if at least one condition is true, and "False" if none of the conditions are met. 

In addition to "True" and "False", the “OR” operator has outputs for each condition you create. This means you can configure the response to each condition. For example: if condition A is triggered, we send message A1. If condition B is triggered, then send message B1, and so on.

If several conditions are satisfied at once and there are outputs for each of them, the bot will go to the output that was satisfied first.

Creating a condition

A condition consists of a variable, the condition itself, and a value.  

Selecting a variable

First, we need to select a variable. What variables are, what they are and how to use them, read in the article "Variables in the script editor".

All types of variables are available for selection: system, local, global and constants.

Selecting the type of condition

Depending on the type of the selected variable (integer or string), the following types of conditions will be available to you:

Equality — The value of the variable on the left must be equal to the value on the right.

Inequality — The value of the variable on the left must not equal the value on the right.

Contains — The value of the variable on the left must contain one of the values on the right.

Does not contain — The value of the variable on the left must not contain any of the values on the right.

Filled — The variable on the left must have some value.

Not filled — The value of the variable on the left is empty.

Larger — The value of the variable on the left is greater than the value on the right.

Less — The value of the variable on the left is less than the value on the right.

More or equal to — The value of the variable on the left is more or equal to the value on the right.

Less or equal to — The value of the variable on the left is less or equal to the value on the right.

Available condition types for integer variables:

Available condition types for string variables:

“Regular Expressions” condition type

This condition type is worth a special attention. It is available for string variables.

Regular expressions is a language for searching in text. It uses symbols and metacharacters. You can use such symbols to set search parameters in the text and check if you have entered your phone number or full name correctly.

You can enter your own value according to the rules of the regular expression language or select one of the prepared ones:

Selecting a value

Now you need to select a value to compare the variable with. You can specify a certain value or select a variable by typing two curly braces "{{" in the input field. 

For conditions like "Equal to", "Not equal to", "Contains", "Does not contain", you can specify multiple values using the semicolon symbol ";". Variables can also be listed.

Outputs from the block

If you set the "AND" operator, there can be only two outputs from the block: "True", "False".

If you set the “OR” operator, there can be two outputs from the block: "True", "False", and outputs for each condition.

In an “OR” statement, you cannot select "True" if all conditions are already selected.

In the “OR” operator, if several conditions are satisfied at once and there are outputs for them, the bot will go to the output whose condition was satisfied first.

Video tutorial

Leave a request for integrator services