4. Steer the conversation with Conditions

In the previous lesson, you learned how to get user input and re-use it as variables. Let's see now how the conversation can be steered in different directions based on variables.

Apart from being re-used inside the conversation itself, variables can help the bot steer the conversation in different directions, by using Condition blocks.

Step 8: Check a variable in a Condition block

Our Bee bot now asks if the user is new, then asks the user information.

We would like Bee to give a slightly different answer depending on if the user is new or returning. To do so, weโ€™ll need a Condition block that checks a {userType} variable.

Condition blocks enable your bot to redirect the user to another block depending on the conditions of the session variables, following an if-then logic.

Get variables under button clicks

Weโ€™ll save a {userType} variable under button click of the Check user type block. This variable can have either the value returning or new.

To save a variable under a button click:

  1. Open the Check user type block.

  2. Under the first Iโ€™m new button, click on + Add a variable and create the variable userType.

  1. Add the value new.

  2. For the second button, do the same with the value returning.

  1. Save your changes.

Now, when a user clicks on one of these buttons, the system will remember the {userType} variable. Let's utilize this variable within a Condition block.

Add a Condition block

We aim to create a Condition block that evaluates the {userType} variable and provides a different response based on its value.

To add a Condition block:

  1. Open the Next block block.

  2. Go to its Settings.

  3. Change its Type to Condition.

  1. Youโ€™ll get a warning message. Click Yes, change type.

  2. Under Bot dialog name, change the block name to Route userType.

  1. Go back to its configuration, and click on the + to add your first condition.

  2. Fill in the block as follows, using the equal case insensitive operator:

    • If {userType} = new,

      • then Go to Send email new user. You can create this new block directly from the text field.

    • Else if {userType} = returning,

      • then Go to Send email returning user. You can create this new block directly from the text field.

    • Else:

      • Go to Error occurred.

The Error occurred block is a default block triggered when an API integration fails to complete a certain request, or when Chatlayer considers your bot to be blocked in a loop.

Your window should look like this:

  1. Save your changes.

Your canvas looks a bit messy now, and thatโ€™s totally normal. Letโ€™s organize it a bit:

Organize your flow

To re-organize your flow when it looks messy, click on the Auto-layout button at the bottom-right corner of your canvas.

What we created should look like this now:

Lesson 4 recap

Congratulations! In this lesson, youโ€™ve learned how to:

Coming next

Coming next, weโ€™ll see how to connect your bot to 3rd party providers so that you leverage your botโ€™s functionalities.

5. Empower your bot with Actions

๐Ÿ’ฌ Feedback

Your feedback on the tutorial means the world to us! Please, let us know what you think through this short form.

Last updated