Creating a Travel Chatbot in Minutes with Dialogflow — Part Two

Susan Li
6 min readJun 17, 2018

--

Photo credit: Dialogflow

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

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.

  1. Create an output context for BookRooms intent, the name of this output context is “setdate”
Figure 1

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.

Figure 2

3. Set default value of system date entity to “#setdate.date”.

#Figure 3

We are now ready to test our updated agent.

Figure 4
Figure 5

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.

Figure 6

We managed to pass information from BookRooms intent to RentCars intent.

Follow-Up Intents

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.

Figure 7

We will configure this follow up intent similar with what we did with RentCars intent.

Add several user expressions.

Figure 8

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.

Figure 9

Set default value for date as “#setdate.date”

Figure 10

Finally, we set the text response.

Figure 11

We are now ready to test our follow up intent.

Figure 12
Figure 13

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.

Non-linear Dialogs

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:

  • good
  • bad

To build this dialog we’ll need to set up a new entity — Rating.

Figure 14

Following is an example how dialogs flows.

Figure 15

To implement this type of Non-linear dialog for our customer satisfaction survey, we need to create five different intents.

  1. Support intent
Figure 16
Figure 17
Figure 18

2. Location-Good intent

If the user rates the hotel location is good:

Figure 19
Figure 20
Figure 21
Figure 22

3. Location-Bad intent

If the user rates the location is bad:

Figure 23
Figure 24
Figure 25
Figure 26

4. Facilities-Good intent

If the user rates the facilities are good:

Figure 27
Figure 28
Figure 29
Figure 30

5. Facilities-Bad intent

If the user rates the facilities are bad:

Figure 31
Figure 32
Figure 33
Figure 34

We are now ready to test our Non-linear dialogs.

Figure 35
Figure 36
Figure 37

Let’s do another test run.

Figure 38
Figure 39
Figure 40

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.

--

--

Susan Li

Changing the world, one post at a time. Sr Data Scientist, Toronto Canada. https://www.linkedin.com/in/susanli/