Conditions
Last updated
Last updated
This section describes the working of conditions within flows. A condition is used to make certain behaviour conditional like:
skipping a node
guarding a trigger
branching
But before going into detail on the above use cases for conditions we will explain the working of conditions.
Conditions are made of one or more rules, also referred to as expressions. An expression is like an equation where two or more values are compared to each other in a predefined way.
The binary addition of the results of all rules will result in either a true or a false outcome. This outcome determines the execution of the logic bound by the condition. For instance, when the condition is used for the "Skip when" option of a node it will skip the node when it evaluates to true.
When you want certain flow nodes to be skipped in certain conditions you can use conditions as "skip logic". Every node in your flow has the ability to be skipped based on a condition. This features is available in the "advanced" section of the properties panel of your flow node.
Triggers to your flows can be guarded by conditions so you can have different entry points for different scenarios. This case you can have a different flow based on user or conversation variables. For instance.
Another way to make your flow behave conditionally is by adding a branch node to your flow. The branches will be executed from left to right whereas the first branched condition that evaluates to true will be executed.
By clicking on the Add condition button the a popup appears in which the condition can be specified. As explained, a condition exists of one or more expressions.
A rule can be based on:
tags
channels
any of the variables
The easiest and most commonly way of creating a rule is by checking the existence of certain tags in your conversation. Therefore the condition type is set to "Tags" initially:
The way the tags are evaluated depends on which expression type is used to compare the selected tags:
any of
One or more of the given tags should be set
all of
All given tags need to be set
none of
None of the provided tags should be set
So the above screenshot shows an example where either the user's phone number or email address need to be filled in to be evaluated to true. This works because the platform will automatically set a user tag when the user's phone number or email address are known, see User tags.
So if, in this example, only one of the tags are present, the condition evaluates to true. If the use case requires both to be present you should set the expression type to 'All of'. If on the other hand you want to check if none of these fields are present you should select 'None of'.
Sometimes you want to execute certain logic based on the channel this conversation is running. This can easily be done using the rule type "channel".
In this example the condition will only validate true on phone channels, which prevents this logic to be executed on any of the other channels.
The most sophisticated way of evaluating rules is using variable comparison. By using logical operators, see next paragraph, the user and/or conversation variables can be compared to certain values in order for the condition to evaluate true or false. Like for instance: when the phone number is equal to a certain number or the user name is equal to a certain name.
You already saw in the above examples the operator ==
being used in a Rule to compare a variable to a value and to compare a channel to one of the channel options. There are also other expression operators that can be used. For instance to check if a variable doesn't equal to a certain value.
The following table describes the different operators in more detail.
==
to check A and B are the same
"info@enreach.com" == info@enreach.com
!=
to check A and B are not the same
"info@enreach.com" != info@dialox.com
Contains
to check if B is a part of A
"info@enreach.com" contains "enreach"
Not contains
to check if B is not part of A
"info@dialox.ai" not contains "enreach"
Starts with
to check if A starts with B
"info@enreach.com" Starts with "info"
Ends with
to check if A ends with B
"info@enreach.com" Ends with "com"
Is empty
to check if A has no value, often used to check if a question was not asked yet.
Email Is Empty
Is not empty
to check if A has a value, often used to check if a question is already asked
Email Is not empty
As explained in the beginning of this chapter, conditions exist out of one or more rules. So when you finished your first rule, feel free to try adding another rule by hovering your mouse over the Rule. Now you see two buttons appear: Add rule and Add group. In this paragraph we focus on adding a new rule.
The new rule can be built in the same way, but now we also need to indicate if this rule adds to the previous rule (AND) or whether the new rule applies separately (OR) in which case just one of the two rules need to evaluate to true instead of both.
When building complex conditions you might want to use groups. A group of rules are evaluated as one. Just as with mathematical evaluations, groups work like parentheses. In this example: (1+1) x (2+2) evaluates to 2 x 4 = 8. When not using the parenthesis, the equation would lead to something completely different: 1 + 1 x 2 + 2 = 5.
A group can be added by hovering the mouse over one of the rules and click on the Add group button:
For conditions it works the same way, so consider the following example:
In this example the condition evaluates to True when either the system is online and the first name of the user is Niels OR the system is offline while the first name is not yet set.