Checkpoints
Create a Dialogflow agent
/ 25
Create Intents
/ 25
Allow Fulfillment to Store Help Ticket Data
/ 25
Tickets are Logged in Datastore
/ 25
Implementing an AI Chatbot with Dialogflow ES
GSP078
Overview
Dialogflow is a natural language understanding platform that makes it easy to design and integrate a conversational user interface into your mobile app, web application, device, bot, etc. Dialogflow can analyze multiple types of input from your customers, including text or audio inputs (like from a phone or voice recording). It can also respond to your customers either through text or with synthetic speech.
In this lab, you will build a Google Assistant chatbot that submits helpdesk tickets. The following is a diagram of the chatbot application on Google Cloud:
The exercises are ordered to reflect a common cloud developer process. You will:
- Set up your lab and learn how to work with Dialogflow and your Google Cloud environment.
- Deploy a simple Dialogflow application.
- Deploy a simple cloud function within Google Cloud to connect with Dialogflow.
- Test your chatbot.
What you'll learn
By the end of this lab, you will have an understanding of the following:
- Basics concepts and constructs of Dialogflow, including intent, entity and context
- Chatbot workflow
- Life of a conversation
Prerequisites
This is a fundamental level lab. Before taking it, you should be comfortable with at least the basics of machine learning and natural language processing. Here are some Google Cloud Skills Boost labs that can get you up to speed:
- Cloud Natural Language API: Qwik Start
- Google Cloud Speech API: Qwik Start
- Entity and Sentiment Analysis with the Natural Language API
- Classify Text into Categories with the Natural Language API
Once you are prepared, scroll down to dive into Dataflow.
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Dialogflow concepts and constructs
Dialogflow is a conversation building tool. It takes the human language and cleverly splits it into intents and arguments.
Agents are best described as NLU (Natural Language Understanding) modules. These can be included in your app, product, or service, and transforms natural user requests into actionable data. This transformation occurs when a user input matches one of the intents inside your agent.
Intents are the predefined or developer-defined components of agents that process a user's request. An intent represents a mapping between what a user says and what action should be taken by your software.
Intent interfaces have the following sections:
- User says
- Action
- Response
- Contexts
Entities are powerful tools used for extracting parameter values from natural language inputs. Any important data you want to get from a user's request will have a corresponding entity.
The entities used in a particular agent will depend on the parameter values that are expected to be returned as a result of the agent functioning. In other words, a developer does not need to create entities for every possible concept mentioned in the agent – only for those needed for actionable data.
There are 3 types of entities:
- System: defined by Dialogflow
- Developer: defined by a developer
- User: built for each individual end-user in every request
It's important to distinguish between the three different types of system entities:
- System mapping: Has reference values
- System enum: Has no reference values
- System composite: Contains other entities with aliases and returns object type values
Contexts represent the current context of a user's request. This is helpful for differentiating phrases which may be vague or have different meanings depending on the user's preferences, geographic location, the current page in an app, or the topic of conversation.
For example, if a user is listening to music and finds a band that catches their interest, they might say something like: "I want to hear more of them". As a developer, you can include the name of the band in the context with the request, so that the agent can use it in other intents.
Fulfillment is a webhook that allows you to pass information from a matched intent into a web service and get a result from it.
All of this new information may be overwhelming, but do not panic — it should all come together once you start developing your Google Assistant chatbot in the following section.
Task 1. Deploy a simple Dialogflow application to submit helpdesk tickets
Enable Cloud Datastore
Cloud Datastore is a highly scalable NoSQL database for your applications. Cloud Datastore automatically handles sharding and replication, providing you with a highly available and durable database that scales automatically to handle your applications' load.
-
Create a new database instance, open the Datastore section in the Cloud Console.
-
In the Console, go to Navigation menu > Datastore
-
The screen should look like this:
-
Click the SELECT DATASTORE MODE
-
From the dropdown Select a location choose nam5(United States)
-
Click CREATE DATABASE
Create a Dialogflow agent
-
In the Console, go to Navigation menu > APIs & Services > Enabled APIs & services.
-
Click on Enable APIs and Services.
-
Search for Dialogflow.
-
Click on the Dialogflow API and if the API is not Enabled, click Enable.
-
In a new tab, go to dialogflow.cloud.google.com.
-
Then check the Terms of Service. Click on Accept.
-
From the left panel, select Create Agent.
-
Now add the agent information:
-
Agent name: Helpdesk
-
Default Time zone: America/Denver
-
Google Project: Your Project ID
-
When you're ready, click Create.
Test completed task
Click Check my progress to verify your performed task. If you have successfully created a Dialogflow agent, you will see an assessment score.
Now you're ready to get started!
-
The Default Welcome Intent is automatically created. Click on it to open it.
-
In the Training phrases section, add some expressions that a user could potentially say. The most common would be "Hi", "Hello", "Good morning". Add these now. Your screen should look something like this:
- Scroll down to the Responses section. Here is where you'll set up the "Text response" that will automatically respond to users. These are all ready to go. If you want, add some more, like, "Hi! How can I help?"
- Click Save in the top right corner.
Time to test what you built so far.
- On the right in the Try it now section, type "Hi" and press enter. You should see a Default Response.
Pretty cool, right? Now things will get more interesting.
Task 2. Create Intents
-
Click on Intents in the left pane, then click on Create Intent.
-
Name the intent "Submit Ticket".
-
Go to the "Training phrases" section and click on Add Training Phrases. Add the following:
-
Ticket
-
Submit ticket
-
Problem
-
Issue
-
I want to submit a ticket
-
I have a problem
-
Scroll down to the "Responses" section and click on Add Response. Enter the following:
-
Sure! I can help you with that. Please provide your name for the ticket.
-
Click Save when you're done.
Test completed task
Click Check my progress to verify your performed task. If you have successfully created a custom intent, you will see an assessment score.
-
Now click on Intents in the left-hand panel, and mouse over your newly created "Submit Ticket" intent. Click "Add follow up intent" and then select custom.
-
Click on the new "Submit Ticket - custom" intent to edit it. Fill in the details and make sure they resemble the screenshot below:
- Intent name: Submit Ticket - collect name
- Training phrases: I am bob
- Training phrases: My name is Lily
- Responses: Thanks $person! Now describe your issue.
As you add your training phrases, notice that when you type "My name is Lily" a default entity is created called person
(if it doesn't appear by default, please select @sys.person
for Lily and bob manually). In the Text response section, a $
is added before person
to represent a variable. This will let the chatbot echo the user's name back to them.
-
Click Save when you're done. Next you'll see how the variables are stored and recalled by Dialogflow.
-
Type in "issue" in Try it now and check the response you get.
-
Type in ‘My name is Lily' and check the response you get.
Notice under Contexts that Dialogflow automatically added a context of "SubmitTicket-followup".
Task 3. Allow Fulfillment to store help ticket data
Now you'll enable Fulfillment so the help ticket information can be submitted to a database, Google Cloud Datastore in this case. It will take a few minutes for your resources to be available.
- Click on Fulfillment in the left panel and switch the Inline Editor toggle to "Enabled".
-
Copy the following code and paste it in the
index.js
tab, replacing the existing content:
- Edit the
index.js
file:
On line 6, replace REPLACE_WITH_YOUR_PROJECT_ID
with your Project ID (in single quotes). Your project ID is on the lab page with the credentials, where you started the lab.
The result should look something like this (but with your own project name substituted):
-
Then click on the package.json tab add this dependency:
Remember to add a comma after the last item in the dependency list.
The result should look something like this:
-
Then click the Deploy button. Wait until you see a message that the deployment was successful (this might take a little while).
Test completed task
Click Check my progress to verify your performed task. If you have successfully allowed Fulfillment to store Help Ticket Data, you will see an assessment score.
-
Next, go back to Intents in the left panel. Click the down arrow next to "Submit Ticket" to reveal its follow-up intents. Mouse over "Submit Ticket - collect name" and click "Add follow up intent", then select Custom.
-
Click on the newly created intent "Submit Ticket - collect name - custom" to open it for editing.
-
Name the intent "Submit Ticket - collect description".
-
Enter some user expressions into Training phrases as shown below. Here is what we selected for Training phrases:
- Everything is hosed
- My laptop won't start
- Nothing works
- My phone screen is broken
Use the following screenshot as a reference:
-
Scroll to the bottom of the screen click on the Fulfillment arrow to toggle the section. Click on Enable webhook call for this intent.
-
When you're finished, click Save.
At this point, the Dialogflow should be set up. Test it in the "Try it now" panel by entering the following conversation:
- Hi
- I would like to submit a ticket
- My name is John
- My phone screen is broken
You should see a default response that resembles the following:
Task 4. Verify that tickets are logged in Datastore
Now verify that the support ticket is getting logged in Datastore.
- From the Cloud Console Navigation menu, go to Datastore.
You should see the entry as shown below.
This verifies that your chatbot is working and logging tickets, awesome!
Test completed task
Click Check my progress to verify your performed task. If tickets get successfully logged in Datastore, you will see an assessment score.
Task 5. Test your Chatbot
Dialogflow provides many types of integrations for your chatbot. Now take a look at a sample web user interface for the chatbot.
-
Click on Integrations in the Dialogflow left panel and then click on the Web Demo integration.
-
Click Enable.
-
Now, click on the URL link to launch Web Demo.
-
Start using the chat interface by typing in the Ask something... section! If you are using a Chrome browser, if you click the microphone icon and you can speak your questions to the chatbot. Start chatting with the chatbot using the following conversation:
- Type "Hi" and hit Enter. The chatbot should respond as before.
- Then enter/say "Submit ticket"
- Provide the name "My name is Lily"
- Provide the ticket details of "My phone screen is broken"
You should receive a dialog output that says a ticket has been submitted. You can also check in datastore to see if the ticket has been logged. The web demo is in its early stages, so if it doesn't work as expected try to run the commands again or refresh the page.
Task 6. Test your understanding
Below are multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.
Congratulations!
You're now a chatbot developer!
Finish your quest
This self-paced lab is part of the Machine Learning APIs quest. A quest is a series of related labs that form a learning path. Completing this quest earns you the badge above, to recognize your achievement. You can make your badge public and link to it in your online resume or social media account. Enroll in this quest and get immediate completion credit. Refer to the Google Cloud Skills Boost catalog for all available quests.
Take your next lab
Try out another lab on Machine Learning APIs, like Vertex AI Workbench Notebook: Qwik Start or Entity and Sentiment Analysis with the Natural Language API.
Next steps / Learn more
- Sign up for the full Coursera course on Machine Learning with TensorFlow on Google Cloud Platform
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated September 26, 2022
Lab Last Tested August 11, 2022
Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.