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.
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:
The Building Blocks of Dialogflow
In this section, will focus on understanding the basics:
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.
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.
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 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:
Note that there are two intents are already created automatically for every agent.
- 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.
- 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).
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 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.
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.
- 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:
2. Cars entity
Similarly, we can define a Cars entity but in a simpler way.
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.
We will require all of these two parameter names because we need all these information before reserve a car.
Next, we are defining prompts for each parameter name.
Once we have our training parameters set up in order, we can specify the text response for RentCars intent.
We are now ready to test our agent.
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.
Define prompts and text response.
Again, let’s test our agent.
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.