CONDITION

Conditional branching is a way of directing users to the next block based on conditions. The condition from top to bottom will correspond to the branch from left to right.

1. How it works

So how does the bot decide which branch to take? This is where the magic happens.

Each branch contains a set of conditions. You can take a value from elsewhere in the flow (e.g. a user response or data from an api call) and check to see whether it meets those conditions.

(To see how to refer to data from elsewhere in your flow check double brace syntax.)

The Bot starts from the first Branch (Top most/Left most) and checks for all the conditions that you have set. It will then simply jump to the first branch for which conditions are met. A branch giving true and matching conditions means that the conditions within that branch are met and satisfied. Jumping to that branch means it will follow the direction of that branch (i.e. wherever you connected the corresponding socket).

Are you more confused now than before?

If so take the example from below:

Over here we are checking the user response from a block named block_1, hence the value we are comparing is {{ursp.block_1}}.

In the first branch we check if {{ursp.block_1}} is less than OR equal to 20,000. Meanwhile, the 2nd Branch has conditions to check if the user response on block gid_1 is greater than 20,000 AND less than 50,000. There is also a third and final branch called a default branch, which will be discussed in a bit.

The system checks each branch in order from top to bottom. So in the example above, it will take the first branch and check whether {{ursp.block_1}} is less than 20,000 or equal to 20,000. If the response meets these conditions, it will not check branch 2 and push the conversation in the direction of branch 1 (i.e. wherever you connected the socket corresponding to branch 1). If it doesn’t meet this condition, it will check branch 2. If it does meet the conditions in branch 2, the conversation will move in the direction of branch 2 (i.e. wherever you connected the socket corresponding to branch 2).

But what if it meets neither of these conditions? What if in the above example {{ursp.block_1}} is 60,000? It is not less than or equal to 20,000 so branch 1 will not be activated. It is not in between 20,000 and 50,000 so branch 2 will not be activated. This is where the default branch comes into play. The default branch is a fallback. If the bot checks every branch that you have created and none of them are activated, then the bot will send you in the direction of the default branch.

AND/OR

With conditional jump feature, you can check multiple conditions in a single branch (in branch two we check if the number is above 20,000 and below 50,000). The way you can do this is using the AND/OR operator within the branch:

The way this works is as you would expect it. If you have two conditions in a branch: condition A and condition B. If a branch calls for condition A AND condition B, then the value being compared has to satisfy condition A and condition B (i.e. the user response has to be both greater than 20,000 AND less than 50,000).

If a condition calls for condition A OR condition B, then the value being compared has to satisfy either condition A OR condition B. Take the following example:

If {{ursp.block_1}} is 30,000 this branch will not be activated. If {{ursp.block_1}} is 10,000 this branch will be activated. If {{ursp.block_1}} is 60,000 this branch will be activated.

What if there are more than two conditions?

Like this:

The branches with the ANDs condition always get grouped together. This means that in the above example {{ursp.block_1}} has to either be less than 20,000 OR between 50,000 AND 70,0000. Consider the following test values:

10,000 will activate this branch

60,000 will activate this branch

30,000 will NOT activate this branch

Think about it this way: when you have AND statements continuously, put a pair of parentheses around all the AND conditions. Consider the following set up:

This would be evaluated as:

condition A OR (condition B AND condition C AND condition D AND condition E) OR condition F

Or {{ursp.block_1}} has to be less than 3,000 OR (between 5,000 AND 500,000 AND NOT equal to 300,000 AND NOT equal to 400,000) OR greater than 700,000

Consider the following test terms:

2,000 -> branch activated

4,000-> branch NOT activated

7,000 -> branch activated

250,000 -> branch activated

300,000 -> branch activated

800,000 -> branch activated

Comparison Operators

Broadly speaking you can make two types of comparison. Number comparisons and String comparison.

Number comparison is used when you want to check a number input that the user has submitted. Like all of the examples above. With number comparison, you can check the whether a value is equal to, not equal to, less than or greater than a specific value. Check the examples above again, I have used all of them at some point.

With String Comparison, you can compare pieces of text. So if a user response is a piece of text (say a city name) using the auto-suggestion feature, you can check and see what city the user typed in using the string comparison.

So what operators do you have access to within String comparison?

Is, Is not, Contains, Not contains.

These operators are fairly self-explanatory, but here is a quick rundown.

Look at the following setup to check the name input by a user:

Contains Operator checks to see if the value you want to check contains a specified string. In the above example, the condition in branch 1 checks to see whether {{ursp.block_1}} (i.e. the user response in the block named block_1) contains Ty. If {{ursp.block_1}} does contain Ty, then branch 1 is activated.

Is Operator checks to see if the value you want to check is a specified string. In the above example, the condition in branch 2 checks to see whether {{ursp.block_1}} is Nguyen. If it is Nguyen, then branch 2 is activated

Not Contains Operator checks to see if the value you want to check does not contain a specified string. In the above example, the condition in branch 3 checks to see whether {{ursp.block_1}} does not contain Phong. If it does not contain Phong, branch 3 is activated.

Is not Operator checks to see if the value you want to check is not a specified string. In the above example, the condition in branch 4 checks to see whether {{ursp.block_1}} is Le. If it is NOT Le, branch 4 is activated.

2. Create Conditional Branching

Method 1. Check on Conditional Branching

Once you check on Conditional Branching, you will see the section to configure Conditional Jump like this:

Add more branchs

Add conditions and logical operators

The condition from top to bottom corresponds to the branch from left to right

Method 2. Create CONDITION block

Once you create CONDITION block, you will see the section to configure Conditional Jump like this: