5. Flow navigation with variables
In this final tutorial we will look at how to use user information and base different conversational flows on that.
Go Tobot dialog enables the bot to redirect the user to a bot dialog, depending on conditions of the session variables. You can define conditions with operators like
smaller than, etc. You can also combine multiple conditions with
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.
- Create a
Go Tobot dialog with the name
- Add a condition with the '+' sign next to 'If'
- Choose a Go To condition saying 'if class equals first' > go to
selected first classbot message
- Open another condition with the '+' sign, next to 'Else if' and do the same for second class.
- If the user has selected no class at all, we want to redirect the user to the bot dialog
class,which we already created. Here, the traveler will be asked explicitly in which class they want to travel.
- Make sure the parent of this Go To is the
departure dateInput Validation.
- Configure the Go To like this:
selected first classbot dialog. We are going to create buttons and save that information in a variable. Click on 'buttons' and create similar buttons as in the
classInput Validation, to ask the user if they want a window seat. Make sure to save this to a variable. Add a Go To that redirects the user to
selected second classbot dialog. Add a text message saying 'Second class confirmed' and go to
- In the
departure dateInput Validation, change the Go To to
- Open the
classInput Validation. Change buttons so that both choices are redirected to the Go To
class redirect. Change the parent to
What we have now done, is that in
class redirectwe 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
classInput 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 bot dialogs. Sometimes the parent is changed, but the Go Tos not and that can cause issues.
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.