The “Formula” Step is a code editor block where you can perform logical and arithmetic operations, use built-in functions, and manage variables.
With it, you can assign values to fields and variables, calculate metrics, compare data, and build complex scenarios directly inside BotHelp.
Where to Find It and How to Enable It
- In the flow builder, select Add Step → Formula.
- A code editor will open inside the step.
For convenience, you can use the expanded editing mode (the “expand” icon).
How the “Formula” Step Works
- The subscriber enters the step.
- The code in the “Formula” editor is executed (from top to bottom, line by line).
- If the execution is successful, the values are written to the selected variables, and the bot continues along the configured Next Step transition.
- If an error occurs during execution (for example, division by zero, an empty value, or incompatible types), the execution stops at the line where the error occurred.
The results from the lines that were successfully executed are saved, and the remaining code is not executed.
After that, the subscriber proceeds to the next step via the Next Step transition.
Variable Naming Rules
1. General Rules
- A variable name can only start with a letter, not a number.
✅Sum1❌1Sum
- Allowed characters: Latin letters, Cyrillic letters, numbers, and underscores.
- Names cannot match:
-
-
system field names (
user_id,bh_user_id,cuid, etc.); -
the prefixes
clientandglobals; -
reserved programming language words, e.g.,
print,true,false, etc.
-
2. Spaces in Names
If you need spaces in a name, access the variable using index notation:
globals['возраст клиента'] = 27
client['ORDER ID'] = 'A-42'
3. Code Limitations
-
Total code size: up to 50 lines and 5000 characters (including line breaks and tabs).
-
String literals (text in quotes
"...") — up to 1000 characters.
4. Recommendations
-
Use Latin letters for variable names.
-
For multiple words, use underscores:
blog_webinar,order_total. -
Give variables meaningful and unique names — it simplifies debugging and teamwork.
Data Types:
-
Number (integer and decimal):
10,2.5 -
String:
"text" -
Boolean:
True,False -
Date/Time:
"2025-10-10"or"10.10.2025 12:00:00" -
Empty Value:
null
Note: Lists ([1,2,3]), dictionaries ({"a":1}), and objects (None) are not supported in the “Formula” step.
Available Functions in the “Formula” Step
The “Formula” step supports a set of built-in functions for working with numbers, strings, dates, and logical conditions.
They allow you to perform calculations, conversions, and validations directly within the scenario, without relying on external systems.
Mathematical Functions
| Function | Description | Example |
|---|---|---|
round(x) |
Rounds a number to the nearest integer (0.5 rounds up). | round(2.5) → 3 |
abs(x) |
Returns the absolute value of a number. | abs(-5) → 5 |
int(x) |
Converts a value to an integer. | int("42") → 42 |
float(x) |
Converts a string to a floating-point number. | float("12.34") → 12.34 |
str(x) |
Converts a value to a string. | str(100) → "100" |
Arithmetic operations supported: +, -, *, /
Logical and Conditional Functions
| Function | Description | Example |
|---|---|---|
if(condition, then_value, else_value) |
Checks a condition. Returns then_value if true, otherwise else_value. |
if(client.age >= 18, "Adult", "Minor") |
if(condition, then_value) |
If else_value is not specified, returns an empty string. |
if(is_null(client.phone), "Phone not provided") |
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") |
Boolean values supported: True, False
String Functions
| Function | Description | Example |
|---|---|---|
len(text) |
Returns the number of characters in a string. | len("Hello") → 5 |
substring(str, n1, n2) |
Trims a string: n1 = chars to keep from the start, n2 = chars to remove from the end. |
substring("BotHelp", 3, -2) → "tHel" |
upper(text) |
Converts text to uppercase. | upper("hello") → "HELLO" |
lower(text) |
Converts text to lowercase. | lower("HELLO") → "hello" |
split(text, separator) |
Splits a string by a separator and returns the first part. | split("Ivan Petrov", " ") → "Ivan" |
match(text, pattern, ignore_case=True) |
Checks if a string contains a specified word (pattern). | match("buy product", "buy") → True |
Date and Time Functions
| Function | Description | Example |
|---|---|---|
get_current_time() |
Returns the current date and time in the workspace timezone. Format: %Y-%m-%d %H:%M:%S. |
globals.now = get_current_time() → "2025-11-11 16:30:00" |
addYear(date, years) |
Adds or subtracts years (accounts for leap years). Use negative numbers to subtract. | addYear("2020-01-01", 3) → "2023-01-01" |
addMonth(date, months) |
Adds or subtracts months (accounts for month length and leap years). | addMonth("2025-01-10", 2) → "2025-03-10" |
addDays(date, days) |
Adds or subtracts days. Use negative numbers to subtract. | addDays("20.08.2019", -99) → "13.05.2019" |
addMinutes(date, minutes) |
Adds or subtracts minutes (for DateTime values). | addMinutes(get_current_time(), 20) → "2025-11-11 16:50:00" |
format_date(date, "format") |
Converts a date to the specified format. Supported formats: %Y-%m-%d, %d.%m.%Y, %Y-%m-%d %H:%M:%S, %d.%m.%Y %H:%M:%S. |
format_date("2025-10-10", "%d.%m.%Y") → "10.10.2025" |
date_diff(date1, date2, unit) |
Returns the difference between two dates. unit can be "days" or "minutes". |
date_diff(get_current_time(), client.birth_date, "days") → 9125 |
All operations are performed in the workspace timezone. Multiplying or dividing dates will cause a Type Error.
Functional Notes
-
Code in the “Formula” step executes line by line, top to bottom, in an isolated BotHelp environment.
-
Syntax is similar to Python but not identical.
-
Only simple expressions are supported — no loops (
for,while), functions (def), or external imports. -
Code cannot call APIs or access external systems.
-
Variables are created upon first assignment.
Если вы не нашли ответ на свой вопрос, задайте его нам в чате внутри кабинета либо напишите в Telegram BotHelpSupportBot или на почту hello@bothelp.io
Получите 14 дней полного функционала платформы для создания рассылок, автоворонок и чат-ботов BotHelp.