Checkpoints
Create a Dialogflow agent
/ 10
Import the Dialogflow agent
/ 10
Set up a phone gateway
/ 20
Welcome the caller
/ 10
Set up fulfillment using Cloud Functions
/ 20
Modify the Fulfillment Code
/ 20
Create custom fallback intent
/ 10
Adding a Phone Gateway to a Virtual Agent
GSP793
Overview
In this lab, you will continue working on the Pigeon Travel virtual agent created in the Building Virtual Agent Fulfillment lab and add a phone gateway to allow users to call into your virtual agent. It is recommended to complete the Design Conversational Flows for your Agent lab first, but it is not required.
Contact Center AI is designed to easily integrate into existing telephony technology. In order to create a phone gateway, you need to have access to a telephony partner, and this lab will give you that access. For production usage we recommend working with one of these partners.
What you'll learn
In this lab you'll learn about the following tasks:
-
Update Default Welcome Intent
-
Add a phone gateway to allow users to dial into our virtual agent
-
Transfer a user using the phone gateway
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.
Enable the API
-
In the Cloud 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.
Task 1. Create your Dialogflow agent
You'll call your agent "pigeon-travel".
-
Go to the Dialogflow Console.
-
Sign in with the Google button, and make sure to select the lab credentials you logged into this lab with.
-
Check the Terms of Service. Click on Accept.
-
Click Create Agent.
-
Now add the agent information:
- Agent Name:
pigeon-travel
- Default Time Zone:
America/Denver
- Google Project: use your Lab Project ID
- Agent Name:
-
Click Create.
Click Check my progress to verify the objective.
Task 2. Import your Dialogflow agent
In the previous lab, you exported the Dialogflow agent you built. You will now import it back in and continue building it.
If you do not have exported files to use, please use this file: pigeon-travel-gsp-793.zip
Download the file to your local workstation.
This will create a new virtual agent project. Now you'll want to import the work you've already done.
-
Click on the settings gear icon (
) next to your agent name.
-
Select the Export and import tab.
-
Click Import from zip.
-
Click Select file and navigate to the zip file which contains the configuration of your virtual agent. You can alternatively drag and drop the file if you prefer.
-
Type in the word "IMPORT" in all caps to enable the import button and click Import.
- Click Done to close out the upload window once the import is complete.
Your existing configuration has been imported into your new agent project.
Click Check my progress to verify the objective.
Task 3. Set up a phone gateway
To set up your gateway, follow these steps:
-
Select a provider. From the Dialogflow Console:
- Select your agent,
pigeon-travel
. - Click Integrations.
- Click Dialogflow Phone Gateway.
- Select your agent,
-
Configure Phone Gateway:
- Select the language - for this lab choose English.
- Select the country code for the telephone number - for this lab select +1 for the United States.
- Click Next.
-
Select a number:
- Choose a telephone number from the list.
- Click Create.
-
Completion:
- The gateway is now active.
- Save the displayed telephone number and close the dialog window. You can click the Dialogflow Phone Gateway integrations button again to retrieve this information.
Click Check my progress to verify the objective.
Task 4. Welcome the caller
Now that you have a working phone gateway agent, look at the intents you imported. This will help you understand how to build your own phone gateway agents.
Follow these steps to greet the caller and provide a list of possible options:
-
Go to the Dialogflow Console.
-
Select your agent.
-
Click Intents.
-
Click Default Welcome Intent.
-
Scroll down to the Events section. Notice that both Welcome (WELCOME) and Telephony Welcome (TELEPHONY_WELCOME) events are present. If the Telephony Welcome (TELEPHONY_WELCOME) is not present, add it. In the events section enter Telephony Welcome and press Enter.
The Telephony Welcome (TELEPHONY_WELCOME) event means that all types of welcome events will trigger this intent. As an alternative, you could create separate intents, each dedicated to a specific welcome event.
- Scroll down to the Responses section and add the DIALOGFLOW PHONE GATEWAY tab by click the plus icon.
-
Click ADD RESPONSES and choose Synthesize Speech.
-
Enter the following in the text field:
Hello! I am the virtual agent for Pigeon Travel. I can help you with many things such as changing your name on your reservation. How can I help you?
- Toggle Use responses from the DEFAULT tab as the first responses to the off position.
-
Click SAVE
-
You can now call the number on a phone and hear the customized response.
Click Check my progress to verify the objective.
Task 5. Set up fulfillment using Cloud Functions to look up reservations in Firestore
In this section, you will set up Firestore for your agent to look up the current reservation and add the change.
Configure Firestore
-
In the Console go to Navigation menu > Firestore.
-
You will be presented with two options, Native Mode or Datastore Mode. Chose SELECT NATIVE MODE.
-
For the location choose nam5 (United States).
-
Click CREATE DATABASE. Once it completes you will have the ability to create a new collection.
-
Click START COLLECTION.
-
Collection ID:
reservations
-
Document ID:
100
-
-
Fill in the details to replicate the details below, then click SAVE.
- Field name: fname
- Field type: string
- Field value: Isabel
Then click the + Add field button to add another:
- FIeld name: lname
- Field type: string
- Field value: Costa
Then click the + Add field button to add another:
- Field name: newname
- Field type: string
- Field value:
You have now added your first document to a Firestore collection.
Firestore Document IDs Best Practice
-
Avoid the document IDs . and ...
-
Avoid using / forward slashes in document IDs.
-
Do not use monotonically increasing document IDs such as:
- Customer1, Customer2, Customer3, ...
- Product 1, Product 2, Product 3, ...
Such sequential IDs can lead to hotspots that impact latency.
Dialogflow Fulfillment
-
Click on Fulfillment in the left menu. It may take a few minutes for the resources to be provisioned.
-
Next to the Inline Editor option, slide the slider to the right so it appears ENABLED. This enables the Cloud Functions editor within your Dialogflow agent.
- Click on the Deploy button on the bottom right. This may take a few minutes.
-
Once deployment is successful, go into the Cloud Console, and using the menu on the left, navigate into Cloud Functions to confirm if the function has been deployed.
-
In the previous lab, you downloaded the Cloud Function source code, you will now upload this code to the newly deployed Cloud Function.
- If you do not have exported files to use, please use this file: pigeon-travel-gsp-793-cloud-function.zip
-
In the Cloud Console locate the newly deployed function and select it.
-
Click on EDIT.
-
Click Next and choose ZIP from Cloud Storage.
- For the ZIP from Cloud Storage enter the following location
qwiklabs-resources-ccai-quest/pigeon-travel-gsp-793-cloud-function.zip
- Click DEPLOY.
Once it completes you now have the code from the previous lab deployed to your fulfillment Cloud Function.
Click Check my progress to verify the objective.
Task 6. Call the number
- Go ahead and dial the number assigned to the Phone Gateway from your own phone.
After the welcome message start the conversation flow by asking the virtual agent to change your name on the reservation. If all goes well, in Firestore you will see the new name set to the name you gave the virtual agent.
Task 7. Fallback to a live agent
What happens when it does not go well? What if the user provided the wrong reservation number. For this you will use the Dialogflow Phone Gateway Transfer Call option.
Before starting, read a little about events since you will use events to trigger an intent.
Events
Intents are normally matched when an end-user expression matches an intent training phrase. However, you can also trigger intents using events. Events can be invoked in many ways.
There are two types of events:
-
Platform events: These built-in events are provided by platform integrations. They are invoked when platform-specific events occur. For example, the FACEBOOK_LOCATION event is invoked by the Facebook integration when an end-user accepts or rejects a request for the end-user's location.
-
Custom events: These are events that you define. You can invoke these events using either fulfillment or the API. For example, you might set a timed alert during a conversation, which invokes an event at a certain time. This event could trigger an intent that alerts the end-user about something.
We will use custom events to trigger a call transfer.
Modify the Fulfillment Code
- Replace the following codes and then Deploy it:
agent.add('I could not find your reservation.');
with
- Replace the following:
console.log('Transaction failure:', error);
with:
- Replace the following:
agent.add('Error reading entry from the Firestore database.');
with :
The function should look like this:
The agent.setFollowupEvent('custom_fallback');
code triggers the custom_fallback event which is associated with an intent. Let's create the intent.
Click Check my progress to verify the objective.
Task 8. Custom fallback intent
The custom fallback intent will be triggered when a reservation is not found or an error occurs when connecting to Firestore which will then transfer the user to a live agent.
To cover this, create a custom-fallback
intent:
-
Click on the ➕ next to Intents in the left menu.
-
Add the name "custom-fallback" into the Intent name text field.
-
In the Events section, add the following, pressing enter when done:
custom_fallback
-
In the Responses section, under Text Responses, enter the following response in the text field:
I'm sorry, I'm not able to find your reservation, but you'll be connected to a live person in a moment.
-
Click the ➕ next to Default and add the DIALOGFLOW PHONE GATEWAY.
-
In the DIALOGFLOW PHONE GATEWAY tab, click ADD RESPONSES and choose Synthesize Speech.
-
Enter in the Synthesize Speech response:
I'm sorry I'm not able to find your reservation but you'll be connected to a live person in a moment.
-
In the DIALOGFLOW PHONE GATEWAY tab, click ADD RESPONSES and choose Transfer Call
-
Enter a number that Dialogflow can transfer in the event the user needs to speak to a live agent.
-
Enable Set this intent as end of conversation.
-
Click the Save button. You may also notice the messages Agent Training started and Agent Training completed on the bottom right of the screen. This lets you know that Dialogflow is retraining your agent model based on the phrases you added.
-
Once training is done, try it out using a phone! Call the number you saved. This time tell the virtual agent the wrong reservation number.
Your agent now responds I'm sorry I'm not able to find your reservation but you'll be connected to a live person in a moment.
, and transfers your call to the number you set.
How this works.
- The system looks for the reservation number in firestore:
if (!doc.exists)
- If the
doc
is false, which means it does not exist, it then triggers the event:
agent.setFollowupEvent('custom_fallback');
- The event is associated with an intent which then allows Dialogflow to speak the response and then transfer the call.
Click Check my progress to verify the objective.
Task 9. (Optional) Export your code
Export your work so you can use it in the next lab. Click on the Source tab under Cloud Functions, and you'll see a button to DOWNLOAD ZIP.
Export your agent
In this section, you will export your agent as a zip file so that you can import it later when you start the next lab. This way you can reuse the intents and entities you've configured so far.
-
Click on the settings gear ⚙ icon next to your agent name in the left menu.
-
In the settings page that opens up, go to the Export and Import tab.
-
Click on EXPORT AS ZIP. This will download your agent into a local zip file.
Congratulations!
You have added a phone gateway to allow users to call into your virtual agent.
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 February 9, 2023
Lab Last Tested February 9, 2023
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.