The functions in this group check conditions and pick the right value right inside the formula — without a separate “Condition” step.
Where it helps:
- calculate a discount based on several conditions at once;
- check whether a field is filled and show the subscriber a clear message;
- avoid calculation errors such as division by zero.
Boolean values are supported: True, False.
Functions
| Function | Description | Example |
|---|---|---|
| if(condition, then_value, else_value) | Checks a condition. If it is true, returns then_value; otherwise, returns else_value. Only the matching branch is calculated, so if(x != 0, 10 / x, 0) doesn't cause an error when x = 0. | if(client.age >= 18, "Взрослый", "Несовершеннолетний") |
| if(condition, then_value) | If else_value is not specified, returns an empty string. | if(is_null(client.phone), "Номер не указан") |
| is_null(var) | Checks if a variable is empty. | is_null(client.email) → True |
| and, or, not | Logical operators for combining conditions. | if(a > 0 and b < 10, "ok") |
| is_int(value) | Checks whether the value is an integer. Also works with strings. | is_int("42") → True is_int(5.5) → False |
| is_float(value) | Checks whether the value is a number, integer or decimal. Also works with strings; the decimal separator can be a dot or a comma. | is_float("5,5") → True |
Example: a discount based on several conditions
Let’s calculate the final discount based on previous purchases and the number of completed lessons. Make sure all the variables are created in advance.
# 1. Loyalty: 20% discount if purchases > 3 base_discount = if(client.sum_orders > 3, 20, 0) # 2. Engagement: 20% for >=10 lessons, 10% for >=5 engagement_discount = if(client.completed_lessons >= 10, 20, if(client.completed_lessons >= 5, 10, 0)) # 3. Final discount client.discount = base_discount + engagement_discount
In line 2 we use the if condition:
- if there are more than 3 purchases, base_discount = 20;
- otherwise — 0.
In line 5 the condition is double:
- 10 or more lessons — engagement_discount = 20;
- 5 or more — 10;
- otherwise — 0.
base_discount and engagement_discount are variables without a prefix. They work only inside the current “Formula” step and are used for intermediate calculations.
In line 8 we add them up and save the result to the user variable discount, which you can show to the subscriber in the next steps.
Example: check whether a field is filled (is_null)
Let’s check whether the subscriber entered a value, get the technical result (True / False) and show a clear message.
- Check the variable with
is_null(). - Save the result to a separate variable.
- Use
if()to turn the result into text for the subscriber. - Show the result in a message.
client.A = is_null(client.answer) client.D = if(is_null(client.answer), "Field is empty", "Field is not empty")
Output in the message:
{%A%}{%D%}
What the subscriber sees
If the field is empty:
1Field is empty
If the field is filled:
0Field is not empty
Important: is_null() returns a logical value. When saved to a variable, 1 means True and 0 means False. The result can only be saved to a variable of the number or text type.
Example: a calculation without a division-by-zero error
if calculates only the matching branch, so the division isn’t performed when there are no orders yet.
client.avg_check = if(client.orders_count != 0, client.revenue / client.orders_count, 0)
If the subscriber has 0 orders, avg_check gets 0 instead of an error.
If you did not find the answer to your question, feel free to contact us in the chat inside your dashboard, message us on Telegram at @BotHelpSupportBot, or email us at hello@bothelp.io.
Enjoy the full functionality of the BotHelp platform for creating broadcasts, automated funnels, and chatbots — free for 14 days.
Sign up for BotHelp
Get 14 days of full access for free — enough to build your first bot and test it on real subscribers.
Create account