Operators

Operators are symbols (or keywords) that indicate various kinds of operations. Operators can be used in AEL expressions, both in responses and input fields (eg. memory).

The following list contains three types of operators:

  • Arithmetic operators perform mathematical operations on numbers. Their results are numbers.
  • Comparison operators compare values with each other. Their results are booleans (true or false).
  • Logical operators connect expressions which results are booleans. Their results are also booleans (true or false).

List of operators

Arithmetic operators

Arithmetic operators perform mathematical operations on numbers. These numbers are called operands. Operands can be literal numbers (eg. 5, 0, 1.5, 319) or numbers stored as variables (eg. memory.someSavedNumber, nlu.variables.numeral.value).

The following table contains all of the arithmetic operators:

OperatorDescription
+Addition. For example, 5 + 4 will return 9
-Subtraction. For example, 5 - 4 will return 1
*Multiplication. For example, 5 * 4 will return 20
/Subtraction. For example, 5 / 4 will return 1.25
%Modulus (remainder). For example, 5 % 4 will return 1

In the example below, the subtraction operator - is used to define memory value memory.available_rooms by substracting the number of bookings received from the number of total available rooms.

470

Adding the expression {memory.available_rooms} in the response, where available_rooms is the key name of the result value of the subtraction, prints the result 1 as the bot's response.

1266

Comparison operators

Comparison operators compare two values with each other. Their results are bolleans (true or false), based on if the comparison is true.

For example, 1 = 3 will return false, and 3 > 1 will return true.

The following table contains all of the comparison operators:

OperatorDescription
=Equality operator. Compares the equality of two operands of the same type. Returns true if they are identical, and false if not. You can compare the two values of each of the following data types: numbers, strings, dates, arrays and objects.
!=Inequality operator. Compares inequality of two operands. It will return false where = would return true. You can compare the two values of each of the following data types: numbers, strings, dates, arrays and objects.
>Greater than. Returns a boolean value true if the left-side value is greater than the right-side value; otherwise, returns false. You can compare the two values of each of the following data types: numbers, dates.
<Less than.Returns a boolean value true if the left-side value is less than the right-side value; otherwise, returns false. You can compare the two values of each of the following data types: numbers, dates.
>=Greater than or equal. Returns a boolean value true if the left-side value is greater than or equal to the right-side value; otherwise, returns false. You can compare the two values of each of the following data types: numbers, dates.
<=Less than or equal. Returns a boolean value true if the left-side value is less than or equal to the right-side value; otherwise, returns false. You can compare the two values of each of the following data types: numbers, dates.

Comparison operators in conditions fields

Besides in AEL expressions, you can also use comparison operators in condition fields of Outputs and Conditional rsponses. Learn more about condition fields.

Examples:

874

The first condition's operator checks if the intent equals (correspond to) "confirmation", whereas the second condition's operator checks if the intent score is grater than or equal to 0.6.

866

This operator checks if the variable's value is lower than 18.

Logical operators

Logical operators and and or are used to connect two or more expressions.

The result of each of the connected expressions has to be a boolean (true or false). If any of these expressions does not result in a boolean, such error will appear: Logical operations are only supported by boolean values.

The result of using logical operator is always a boolean.

OperatorDescription
andIt results in true if both of the expressions result in true. Otherwise, it results in false.
orIt results in true if at least one of the expressions results in true. Otherwise, it results in false.
notChanges true to false and vice versa, eg. not (5 > 1) will result in false, and not false will result in true.

You can find the logical operators in the Memory parameters of the Custom blocks or in the Output conditions needed to steer a conversation.

AND operator

872

In the example above, the bot checks if the user is logged in AND if the intent matched is "transfer". If any of the two conditions are not matched, the bot will not continue.

OR operator

874

In the example above, if the nlu.user_input is "Electricity" is matched or if the variable "electricity" is matched the bot will continue. Just one of the two conditions is needed.

Examples

Using Operators in Response fields

Operators are used to define conditions in Response fields.

918

What’s Next