Build your chat bot with DialogFlow
Published: 2021-09-07 10:04:45

__What is dialog flow ?__

Dialog flow is a NLP platform that helps us to provide new ways for users to interact with our product, let the product be anything like a mobile app, web app, interactive voice response system, bots etc. Before going with the implementation we have to have some basic idea about some terminologies of dialog flow.

__IMPLEMENTATION__

__Step 1__

Create a dialog flow agent.

__What is an agent ?__

Agent represents an `individual chat bot` and the chat bot is literally a took that takes user input as text or speech and translates it to structured data format which we can use for further evaluation in our app. For easy understanding, consider `Dialog flow as a virtual call center` and the `agent is a customer service representative` who has been trained to solve a variety of problems.

In our case let's create an agent which would help our users to update their personal information.

__Step 2__

Create intents for the agent. An agent can have multiple intents.

__What is an intent ?__

When an agent receives input (end-user expression) from the user, the agent has identify the intention of the query or information from the user. For this we have to create multiple intents which will be auto identified by the agent with the help of pre-existing machine learning algorithms.

For the personal information agent, we can create our first intent called the UpdatePersonalInfo. 

__Step 3__

Create training phrases for the intent we have created. 

__What are training phrases ?__

They are occurrences or short phrases from the user that will trigger this intent. The machine learning algorithm is going to use Natural Language Processing to figure out which phrases are similar to the one's we add here. The more data we add here, we will get more accurate results. 

For our UpdatePersonalInfo intent, we can add training phrases like `Change my display name`, `How to change my name ?`, `How to change my email ?`, `How to update my personal information ?`, `I want to update my personal information`


__Step 4__

Create parameters.

__What are parameters ?__

When a user triggers an intent, usually there are multiple pieces of information required in order to successfully solve the problem, which can be achieved by using parameters. We can set optional and mandatory parameters that dialog flow will try to collect from the user. 

__Entity__

While creating parameters, dialog flow will require us to map the pre-defined __entities__ like `@sys.any` to automatically validate the input from the user, if it is an email parameter we can have the entity as `@sys.email`.

__Prompts__

We can also set up the prompts for the parameters which dialog flow will use to query the user for the mandatory information. For example, for the name parameter, the prompt will be `What is your name ?`


__Step 5__

__Fulfillment `(Default response or via webhook)`__

From the previous step if the user receives some input from the end-user, if we don't have any additional work to do in the backend, we can `simply define a response in the dialog flow console`. But in a lot of cases, we have to make a call to an api which would be required to fetch responses from a completely separate system and for this, `we need to use a webhook`.

Enabling the webhook will allow us to write custom code on the backend server to format the responses dynamically and handle anything else that the user is trying to do.