Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

CHAPTER 2

Getting Started with


Dialogflow Essentials
Dialogflow Essentials is the tool you can use to build conversational UIs. It comes as a
trial and a pay-as-you-go edition. In this chapter, you will learn how to set up your first
Dialogflow agent with Dialogflow Essentials.
This includes: the location of your agent and its data storage, logging, monitoring,
user roles, and quotas. It discusses in-depth information on all the possible settings. At
the end of the chapter, developers can learn how to set up Dialogflow for API access.

Dialogflow Essentials Editions


Dialogflow Essentials pay-as-you-go edition is the enterprise tier of Dialogflow and is
part of Google Cloud. The pay-as-you-go edition is targeted at organizations that need
enterprise-grade service. Dialogflow Essentials pay as you go has coverage against the
most important global compliance & regulation standards (e.g. GDPR), and provides an
SLA, support packages, and Google Cloud Terms of Services. On top of this, it has a
higher quota limit and voice interaction and is fully integrated with Google Cloud,
making it easy to consume other Cloud services to build a full advanced solution. (Think of
additional machine learning APIs such as Translation, masking sensitive user data (GDPR)
with the DLP API, sentiment detection with the NLP API, Cloud Functions
fulfillment, BigQuery data warehouse for analytics, etc.)
The no-charge Dialogflow trial is not part of Google Cloud.

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-NE1 - Tokyo. Japan


dialogtlowcookbpok

a AU-SE1 - Sydney, Australia

Intents EU-W2 - London, England, UK duct regex

-1, muryT,r.vi Is°le


rh entities
• Coliect_Curfent_Playing_Game

Figure 2-1. Dialogflow location dropdown

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.

General Languages ML Settings Export and import Environments Speech Share

LOG SETTINGS

Log interactions to Dialog flow

Collect and store user queries. Logging must be enabled in order to use Training, History

and Analytics.

Log interactions to Google Cloud

Write user queries and debugging information to Google Stackdriver.

Figure 2-2. Log Settings in the settings panel

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

Creating a Dialogflow Trial Agent


Dialogflow is a Software as a Service (SaaS) solution; it runs in your browser.
Let's create an example agent.
Open https : //dialogf low. cloud .google. com/.
Sign in with a Google identity. For consumers, this can be a Gmail address, and for
organizations this can be a Google Cloud Identity or Google Workspace entity tied to your
own domain.
If you have used Dialogflow before, you will automatically log in to an active
Dialogflow project.
If it's your first time logging in to Dialogflow, it might be that you see a pop-up (see
Figure 2-3). You will need to agree to the Dialogflow trial terms and conditions, with
additional Firebase terms and conditions. The last one will be used when using the no-
charge cloud services, such as the inline fulfillment editor, which under the hood uses a
no-charge Firebase cloud function.

Welcome to Dialogflow!

Terms of Service *

❑ Yes, I have read and accept the agreement

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.

Web & App Activity S

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

J Include audio recordings. Learn more

0 This setting is not currently available for your account type

Figure 2-4. Web & App Activity in your Google profile

Next, click the Create Agent button.


To create another new project, click the dropdown (under the Dialogflow logo, see
Figure 2-5). It will show you a list of active Dialogflow projects, wherein at the bottom,
there will be the menu option: Create Agent.

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

• Set a Dialogflow project name

• Set a default language (additional languages can be added in later


steps)

• Set a default time zone (when conversations are mapped to date/time


objects, it will use the default time zone)

VideoGameAgentl CREATE

DEFAULT LANGUAGE 0 DEFAULT TIME ZONE

English — en (GmT+1:00) Europe/Madrid


Prue ary language for your agent Other languages Date and time requests are resolved using this
can be added later. tirnezone.

GOOGLE PROJECT

Create a new Google project


Enables Cloud (unctions, Actions on Google and permissions management.

AGENT TYPE

Set as Mega Agent

Combine multiple Dialogflow agents (i.e. sub agents) into a single agent (1.e_ mega agent).

Figure 2-6. Creating a new agent in Dialogflow Essentials

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

Creating Dialogflow Agents for Enterprises


When you are worldng for an enterprise, and you want to create a secure Dialogflow
agent committed to compliance, you can create a Dialogflow project, as before. Still, you
will have to upgrade the project to a (paid) enterprise tier. Afterward, you will have to
enable the Dialogflow API in your Google Cloud project.
First, navigate to http : //console. cloud . google com. Sign in with a Google identity.
For consumers, this can be a Gmail address, and for organizations this can be a Google
Cloud Identity or Google Workspace entity tied to your own domain.
First-time Google Cloud users will need to accept the Google Cloud terms and
conditions page while setting the country of origin (see Figure 2-7).

low and receive a $ 300 credit to discover Gooale Cloud products. More Information

Cloud Google Cloud Platform


IS Englig

Welcome Lee
Create and manage your Google Cloud Platform instances, drives, networks, and other
resources in one place.

Land

The Netherlands •Pr

Terms of Service

❑ I agree to the Google Cloud Platform Terms of Service and the Terms of
Service of all applicable services and APIs _

Updates via email

❑ I would like to receive periodic emails with news, product updates and
special offers from Google Cloud and Google Cloud Partners.

AGREE AND CONTINUE

Figure 2-7. Accept the Google Cloud terms and conditions

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.)

Google Cloud Platform Select a project v.

Figure 2-8. Google Cloud project selector in the Google Cloud console

In the pop-up, click New Project as shown in Figure 2-9.

Select from CLOUDTRECKS EU T NEW PROJECT

Search pr j d fold

1—Ck

RECENT STARRED PREVIEW ALL

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

In the create project screen, you will need to

• Set a project name.

• Select a Billing Account. This billing account will be used to invoice


this project.

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

Figure 2-10. Upgrade to Dialogflow pay as you go

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

Dialogflow Pricing Plans

Trial Edition

cu Unlimited usage for Aohons on Googie usage for Actions an Goggle

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

In all plans: In all Mann'


Speech Synthesi s, Anelytlos. Code Editor, Multilingual Support Speech Synthesis, Analytics, Code Editor, Multdingusl Support

Googie APIs & firebase TaS s14 Goggle Cloud MS oF'


See full plan details eR See full plan delallscr•

SELECT PLAN CURRENT PLAN

Figure 2-11. Select a Dialogflow edition

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

Figure 2-12. Notice the selected plan in your Dialogflow menu

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).

User Roles and Monitoring


Since you are using Google Cloud, enterprises can create and view custom audit reports,
logging, and debugging through Cloud Logging.
Enterprise admins can invite and enroll chatbot users from the Google Cloud
console by using Cloud IAM. It's possible to set user and group privileges or set security
and control policies. They can also use directory sync (like Active Directory Sync) to
import and enroll company users. This can be done via webhooks with Cloud Directory
Sync and the Directory API.
Suppose you have integrations with other Google Cloud resources, like Cloud
Functions or additional machine learning APIs, and you don't want to grant full project
access to an application. In that case, you must assign the Dialogflow API roles (Admin,
Client, or Reader) in the Google Cloud IAM console. You can find this configuration when
you select IAM & Admin in the Google Cloud console and look for the service account
used by Dialogflow. (See the Settings panel in Dialogflow for the name.)

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.

Using VPC Service Controls


VPC Service Controls can help you mitigate the risk of data exfiltration from Dialogflow.
You can create a service perimeter, which is an organization-level method that protects the
resources and data that you specify in your project. You can protect agent data and intent
detection request and responses. When you create a service perimeter, include Dialogflow
(dialogf low . googlea pis . corn) as a protected service.

Using Developer Features


When developers want to use Dialogflow by using the SDKs, you will need to enable
the Dialogflow API from the cloud console. It's possible to enable this via the Google
Cloud console by clicking this link: https : //console. cloud .google. com/flows/
enableapi?apiid=dialogflow.googleapis.com—or by using the Google Cloud
command-line tools (gcloud), they can answer the following command:

gcloud services enable dialogflow.googleapis.com

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.

Configuring Your Dialogflow Project


Click the cogwheel icon right under the Dialogflow logo to enter the settings page.
On this page, you can add additional languages, tweak the ML settings, share the
project with others, or create multiple environments.
Let's have a look through all these settings.

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:

• Description: Description of the agent.

• Default Time Zone: Default time zone for the agent.

• Google Project

• Project ID: Google Cloud project linked to the agent

• Service Account: Service account used by Dialogflow for system


integration

• Trial or Pay as you Go

• Beta Features: Toggle to enable beta features for the agent.

• Log Settings

• Log interactions to Dialogflow: You will be able to use the


History and Training features in Dialogflow.

• Log interactions to Google Cloud: This option is only available


if Log interactions to Dialogflow is enabled. Disabling
Dialogflow's logging will also disable this setting. It will make
use of logging features in Google Cloud (previously known as
Stackdriver).

• Delete Agent: Completely deletes the agent and cannot be undone.


If the agent is shared with other users, those users must be removed
from the agent before you can delete it.

41
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

dialogflowcookbook SAVE

General Languages ML Settings Export and Import Environments Speech Share Advancec

DESCRIPTION

VideoGame Agent

DEFAULT TIME ZONE

(GMT+1 :00) Europe/Madrid

Dale and tune requests are resolved using tills tiniezone.

GOGGLE PROJECT

Project ID dialogflowcookbook (Googfe Cloud C? I Actions on Google Gr )

BETA FEATURES

as Enable beta teatures and APIs

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

General Languages ML Settings Export and Import Environments Speech Share

English — en DEFAULT

Dutch — ni

Danish - da

German — de

Spanish — es

French — fr

Hindi — hi

Figure 2-14. Select Dialogflow languages

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

General Languages ML Settings Export and Import Environments Speech Share

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

Figure 2-15. ML Classification Threshold, a confidence score

You can find the confidence level in your RAW API response; notice the following
line in Figure 2-16:

"intentDetectionConfidence": 0.7057321,

Diagnostic info

Raw API response

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 ),

CLOSE COPY RAW RESPONSE

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

171 intents Event • Low

Entities 0 Ignore
Traini Searct train=ng r Q /S.

Knowledge

FulfilImant

integrations
1.5 How can I get lo you?

Training 59 Vvhats your a ddresi.,")

Figure 2-17. Each intent can have individual priorities to improve the intent
detection

Automatic Spell Correction


If this is enabled and user input has a spelling or grammar mistake, an intent will be
matched as though it was written correctly (based on its training phrases and used
entities). The detect intent response will contain the corrected user input. This also
applies to matches involving both system and custom entities. For example, "I want to
buy purchase an Swtch." It will figure out the right intent and write down the correct
parameter, which will be "Switch."
Spell correction is available for all languages supported by Dialogflow.

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.

Spell correction increases the agent's response time slightly.

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

• Automatically validate the agent when agent training is performed.

TRAIN

Figure 2-18. Enable agent validation

46
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

Export and Import


Note Figure 2-19; in this tab, you can import and export agents. Export means you will
create a backup of the agent. It will return a zip file, which contains JSON files of all the
intents and entities.
With Restore from Zip, you can replace the current agent version with a new one.
All the intents and entities in the older version will be deleted. There is also Import from
Zip, which uploads new intents and entities without deleting the current ones. Intents and
entities with the same name will be replaced with the more recent version.

dialogflowcookbook SAVE

General Languages ML Settings Export and Import Environments Speech Share Advanced

EXPO!? I AS ill' Create a backup of the agent

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

Figure 2-19. Export and Import

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.

PUBUSH IN GOOGLE ASSISTANT O. NEXT

Figure 2-20. Publish a version to an environment

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.

Improve Speech Recognition Quality


In this section, you can find settings for the speech recognition model. It's making use of
the Google Cloud Speech-to-Text model under the hood. There are two toggle switches
available.

Enable Enhanced Speech Models and Data Logging


By enabling speech models and data logging, you agree to the terms and conditions of the
data logging agreement (which amends the agreement governing the customer's use of
Google Cloud services). Enabling data logging will improve your Speech-to-Text.

48
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

Enable Auto Speech Adaptation


To bias your Speech to Text model, to make sure it understands how you trained your
agent, you can enable Auto Speech Adaptation. See Chapter 7, "Improving Speech to
Text Quality" section, for more information.

Text to Speech
In this section, you can find the settings for the Text to Speech synthesizer to tweak the
voices and audio output.

Enable Automatic Text to Speech


Automatically convert default text responses to speech in all conversations. You will
get both the text version and the audio string. You can test this in the simulator (see
Figure 2-21); after enabling this setting, you will see a little widget with an audio player.

Try :E now

USER SAYS COPY CURL


Hi there

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

Figure 2-21. Text to Speech in the simulator

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:

• Agent Language: Choose the default language for voice synthesis.

• Voice: Choose a voice synthesis model.

• Speaking Rate: Adjust the voice speaking rate.

• Pitch: Adjust the voice pitch.

• Volume Gain: Adjust the audio volume gain.

• Audio Effects Profile: Select audio effects profiles you want to be


applied to the synthesized voice. Speech audio is optimized for the
devices associated with the selected profiles (e.g., headphones, large
speakers, phone calls).

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

General Languages ML Settings Export and Import Environments Speech. Share A

Ou tput Au dio Encoding

16 bit linear PCIV1 (signed, Ii.._

VOICE CONFIGURATION
Configure your agents synthesized voice in the V2 API and Telephony integration.

Ag ant Language

en (English)

vflcc

Automatic 4r•

SPEAKING RATE: 1 0 PITCH: 0 (SEMITONES) 0 VOLUME GAIN: 0 (DB) o

Select 'Audio Effects' profiles. (For standard API calls, won't affect Telephony integration) 0

Figure 2-22. Voice configuration

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:

• Edit access to all Cloud project resources using Cloud


Console or APIs

• Edit access to Dialogflow Console to edit agents

51
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

• Can detect intent using an API

• See IAM primitive role definitions

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:

• Read access to all Cloud project resources using Cloud Console or


APIs

• Read access to Dialogflow Console

• Cannot detect intent using an API

Press Add and don't forget to hit the Save button.

dialogflowcookbook SAVE

General Languages ML Settings Export and Import Environments Speech Share

After you grant or revoke access to your agent, it may take some time for the change to be
effected_

WHO HAS ACCESS

admin@oloudtricks_eu ADMIN

INVITE NEW PEOPLE DEVELOPER

Enter email__ REVIEWER

ADD

Figure 2-23. Share settings. Don't forget to hit Save!

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.

• Enable Sentiment Analysis for the current query

Note: Sentiment Analysis is not supported for queries originating from Goggle Assistant.

Figure 2-24. Enable sentiment analysis

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

Raw API cospanse

21 tf sgmt im entAna ly isRe sult": {


22 "qkm.tyTextSentiment": {
23 "score' : 0. 9,
24 "magnitude"s 0.9
25 }
26 }
27 ),
28 "outpdtA udie:
'1.Ik1GRjy8AQMOVZFZMI4ISAAAAABAAEAwF0AAIC7AAACABAAZGF0YRiBAQ

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 [

CLOSE COPY RAW RESPONSE

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.

Configuring Your Dialogflow for Developers


You are a developer, and you want to have developer access.
Select IAM & Admin > Service Accounts. You will see a service account email
addresses, like Figure 2-26.

54
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

Google Cloud Platform :■ di alogfiowcoo khook 4 4a A A

0 IAM & Admin Service accounts SHOW INFO PANEL

Filter table
-11 IAM

Email Status
e
Actions
Identity & Organization
°A
@appspot.gserviceaccount.corn
Policy Troubleshooter

tzi Organization Policies


o-3

it Quotas cc [email protected]. corn

°S Service Accounts

"A! dialogflow-

ra ciam.gserviceaccount.conn
Manage resources

Figure 2-26. Service accounts in the Google Cloud Console

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.)

Goode Cloud Platform diahloky,../(,,,kbook 0. al 0 A

0I AM & Adi SHOW INFO PANEL

Create private key for "App Engine default service account"


IAM
Downloads a file that contains the private key. Store the File securely because this key
e Identity 8 0 rg can't be recovered if lost. ig on compute Erigine
rice accounts.

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

Figure 2-27. Create a private key from a service account

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:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account . j son

For Windows environments:

set GOOGLE_APPLICATION_CREDENTIALS=c: \ path \to \ service_account. json

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.

• You have created a Dialogflow project, and now you want to


configure it.

• You are a developer, and you want to have developer access.

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

https: //cloud .google.com/dialogflow/docs/editions

• Firebase terms and conditions

https : //firebase.google. com/terms/

• Dialogflow Enterprise/Google Cloud terms and conditions

https : //cloud . google . com/terms/

56
CHAPTER 2 GETTING STARTED WITH DIALOGFLOW ESSENTIALS

• Dialogflow tiers and pricing

https://cloud.google.com/dialogflow/pricing#es -agent

• Dialogflow tiers and quotas

https://cloud.google.com/dialogflow/quotas

• The blog post about storing Dialogflow data in BigQuery

https://cloud.google.com/blog/products/ai-machine-
learning/simple-blueprint-for-building-ai-powered-
customer-service-on-gcp

• Directory Sync in Google Cloud

https://tools.google.com/d1page/dirsync/

• Google Cloud IAM

https://cloud.google.com/resource-manager/docs/access-
control-org

• Dialogflow access control

https://cloud.google.com/dialogflow/es/docs/access -control

• Request a higher quota

https://console.cloud.google.com/apis/api/dialogflow.googleapis.
com/quotas

• VPC service controls

https://cloud.google.com/vpc-service-controls/docs/service-
perimeters

• Service accounts

https://cloud.google.com/docs/authentication#service_accounts

• Authenticating as a service account

https://cloud.google.com/docs/authentication/production

• Data logging

https://cloud.google.com/dialogflow/es/docs/data -logging

57

You might also like