Condition
Last updated
Last updated
Conditions allow you to branch your script, guiding it, depending on the received messages and variables.
For example, if a user came to VK, one chain can be launched for him, and another one for those who wrote in telegram. To add a branch, let's create a simple condition block on the screen. You can do this by right-clicking in an empty area of the screen, or through the left auxiliary menu.
Using the buttons, you can add conditions on messages and variables, as well as complex conditions in the SmartQuery language.
There are also two fields that indicate where the chain will go if the conditions are met and otherwise.
Please note that the "Then" and "Else" fields at the bottom of the block menu are identical to the rectangles on the block itself. You can select the next block from the drop-down list, or connect the "To" rectangle with an arrow to the desired block directly on the screen.
The condition consists of 3 elements: key, comparison type, value.
To check the condition, the bot takes the value of the key and checks it according to the specified comparison type. In the example above, the key is the user's last message, the bot checks if it is equal to the word "hello".
All conditions consist of 3 groups: conditions for a message, conditions for variables and complex conditions.
The conditions are combined with each other according to the principle "do all or do only one".
For example, if you want to run a script with the words "Hello", "Hello", "Good afternoon", then you need to configure the bot to select one of these conditions.
If you want to check several parameters at the same time, then check the item "All conditions":
The main condition is the condition on the message. Such condition checks the last message of the user.
The check is carried out using the following types of comparison:
equals
not equal
it seems
contains
begin with
does not begin with
ends with
does not end with
contains the string
does not contain a string
Let's consider some of them. Equal and Not Equal
The equals and not equals comparison types check whether the message is explicitly equal or not equal to the given text. For example, the message "hello" will only match this text.
These comparison types check that the message contains the given words. The message can contain these words consecutively anywhere in the message.
In this mode, the bot checks that the user's message starts or ends with the text specified in the condition.
This condition compares texts using a smart algorithm that uses machine learning. This mode is best for comparing small phrases.
For example, if you set the condition that the message should be similar to "delivery address", then the bot will respond to similar phrases
Conditions on variables significantly expand the functionality of conditions! For example, you can check user data or special variables. To add a condition on variables, click "+ condition on a variable"
Чтобы добавить условие на переменные, нажмите "+ условие на переменную"
The message condition group is checked TOGETHER with the variable condition group. Thus, for the general condition to be met, both groups must be satisfied
In the example above, the condition will be met only if the message is equal to "hello" AND if the type of the channel where the message was received is telegram.
In conditions on variables, you can specify both special and your own custom variables.
Complex conditions are written in the SmartQuery language.
To add such a condition, click on the "+ Complex condition" button.
With their help, you can, for example, check for the presence of an element in an Array, or combine several conditions using AND and OR, for example
The "Check Code" button executes the code specified in the input field and, if there are no errors, shows the value of the resulting expression.
Please note that code verification is performed on behalf of the current user (admin). That is, its local and special variables will be used.
Also note that when checking the syntax, the values of changed variables are NOT saved.