DEV Community

Cover image for Build your chat bot with DialogFlow
Hari Krishnan
Hari Krishnan

Posted on

Build your chat bot with DialogFlow

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.

Top comments (0)