Creating a Travel Chatbot in Minutes with Dialogflow — Part One

Susan Li
6 min readJun 14, 2018

--

Photo credit: Dialogflow

Formerly known as Api.ai, Dialogflow is a Google owned developer of human-computer interaction technologies based on natural language conversations.

In this article, I will show you the process of creating a basic travel chatbot using Dialogflow. Because its simple, easy and intuitive user interface, you will not need any deep learning or natural language processing expertise. Together, we will make our hands dirty and build interaction models of intents, context, entities and other building blocks. Let’s get started.

Set Up Dialogflow

Go to www.dialogflow.com/, click “SIGN UP FOR FREE” button.

Figure 1

Dialogflow is closely integrated with other Google products. If you already have a valid Gmail account, set up is easy. After you successfully signed up, you will see a screen like this:

Figure 2

The Building Blocks of Dialogflow

In this section, will focus on understanding the basics:

Create Agent

An agent is a natural language understanding model which understands a user means when this user types a query. We will create an agent and configure it completely from scratch in a minute.

Specify Intents

Intents are user actions or goals that user wants to accomplish when he (or she) types a text message or sentence into a chat window.

There are several different intents, some intents are set up by default at Dialogflow such as welcome and fallback intents. We will set up a few custom intents as well.

Define Entities

Entities are user parameters which are configured according to users. For example, when we book a hotel room, the types of the room and the dates of staying can be entities. We will need to pre-define these so that the Dialogflow can understand them.

User expressions

User expressions are training data for our NLP models. The more user expressions we can configure for our agent, the more intelligent our bot will appear.

Create First Agent

The agent we are going to create is TripPlanner which will help us book hotel rooms and rent cars. After creating the agent, you will see a screen like this:

Figure 3

Note that there are two intents are already created automatically for every agent.

  1. Fallback intents are the rules that are triggered if a user’s expression does not match any other intent. In another word, if our agent can’t figure out what a user says, it will simply call the fallback intents.
  2. Welcome intents have a pre-defined welcome event and text responses and simply saying friendly words to keep the conversation going.

Create Custom Intents

A custom intent is created by us and represents a mapping between what a user says and what action should be taken by our agent. Because our agent’s job is planning trips, so we will create two intents (BookRooms & RentCars).

Figure 4

Define Entities

Entities are powerful tools used for extracting parameter values from natural language inputs. Any important data we want to get from a user’s request, will have a corresponding entity.

There are 3 types of entities: system entities (defined by Dialogflow), developer entities (defined by us), and user entities (built for each individual end-user in every request).

System entities

System entities are pre-built entities provided by Dialogflow in order to facilitate handling the most popular common concepts such as dates and cities. We will encounter them a lot in the following sessions.

Developer entities

Our TripPlanner agent uses a custom developer entity to recognize type of hotel rooms and cars. Therefore, we will focus on learning how to create developer entities such as rooms entity and cars entity.

  1. Rooms entity

After we created a Rooms entity, and added entity values such as single rooms, double rooms etc and their synonyms as a csv file, Dialogflow will set up entity values and corresponding synonyms in a tabular format like so:

Figure 5

2. Cars entity

Similarly, we can define a Cars entity but in a simpler way.

Figure 6

User Expression for Intents

Configure and test RentCars intent

We are going to specify several user expressions (i.e. training phrases) for RentCars intent. When we add user expressions to the “training phrases” section, they are annotated automatically. The system detects the correspondence between words (or phrases) and existing developer and system entities and highlights such words and phrases. It also automatically assigns a parameter name to each detected entity.

The system is able to recognize dates such as June 21, next Monday, the day after tomorrow, tomorrow and so on. These are system entities that defined by Dialogflow. It is also able to understand “sedan, “SUV”, “convertible” and “hatchback” which are developer entities we defined earlier. For the entity we did not define earlier, such as “sport car”, we can add manually.

Figure 7

We will require all of these two parameter names because we need all these information before reserve a car.

Figure 8

Next, we are defining prompts for each parameter name.

Figure 9
Figure 10

Once we have our training parameters set up in order, we can specify the text response for RentCars intent.

Figure 11

We are now ready to test our agent.

Figure 12
Figure 13
Figure 14

So far, we are able to create RentCars intents with custom logic. Similarly, we can create intents for booking hotel rooms.

Configure and test BookRooms intent

Add user expressions. The more examples we add, the smarter our agent becomes.

Figure 15

Define prompts and text response.

Figure 16
Figure 17

Again, let’s test our agent.

Figure 18

Our trip planner chatbot worked!

There are many things we can do to make out agent smarter such as define and add a context to an intent, add follow-up intent and so on. We will save them for the next time.

--

--

Susan Li

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