If/else decision tree
  • 08 Jun 2022
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

If/else decision tree

  • Dark
    Light
  • PDF

Article summary

In this article we're going to look at the If/else Decision Tree block.

Use this to test multiple conditions to direct a user down a particular path depending on whether the conditions are met. If/else works much like True/false does, however, instead of having only a TRUE/FALSE avenue for your bot to explore, you can have multiple possible avenues over which you can route a conversation.

NOTE

"If/else Decision Tree" can typically used in conjunction with other blocks such as "Set a variable" which you can find in the "Advanced" category of the block builder.

Let's dive in!


TYPICAL USES FOR THIS:

  • Testing whether multiple conditions are met for one or more variables.
  • Providing your bot with logic that enables it to test certain inputs and/or direct users through decision trees based on the testing of those inputs against variables you have set here.

STEP 1: Add a new block.


STEP 2: Select the "Advanced" category.


STEP 3: Select the "Set a Variable" block.

The following window will appear:


Let's explore the elements of this page.

You have a few elements with which you can interact here such as:

  • Conditions - which are made up of these sub-elements:
    • @@Variable
    • Operator
    • Comparison Value

Let's start with "@@Variable".

You can either select from an existing variable, or simply type in a completely new one. For this example, we are going to use the existing system variable called "@@Gender". For this example, we are going to test whether the user has a known gender in order to direct them appropriately.

Let's set it to "@@Gender"

TIP!
You can click the drop-down to select from system variables or any of your existing variables you have already created. We explore the "Set a variable" block in a previous article. You can also create a new variable here if you'd like, however, you will need to ensure you use the corresponding variable in a new block with the "Set a variable" block to make sure your If/Else test works.

Operator:

The Operator defines how you want to "test" the value of the variable you selected. 

Select from the list of available drop-down options - for the purposes of this example, we are going to choose "Equal To".


Comparison Value:

Based on our example, we want to test if our "@@Gender" variable is "Equal To" a value of "Male".

Therefore, we must set the "Comparison Value" to "Male " (to match the value set in our variable "@@Gender" as follows:


STEP 4: Click on "Save" to save the the True/false block. At minimum, the following elements of this block must be completed:

  • @@Variable you are testing.
  • Operator you are using against the "Comparison Value" for your "@@Variable"
  • Comparison Value - This may or may not be required depending on the operator type.

STEP 5: Use the "+ ADD NEW RULE" button and add a second variable, this time for:

  • Variable "@@Gender" 
  • Operator "Equal To"
  • Value "Female"

Example:

You can "+ADD NEW RULE" if you'd like to test more than the 2 in the above example is met (depending on the scenario of your conditions of course). Simply click on the blue button and complete the conditions as many times as required.


Result:

Once saved, you will see your If/Else Decision Tree block will appear in your bot editor window attached to the last block onto which you added your "If/Else Decision Tree" block.

From here, you can then continue building your bot by adding additional blocks taking whatever avenue you prefer.

Done! You've successfully used the "If/Else Decision Tree" block.


What's Next