# Dialogflow CX: Bot Building Basics - GSP928

## **Overview**

Dialogflow CX provides a simple, visual bot building approach to virtual agent design. Bot designers now have a much clearer picture of the overall bot building process and multiple designers are able to easily collaborate on the same agent build. Dialogflow CX supports [many languages](https://cloud.google.com/dialogflow/cx/docs/reference/language) for your agent to use and understand, but this lab will be using only English.

In this lab you will build a conversational agent using Dialogflow CX.

**Prerequisites**

You should be generally familiar with the [basic concepts](https://cloud.google.com/dialogflow/cx/docs/basics) of conversational AI. Read through these [Sample Transcripts](https://docs.google.com/document/d/1AqokDOCJIOhGoLzZp9bNxV7khnZEqFADfaaEtO_Lg6Q/edit?usp=sharing) to get an idea of what client transcripts might look like. Often the first step in creating an agent is to read through client transcripts and/or other contextual data to understand the use case and specific business requirements.

---

### **Task 1. Create your agent**

1. Visit the [Dialogflow CX console](https://dialogflow.cloud.google.com/cx/projects), then select your Cloud Project name. Your Cloud Project name should match your Project ID for your lab like: ***qwiklabs-gcp-xx-xxxxxxxxxxx***
    

![Dialogflow CX console with project name highlighted](https://cdn.qwiklabs.com/8Sfq0FGxRdMCrLG%2FBV0vbPpqvy1kjPNDxuo2XoTVV%2Fc%3D align="left")

Click *Check my progress* to verify the objective.

Enable API

**Check my progress**

2. Click **Create agent &gt; Build your own** If you do not see this page, refresh your browser.
    

![Agents page with Create agents button highlighted](https://cdn.qwiklabs.com/IKmtRUM5cYGrdyV9mxuen02E4reTtmqQKTXCSyBRVuA%3D align="left")

3. Name your agent `Flight booker`.
    
4. Pick **global** from the Location drop-down.
    
5. Click **Create**.
    

![Create agent window, with display name and location fields completed](https://cdn.qwiklabs.com/jQwCTvg7P1sq8Gsmx1sh67fyuw0NyvOx3vC%2BTz6Z4aI%3D align="left")

6. After creating the agent, navigate to **Agent Settings** &gt; **General** &gt; **Logging settings** and check the boxes next to **Enable Cloud Logging** and **Enable Conversation History** option. It will generate logs for this agent.
    
7. Click **Save**.
    

![Agent Settings General tabbed page with Enable stackdriver logging option selected](https://cdn.qwiklabs.com/e%2Fe5l7ixl3Ia4gikhgyOp8EkcH2Gx%2Fnznkih4SRjPBg%3D align="left")

Click **Check my progress** to verify the objective.

Create an Agent

**Check my progress**

You must enable the Dialogflow API for your project to be able to access the Dialogflow CX console.TrueFalse

### **Task 2. Intents**

Intents are the reasons an end-user has for interacting with the agent, for example, ordering something. You can create an [intent](https://cloud.google.com/dialogflow/cx/docs/concept/intent) for every topic they may want to navigate.

Intents can be reused across Pages and Flows. Each intent is defined by training phrases end-users typically ask. These can be annotated or "labeled" to collect specific parameters, such as arrival city or departure date.

Dialogflow CX will suggest annotations as you include training phrases for the intent; they can also be manually annotated to collect the parameter values you want to extract from the end-user's interaction with your agent.

**Recommended:** in order to reuse intents as well as make maintenance easier, name your intents with clear and explicit names.

Format of intent: `category.some_description`

Example of formatting:

* Core Intents: `main.book_a_flight`
    
* Common intent but not core: `supplemental.flight_emissions`
    
* Reusable intents: `confirmation.yes`, `confirmation_no`, `redirect.live_agent`.
    

**Create your first intent**

1. Click **Manage** &gt; **Intents** &gt; **\+ Create** :
    

![Intents tab with Create button highlighted](https://cdn.qwiklabs.com/1XNo8T2IWshePmq%2B2NGlegvZzBonE8%2BKbk54LL7Y3VA%3D align="left")

2. Display Name: `main.book_a_flight`
    
3. Under the **Training Phrases** header, add each of the following phrases into Dialogflow, click **Enter** after each phrase:
    

* Book a flight
    
* Can you book my flight to San Francisco next month
    
* I want to use my reward points to book a flight from Milan in October
    
* My family is visiting next week and we need to book 6 round trip tickets
    
* Four business class tickets from Taiwan to Dubai for June 2nd to 30th
    
* I need a flight Saturday from LAX to San Jose
    
* Book SFO to MIA on August 10th one way
    
* Help me book a ticket from 4/10 to 4/15 from Mexico City to Medellin Colombia please
    
* I am booking a surprise trip for my mom, can you help arrange that for May 10th to May 25th to Costa Rica
    
* Do you have any cheap flights to NYC for this weekend
    
* I want to fly in my cousin from Montreal on August 8th
    
* I want to find two seats to Panama City on July 4th
    
* For my wedding anniversary we want to go to Seattle for Christmas
    

**Note:** For higher model accuracy, using 20-50 training phrases with short and long response options is recommended.

4. Click **Save**.
    

![Intents tab with Save button highlighted](https://cdn.qwiklabs.com/jrlhynYAuvLjHaSQSFzu6LkthSmSckr1%2FsN1sTN9eFQ%3D align="left")

5. Some words are highlighted because Dialogflow has automatically labeled the entities, such as a date, place, or number.
    

![Intents page displaying highlighted dates, places, and numbers](https://cdn.qwiklabs.com/zJ4LuQQM0x33Q%2BjVHzkR%2Fa8D%2BG2cWIBQNScH32ZXn9Q%3D align="left")

**Note:** You can also add training phrases in bulk by creating a training phrase CSV file and uploading it to Dialogflow.

### **Task 3. Flows and pages**

[Flows](https://cloud.google.com/dialogflow/cx/docs/concept/flow) are used to define topics and the associated conversational paths. Every agent has one flow called the Default Start Flow. This single flow may be all you need for a simple agent.

More complicated agents may require additional flows, and different development team members can be responsible for building and maintaining these flows.

![Default Start Flow diagram](https://cdn.qwiklabs.com/d7XD2Pwy%2F8vwGLM47ZtSJeQM75y8i%2BzSpU2SjYIhUus%3D align="left")

Every flow starts with a [Page](https://cloud.google.com/dialogflow/cx/docs/concept/page), and is made of one or multiple different pages thereafter to handle the conversation within a particular flow. The current page an end-user is on is considered the "active page". Each page can be configured to collect any required information from the end-user.

**Build from your Default Start Flow**

The page your agent starts from is called the *Default Start Flow.* Pages store routing logic, responses (known as *Fulfillment*), specific actions to take if an intent cannot be matched (known as *no-match*) or receives *no-input* (which is when the agent does not receive a response in time).

1. Click **Build**.
    
2. Click **Start** to open the page.
    

![Default Start Flow pagewith Build and Start button highlighted](https://cdn.qwiklabs.com/xUY%2FkhhER9yr0MLLKWA885K0QfuZnrwsfMg3Ew1Rm%2BY%3D align="left")

3. From the expanded options on the Start page, select the **+** icon next to **Routes**.
    

![Routes and plus icon highlighted](https://cdn.qwiklabs.com/0l53fY%2FDvU%2FtmRMMUth5pq8SylarTRKi4C04HQS1jNY%3D align="left")

4. Select the intent **main.book\_a\_flight** from the drop-down, then click **Save**.
    

![Route window with main.book_a_flight intent selected and Save button highlighted](https://cdn.qwiklabs.com/9nVIMdFvY7yrrKyWbia%2Fb4onKN8tAovD%2BiAlSWlVrTc%3D align="left")

5. Next, in the Routes section, click the **main.book\_a\_flight** route.
    
6. Scroll down to **Transition** and choose **\+ new Page** from the drop-down.
    
7. Name the page `Ticket information` and click **Save**.
    

![Highlighted Page name field populated with Ticket information](https://cdn.qwiklabs.com/p7W8gbTRuIsw8CDW5QU9%2BpdWYwSVITY5X9NY%2F6dH%2BPI%3D align="left")

8. Exit out of the windows to return to the main display of flows to see your new **Ticket information** page connected to the **Start** page.
    

![Main display with flow diagram](https://cdn.qwiklabs.com/hx2do5qJPo8ouN8BrFJF6sFMIyxpPRGWNKrnbI5Xd90%3D align="left")

The beginning of the flow now includes a greeting, and will then proceed to the *Ticket information* page when the `main.book_a_flight` intent is matched. On the Ticket Information page you will collect parameters from the end-user so they can book their flight.

### **Task 4. Entities and parameters**

* [Entities](https://cloud.google.com/dialogflow/cx/docs/concept/entity) define the type of information you wish to extract from an end-user, ex: city you want to fly to. Use Dialogflow's built-in " [system entities](https://cloud.google.com/dialogflow/cx/docs/reference/system-entities)'' for matching dates, times, colors, email addresses, and so on.
    
* System entities can also be “extended” to include values that are not part of the default system values. If you need to create a fully customized entity, you can do so by creating a [Custom Entity](https://cloud.google.com/dialogflow/cx/docs/concept/entity-custom) type for matching data that is custom to your business and not found as a system entity.
    
* [Parameters](https://cloud.google.com/dialogflow/cx/docs/concept/parameter) are information supplied by the end-user during a session, such as date, time, and destination city. Each parameter has a *name* and an *entity type*. They are written in snake\_case (lowercase with underscores between words)
    

**Create your first set of parameters**

Next you will use an entity to extract a required parameter from the end-user.

1. Click on the page **Ticket Information**, then the **+** by **Parameters** to collect flight data.
    
2. Enter `departure_city` in the **Display name** field.
    
3. Choose `@sys.geo-city` from the **Entity type** drop-down.
    
4. Scroll down to **Initial prompt fulfillment &gt; Agent responses &gt; Agent Says** and add `What city would you like the flight to depart from?`
    
5. Click **Save**.
    

![Initial prompt fulfillment section with Agent says field populated](https://cdn.qwiklabs.com/bnMqg2xeuR4wMFIsFkZXwSf5%2BveU6us8teNywR%2BqjTE%3D align="left")

6. Exit out of this window to make another parameter.
    
7. Click the **+** by **Parameters** again to create 4 additional parameters one by one with the following name, entity type, and how the agent will prompt the end-user.
    

| **Display name** | **Entity type** | **Agent says** |
| --- | --- | --- |
| departure\_date | @sys.date | What is the month and day of the departure? |
| destination\_city | @sys.geo-city | What is your destination city? |
| return\_date | @sys.date | What is the month and day for the returning flight? |
| passenger\_name | @sys.any | What is the passenger's name? |

When finished they are listed like this:

![Parameters page displaying the list of added parameters](https://cdn.qwiklabs.com/QSVShx7XAKQByaf7pZaaR4QZ6HXco0tatM0ulrOd%2Fpw%3D align="left")

**Note:** The **order** in which the parameters are listed affects the order in which the flight booking agent will ask for each. You can easily change the order by dragging parameters up or down.

**Knowledge check**

The primary reason that an end-user is interacting with your agent is captured by which resource type?IntentsParametersEntitiesPagesFlows

**Submit**

### **Task 5. Conditions**

Once the agent has collected the necessary 5 flight booking parameters, you want to route the end user to another page using a routing [*condition*](https://cloud.google.com/dialogflow/cx/docs/reference/condition), which you will create next.

1. Exit out of the parameter window to return to the **Ticket information** page again.
    
2. Scroll down to locate **Routes** and click the **+** sign next to it.
    
3. Scroll down to **Condition** &gt; **Condition rules** &gt; select "Match **AT LEAST ONE** rule (OR)"
    
4. In the **Parameter** field enter `$page.params.status`.
    
5. Choose the `=` sign in the **Operand** drop-down.
    
6. In the **Value** field enter: `"FINAL"` (ensure you include the double quotes).
    
7. Click **Save**.
    

![Condition section with Parameter field highlighted](https://cdn.qwiklabs.com/yQ2ra9mlOCBSnNUv4%2FP5dRH3iIM%2B3OZLPVPT6QpTn%2Fs%3D align="left")

**Knowledge check**

What’s the correct way to check if all parameters on a Page are filled?$page.params.status = “FINAL”$page.params.status = FINAL#context.params.status = “FINAL”#context.params.status = FINAL$session.params.status = “FINAL”$session.params.status = FINAL

**Submit**

### **Task 6. Fulfillment**

Now add a response to say to the end-user when all 5 of their booking parameters are collected. These responses are called *Fulfillment*.

1. From the condition you just made, scroll down a bit and locate the section called **Fulfillment**.
    
2. Under **Agent responses** type the following for **Agent says**: `Thank you for that information. Let me check on the availability of your ticket`.
    
3. Click **Save.**
    

(Now stay on this page while you read on to the next step of confirming information.)

![Fulfillment section with highlighted populated Agent says field](https://cdn.qwiklabs.com/pXppHlviKTcdwp%2FteAXJ0lTPhFCkvAEMHcPsZeJ6Pao%3D align="left")

### **Task 7. Confirming information**

After offering a response (or *fulfillment*), you need to create a transition to a new page that will repeat back to the end-user if the travel information collected (*parameters*) are correct.

1. Continue to scroll down (past the fulfillment you just created) until you reach **Transition**.
    
2. On the **Page field**, select the drop down to choose **\+ new Page**.
    
3. Type `Confirm trip` in the field called **Page name**.
    

![Transition section with populated Page name field highlighted](https://cdn.qwiklabs.com/eLRI2GAJSDPyQHGrKMl6EXE%2Bdv1qvqpoDhoec8nZjes%3D align="left")

4. Click **Save**.
    
5. Exit out of the window.
    
6. Take a look at the flow of your 3 pages.
    

![Main display with flow diagram. Flow points include Start, Ticket information, and Confirm Trip](https://cdn.qwiklabs.com/OL9OG2ZeSmaHeK8YE1zgABoUc1mm%2FsR5mXm1Q5hDPHM%3D align="left")

**Repeating back the parameters collected from end-users**

[Session Parameters](https://cloud.google.com/dialogflow/cx/docs/concept/parameter#session) store information *previously collected* from the end-user and are active throughout the session. They also help you repeat information back to the end-user.

For example, we can have the agent repeat back a passenger's name: "*Thanks for providing that information, $session.params.passenger\_name.*" *This displays to the end-user as "Thanks for providing information, John Day*."

They are formatted as follows:

* *Prefix*: **$session.params.**
    
* *Entity Name:* **passenger\_name**
    

So referencing the departure city would look like: $session.params.departure\_city

1. Starting from the Build view, click on the **Confirm Trip** page &gt; **Entry fulfillment** &gt; **Edit fulfillment** field.
    

![Confirm trip window with Edit fulfillment field highlighted](https://cdn.qwiklabs.com/vdYhvpEdo9kIZMa5LiLLsmnCVVYv%2Fpwmzv1XfU6jm%2Fk%3D align="left")

2. Since you used 5 parameters, you can repeat them back to the user via the following session parameters. Paste the following text within the **Agent says** section:
    

```bash
This is to confirm that $session.params.passenger_name will fly
From: $session.params.departure_city
To: $session.params.destination_city
Leaving on: $session.params.departure_date
Returning on: $session.params.return_date

Is this correct?
```

![Fullfillment window with Agent says field populated](https://cdn.qwiklabs.com/X3TKPGbbLtbtOAcv1yTQHq2O2g87NRPd4DfTXwbq6eA%3D align="left")

3. Then click **Save.**
    
4. This is what it will look like to the end-user when the virtual agent repeats back the collected session parameters:
    

![Virtual agent displaying the collected session parameters](https://cdn.qwiklabs.com/ws%2FUXP9uoxUf3i9%2F8pUH7%2BFuMW4W2rhyQsvuR%2B435T4%3D align="left")

**Positive confirmation route**

1. Exit out of the window to return to your **Confirm Trip** page. Click **+** next to **Routes.**
    

![Confirm trip page with plus button highlighted](https://cdn.qwiklabs.com/65RNySvyeOId7QQmkEwo2HBpdLcquMqF8NhIbbHGWwQ%3D align="left")

2. Click the **Intents** drop-down , then click **\+ new Intent.**
    

![Intent drop-down menu with + new intent option highlighted](https://cdn.qwiklabs.com/CkYRejhy7UQpzS2Shnit6gS4FVzVmWZBeG6xbLLGR18%3D align="left")

3. In Display name type `confirmation.yes`.
    
4. In Training phrases enter `yes` then **Enter** (you can add more phrases like "correct", "yup", etc., to improve the NLU matching for this intent).
    

![Training phrases section with yes and correct populated in the text field](https://cdn.qwiklabs.com/VnFID7hdHg75QIoicxTbh36JNTi6tojY2ZoGeT6Ghnk%3D align="left")

5. Click **Save**.
    
6. After saving, scroll down to the **Fulfillment** section and under **Agent responses** enter `Great, your flight is booked!` for **Agent says**.
    

![Highlighted Agent says field displaying the message: Great, your flight is booked!](https://cdn.qwiklabs.com/vlUvH7NWH8UPrsdmc2SRV%2B2mVmQqrvyhtae0C1ibu9A%3D align="left")

7. Then click **Save**.
    
8. Click the back arrow, next to **Route**.
    

![Back arrow highlighted](https://cdn.qwiklabs.com/U5hS2FWYKWC2YjQaPjbtTgOG08NbEgUCw2Q02vCMQAU%3D align="left")

**Negative confirmation route**

Now add logic to route an end-user to recollect their flight parameters if they say the information is incorrect.

1. Still on the Routes section select **Add route**.
    

![Add route button highlighted](https://cdn.qwiklabs.com/kbEpP1cU%2BT%2BOzT8O5Pfndh3u9li%2FlxHB%2FcIEt7SNmUU%3D align="left")

2. From the Intents drop-down choose **\+ new Intent**.
    
3. Name the intent `confirmation.no` in the Display name field.
    

![Highlighted Display name field with confirmation.no entered](https://cdn.qwiklabs.com/shgQSeupOiYQRDgxjHv%2Fc0m%2FUltQRGh5NtroQWncUiY%3D align="left")

4. Scroll down to the Training phrases section type `no` then click **Enter**.
    

![Training phrases section with no highlighted](https://cdn.qwiklabs.com/RndBK84cqz%2Bwx9WOWBlbuqrilnyme2gbwaXQvKjpHcM%3D align="left")

5. Click **Save**.
    
6. Next, scroll down to the section called **Transition** &gt; **Page**, then choose **Ticket information** from the drop-down.
    

![Transition section with Ticket information selected i the Page dropdown menu](https://cdn.qwiklabs.com/uwTzIU7cgTtvTdNJpLBzYQTt5cKqqvE7RWE%2F0%2FKvndo%3D align="left")

**Note:** This is to prompt the user again for their flight information.

7. Scroll up to **Parameter presets** and click **Add parameter** . Enter the following *5* values and assign their value to **null** *without* the quotation marks.
    

**Note:** You will need to delete the quotation marks in the value column and type **null**. This is to delete the parameters collected from the end-user.

| **Parameter** | **Value** |
| --- | --- |
| `departure_city` | null |
| `destination_city` | null |
| `departure_date` | null |
| `return_date` | null |
| `passenger_name` | null |

![Parameter presets section with null value for each of the five parameters](https://cdn.qwiklabs.com/j%2B%2BQiMSwDGsFDnzkYKZ48X5fDbAAN%2F5%2Bf2IH%2BNB%2BImc%3D align="left")

The purpose of this is to remove the value that was previously collected from the end user to allow them to submit a new value. If this step is missed, it might result in an infinite loop scenario in your bot!

8. Click **Save**.
    
9. Exit out of the window to return to the Build view, you will now see how all 3 pages flow. Note that the last page has two arrows between the Confirm trip and Ticket information page because the `confirmation.no` intent is linked back.
    

![Build view displaying the flow diagram](https://cdn.qwiklabs.com/QOPWL1LQZXYiLCyzq91bQBA6XfeSAUw4ANC4qK%2BqvB4%3D align="left")

**Knowledge check**

Select the agent response that’s best for casually confirming that tickets are booked.The transaction you requested has been completed. You will receive an electronic copy of your tickets within the next 6 hours. Now, would you like to continue browsing upcoming events?You’re all set! Look for the tickets in your email later today! Now, are there any other events you’re interested in?

**Submit**

### **Task 8. Testing**

1. To test that your agent works as intended, click on **Test Agent** in the upper right corner of the screen.
    
2. Interact with the agent as if you were the end-user. As you move through the main flow, notice the pages, intents, and transitions you created.
    

Depending on how you arranged your parameter collection, you can try typing in the following sample dialogue:

* I'd like to book a flight
    
* Austin
    
* Tomorrow
    
* Boston
    
* Next Friday
    
* Mickey Mouse
    
* Yes
    

This should result in a successful transaction through your agent, commonly known as the “happy path”.

Here is an example of the above agent testing in the Test Agent console:

![Test Agent console with simulator flow example](https://cdn.qwiklabs.com/LIP9dwj3V2o6IYPaNdoH%2BfhfxK2%2B6NElFTrTscAOOeE%3D align="left")

Click *Check my progress* to verify the objective.

Test the agent

**Check my progress**

### **Task 9. Exporting your agent**

When you build an agent for one project, you can export it to use in a different project. You can export your agent and save it to use in future labs or to continue building in your own personal project!

1. In the **Agent** drop down at the top of the Dialogflow CX console, click **View all agents**.
    

![Expanded Agent dropdown with View all agents button highlighted](https://cdn.qwiklabs.com/UGdtXF8vOtRq5x%2BwsNIJSLP3er4ltgv2c8tmtbsLQqw%3D align="left")

2. On the Agent list screen, click the context menu next to your agent and then click **Export**.
    

![Expanded context menu with Export button highlighted](https://cdn.qwiklabs.com/aOM2Di5MA10kESriBhumgrBYpQp06MVVpZ9wVl1agAk%3D align="left")

3. On the Export Agent screen, choose **Download** to local file, then click **Export**.
    

![Export Agent page with Download option selected and highlighted](https://cdn.qwiklabs.com/X3sbOk38m%2BDMkPxxIMKjhW57JKHTFo7VOOhKWNfgAkw%3D align="left")

---

### Solution of Lab

%[https://www.youtube.com/watch?v=G6L_hTCahgc] 

Download file: [gsp928.blob](https://github.com/ePlus-DEV/storage/blob/main/labs/GSP928/gsp928.blob)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723260297260/7a123acd-f027-4c8b-80ae-2ddd22536763.png align="center")
