Google Dialogflow
- Shuvam Aich
- Jun 21, 2021
- 5 min read
Updated: Aug 24, 2021
Dialogflow is a natural language understanding platform that makes it easy to design and integrate a conversational user interface into your mobile app, web application, device, bot, interactive voice response system, and so on. Using Dialogflow, you can provide new and engaging ways for users to interact with your product.
Dialogflow can analyze multiple types of input from your customers, including text or audio inputs (like from a phone or voice recording). It can also respond to your customers in a couple of ways, either through text or with synthetic speech.

Creating an Agent: BurgerBot
We first need to assign a name to the chatbot, in our case it is BurgerBot. It creates a conversational agent for us. This is the console where we are going to work:

There are two default intents already created:
The default fallback intent
The default Welcome intent
We train our chatbot to identify user intentions with the help of the intents.

Eg. "I want to set an appointment". To set an appointment - here is an intent. To control this we provide Dialogflow with different examples of user's intent. Dialogflow then trains the machine learning model and maps the user's phrase to the correct intent. This process is called intent matching.
After knowing the user's intents, we would like to provide them with a response. With Actions and Parameters, we can collect the variables we want to store. For eg. "Call me Shuvam", here Shuvam needs to be stored and identified as my name by the chatbot in order to remember me by that name and produce an output whenever I interact with the chatbot. Or we can also store the variable in our backend database for later purposes to give a dynamic response.
Thus an intent consists of the following:
Training Phrases
Actions and Parameters
Response
Changing our Welcome intent
Our welcome intent is set by default. The default training phrases include - heya, hello, hi, howdy, hi there, greetings, etc. and it also includes default test phrases as responses to these training phrases eg. Hey! How can I help you?
As we are trying to make BurgerBot, a chatbot for a restaurant called BurgerPalace, we set our response to our default training phrases to Hey there! Welcome to Burger Palace. I am Burgerbot and I am here to assist you. Then we add another response: Before we begin your order, can I get your name? Now response to this phrase should be collected as a variable to be referred in the future.
Creating an intent: Delivery
Suppose we write "I want to order a burger" to the chatbot. The chatbot responds with the default fallback intent: "Sorry, I could not understand you." This is because we have not yet trained our model to respond to such user utterances. So lets create an intent called Delivery.
The intent, Delivery, consists 8-9 training examples related to delivery of the food eg. Do you deliver? Do you provide home delivery? etc. The default response to these questions as "Due to the current pandemic situation, we are only providing home delivery. We will ask for an address to deliver once we finish taking your order".
Creating another intent: Operation Time
Training Phrases:
What is your opening time?
What is your closing time?
What are your delivery timings?
Is the shop open?
What are your working hours?
Responses:
We are open 7 days a week from 10:00 am to 22:00 pm. But due to the current pandemic situation, we are only offering home delivery services.
Creating another intent: Order
Training Phrases:
Can I order?
I would like to place an order
I would like to order a burger
Can you take my order?
I want the cheese burger
Responses:
Great! We have confirmed your order.
Creating another intent: Thank You
Training Phrases:
Thank you very much
Thank You
Thank you for placing my order
Thanks for the service.
Great! Thanks a lot.
Responses:
You're Welcome.
We hope to see you again.
Entities
Entities are used to pick out specific pieces of information that the user mentions while chatting with the bot. It can be anything starting from street address to product names and amounts with units - any important form of data that we want to get from an user's request. Dialogflow has three kinds of entities:
System Entities
Developer Entities
User Entities
System entities are built in entities and they cover common use cases such as names, dates, geography, etc.
Developer Entities allow us to define our own entities based on list of words. When user gives an input, words are matched through the list and even the synonyms can be matched from that list to let our agent know that the user has given us some useful piece of data in his input.
User entities are defined for a specific user session. It helps us to match the details of the user, such as previous orders, etc. They can be created through APIs.
In our project, we are only going to use system and developer entities.
Creating an entity: Toppings

Creating another entity: BunOptions

Now we move to our "Order" intent and map our entities to training phrases. Eg. in the phrase "I want a cheese burger" we can map toppings with cheese.

We have also set some prompts. If we do not mention the toppings or the bun options, a prompt will ask us to enter the option.
Follow up intents and contexts
During a conversation, when our agent needs to ask a user any follow up questions what we can do is we can give follow up intents to automatically set context for a pair of intents. A follow up intent is a child of its associated parent intent.
Contexts are used to control the flow of a conversation. Dialogflow contexts are similar to our natural language context. So for example, if a person says to you, "they are orange in color", so you need context in order to understand what "they" are. Similarly for dialogflow to handle an end user expression, it needs to be provided with context in order to correctly
match an intent.
First lets create a custom follow up intent for the "Welcome" intent i.e. if the user types phrases like hello, hi, etc. Now lets add training phrases to take the name as input.

If we want to access the person's name in any other intent apart from this intent, we will have to set up an output context. So inside the output context we are going to add person and this 5 here is the life span, so life span is the number of conversational rounds for which a context remains active, after which it expires and then we won't be able to access it. So click on this five and change it to 10

Now we create a follow up intent "yes" for "order" intent where we asked for the confirmation of the order to the customer and handle the response which can be yes or no.
This is the default response to that intent:

Then we create a follow up intent "no" for "order" intent where we asked for the confirmation of the order to the customer and handle the response which can be yes or no.
Finally to test the chatbot, go to Integrations and select Dialogflow Messenger. And its done! We now have a fully functioning chatbot.
Comments