Conversational AI With DialogFlow - DigiBP/digibp.github.io GitHub Wiki

This hands-on demonstrates how to create a Conversational AI implementation with Google DialogFlow for a pizza ordering service.

Contents:

Pre-requisite - Google account

You need a Google account to follow this tutorial.

1. DialogFlow SignIn

Access the DialogFlow on www.dialogflow.com and sign in with your Google account. After successful sign-in, DialogFlow will prompt you for necessary permissions as shown in the figure below.

Click on Allow button and you will be directed to the DialogFlow homepage. Click on the "Go To Console" link on the top right corner, as shown in the figure below.

2. Create a basic agent

Now you can start creating your basic pizza order agent.

a. Create new agent

Add the name of your agent, for eg. "PizzaService" and click Create, as shown in the figure below. This will create a new agent and you will be taken to the Intents section.

Your agent has two default intents - Default Welcome Intent and Default Fallback Intent.

b. Welcome Intent

Let's modify the Default Welcome Intent for the pizza order example.

Modify the training phrases as shown below.

Change the default response to fit the pizza example, as shown in the figure.

c. Pizza Ordering Intent

Create another intent to actually place an order for the pizza, called "Pizza Ordering".

Add training phrases for the intent as shown below.

Add default response for the intent as shown below.

d. Add Goodbye Intent

It is recommended to add a separate Goodbye intent. Create a new intent as before and name it "Goodbye".

Modify the default response for the intent.

Your basic Pizza Ordering agent is ready.

e. Test the Basic Agent

The next step after creating, as usual, is to test. Invoke your agent by typing (or saying) "hi" on the right section of DialogFlow.

You can also use this section to test your changes with every step. If the agent does not respond as expected, go back, make changes and test again until you are satisfied!

3. Create a conversational agent

To make the agent smarter, we need to add a few more features. We will first create Entities.

a. Create Entities

Create the following entities - PizzaType, Size and Topping.

Select the checkbox "Allow automated expansion" for all entities.

b. Link entities to training phrases

Now it's time to link the entities to the training phrases in the intent. Go back to the Pizza Ordering intent, double click on, for example, "Margherita" and select the entity $PizzaType. Identify all entities in the training phrases and link them to the corresponding entity name.

c. Add Actions and Parameters

To enable a conversation flow, you can add Actions and Parameters. All the entities identified in the training phrases will be displayed in this section as shown below.

You can add additional parameters like Name and Address and choose corresponding "System Entities" i.e entity types provided by DialogFlow. Note that the entities you created earlier are the "Developer Entities". Since it is possible to specify multiple values for the parameter Topping, select the checkbox "IS LIST".

d. Add conversation prompts

Select the checkbox "REQUIRED" for all parameters, because in our example we will be asking the user for each one. In the "PROMPTS" column, specify a question for the user for every parameter, as shown below.

Now your agent can carry on a brief conversation with the user.

e. Test conversational agent

Now it's time to test your conversational agent. Invoke it by saying hi in the testing section as before. The agent should ask questions as specified in the prompts. Conclude the conversation by saying "bye".

4. Add Fulfillment

Occasionally, you might want your agent to perform some action besides carrying out a conversation, for example, reading/saving data. This can be done by adding a Fulfillment.

a. Enable webhook

The first step is to enable the webhook for the intent through the control at the bottom of the page.

b. Add Fulfillment webhook

The next step is to add the webhook (url) to the intent. Go to Fulfillment section, enable webhook and enter the url for the fulfillment.

In the ongoing example, a webhook url for an Integromat scenario has been used. The scenario saves the pizza order to a Google sheet.

The parameters defined in the Actions and Parameters can be accessed in the Webhook as shown in the image below:

The response can be sent to the agent using the key "fulfillmentText". Please note that the text in the "fulfillmentText" will overwrite the default response of your intent.

Creating Integromat scenarios has been explained in Hands-on Service Integration using Integromat.

5. Try advanced features

Try out the following features depending upon your usecase:

  • Add Yes/No Follow-up intents
  • Enable multi-language functionality
  • Add input/output contexts
  • Trigger intents based on platform-specific or custom events
  • Enable Small Talk
  • Re-use a prebuilt agent
  • Integrate the agent with Web Demo/Slack/Facebook Messenger

Have fun creating your Conversational AI agent!

⚠️ **GitHub.com Fallback** ⚠️