Deconstructing Chatbots: Getting Started with Dialogflow

Priyanka Vergadia
Google Cloud - Community
4 min readFeb 11, 2019

--

In the last article we introduced Dialogflow, which is an end-to-end tool powered by Natural Language Understanding to facilitate rich and natural conversations. In this article we will dissect the architecture of a chatbot to better understand the building blocks of a conversation experience powered by Dialogflow.

https://www.youtube.com/watch?v=Ov3CDTxZRQc

Here is the high level architecture:

High Level Architecture of a Dialogflow powered conversational experience
  • Dialogflow sits in the middle of the stack.
  • A user can interface with it via all the common channels including text, website, phone app, messengers, twitter, and all the smart voice devices like google home.
  • Dialogflow handles the job of translating natural language into machine-readable data, using a machine learning model trained by your examples.
  • Once it identifies what the user is talking about, it can hand this data to your backend where you use it to make stuff happen
  • At the backend you can fulfill the request by integrating with your other services, databases or even third party tools like your CRM.

Let’s dig one layer deeper into the Dialgflow piece itself.

We first create an Agent within Dialogflow. An agent is essentially your entire chatbot application, the experience of collecting what the user is saying, mapping it to an intent, taking an action on it and providing the user with a response. And in the Agent, this all starts with a trigger event, called an Utterance. This is how our users invoke the chatbot.

So if we say: Hey google, play some music — the whole sentence is utterance. While the phrase “Hey google” is the trigger.

Let’s take another example. Hey Google, talk to Appointment Scheduler. The phrase “talk to Appointment scheduler” is the invocation phrase for our chatbot and “Appointment Scheduler” is the invocation name.

Once the bot is activated and has collected the user utterance. We need to understand the users intent. Essentially, why do they want to talk to our bot..

Intent

So when you say “I want to set up an appointment” — The phrase “set appointment” is the intent here

Or if you ask “What are your hours of operation”? — then hours of operation is the intent.

Training phrases and intent matching

To control all this, you provide Dialogflow with different examples of users intents, like set appointment, hours of operation etc.. Dialogflow then trains a Machine Learning model with many more similar phrases and finally maps the users phrase to the right intent. This process is called intent matching.

Now that we know our users intent, we need to know what to do, to provide a response. For that, you configure Actions and Parameters to define the variables you want to collect and store.

Action and parameters — Entities

Let’s look at an example — Set an appointment for 5am tomorrow.

When a user says that — 5 am and tomorrow are the two critical pieces of information in that statement that we would actually need to book an appointment. Those variables are defined as entities.

Intent Response

Dialogflow offers different types of entities, we will cover those in detail in an upcoming article.

Once we have the variables, we may use them to provide a static response to the user. In most cases we may want to send the variables to our backend, take some action and then provide a dynamic response to the user.

To summarize an intent includes the training phrases, actions and parameters and response. Depending on what services your bot offers, you might typically have from few to 1000’s of intents. They could also be in different languages.

While we are looking at the architecture, it is worth mentioning context. Context is a method for your chatbot to store and access variables so it can exchange information from one intent to another in the conversation. Context is actually a very important topic, so we will cover context in a future article in detail.

Fulfillment is the last piece in the puzzle, it is the code that you write to interface with backend services to respond to a dynamic request.

Dialogflow has inbuilt integration with Google Cloud Functions to interface with your backend.

You can also provide any other custom HTTP or HTTPS endpoint to connect Dialogflow to your backend.

In this article, we looked at a simple high level architecture to set up an agent in Dialogflow, we also learned about intents, entities, context and fulfillment at a high level.

In the next article, I will walk through building a simple appointment scheduler chatbot. So, continue following Deconstructing Chatbots…

--

--

Priyanka Vergadia
Google Cloud - Community

Developer Advocate @Google, Artist & Traveler! Twitter @pvergadia