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
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:
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:
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:
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:
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
blockClick on
Buttons
Add the following text message: What kind of seat would you like?
Click on
Add button
, selectGo to
Under
Title
, write WindowUnder
Go To
, select theConfirm booking
blockClick on
+ Add a variable
Fill the
Variable
with seat and theValue
with windowDo the same for the aisle seat option until it looks like so:
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
blockClick on
Text
to add a text messageEnter the following message in the text field: Second class confirmed
Scroll down, and under
Go To
, select theConfirm booking
blockClick
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 itChange its
Go to
to theClass redirect
Go To blockClick
Save
Open the Class block by double clicking on it
Change the
Go to
's inside the Quick Reply Buttons so that they Go toClass 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 support@chatlayer.ai.
Last updated