What are expressions?¶
Expressions are dynamic tools that you can use in messages or actions to perform calculations, evaluations, or use native variables. They are very useful for customizing your bot and making its messages change in real time.
How to write expressions?¶
The format of the expressions is the following:
{expression}
-
They are always enclosed in curly braces
{ }
: This tells the bot that you are using an expression. Example:{2 + 2}
or{first_name}
. -
Optional spaces: You can include or omit spaces inside the curly braces, both will work the same. Example:
{3+5}
and{ 3 + 5 }
are the same.
Data types you can use¶
-
Texts: Written between double or single quotes. Examples:
-
Double quotes:
"Hello"
-
Single quotes:
'World'
-
-
Numbers: Integers and decimals, written without quotes. Examples:
-
Integer:
23
-
Decimal:
17.3
-
-
Dates: Text in a specific format (
"DD-MM-YYYY HH:MM:SS"
). TheHH:MM:SS
(time) part is optional. Examples:-
Date only:
"12-31-2024"
-
Date and time:
"12-31-2024 23:59:59"
-
-
Booleans: Represent
True
orFalse
. -
None
: Represents a non-existent or empty value. Also when an invalid format is used in an expression.
Basic operators for working with expressions¶
-
Arithmetic: For performing mathematical calculations.
+
Addition:{2 + 3}
➡️5
-
Subtraction:{7 - 4}
➡️3
*
Multiplication:{5 * 5}
➡️25
/
Division:{8 / 2}
➡️4
%
Remainder:{10 % 3}
➡️1
**
Exponentiation:{2 ** 3}
➡️8
//
Integer division:{10 // 3}
➡️3
-
Comparison: To evaluate conditions, return
True
orFalse
.==
Equal:{5 == 5}
➡️True
!=
Not equal:{"hello" != "world"}
➡️True
>
Greater than:{10 > 5}
➡️True
<
Less than:{2 < 5}
➡️True
>=
Greater than or equal:{3 >= 3}
➡️True
<=
Less than or equal:{2 <= 3}
➡️True
Practical examples¶
-
Basic calculations:
{2 + 5}
➡️7
{2 * (3 + 1)}
➡️8
-
Using variables:
{balance == 10}
➡️True
orFalse
, depending on the value ofbalance
.{first_name != "John"}
➡️ ReturnsTrue
if the name is notJohn
.
-
Comparing dates:
{"28-02-2024" > "28-02-2023"}
➡️True
, because 2024 is later than 2023.
-
Dynamic text in messages:
"The result of 3 + 2 is {3 + 2}"
➡️"The result of 3 + 2 is 5"