arrow-flex-shortarrow-flexarrow arrowsbinocularsbsichartcogsflex-icongeargithubglobelightnings linkedinlock plantscalestarget triangle-icon twitter

The Nuts and Bolts of Dialogflow

Vitalii
June 03, 2019

Dialogflow is a Google service which enables you to build virtual agents that run on Google Cloud Platform. It means you can scale it to be able to handle hundreds of millions of users.

In this article we are going to describe the 3 most important components of Dialogflow in order to explain how to build basic conversation flows using this service. So they are:

1. Intents

To define a conversation’s flow, you need to create intents for your agent that map user utterance to responses.

Intents

In the picture above you can see each intent has a collection of fields like contexts, events, training phrases, responses, etc. Let’s go through some of them.

Training phrases are list of possible sentences or phrases that users might say to match specific intent. But what does “Match intent” mean? Each intent has its own collection of parameters and responses. Once the user says a phrase or sentence similar to a training phrase, DF returns a JSON response including all intent parameters and responses. The short example of a JSON response looks like this


{
  "responseId": "b1b2b434-37fe-4141-8365-98a78742b89e",
  "queryResult": {
    "queryText": "speak to bank staff",
    "parameters": {
      "store_extension": "3223",
      "whisper_message": "Bank Store Branch",
      "final": "yes"
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Thank you. Let’s get you somewhere so we can help you...",
  ...
  }
}

Text response - This field returns the response of the intent. You can specify a variety of responses, DF will pick one of them randomly.

Events - Dialogflow allows us to trigger some intents without using any phrases (API only). For example you may want to greet the user before he or she has said anything. For this you should assign an event to intent and call this event from your app.

Parameters are the list of meta-data which you will receive in a JSON response. This list may also may contain conversation entities which we will explain next.

2. Entities

Entities are Dialogflow's mechanism for identifying and extracting useful data from natural language inputs. Thanks to them you don’t need to get important data from user’s’ utterances. There are the following 3 types of entities:

  • System entities
  • Developer entities
  • Session entities

Entities

System entities - Default entities like phone number, country, number, zip-code, URL, time, address, etc. All these entities are available by default in any Dialogflow agent.

Developer entities - Custom entities created by a developer on Dialogflow. This means you can determine any important information which you would like to get from user’s input. On the picture below you can see the example of developer entity. We created the “Subject” entity to get subject related phrases from the user’s input.

Subject entities

If any user uses “programming” in the utterance, Dialogflow will understand that this was related to Computer Science and return the “computer-science” value.

Session entities - Conversation specific entities. For example, you might create an entity type to represent the time-sensitive options available to a particular user when making a booking. This entity type requires deeper understanding and may be created only through the API.

3. Contexts

Contexts represent the current state of a user's request and allow your agent to carry information from one intent to another. It allows you to create conversations with more than one level, i.e. clarify some details, confirm some actions, etc.

There are two fields for contexts:

Input context - if input context is added to the intent it won’t be triggered unless exactly this context is attached to the request, e.g. let’s imagine we need to create a flow like:


Customer: I want to speak to the manager
Bot: Ok, and what would you like to talk to them about?
Customer: About furniture
Bot: Ok, connecting you to the store manager

So, if the user says “About furniture” as a first utterance, it won’t match the relevant intent, but if it happens after “I want to speak to the manager”, it will trigger the correct intent.

Output contexts - if output context is added to the intent it means this context will be attached to the next N utterances. Where N is the number that is placed before context name, see the picture below. N.P. By default contexts expire in 20 minutes after last usage.

Context

Dialogflow provides default follow-up intents like “yes”, “no”, “repeat”, etc. It adds the list of default training phrases and required contexts. It’s useful when you need to add some common logic to your conversation flow.

Context 2

Dialogflow also allows developers to carry parameters from parent to child intent through contexts. Let’s take a look at an example; we need to build a flow where the user chooses the subject, and then confirm if it’s correct:


Customer: I would like to subscribe to some courses
Bot: What subject are you interested in?
Customer: I would like to improve my programming skills
Bot: Would you like to subscribe to programming courses?
Customer: Yes, it would be great

As we can see here the last utterance is “Yes, it would be great” which doesn’t have any entities like “programming”, so how can we let the backend application know what kind of courses are required? This is possible using the pattern:


#<context_name>.<parameter_name>

The picture below shows the example of a subject parameter from parent’s intent

Subject parameter from parent intent

As you can see Dialogflow is a simple and powerful service which allows us to build automated virtual agents really easily. In this article we reviewed its 3 main components to provide enough information to build basic conversation flows. It has many more interesting and useful features like training, analytics, integrations, etc. All these advantages make the development process simple and enjoyable.

Articles

By using this website you agree to our cookie policy
x