Skip to content

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}
  1. They are always enclosed in curly braces { }: This tells the bot that you are using an expression. Example: {2 + 2} or {first_name}.

  2. 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

  1. Texts: Written between double or single quotes. Examples:

    • Double quotes:

      "Hello"
      
    • Single quotes:

      'World'
      
  2. Numbers: Integers and decimals, written without quotes. Examples:

    • Integer:

      23
      
    • Decimal:

      17.3
      
  3. Dates: Text in a specific format ("DD-MM-YYYY HH:MM:SS"). The HH:MM:SS (time) part is optional. Examples:

    • Date only:

      "12-31-2024"
      
    • Date and time:

      "12-31-2024 23:59:59"
      
  4. Booleans: Represent True or False.

  5. None: Represents a non-existent or empty value. Also when an invalid format is used in an expression.


Basic operators for working with expressions

  1. 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
  2. Comparison: To evaluate conditions, return True or False.

    • == 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

  1. Basic calculations:

    • {2 + 5} ➡️ 7
    • {2 * (3 + 1)} ➡️ 8
  2. Using variables:

    • {balance == 10} ➡️ True or False, depending on the value of balance.
    • {first_name != "John"} ➡️ Returns True if the name is not John.
  3. Comparing dates:

    • {"28-02-2024" > "28-02-2023"} ➡️ True, because 2024 is later than 2023.
  4. Dynamic text in messages:

    • "The result of 3 + 2 is {3 + 2}" ➡️ "The result of 3 + 2 is 5"