Professional Documents
Culture Documents
Cap2 DialogFlow
Cap2 DialogFlow
29
© Lee Boonstra 2021
L. Boonstra, The Definitive Guide to Conversational AI with Dialogflow and Google Cloud,
https://doi.org/10.1007/978-1-4842-7014-1_2
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Just like other free Google tools, Dialogflow free version is part of the no-charge
Google consumer terms. This means, like in the case of Gmail, that your data can be
used to improve products, machine learning model training, or advertising.
Where is the Dialogflow data processed? You can choose this while creating a
project. Part of Google Cloud also means the best latency. When you are connected to
Google Cloud, you will use the Google Cloud cables under the ocean. Therefore, your
connection will be much faster and will be secure.
Dialogfrow
Essentials
US - use, (Global) Intents
As seen in Figure 2-1, by default, the PII data (like chat history, analytics, and logs) are
stored in the global Dialogflow servers. Before you create a new Dialogflow agent, you can
choose a location for your Dialogflow project. At the time of writing this, you can choose
between the US, Asia (Japan), Australia (Sydney), and the UK (London), and you can find
this setting in the dropdown next to the Dialogflow logo. After selecting the region, you will
switch to a new Dialogflow environment where you can create a new agent.
Note The regions Australia, Asia, and the UK don't offer all the same features as
for the USA (Global). For example, region Asia is missing beta features such as the
FAQ knowledge base, and it doesn't come with prebuilt agents, small talk, and
out-of-the-box integrations. The last one seems essential, but you can build
integrations manually as described in Chapter 10.
30
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Besides, you can turn the storage of data off in the Dialogflow settings screen; see
Figure 2-2. Click the cogwheel icon right under the Dialogflow logo. Once the data is
turned off, no PII data will be stored. Especially for European countries that deal with the
GDPR, this might be interesting.
Note Since Brexit happened, the United Kingdom is not part of the European Union
anymore. This means according to the General Data Protection Regulation (GDPR)
compliance that storing logs and history data into the UK region isn't
compliant. The best solution is to create your agent in the global region (to get
access to all the features), but turn off all logs in Dialogflow. Instead, you can store
the chat history in Google Cloud BigQuery where you can choose Europe as a
region. This approach is explained in Chapter 13.
LOG SETTINGS
Collect and store user queries. Logging must be enabled in order to use Training, History
and Analytics.
However, I do advise that you still capture the analytics of your chatbot. You could
easily do this by building an additional layer that pushes incoming messages from the
Dialogflow SDK directly to Google Cloud BigQuery. BigQuery is part of Google Cloud, and
Europe can be chosen for data storage. Other Google Cloud resources allow you to store
data in a data center of a particular country. (For example, Google Cloud Storage can store
the data in a data center in the Netherlands).
31
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Welcome to Dialogflow!
Terms of Service *
By proceeding and clicking ihe button below, you agree to adhere to the Terms of Service.
Additionally you may have access to certain Frehase services_ You agree that your use of
Firebase services will adhere to.the applicable F■HInse 7er ma nf Servi,:e If you Integrate any
a pps with Firebase on this project, by default, your Firebase Analytics data will
enhance other Firebase features and Google products. Y04.1 can control how your rirebase
Analytics data is chased in your Firebase settings at anytime
Figure 2-3. First-time users can accept the consumer terms of service
In case you are planning to build voice bots in your browser or with Google Assistant,
make sure you have enabled Web & App Activity. You can access this settings page from
http: //myaccount . google . com/activitycontrols (see Figure 2-4).
32
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Google Account 0
Activity controls
The data saved in your account helps give you more personalized expenences across all Gongle
services. Choose which settings will save data in your Google Account.
Saves your activity on Google sites and apps, including associated info like location, to
give you faster searches. better recommendations, and more personalized experiences in
Maps, Search, and other Google services_ Learn more
El Include Chrome history and activity from sites, a pps, and devices that use Google
services
V Dialogflow
Essentials
us
dialogflowcookbook
General
chatbotportal-prod
dialogflow-hangouts
LOG SE
Figure 2-5. You can select Dialogflow agents with the dropdown
33
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
In the create agent screen (see Figure 2-6), you will need to
VideoGameAgentl CREATE
GOOGLE PROJECT
AGENT TYPE
Combine multiple Dialogflow agents (i.e. sub agents) into a single agent (1.e_ mega agent).
Optionally, you could point to an existing Google Cloud project. When you leave it
empty, Dialogflow will create an underlying project in Google Cloud for you.
Do not enable the Mega Agent switch. We will discuss this feature in Chapter 9 to
orchestrate multiple sub-chatbots. For now, leave it off.
Click Create, and Dialogflow will create a new Dialogflow standard (no charge)
project for you.
34
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
low and receive a $ 300 credit to discover Gooale Cloud products. More Information
Welcome Lee
Create and manage your Google Cloud Platform instances, drives, networks, and other
resources in one place.
Land
Terms of Service
❑ I agree to the Google Cloud Platform Terms of Service and the Terms of
Service of all applicable services and APIs _
❑ I would like to receive periodic emails with news, product updates and
special offers from Google Cloud and Google Cloud Partners.
35
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
When it's your first time using Google Cloud, you will need to provide a billing
account. Google Cloud is pay per use, and even while it comes with free credits (which
are more than enough for building chatbots), you will have to specify a payment method,
such as a credit card. This will protect Google Cloud from robots abusing free accounts. In
the left menu, you can select Billing > Create account. You will specify a billing
account name, organization name, and a country (the currency will be tied to it). On the
next screen, you can enter your payment address and payment method details.
Once you are logged in to the Google Cloud console and have a valid billing account,
you will need to create a project. Click the Select a project button in the blue top bar, next to
the Google Cloud logo. (See Figure 2-8.)
Figure 2-8. Google Cloud project selector in the Google Cloud console
Search pr j d fold
1—Ck
Name ID
dialogflowcoakbook 0 dialogflowcookbook
* :• chathotportal-prod 0 chalbotportal-proci-256715
Figure 2-9. Create a new Google Cloud project in the Google Cloud console
36
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Click Create.
Next step, let's open in another browser tab the Dialogflow console:
http://console.dialogflow.com
The steps will be similar to the previous section. However, now you can import your
newly created Google Cloud project in the create agent screen.
Click Create.
The last steps are to upgrade your Dialogflow plan from a trial tier to an enterprise
tier. In the menu, click the Upgrade button (see Figure 2-10).
Docs
Trial
Fwo Upgrade
Dialogflow CX •
Support
You will see a pop-up like Figure 2-11, and you can select a plan. There are two plans to
choose from, Trail and Essentials. The primary difference between both plans is that the
Essentials plan offers enterprise-ready features, such as Google Cloud terms and
conditions, and SLA, support, and higher quotas.
37
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Trial Edition
al usage Quotas for text, audio and phone ea. Unlimited usage fa text audio and phone
01 Usage votes far kneviredroonneeldis I.: sage quotas for knowledge connectors
By selecting the Essentials plan, you agree with the Google Cloud (enterprise) terms
and conditions.
After you have set the enterprise plan, you will see that the enterprise plan is active
for your project in the menu (notice Figure 2-12), and you can change it at any time.
> Docs
bearbeiten
Dialogflow CX
0 Support
38
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Quotas
Besides the Cloud terms and conditions, SLA, and support, another reason for many
customers to make use of the Enterprise tier is the higher call quota. Each time you
interact with Dialogflow, a user utterance will be seen as a single API/Dialogflow agent call.
The trial Dialogflow version has a maximum of API calls. The trial version can get a
maximum of 180 text chatbot calls per minute, whereas the enterprise tiers can have 600
requests per minute. Google Cloud has documentation on all the quotas, and often the
quota can be increased. To request a higher quota, click Apply for a higher quota in the
quota edit form to submit a Dialogflow Quota Increase Request (htt ps : //console.
cloud.google.com/apis/api/dialogflow.googleapis.com/quotas).
39
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
The Dialogflow Console provides the Owner/Admin role to the user who created the
agent. If you want to change the Owner/Admin, add multiple Owners/Admins for one agent,
or remove Owners/Admins for an agent, you will need the Google Cloud console for IAM &
Admin as well.
There are multiple authentication options, but it is recommended that you use
service accounts for authentication and access control. A service account provides
credentials for applications, as opposed to end users. Projects own service accounts, and
you can create many service accounts for a project. For more information, see Service
accounts.
40
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
General
As you can see in Figure 2-13, in the general tab, the following settings are available:
• Google Project
• Log Settings
41
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
dialogflowcookbook SAVE
General Languages ML Settings Export and Import Environments Speech Share Advancec
DESCRIPTION
VideoGame Agent
GOGGLE PROJECT
BETA FEATURES
Be the first to get access to the newest features and latest APIs (Full V2-beta API reference)
LOG SETTINGS
• Log interactions to Dialogflow
Figure 2-13. Dialogflow settings panel
Languages
The languages tab is where you can add additional languages to your agent. As seen in
Figure 2-14, Dialogflow Essentials supports 21 agent languages; you can pick multiple
from the pop-up.
42
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
dialogflowcookbook SAVE
English — en DEFAULT
Dutch — ni
Danish - da
German — de
Spanish — es
French — fr
Hindi — hi
ML Settings
The Dialogflow Essentials main concept is Intent Classification. (Chapter 3 will go into
details on how this works.) Training phrases will be labeled with an intent name by a
conversational designer. Once a chatbot is in production, the underlying Dialogflow
machine learning model can match a user utterance with the defined intent based on the
training phrases the model was trained on. Sometimes, various intents contain
similar training phrases. One intent might be more relevant than the other intent.
Especially when your agent grows, and more intents will be added to your agent, it can
happen that the wrong intents got matched. The generic solution to this problem would be
to change the ML Classification Threshold. The threshold value is like a confidence score.
If the returned value is less than the threshold value, then a fallback intent will be triggered,
or if there are no fallback intents defined, no intent will be triggered.
You can find the ML Classification Threshold in the settings section under the ML
Settings tab; see Figure 2-15.
43
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
ML CLASSIFICATION THRESHOLD
Define the threshold value for the confidence score. If the returned value is less than the threshold
value, then a fallback intent will be triggered, or if there is no fallback intents defined, no intent will be
triggered.
0.3
You can find the confidence level in your RAW API response; notice the following
line in Figure 2-16:
"intentDetectionConfidence": 0.7057321,
Diagnostic info
IR "intent": {
19 "name": "projects/dialogflowcookbookiagent/intentsi763fecla0-f905-40ce-arife-
df58e694ce7d",
2U "displayName": "Get_Url"
2L lo
22 "intentDetectionConfidence": 0.44944352,
23 "languageCode: "en",
24 "sentimentAnalysisResult": (
25 "queryTextBentiment": {)
26
27 ),
Figure 2-16. When you click the Diagnostic Info button in the simulator, you can see
the RAW API response, with the intentDetectionConfidence
Sometimes, you don't want to fix the ML confidence level on the agent level but the
intent level. Maybe because certain intents are exceptional, it's possible to change the
priority per intent. You can give the intent a higher or lower priority. It's even possible to
ignore specific intents, maybe because you are still working on it.
44
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
The way how you can do this is by selecting the intent from the intent screen.
At the top of your intent screen, you can click the blue dot. This will show a little pop-
up; look into Figure 2-17 to find this feature.
qo Dialogflow us
• Highest ncation SAVE
Essentials
High
dialog flowcookbook
Contf
CM • Normal
Entities 0 Ignore
Traini Searct train=ng r Q /S.
Knowledge
FulfilImant
integrations
1.5 How can I get lo you?
Figure 2-17. Each intent can have individual priorities to improve the intent
detection
45
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Note If the misspelled and corrected user input matches different intents, the
intent matching the misspelled user input is selected.
Spell correction can't correct ASR (automatic speech recognition) errors, so we don't
recommend enabling it for agents using ASR inputs. Auto Speech Adaptation might
help; see Chapter 7. But neither of these features works with Actions on Google
since Actions on Google uses its own Speech-to-Text/Text-to-Speech layer.
Corrected input can match the wrong intent. You can fix this by adding commonly
mismatched phrases to negative examples.
Automatic Training
By default, the underlying machine learning model will be updated automatically when
intents or entities have been added or edited. You can disable or enable automatic
agent training. A use case for this is, for example, when you want to test how well your
machine learning model performs. In Chapter 13, machine learning model health will be
discussed.
Agent Validation
By default, Dialogflow will run an agent review of your agent each time you make
changes to your agent. As seen in Figure 2-18, you can disable or enable agent validation in
the settings section; see Chapter 5 for more information.
AGENT VALIDATION
TRAIN
46
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
dialogflowcookbook SAVE
General Languages ML Settings Export and Import Environments Speech Share Advanced
Replace the current agent version with 5 new One. All the intents and entities En
SraP1' CM ZIP
the older version will be deleted.
Upload new intents and entities without deleting the current ones Intents and
iMPORT FROE...1
entities with the same name will be replaced with the newer version
Environments
As seen in Figure 2-20, to access the environment settings, click the Environments
tab. You can create multiple versions of your agent and publish them to separate
environments. When you edit an agent, you are editing the draft agent. At any point, you
can save the draft agent as an agent version, which is an immutable snapshot of your agent.
When you save the draft agent, it is published to the default environment. When you
create agent versions, you can publish them to custom environments. You can create a
variety of custom environments such as testing, development, production, and so on. And
via the options menu, it's also possible to revert to previous versions.
47
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
D. Version info
Description (optional)
Add a note or comment abOut this version
Of To publlsh a version to Google Assistant, Choose "Publish Google Assistant" below, and complete
the process in Assistant console.
Speech
To access the speech settings, click the Speech tab.
These contain the speech recognition settings (Speech to Text) and speech synthesis
(Text to Speech) settings.
48
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Text to Speech
In this section, you can find the settings for the Text to Speech synthesizer to tweak the
voices and audio output.
Try :E now
0 DEFAULT ',.ESPONSE
1
Hi, I am the virtual video game chat agent. I can
talk with you about video games or I can tell you
which latest games have been released. What
would you like to know from me?
OUTPUT AL DO 0
0. 0:00 / 0:09 ul
49
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Voice Configuration
Note Figure 2-22; configure your agent's synthesized voice in the V2 API and Telephony
integration with the following settings:
For more information on tweaking the Text to Speech, see Chapter 7, the SSML
section.
Note All of these settings won't include Actions on Google. As the Google
Assistant uses, it's on Speech to Text and Text to Speech models.
50
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
dialogflowcookbook SAVE
VOICE CONFIGURATION
Configure your agents synthesized voice in the V2 API and Telephony integration.
Ag ant Language
en (English)
vflcc
Automatic 4r•
Select 'Audio Effects' profiles. (For standard API calls, won't affect Telephony integration) 0
Share
Note Figure 2-23; the Share tab allows you to share your Dialogflow agent with others.
You can add an email address, and you will specify the role of this user, either Reviewer or
Developer.
The developer role in Dialogflow maps to an IAM role in the Google Cloud Console:
Project > Editor. It grants to project editors that need edit access to all Google Cloud and
Dialogflow resources:
51
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
The review role in Dialogflow maps to an IAM role in the Google Cloud Console:
Project > Viewer. It grants to project viewers that need read access to all Google Cloud
and Dialogflow resources:
dialogflowcookbook SAVE
After you grant or revoke access to your agent, it may take some time for the change to be
effected_
admin@oloudtricks_eu ADMIN
ADD
52
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Advanced
At the time of writing, in the Advanced tab (Figure 2-24), there is only one setting
to control: Sentiment Analysis. You can enable sentiment analysis for supported
languages. Enabling sentiment analysis will return a score and a magnitude with your
intent detections.
dialogflowcookbook SAVE
'al Languages ML Settings Export and Import Environments Speech Share Advanced
SENTIMENT ANALYSIS
Sentiment Analysis uses Cloud Natural Language to provide a sentiment score for each user query.
Note: Sentiment Analysis is not supported for queries originating from Goggle Assistant.
The score of a sentiment detection indicates the overall emotion of the user
utterance. The magnitude of a sentiment detection indicates how much emotional
content is present within the user utterance, and this value is often proportional to the
length of the user's utterance.
You can test it in the simulator (Figure 2-25). Try typing "Thank you for helping me." It
returns a positive query score between 0 and +1. Next, type "That didn't work at all." in the
simulator. You will now see a negative score between -1 and 0 show up.
53
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Diagnostic info
AAAAAAAAAAAAA... (The content is truncated. Click 'COPY' for the original SBON.}mr
29 m a l t e r n a t i ve Q u e r y1 e 5 u l t e r [
Figure 2-25. When a user says something positive, the API response will yield a
positive sentiment
For more information on sentiment, check out the sentiment analysis section in
Chapter 13.
Note Each Google Cloud project can have only one Dialogflow agent. In case your
Dialogflow agent needs a test and development version, you can make use of the
versions feature in Dialogflow. Or you could create more Google Cloud projects, one
for the test agent and one for the development agent.
54
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
Filter table
-11 IAM
Email Status
e
Actions
Identity & Organization
°A
@appspot.gserviceaccount.corn
Policy Troubleshooter
°S Service Accounts
"A! dialogflow-
ra ciam.gserviceaccount.conn
Manage resources
If you have not already, download a service account key for this service account, and set
the GOOGLE APPLICATION CREDENTIALS environment variable to its path. You can download
the service account JSON key by clicking the options button in the actions column and
selecting Create key. In the pop-up, you can choose JSON and Create.
(See Figure 2-27.)
Key type
A. Policy Troubli
® JSON
ice account features,
ounts entirely. Learn
❑ Organization Recommended
ID P12
g Quotas For backward compatibility with code using the P12 format
Service
itus Actions
CANCEL CREATE
Ei Manage
55
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
It will download the JSON file to your disk, and you will need to assign this to an
environment variable called GOOGLE APPLICATION CREDENTIALS.
Assign the key to environment var GOOGLE_APPLICATION_CREDENTIALS.
For Linux/MacOS environments:
Summary
This chapter addresses the following tasks:
• You want to start with Dialogflow and set up a Dialogflow trial agent.
• You are working for an enterprise, and you want to create a secure
virtual agent committed to compliances; you can create a Dialogflow
Essentials pay-as-you-go agent.
In case you want to build this example, the source code for this book is available
on GitHub via the book's product page, located at www. apress . com/ISBN. Look for the
_dialogflow-agent folder.
Further Reading
• Compare Dialogflow editions
56
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS
https://cloud.google.com/dialogflow/pricing#es -agent
https://cloud.google.com/dialogflow/quotas
https://cloud.google.com/blog/products/ai-machine-
learning/simple-blueprint-for-building-ai-powered-
customer-service-on-gcp
https://tools.google.com/d1page/dirsync/
https://cloud.google.com/resource-manager/docs/access-
control-org
https://cloud.google.com/dialogflow/es/docs/access -control
https://console.cloud.google.com/apis/api/dialogflow.googleapis.
com/quotas
https://cloud.google.com/vpc-service-controls/docs/service-
perimeters
• Service accounts
https://cloud.google.com/docs/authentication#service_accounts
https://cloud.google.com/docs/authentication/production
• Data logging
https://cloud.google.com/dialogflow/es/docs/data -logging
57