Links

5. Flow navigation with variables

In this tutorial we will look at how to steer the conversation depending on user input.

Step 19: Go to bot block

The Go To block enables the bot to redirect the user to another block, depending on conditions of the session variables. You can define conditions with operators like equals, greater than, smaller than, etc. You can also combine multiple conditions with AND and OR.
Consider the following scenario where the user asks the bot the following:
I want to book a train from Paris to London in first class please.
We already have a lot of information in this expression. Let's say we now want to show a different message for first class tickets, seeing there are more facilities in first than in second class.
  • Drag and drop a Go To block to your canvas
Drag and drop a Go To block to your canvas
  • This will open the Go To block
  • Click on '+' to add an If condition
  • Fill the condition so that if the variable class equals first, then the bot will go to a new block that you'll call Selected first class. It should look like so:
Make an If condition within a Go To block
  • Click on '+' again to add another condition, and fill it in so that it checks if the selected class was second. Steer the conversation to a new Selected second class block accordingly. It should look like so:
Make an Else If condition within a Go To block
  • If the user has selected no class at all, we want to redirect the user to the bot block , which we already created. There, the traveler will be asked explicitly in which class they want to travel. Fill your last condition accordingly:
Fill an Else condition within a Go To block
  • Now, on top of the window, click on Settings
  • Change the block name by 'Class redirect'
  • Click Create to save your changes
On your canvas, your Go To block should look like so:
The Go To block Class redirect checks the class and redirects the conversation accordingly.

Step 20: First class options

Let's now add buttons to our blocks so that the user can also choose a seat on the train. To do this, we will save the user seat option under a variable:
  • Open the Selected first class block
  • Click on Buttons
  • Add the following text message: What kind of seat would you like?
  • Click on Add button, select Go to
  • Under Title, write Window
  • Under Go To, select the Confirm booking block
  • Click on + Add a variable
  • Fill the Variable with seat and the Value with window
  • Do the same for the aisle seat option until it looks like so:
Save the user input into a variable by using buttons
  • Click on Save to save your changes
Now your user's seat option is asked and saved through a button click!

Step 21: Final touches

  • Open Selected second class block
  • Click on Text to add a text message
  • Enter the following message in the text field: Second class confirmed
  • Scroll down, and under Go To, select the Confirm booking block
  • Click Save to save your changes
At this stage, your canvas should look like so:
Now, let's make sure that after the user was asked for a departure date, then the bot checks if they have selected a class:
  • Open the Departure date block by double clicking on it
  • Change its Go to to the Class redirect Go To block
  • Click Save
  • Open the Class block by double clicking on it
  • Change the Go to's inside the Quick Reply Buttons so that they Go to Class redirect
  • Click Save
Your canvas should look like so:
What we have now done, is that in Class redirect we check if the class has already been given in the expression by the user. If that is the case, we confirm second class or give extra options for first class. If class has not been given yet, the user can choose this in the Class Input Validation. If the user chooses their class in the Input Validation, then they are redirected to the class options.
Let's test this new functionality in the emulator:
​
That looks great! If something is not working correctly, double check the Go Tos in the blocks. Sometimes the parent is changed, but the Go Tos not and that can cause issues.

Lesson recap

That was it! You have completed Choo Choo, great job!
You should now be comfortable with the basics of bot building on the Chatlayer platform:
  • Creating Bot Messages
  • Asking for user input in Input Validations
  • Creating intents and expressions
  • Using contextual entities
  • Using a Go To to steer the conversation
Make sure to check out the rest of the documentation as well.
Good luck with building your own bot! If you have any questions, please do not hesitate to contact us at [email protected].
​