Dialogflow Basics

Candy Tsai
DeepQ Research Engineering Blog
5 min readMay 22, 2018

Dialogflow is a NLU (Natural Language Understanding) engine to enable users to build intelligent chatbots readily. The major selling point of Dialogflow is its intuitive and easy to use interface. There are three ways to use Dialogflow in an application:

  1. Build a chatbot with absolutely no code: using Dialogflow’s one-click integration
  2. Use the fulfillment system to enable the bot to have various non-conversational functions (e.g. look up the weather, retrieve information via 3rd party APIs)
  3. Purely as an NLU service: the user’s server will call Dialogflow’s API

This article is focused on the fundamentals of Dialogflow, so it doesn’t matter how you use it in an application, the basics all apply.

Agents

I see it as the basic unit for Dialogflow’s NLU modules. The agent converts what the user says into a particular intent and is responsible for the conversation flow.

Basics

  • Intents
  • Contexts
  • Entities
  • Actions and Parameters
  • Events

Intents

What are intents? In a really straightforward explanation, intent is:

What does the sentence mean to the user?

When the user says the following:

  • “How are you?”
  • “What’s up?”
  • “Wazzzup?????”
  • “How do you do?”

Although using totally different words, they all are meant to be a greeting from the user. Therefore, the user’s intent is “Greeting”. In Dialogflow, we would do this by creating a new intent called Greeting and add what the user would say to “Training phrases”.

Create an intent named greeting.

Contexts

Imagine that you are walking past your friends, and overheard someone says “Yes!”. “Yes!” on what? You definitely won’t have a clue.

In chatbots the same rules apply. Just like humans need contexts to figure out what a particular word or sentence means, chatbots need them too. Without contexts, the word or sentence could have absolutely no meaning or meant something totally different from the the user’s original intent.

For example, a context to the answer “Yes!” might be:

  • User: “Can I register for the XXX event?”
    (Intent: Register_XXX, Output Context: register_XXX)
  • Bot: “Do you have the required documents YYY and ZZZ?”
  • User: “Yes!”
    (Intent: Register_XXX_Success, Input Context: register_XXX)
  • Bot: “Send in the documents and see you at XXX!”
Register_XXX Intent
Register_XXX_Success Intent

Now let’s take a closer look at Dialogflow’s contexts. Contexts expires after the given lifespan or 10 minutes. When the context’s lifespan is set to 0, it deletes the context. The lifespan of the context can be set by clicking on the current lifespan number.

The lifespan of the context can be set by clicking on the current lifespan number.

Entities

Entities are used to extract parameter values. Built-in entities, also known as system entities are defined by Dialogflow (e.g. @sys.geo-city or @sys.date).

Developers also can define custom entities like a list of items available in the store.

A items entity

What’s more powerful about entities is that we can assign synonyms so that they can be recognized as the same entry.

Actions and Parameters

Just think of actions as an optional field that the server or fulfillment webhook can receive. Yeah that’s it about actions.

Parameters are pieces of information that we want to retrieve from the user, such as time, location, or anything of interest.

For instance, if the user says “Please tell me the weather”, the bot won’t have enough information about what weather information does the user want. The weather of where? Does the user want today’s weather forecast or tomorrow’s?

In Dialogflow, one can set a parameter to be required. Just think of it as when registering for an account at some website, it would want us to fill the required fields and will not process the form if those fields are not filled.

Events

Everything that we have learnt has one thing in common: the trigger is based on a text message that the user sends. What would happen when the user sends a location message?

Dialogflow by default supports the following events for its one-click integration, therefore, these event names are reserved.

List of reserved names that are supported by default when using Dialogflow’s one-click integrations.

If you have your own server, then you can send API requests to trigger intents with events.

Training

What happens if the bot has no matching intent for what the user says?

Training will collect all of the dialogs and provides an UI for us to assign intents to unmatched phrases.

Analytics

Analytics provides a basic view of how users are using this bot and is associated with Chatbase: https://chatbase.com/.

Chatbase is like Google Analytics for bots.

API V1 vs V2 and BETA Features

On April 17, 2018, Google announced that Dialogflow’s V2 API is generally available. I believe the biggest impact are the following features that are only available in V2:

  • Speech to text
  • New APIs for agents: import, export, restore (can only be done by using the UI in V1)
  • Enterprise Edition

V2 is totally incompatible with V1, so it is undoubtedly going to be a big switch if you are already on V1.

Last but not least, a better version control system is in BETA now!

Other Important Things to Notice

  1. The default language cannot be changed after you create the agent.
  2. If you want training to be available for Chinese, please use zh-CN.

References

--

--

Candy Tsai
DeepQ Research Engineering Blog

Front end developer who specializes in evangelizing Winnie the Pooh.