Creating a Travel Chatbot in Minutes with Dialogflow — Part Two
Last week, we created a simple chatbot to plan our trips such as book a hotel room and reserve a car, and we were able to have some conversations with our chatbot. What we did was designing a conversation flow for parameter value collection within a single intent. This is useful when an action can’t be completed without a specific set of parameter values. Now, we want to manage conversation flow in our Dialogflow chatbot and we want to make our chatbot more sophisticated.
Contexts represent the current context of a user’s request. In our case, we first want date information to pass from BookRooms intent to RentCars intent.
- Create an output context for BookRooms intent, the name of this output context is “setdate”
2. Add “setdate” context as an input context for RentCars intent. Remember, the “setdate” context flows out of BookRooms intent and flows into RentCars intent.
3. Set default value of system date entity to “#setdate.date”.
We are now ready to test our updated agent.
Notice that our agent booked a car at the same date of booking the hotel room. Our agent is smart enough to pick up the default value of the date from BookRooms intent.
We managed to pass information from BookRooms intent to RentCars intent.
Natural human dialogs are filled with follow-ups and confirmations, for example:
User: I want 2 hamburgers and one Cola.
Agent: Do you want fries with that?
User: Sure, sounds good, thanks
Follow-up intents make these types of natural conversation flows easy to build and customize. With this feature of Dialogflow we can define dialog situations that may follow any given “parent” intent we are currently working on.
We are going to set up a follow up intent now. In our case, BookRooms is a parent intent, we simply add a custom follow up intent under BookRooms intent, then we will get a follow up intent named BookRooms — custom. This follow up intent will allow us to rent a car as a follow up to book a hotel room.
We will configure this follow up intent similar with what we did with RentCars intent.
Add several user expressions.
Because this is a follow up intent, we have to get “date” information from input context rather than user expressions. Therefore, we have to manually input “date” parameter.
Set default value for date as “#setdate.date”
Finally, we set the text response.
We are now ready to test our follow up intent.
Not too shabby! Our agent was able to carry on a more natural and helpful conversation with us.
The type of the above dialogs is liner dialogs. The aim of which is to collect the information necessary to complete the required action.
Unless linear dialogs, Non-linear dialogs require more than one intent to implement. Every intent is responsible for extracting some information from the user. Non-linear dialogs branch to the next intent based on responses from the previous intent.
Let’s look at an example of a non-linear dialog. In this example, our agent handles a customer satisfaction survey for a hotel.
It starts with these two questions:
- How would you rate the location of the property?
- How would you rate the facilities at the hotel?
For each question, there are two accepted answers:
To build this dialog we’ll need to set up a new entity — Rating.
Following is an example how dialogs flows.
To implement this type of Non-linear dialog for our customer satisfaction survey, we need to create five different intents.
- Support intent
2. Location-Good intent
If the user rates the hotel location is good:
3. Location-Bad intent
If the user rates the location is bad:
4. Facilities-Good intent
If the user rates the facilities are good:
5. Facilities-Bad intent
If the user rates the facilities are bad:
We are now ready to test our Non-linear dialogs.
Let’s do another test run.
The above are examples that include two branches, there are many more branches existed and feel free to try others and see how they work.
So far, we have been able to manage conversations in Dialogflow chatbot for both linear and non-linear dialogs, and we have been working with Dialogflow’s intuitive interface. Next, we will get to the deployment and 3rd party integration.