Conditional IF statement
Checking if a variable is not empty
To verify that a variable contains a value (i.e., it is not None and not an empty string), you must check that it is NOT equal to an empty string.
Correct formula:
"#{value}" != ""
This is essential for validating data, such as ensuring a response was received from an external API call before proceeding.
IF()
Description
if(condition, value_if_true, value_if_false)
condition - trigger
value_if_true - value if True
value_if_false - value if False
Maximum expression length: 2000 characters
Example
Let’s go through a few examples:
SILENCEDAYS_2 = if(SILENCEDAYS_2 == 1, 1, 0). In this case, if the variable SILENCEDAYS_2 exists and equals 1, its value remains 1. If it doesn’t exist or has a different value, it will be set to 0. This is useful before performing mathematical operations to safeguard against empty or undefined variable values.
ClientName = if(ClientName == 1, P1, if(ClientName == 2, P2, if(ClientName == 3, P3, 7))), where P1, P2, P3 are variables.
If ClientName equals 1, then the value P1 will be assigned; if ClientName equals 2, then the value P2 will be assigned; if ClientName equals 3, then the value P3 will be assigned; otherwise, the value 7 will be assigned.
As you can see, nested if constructions can be used. This is useful when you want to teach the bot to calculate the order amount, where the unit price depends on the quantity:
Order_Amount = 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, 25*Quantity, 30*Quantity), 35*Quantity), 40*Quantity), 45*Quantity), 50*Quantity), 55*Quantity), 60*Quantity), 65*Quantity), "Cannot calculate... There was an error somewhere in your order. Please try again from the beginning.") * 100) / 100



Code example for copying
SILENCEDAYS_2 = if(SILENCE_DAYS_2 == 1, 1, 0)
ClientName = if(ClientName == 1, Р1, if(ClientName == 2, Р2, if(ClientName == 3, Р3, 7)))
Order_Amount = 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, 25*Quantity, 30*Quantity), 35*Quantity), 40*Quantity), 45*Quantity), 50*Количество), 55*Quantity), 60*Quantity), 65*Quantity), "Cannot calculate... There was an error somewhere in your order. Please try again from the beginning.") * 100) / 100Last updated