How to calculate a mathematical expression using variables and mathematical functions

Quick access to function descriptions:


The field "Calculator" is provided for any arithmetic calculations and assigning values to variables in the extended settings of blocks

When working with a calculator, the name of a variable cannot start with a number. Cannot: <1_name>, but <name 1>. The variable name cannot consist of two words, use the "" underunderline to separate the character. Cannot <name Client> , but need <Name_Client>

How to use in a constructor.

In the "Variable assignment" box, you do not need to use #{}

An example of counting a variable in the Calculator (Variable Assignment) field

Variables can be written simply by name or by #{}. All variables will automatically be returned to floating-point numbers.

The calculator supports all necessary logical and arithmetic operations.

In the calculator it is possible to use comments, to do this format /* text comment */


"E": number e

Supported operators

"+": addition

"-"': subtraction

"*" multiplication

"/": division

"%'": remainder of division

"^ " "**": degree

"==" "!=" " >" "<" ">=" "<=": comparison operators "and"

"AND" "&&": Logical AND

"or" "OR" "||": logical OR

Important! Logical conditions with variables must be written in the variable field for comparison!

For example,in the picture below, an arrow jump will occur if the NUMBER variable is filled in:

Supported features

Mathematical features

random(low, high) - to get a random number. The input function accepts 2 parameters: lower bound and upper. Example: random(-10,10)

md5(text)" - to get md5 hash from a string. For example hash = md5("Hello world") returns 3e25960a79dbc69b674cd4ec67a72c62

sha256(text) - to get the sha256 hash from the string. For example, hash = sha256 ("Hello world") returns 64ec88ca00b268e5ba1a35678a1b5316d212f4f366b24772325a348aeca37f3c

sha1(text) - to get sha1 hash from string. For example hash = sha1("Hello world") returns 7b502c3a1f48c8609ae212cdfb639dee39673f5e

fac(num) - to obtain factorial. To input takes 1 parameter: number. Example f = fac(5) returns 120

log(num, base) - to get the logarithm value. Input accepts 2 parameters: number and base (default e). For example, f = log(E) returns 1, and f = log(100, 10) returns 2

min(a, b, c) - to find the minimum number of enumerations. There is an unlimited number of parameters (each parameter number). Example: min(4, 2, 9, 6) returns 2

max(a, b, c) - to search for the maximum number of enumerations. There is an unlimited number of parameters (each parameter number). Example: max(4, 2, 9, 6) returns 9

int(num) - to bring fractional numbers to an integer. The fractional part is simply cut off. Example: int(1.8) returns 1

is_int(txt) - to check if a string is a number. Example: is_int("5") returns True, and is_int("text") will return False

is_float(txt) - to check whether a string is a number (including fractional ones)

round(num) - for mathematical rounding of a number. Example: round(1.8). You can round to a certain decimal place. For example: round(1.8888888, 2) will round to 1.89 The difference between "int" and "round" is shown below:

pow(num, st) - to raise a number to a power. Input 2 parameters: number and degree. Example: pow(5, 2) returns 25

"sin" "cos" "tan" "asin" "acos" "atan" "atan2": Trigonometric functions

sqrt(num) - to get the square root of a number. Input 1 parameter: number. Example: sqrt(25) returns 5

floor(num) - to get the whole part from the number. Example: floor(25.66) returns 25

ceil(num) - for rounding a number to a larger number. Example: ceil(25.66) returns 26

abs(num) - absolute value(positive number). Example: abs(-256) returns 256

exp(num) - raising e to the degree of the parameter. Example: exp(2) returns 7.38905609893065

Mathematical functions can be performed not only in the Calculator field, but also directly in the answer field, writing the expression as #{2+2} , #{random (0,100)} etc.

With a click notification

proxy(lnk) - to receive a link with a click notification. The input is given a link. If you pass another parameter after minutes, which is not zero, then the reference is a one-time one. Example:

proxy_date(lnk, date, time) is- to receive a link with a click notification with a specified access time. The first parameter passes the link to the input, the second and third parameter is the date and time when the link stops working. If you pass another parameter after minutes, which is not zero, then the reference is a one-time one. Example:

proxy_timeout(lnk, minut) - to receive a link with a click notification with a specified timer access to it. The first parameter passes the link to the input, the second parameter - the number of minutes the link has. If you pass the third parameter after minutes, which is not zero, then the reference is a one-time one. Example:

The functions are designed to bring links to a short and beautiful look. We recommend that you use the functions below to keep the client from being confused by long multiple-line links.

The functions are similar to those used to retrieve links with a click notification.

Functions below without a callback, unlike proxy

short(lnk) (similar to proxy) - A link is passed to the input. If you pass after minutes another parameter, not equal to zero, the link is a one-time one. hort_timeout" (similar to short_date(lnk, date, time) (similar to proxy_date) (similar to proxy_timeout ) - The first parameter is passed the link, the second and third parameter are the date and time when the link ceases to work. If you pass another parameter after minutes, which is not zero, then the reference will be one-time.

short_timeout(lnk, minut) - The first parameter passes the link, the second parameter - the number of minutes the link acts on. If you pass the third parameter after minutes, which is not zero, then the reference is one-time.

remove_links() - deactivation of all short links sent to the client

remove_one_time_links() - deactivation of all one-time links sent to the client

remove_timer_links() - deactivation of all temporarily available links sent to the client

To work with regular expressions

Searches the string by regular expression.

findall(reg, str, index) - to find all occurrences of a group in a string. 3 parameters. The first regular expression, the second row in which the search takes place. The third optional index of the found result. The index is counted from scratch. That is, the first result found will have index 0.

For example:

findall('.ru /(.+) /', '', 0)

The result will be: ab252acn

sumilar(str1, str2) - to compare strings against the list. Returns True if strings are exposed by less than 30%. Example of use: time zone = if(similar(city, 'Paris'), '0', time_zone)

To work with strings

substring(str, n1, n2) is- for string trimming. The input takes 3 parameters - the original string and the trim boundaries. 2 other parameters: cropping on the left and cropping on the right. If the second parameter is positive, it is long relative to the beginning. If it is negative, it is relative to the end. If the parameters are invalid, the function returns an empty string. To trim from the beginning, pass only one number. Example:

substring('text to trim from the beginning by 4 characters', 4)

substring('text for trimming from 4 to 2 characters', 4, 6)

substring('text for trimming from end to 4 characters', 0, -4)

substring('text for trimming from beginning and end to 4 characters', 4, -4)

endswith(str, substr) - to check whether the string ends with the specified substring or not. The first parameter is a string in which you are looking, the second - what you are looking for

startswith(str, substr) - to check whether the string with the specified substring starts or not. The first parameter of the string in which you are looking, the second - what you are looking for

contains(str1, str2) - to check if the second line is in the first. The first parameter is the string in which you are looking for, the second parameter is the string that you are looking for. The search is case-sensitive. If you do not need to register, pass the third option False

len(str) - to count the number of characters in a string. Example: len("how beautiful this world is!"). The result of the work is shown below:


concat(str1, str2) - for concatenation (addition) of strings, directed to parameter.

splitter(str, s, n) is- to split a string into parts. The first parameter is a string, the second separator, and the third (optional) maximum number of elements. The function returns an array of elements. Example of use: elements = splitter(’s, W, q', ',')

lower(str) - to lower case the string.

upper(str) - to bring a string to the upper case.

strip(str) - for trimming spaces along the edges of a string.

capitalize() - to replace the first character of a string with the same upper case character (writes the big words).

normalizePhone(snumber) is to bring the phone number to the standard look. Removes all but the digits and, if the phone starts with 8, changes it to 7. Example: normalizePhone("+7978-999-99-99"). The result of the work is presented below:

This feature works with all numbers around the world

replace(str, s1, s2, n) - to replace the entry of a string on a different string. Accepts 4 parameters: the line where the replacement will occur, what to replace, how many times to replace (optional). Example: replace("wwww2222ww", "w", "e", 1). Result: ewww2222ww. Example of usage in the figures is shown below:

base64(str) - to encode base64 string

base64decode(str) - to decode base64 into a string

urlencode(str) - to encode a string so that it can be transmitted via http. For example: Ivan Ivanovich will become Ivan%20Ivanovich, and Anna&Maria will become Anna%26Maria

select_random(str, s) - to select a random element in the delimited string. The first parameter is a string with elements, the second divisor. The second default setting is '|'. Example of use: select_random('first element | second element | still element | and another')

tg_escape(str) - to screen a variable to display it in a telegram message with markup enabled. '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'

To work with clients

was_in_state(id) - to check if the client was in a specific circuit block of the schematic block. was_in_state(message_id) - to check if the client was in the selected state(block). Block number can be taken from the editor:

days_from_last_message() - to determine the number of days since the last replica of the client. Created to check for 24-hour window. Example: d = days_from_last_message()

free_client() - to remove a responsible operator Example: free_client()

assign_to_user(email) - to assign a dialog to the operator. Example: assign_to_user('operator email')

If you write this: assign_to_user(), the dialog will be assigned to a random operator who is currently on a shift

distribute_client() - to assign the dialog to the operator according to the auto-detection settings. Example: distribute_client()

get_operator() - to receive the email of the responsible operator. Example: get_operator() Can be used to set a task to the responsible, etc. or to check if there is a responsible operator. If there is no responsible, None will return.

get_operator_name() - to get the name of the responsible operator. Example: get_operator_name() Can be used to output information to the client. If no one is responsible, None will return. If no name is assigned to the operator, the email will be returned.

delete_pended_messages() - to delete all scheduled messages for the current client. By default, it also removes messages created by the "Do not cancel" arrows. In order not to cancel messages from the "Do not cancel" arrow, you must pass the False: delete_pended_messages(False) parameter

set_note(comment) - to add a comment to the dialog. Example: set_note(ː Redo')

add_unread(count=1) - to mark the dialog with the client as unread

clear_unread() - to mark the dialog as read

get_state_id() - to get the funnel stage id in Salebot SRM

change_state(funnel stage id) - to move the lead to the funnel stage by stage id

To check the subscription to Instagram account

check_insta_subscription() is a method for checking whether a client is signed to your Instagram account or not.

Works only on "Premium" tariff

To check whether there is Whatsapp on the phone number

check_whatsapp(snumber) - a method to check if the given number whatsapp

To work with column letters

If you need to translate a column letter into a digit, you can use the c2n calculator if you want to translate the digit into a letter, then use n2c. You can also add column letters to offset via the addCols function, which accepts the first parameter string with the letter column and the second offset. Transmit negative offset to go left.



To work with lists

inlist (list number) - to check for users in the list

Example: Answer = if (inlist(12333) == True, "you are in the list of participants", "you are not in the list")

add_to_list(list number) - to be added to the list

remove_from_list(list number) - to remove from the list

move_to_list(list number) - to move to the list

When moving, the person will be removed from all lists and added to the selected one.

list_size(list number) - to count the number of people in the list

lists_joint_count(array) - to count the number of unique unique people is in several lists.

The input accepts an array with list numbers. Returns a number.

lists_joint_count('[1, 2]')

To work with tasks

Task functions return the True activity execution status or task identifier if successful. In case of failure False or None is returned.

Salebot works with dates in the format "" and with time in the format "HH:MM"

create_task('email of the responsible', 'task name', 'run date', 'description', 'run time') - to create the task

The "Run time" parameter is optional.

The function returns the number of the created task. The other functions work with this number.

update_task('task number','responsible email', 'task name', 'run date', 'description', 'run time') - to update the task

The "Run time" parameter is optional.

done_task('task number')-to mark the completion of the task

delete_task('task number') - to delete the task

To work with messages in Telegram

remove_last_message() - to remove the last message from the bot

Allows you to make changing messages.

It works in Telegram

last_message_id()-to get the number of the last message from the bot

If a picture and text were sent, the message numbers are separated by the underscore symbol

To work with coordinates

distance(lat1, lon1, lat2, lon2)- to calculate the distance between two coordinates in kilometers

Example: distance(52.2296756, 21.0122287, 52.406374, 16.9251681)

Result: 278.5459739738798

To sort arrays and dictionaries

Salebot can sort arrays, dictionaries by value and dictionaries by key in ascending and descending order.

sort(mass, b) sort array or dictionary. Accepts 2 parameters. JSON for sorting and sorting direction. The second parameter is optional, by default it is sorted in ascending order (b = False), and you need to pass True to sort in descending order.


Result: {"Vanessa":15,"Sawyer":4,"John":3}

sort_by_value(dict, b) - Sorts the dictionary by values. Accepts 2 parameters. JSON for sorting and sorting direction. The second parameter is optional, by default it is sorted in ascending order (b = False), and you need to pass True to sort in descending order.

Result: {"John":3,"Sawyer":4,"Vanessa":15}

To send e-mail

send_email(to_email, subject, message) The first parameter is sent to the recipient’s email, the second message header, the third message text. send_email('', 'This is the title', 'And here I write the text')

To check "if" condition

3 parameters: condition, value if condition is true, value if condition is false

To check whether the variable value is empty (whether it is None or "") use the following formula: "#{value}" == "" where value is the variable name For example, this may be necessary when receiving data from a third-party resource through requests.

Example: DAYSOFSILENCE_2 = if(DAYSOFSILENCEA_2 == 1, 1, 0). In this case, if there is a variable DAYOFSILENCE_2 with a value of 1, its value will remain 1, and if it does not exist, it will be 0. It is convenient to use before mathematical operations to insure against empty values of variables. Or another example Customer = if(Customer == 1, P1, if(Customer == 2, P2, if(Customer == 3, P3, 7))), where P1, P2, P3 are variables

You can also use nested if constructs. This is useful if you want to teach a bot to calculate the amount of the order, when the value of the unit of goods depends on its quantity.

For example: Total=round(if(Quantity >=100, if(Quantity >=200, if(Quantity >=300, if(Quantity >=400, if(Quantity >=500, if(Quantity) >=1000, if(Quantity >=2000, if(Quantity) >=3000, if(Quantity >=5000, 25Quantity,30Quantity,35Quantity), 40Quantity), 45Quantity), 50Quantity), 55Quantity), 60Quantity),65*Quantity "I can not calculate... You are mistaken somewhere when placing an order. Try again from the beginning.") *100)/100

Maximum expression length: 1000 characters

The result of such a formula is shown in below, and an example of field filling is also shown below:

Last updated