dialogflow

DialogFlow – Introduction and Basics

In this article we will learn about basics that one needs to know about DialogFlow.

Introduction

DialogFlow previously known as API.AI is a Natural Language Understanding (NLU) engine which provides its user a platform to develop intelligent chat-bots. The main benefit of using dialogflow is it provides an intuitive and easy to understand interface to work with.

There are three ways through which one can create a DialogFlow application:

  1. By using dialogflow’s one click integration i.e. you can build a bot without knowing any code.
  2. Using fulfillment to make a bot that has non-conversational functions i.e. getting data from some 3rd party API’s / by integrating your own custom API call.
  3. Integrating DialogFlow API in user defined servers and calling them when needed i.e. making a pure NLU service.

As i mentioned earlier this article is focused on basics of DialogFlow, So no matter which one of the above mentioned method you use it applies to all.

So let’s get started with the terminologies and understanding them.

Agent

Agents can be described as base unit of dialogflow’s NLU module. In my opinion it is a series of request-response pairs i.e.

  1. User interacts with your agent and sends a request.
  2. Natural Language Understanding (NLU) engine processing is done.
  3. And, a response is sent back to the user.

request_response

By looking to above mentioned image we can say that agent is responsible for the conversation flow. If you are new or have been using dialogflow for sometime you know it is a tedious job to every time start from a scratch, to mitigate this Dialogflow provides some pre-built agents to get you started. This Pre-built agents cover common use-cases like hotel booking, navigation, and online shopping.

Now lets understand the basic terminologies that you are going to deal with whenever you are going to create a chat-bot using Dialogflow.

Intents

In simple language Intents are created by the bot developers as a way of intimating the Dialogflow service “here is a list of tasks that the user might ask the chatbot to do”. Generally an intent represents one dialog turn for the conversation.

Lets take an example when a user says any of the following:

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

Here although the phrases seems different but all the phrases seems to be king of greeting. Here the user intents to “Greet”, So in dialogflow we will be handling it by creating an intent named “Greeting” and add all the phrases which a user can use to greet in “Training phrases” section.

Intents

By this we can come to a conclusion that an intent is a way of specifying what the user wants to do (“intention”) and then providing an appropriate response.

Entities

Entities are used to extract parameters from the phrases that are mentioned in Intents. DialogFlow also provides inbuilt entities which are called system entities (e.g. @sys.geo-city or @sys.date).

Here is the definition given by DialogFlow:

entities_definition

That might sound a bit too vague, but there is a reason for that. Entities can actually be used to capture a lot of things like size details, user authentication details, etc. Lets take a look in the below given image and take a detailed look in the entities section.

create-entities

In above image i have defined an entity for getting T-Shirt size details from user. Here i can define up-to 2000 entities which is a huge number. It also provides an option to “Define synonyms” for defined entity parameter so that they can be recognized as the same entry.

Types of entities

There are three types of entities in Dialogflow.

System entities

These are predefined entities – i.e. these are values Dialogflow can extract out of the box, with no assistance from the bot creator. They have the prefix @sys. Here is a list of system entities you can identify in Dialogflow:

  • dates and times
  • numbers (including flight numbers)
  • amounts with units – currency, length, area etc.
  • unit names
  • geography – address, zip code, capital, country, city, state, airport etc
  • contact – email and phone number
  • names
  • music artist and music genre
  • color
  • language

Developer entities

The entities you declare – such as CityList – are called developer entities.

User entities

There is also the concept of “short-lived” entities called user entities. A good example of this is the idea of a user’s custom playlist of songs. (Obviously, since it is end-user specific, there isn’t a way to declare these as developer entities). This is a somewhat advanced concept so I won’t be going into it in too much detail here.

Hopefully, you can now see why the documentation defines entities as “powerful tools for extracting parameter values from natural language inputs”.

Context

dialogflow_contexts

While this is a good definition,We will define it in more simple words. Lets take an example:

Imagine you are passing by your friend and suddenly he says “yes” and you stand clueless why he said yes. similar thing applies with DialogFlow Chat-bot they also need context to figure out what a particular word or sentence means. Without contexts, the word or sentence could have absolutely no meaning or meant something totally different from the user’s original intent.

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

  • User: “Can I register for the XYZ event?”
    (Intent: Register_XYZ, Output Context: register_XYZ)
  • Bot: “Do you have the required documents YYY and ZZZ?”

Now as the context’s definition is clear lets take a look at the lifespan of the context. By default, output contexts expire after either five requests or 20 minutes after its corresponding intent is matched. If the same output context is included in another intent, the context resets the counter and clock to five requests and 20 minutes.

for example if the “likes cats” context has a lifespan of two and the context’s lifespan isn’t reset by its related output, the agent could only observe “likes cats” for two conversational turns, as shown in the following example:

  • “Do you like cats?” – Context is attached to this intent.
  • “Yes, I do.” – Context is set and activated.
  • “Do you want to see a cat picture?” – Turn 1.
  • “Sure!” – Turn 1.
  • “Here’s a cat picture.” – Turn 2 and context is removed.

lifespan

Fulfillment

Fulfillment is code that’s deployed as a webhook that lets your Dialogflow agent call business logic on an intent-by-intent basis. During a conversation, fulfillment allows you to use the information extracted by Dialogflow’s natural language processing to generate dynamic responses or trigger actions on your back-end.

Most Dialogflow agents make use of fulfillment. The following are some example cases where you can use fulfillment to extend an agent:

  • To generate dynamic responses based on information looked up from a database.
  • To place orders based on products a customer has asked for.
  • To implement the rules and winning conditions for a game.

What is a webhook?

The webhook is some code (usually running on a server outside of Dialogflow) which performs your chatbot’s business logic.

In this case, since you want to add two numbers, the webhook will have some code which adds the two numbers. While this might seem like a lot of overhead to have a webhook just to do some simple math computation, that is how Dialogflow works.

The Dialogflow philosophy (as of this writing) is to offload all the business logic to your webhook.

Summary

That is all you need to know about DialogFlow to get started. In next article i will cover step by step process to create a Google Assistant bot. If you have any queries you can leave comment below or contact us through our Facebook page.

2 Replies to “DialogFlow – Introduction and Basics”

Leave a Reply