Establishing a Dialogflow Webhook

45 minutes
  • 6 Learning Objectives

About this Hands-on Lab

Google Cloud Dialogflow creates virtual agents capable of conversing with people to convey and receive information in context. While the Dialogflow UI is quite robust, there are situations that require calculations which can be supplied by a Google Cloud Function when called by a webhook. In this Hands-On Lab, you’ll import a Dialogflow CX agent and then modify it to replace a static response with one programmatically output by a Cloud Function and integrated by a webhook.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable APIs
  1. Enable DialogFlow API.
  2. Enable Cloud Functions API.
  3. Enable Cloud Build API.
Retrieve Working Files
  1. Activate Cloud Shell.
  2. Retrieve the working files:
git clone https://github.com/linuxacademy/content-google-cloud-certified-professional-machine-learning-engineer
  1. Change to the establish-dialogflow-webhook directory.
  2. Download the exported Dialogflow agent:
    cloudshell download exported_agent_acg-apparel.blob
Import the Dialogflow Agent
  1. Go to the Dialogflow CX console at https://dialogflow.cloud.google.com/cx/projects.
  2. Select the project starting with establishing….
  3. Create Agent with the following parameters:
    • Name: ACG Apparel
    • Region: us-east1
  4. Restore the previously downloaded agent.
Create the Cloud Function
  1. Navigate to Cloud Functions.
  2. Apply the following parameters:
  • Function name: hoodie-dialogflow-webhook
  • Region: us-east1
  • Trigger type: HTTP
  • URL: Copy and save the value. (You will need this URL when configuring the webhook.)
  • Authentication: Require authentication
  • Require HTTPS
  1. Select Go 1.16 for the Runtime.
  2. Copy the contents of the function.go file and paste to the function.go field.
  3. Name the entry point HandleWebhookRequest.
  4. Deploy.

    Note: This process can take up to two minutes to complete.

Insert the Webhook
  1. Switch to the Dialogflow CX Console.
  2. Create the webhook with the following details:
  • Display name: hoodie-agent-webhook
  • Webhook URL: Paste the previously copied webhook URL
  • All other fields use default values
  1. Apply the webhook.
  2. Delete the existing text response under the Agent says heading. When you hover the text, the delete button appears.
  3. Enable webhook.
  4. Use the hoodie-agent-webhook.
  5. Set up the parameter.
  6. Add the following text response in the Agent Says field, You can cancel your order within $session.params.cancel-period business days. Thanks for your order. Have a great day!.
Test the Webhook
  1. Test agent by using the following responses:
    Hello
    I would like to buy a hoodie
    Green please
    Large I think

Additional Resources

Management has approved the enhancement of your current Dialogflow CX agent, which is being used to take orders for clothing from customers, so that the agent programmatically asserts when the order will be available. Your job is to adapt the existing agent to issue the webhook, set up the Cloud Function, and test to verify functionality.

Resources:

GitHub repo: https://github.com/linuxacademy/content-google-cloud-certified-professional-machine-learning-engineer

Dialogflow link: https://dialogflow.cloud.google.com/cx/projects

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?