Dialogflow CX:构建零售业虚拟客服

1. 准备工作

在此 Codelab 中,您将了解如何使用 Dialogflow CX(一种用于构建对话式界面的对话式 AI 平台 [CAIP])构建零售聊天机器人。Dialogflow CX 可以实现虚拟客服,例如聊天机器人、语音机器人、电话网关,并支持 50 多种不同语言的多个渠道。

此 Codelab 将引导您构建零售网站聊天机器人。我们要为其构建聊天机器人的虚构商家名为 G-Records。G-Records 是一家位于加利福尼亚州的摇滚唱片公司。该唱片公司签约了 4 支摇滚乐队:Alice GooglerG's N' RosesThe Goo FightersThe Google Dolls。G-Records 向所有摇滚乐迷销售乐队商品。

在本 Codelab 结束后,您可以使用聊天机器人订购衬衫或音乐,也可以询问订单相关事宜。

最终结果

学习内容

通过实践,您将了解 Dialogflow CX 相较于 Dialogflow ES 的优势!其中包括以下概念:

  • 如何在 Google Cloud 中创建 Dialogflow CX 虚拟客服
  • 了解如何创建流程
  • 了解如何创建实体
  • 了解如何创建 intent
  • 了解如何使用状态处理程序创建页面和转换页面
  • 了解如何使用 intent 路由转换页面
  • 了解如何使用参数和条件路由转换页面
  • 了解如何使用系统函数返回条件响应
  • 了解如何创建回退消息
  • 了解如何使用模拟器
  • 了解如何创建测试用例和测试覆盖率

最终的 Dialogflow CX 客服设计将如下所示:

最终结果

所需条件

  • 您需要拥有 Google Identity / Gmail 地址才能创建 Dialogflow CX 客服。
  • 拥有 Google Cloud 的访问权限。

2. 环境设置

创建 Google Cloud 项目

由于 Dialogflow CX 在 Google Cloud 中运行,因此您必须创建一个 Google Cloud 项目。项目用于组织您的所有 Google Cloud 资源。项目由一组协作者、已启用的 API(和其他资源)、监控工具、结算信息以及身份验证和访问权限控制组成。

创建新项目时,您需要输入项目名称。并且您必须将其关联到现有的结算账号和组织。

结算账号用于定义一组给定资源的付款方,并且可以关联到一个或多个项目。项目的使用费将计入关联的结算账号名下。在大多数情况下,您应在创建项目时配置结算信息。如需了解详情,请参阅结算文档。确保您的 Cloud 项目已启用结算功能。

创建新项目

启用 Dialogflow API

如需使用 Dialogflow,您必须为项目启用 Dialogflow API。

  1. 选择要为哪个项目启用 API,然后点击继续
  2. 收起“API 和服务”菜单,然后点击创建凭据
  3. 点击应用数据
  4. 由于您目前不使用 Kubernetes Engine、App Engine 或 Cloud Functions,因此请回答不,我没有使用它们
  5. 点击完成

设置凭据

创建新的 Dialogflow CX 客服

如需创建新的 Dialogflow CX 客服,请先打开 Dialogflow CX 控制台:

  1. 选择之前创建的 Google Cloud 项目。
  2. 点击创建代理

填写基本代理设置表单:

  • 您可以选择任何显示名。
  • 选择以下位置:us-central1
  • 选择您的首选时区。
  • 选择 en - 英语 作为默认语言

点击创建

创建代理

好的,一切就绪。我们终于可以开始对虚拟客服人员进行建模了。

3. 流

复杂的对话框通常涉及多个对话主题。例如,我们为 G-Records 构建的聊天机器人旨在销售乐队商品,因此我们会围绕商品目录、付款、订单状态和客户服务问题进行对话。我们可以将这些对话主题拆分为多个流程。

零售流程

借助流程,团队可以处理各个对话路径。最佳实践是简化流程,使其能够轻松适应屏幕,并且更加模块化。

流程是 Dialogflow CX 中的一个新概念。Dialogflow Essentials 中有一个概念叫做“超级代理”,与“流”有点类似。不过,您会更频繁地使用流程。

在本实验的后面部分,我们将使用可结束流程的状态处理脚本(以便它跳回到下一个或上一个流程),或者您也可以结束整个客服人员会话。

我们来创建一些流程。

创建流程

  1. Dialogflow CX 中,依次点击 + 图标 > 创建流程
  2. 指定名称:Catalog,然后按 Enter 键。

创建流

您的第一个流程“目录”已创建。现在,创建其他流程:

  • Order Process
  • My Order
  • Customer Care

流

在本实验的后面部分,我们将设置页面状态处理脚本,以确保最终可视化结果如下所示:

流

模拟器

在 Dialogflow CX 控制台的右侧,您可以使用内置模拟器测试虚拟客服人员。您可以从对话开头或特定流程开始测试对话。

  1. 点击屏幕右上角的测试代理按钮。
  2. 在“与客服人员交谈”字段中,输入:Hello 虚拟客服人员会使用默认欢迎文本进行回复:您好!您需要什么帮助?

模拟器

我们来修改此默认欢迎文本。

默认初始流

首先,我们创建一个意图路由,该路由将在您向虚拟客服人员问好时触发。

  1. 在左侧的 Build > Flows 边栏中,点击默认初始流,然后选择 Start 树节点。

此时会打开开始页面。系统会自动在构建 > 页面边栏部分中选择“开始”页面。

  1. 开始 > 路由中,点击默认欢迎 intent

意图用于对一轮对话中的最终用户意图进行分类。在 Dialogflow CX 中,意图可以是状态处理程序的一部分,用于路由下一个活跃页面或执行方式

  1. 移除所有“客服人员的回答”条目,然后添加以下新文本:

Welcome, I am the virtual agent of G-Records, a fictional rock label. You can order artists merchandise, ask questions about your order or shipping, and I can tell you more which artists are currently signed with us. How can I help?

为了简化对话,我们还需要一些快速回复按钮 / 建议条状标签。

  1. 依次点击 Add dialogue option > Custom payload(添加对话选项 > 自定义载荷),然后使用以下代码段。
  2. 将以下代码段用作自定义载荷,然后点击保存

如需详细了解自定义载荷,请参阅文档

{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Which artists?"
            },
            {
              "text": "Which products?"
            },
            {
              "text": "About my order..."
            }
          ]
        }
      ]
    ]
  }

默认欢迎意图

  1. 接下来,在模拟器中测试欢迎 intent。

您可能想知道为什么看不到任何富媒体内容。这是因为建议条状标签等富媒体内容依赖于集成。以下步骤需要有结算账号,但如果您没有结算账号,可以跳过这些步骤。

  1. 在左侧边栏中,依次点击管理 > 集成
  2. 选择 Dialogflow Messenger,然后点击连接
  3. 在弹出式窗口中,点击启用

集成启用

系统随即会显示另一个弹出式窗口,其中包含集成 JavaScript 代码,您可以将其粘贴到您的网站中,以便在您的网站上集成 Dialogflow Messenger 组件。由于我们尚无网站,因此将直接在该工具中测试虚拟客服人员。

Dialogflow Messenger 立即试用

  1. 点击立即试用链接。
  2. 点击右下角的聊天机器人图标,打开聊天窗口。写入 Hello 以发起对话。

Dialogflow Messenger 立即试用

目前,当您点击建议条状标签时,虚拟客服人员无法理解您的意思。这是因为我们的虚拟客服人员尚未在不同状态之间切换。我们可以在 Dialogflow CX 中使用页面来实现此目的。继续本实验,我们先创建一些实体 intent

4. 实体类型

实体类型用于控制最终用户输入数据的提取方式。Dialogflow CX 实体类型与 Dialogflow ES 实体类型非常相似。Dialogflow 提供预定义的系统实体,这些系统实体可以匹配许多常见数据类型。例如,有用于匹配日期、时间、颜色、电子邮件地址等类型的系统实体。您还可以自行创建自定义实体来匹配自定义数据。

首先,我们需要准备所有自定义实体,然后才能设计流程中的页面。我们将创建以下实体:

Dialogflow 实体

创建实体

我们来创建一个音乐人实体。

  1. 依次点击管理 > 实体类型
  2. 点击 + 创建
  • 显示名称:Artist
  • 实体:
  • The Google Dolls(同义词:Google Dolls
  • The Goo Fighters(同义词:Goo Fighters
  • G's N' Roses(同义词:Gs and Roses
  • Alice Googler
  • 点击“高级选项”,然后勾选模糊匹配。(即使您拼写乐队名称有误,系统也可能会将其与正确的实体进行匹配。)
  • 在“高级选项”中,还要选中在日志中隐去。(如果您拼写乐队名称有误,系统会在日志中更正名称。)
  1. 点击保存

我们还需要一个 Merch 商品实体:

  1. 依次点击管理 > 实体类型
  2. 点击 + 创建
  • 显示名称:Merch
  • 实体:
  • T-shirt
  • Longsleeve(同义词:Longsleeve shirt
  • Tour Movie
  • Digital Album(同义词:MP3 AlbumMP3
  • CD(同义词为 DiscPhysical CD
  1. 点击保存

我们还需要一个 Album 实体:

  1. 依次点击管理 > 实体类型
  2. 点击 + 创建
  • 显示名称:Album
  • 实体:
  • Live
  • Greatest Hits(同义词:Hits
  1. 点击保存

我们还需要一个用于服装尺寸的实体:

  1. 依次点击管理 > 实体类型
  2. 点击 + 创建
  • 显示名称:ShirtSize
  • 实体:
  • XS(同义词:Extra Small
  • S(同义词:Small
  • M(同义词:Medium
  • L(同义词:Large
  • XL(同义词:Extra Large
  • 2XL(同义词:Extra Extra Large
  • 3XL
  1. 点击保存

以及一个用于订单号的实体,通常由 4 个字母数字和 3 个数字组成。(例如 ABCD123)

  1. 依次点击管理 > 实体类型
  2. 点击 + 创建
  • 显示名称:OrderNumber
  • 正则表达式实体
  • 实体:[A-Z]{4}[0-9]{3}
  1. 点击保存

您的实体配置应如下所示:

@音乐人:@Artist 实体类型

@Merch:@Merch 实体类型

@Album:@Album 实体类型

@ShirtSize: @ShirtSize 实体类型

@OrderNumber: @OrderNumber 实体类型

准备好自定义实体后,我们就可以准备 intent 了。我们继续完成实验。

5. intent

“intent”用于对一轮对话中的最终用户意图进行分类。在 Dialogflow CX 中,这些功能已大大简化,不再是构建对话控制的基础组件。Dialogflow CX 仅使用意图来匹配用户所说的内容。在 Dialogflow ES 中,您必须将所有内容都与 intent(参数、事件、执行方式等)相关联。Dialogflow CX 中的 intent 仅包含训练语句,因此可重复使用。它将不再控制对话。因此,创建 intent 的过程将非常简单明了:

意图中的训练短语可以使用实体提取“变量”输入,因此最好提前创建实体类型,这正是我们在本实验步骤的上一个页面中所做的。

创建 intent

首先,我们需要准备所有 intent,然后才能设计流程中的页面。

  1. 依次点击管理 > 意图
  2. 点击 + 创建

请使用以下详细信息:

  • 显示名为 redirect.artists.overview
  • 广告内容描述 Artists overview: The bands supported by the label

新 intent

向下滚动,然后创建以下训练短语

  • Which bands are signed?
  • Which bands
  • Which artists
  • Which artists are part of the record label
  • Who is part of the label
  • From which bands can I buy merchandise
  • Band merchandise
  • Which music do you have?
  • I would like to know who are signed to the label
  • Who are supported by the label
  • From who can I buy shirts
  • What music can I order
  • Can I get an overview of all the artists

训练短语

  1. 点击保存
  1. 现在,我们继续创建所有其他 intent。发挥想象力,编写更多训练短语。最佳实践是,每个 intent 至少包含 10 个训练短语,以涵盖用户可能触发该 intent 的不同方式。鉴于本实验的目的,少一些也无妨。

请注意以下几点:

  • 请注意,在您输入训练短语时,Dialogflow CX 会自动为实体添加注释。如果未能成功,您可能需要更新实体(通过添加同义词)或自行手动为训练短语添加注释。
  • 训练短语更短:Dialogflow 的 NLU 系统也可以使用更短的训练短语,我们在下方提供了几个示例。
  • 过度训练:为某个 intent 提供的训练短语过多可能会导致过度训练,从而导致不理想的结果。最佳实践是使用迭代和增量测试,并在没有匹配的意图时添加训练短语。

显示名

训练短语

redirect.product.overview

"Which products do you sell?", "What merchandise items do you have?", "What are you selling?", "What are the items?", "Which products?" "What merchandise?", "Please tell me what you have"

confirm.artists.overview

"Yeah, let me buy merchandise", "Yes, I want to purchase something", "Yes, I would like to order merchandise from Alice Googler" (注意:Alice Googler 应被识别为 @Artist 实体!)"Ok, let's buy stuff."

redirect.price

"How much does a t-shirt cost?", "What's the price for the tour movie?", "The album is how much?", "I want to know the price of a longsleeve shirt", "What's the price difference?", "What does each product costs?", "What does it cost?", "What is the price?"

redirect.product

"Tour movie", "I am interested in a t-shirt", "Can I buy a digital album?", "I want the CD", "I want to buy something", "Can I purchase a record?", "I want to buy a t-shirt size M of The Google Dolls", "Can I purchase the Alice Googler digital album?"

redirect.product.of.artist

"Yeah, let's shop", "Give me merch of Alice Googler", "Shirts of The Google Dolls that would be nice.", "Yes", "I want The Goo Fighters stuff", "Yes, I want to order merchandise", "Yep, give me items of G's N' Roses", "Go for it", "Anything Alice Googler", "I am a G's N' Roses fan!", "Google Dolls", "Yes of The Google Dolls"

redirect.shirts

"Shirts", "I want to buy shirts", "I am interested in shirts", "I want a shirt", "Shirts of G's N' Roses please", "Give me shirts of the Google Dolls", "I want to buy shirts of Alice Googler"

redirect.music

"Music", "I want to buy music", "I am interested in music", "Give me music of the Goo Fighters", "Music of Goo Fighters please", "Interested in buying the Alice Googler album", "Purchase Alice Googler music"

redirect.album

"Hits", "Live Album", "I want the Greatest Hits Digital Album", "Give me the Greatest Hits CD", "Hits on MP3"

redirect.shirt.size

"XS", "I have M", "I want Large", "My size is 3XL", "Extra Large is the size"

redirect.my.order

"About my order", "I have a question about my order", "My order is ABCD123, I have a question about my order."

status

redirect.my.order.status

redirect.my.order.canceled

"I want to cancel my order", "I want to cancel order ABCD123", "Please cancel order ABCD123", "Undo my order", "Stop my order", "Cancel"

redirect.shipping.info

"How long will it take?", "How long is shipping?", "How long does shipping take?", "When will I receive it?"

redirect.refund.info

"I want a refund.", "Can I get a refund", "I want to return the CD", "I want to return my t-shirt"

redirect.swapping.info

"I want to swap my item", "Can I change my t-shirt for a larger size?", "Can I change my product?", "I want to swap the CD"

redirect.order.process

"I want to buy a t-shirt of the Google Dolls, size S", "Let me buy the digital CD of Alice Googler", "Get me the tour movie of G's N' Roses", "Buy a longsleeve shirt of The Goo Fighters", "Purchase the Alice Googler t-shirt", "Please order me the Google Dolls CD"

confirm.proceed.order

"Yes", "Yes, please continue", "Yes order", "I want to order", "Yeah", "Yep", "I confirm", "Agree", "Go ahead", "Order", "Buy it", "Purchase", "Okay"

decline.proceed.order

"No", "I rather not", "I don't want it anymore", "Don't order", "Stop", "Not anymore", "Nope", "Go back", "Reset", "Decline", "I don't need it"

redirect.home

"Go back", "Home", "Help", "What else can I ask", "Restart", "Can you tell me what I can order?", "What questions can I ask", "I need help", "Advice please", "Hi", "Hello", "Good day!"

redirect.end

"No that's it, goodbye", "Bye", "Cheers", "End", "That's it", "No more questions", "Exit", "Have a good day", "End Call", "Close"

现在,我们已经准备好可重复使用的元素(流程、实体和 intent),接下来可以通过创建页面和状态处理程序将这些元素整合到一起。

6. 页面和状态处理程序

Dialogflow CX 对话(会话)可以描述并直观呈现为有限状态机。以自动售货机为例,它可以建模为有限状态机。它具有以下状态:等待硬币、选择糖果、给予糖果,并在给定一组输入的情况下,在这些状态之间移动。例如,插入硬币会使自动售货机从“等待硬币”状态转变为“选择糖果”状态。我们可以使用页面为 Dialogflow CX 虚拟客服建模这些状态。

当最终用户在对话中与 Dialogflow CX 互动时,对话会从一个页面移动到另一个页面,因此在任何给定时刻,只有一个页面是当前页面,当前页面被视为活跃页面,与该页面关联的流也被视为活跃流。

您可以为每个流程定义多个页面,其中组合页面可以处理该流程所针对的主题的完整对话。每个流都有一个特殊的初始页面。当流最初处于活跃状态时,初始页面将变为当前页面。每轮对话期间,当前页面要么保持不变,要么转换到其他页面。借助此概念,您可以创建包含多个页面和多个对话回合的大型聊天机器人。

页面包含执行方式(静态条目对话框和/或 Webhook)、参数状态处理脚本。对话控制通过状态处理程序进行,您可以创建各种转换路由以转换到其他 Dialogflow CX 页面,包括使其具有条件(用于对话分支)。

对话的状态通过处理页面之间的转换来控制,其中涉及三种不同类型的路由:

  • intent 路由:应匹配 intent 的情况(例如,根据最终用户所说的内容更改页面)。(图表中的蓝线)。
  • 条件路由:应检查条件的时间(例如,根据会话中存储的特定参数更改页面)(可视化图表中的橙色线条)。
  • 事件处理脚本:应处理特定回退事件的情况(例如处理无输入、无匹配,以便为最终用户明确意图路线或条件路线)(直观图中的绿色线条)。

对话语句(即向用户返回的内容或响应)由执行方式定义,执行方式可以是静态的,也可以是动态的:

  • 静态 fulfillment:何时提供静态 fulfillment 响应
  • 动态执行方式:何时为动态响应调用执行方式网络钩子

对于零售聊天机器人,我们将创建一些intent 路线并提供一些静态条目执行响应,这些响应将在页面激活后立即向用户显示。稍后,我们将使用条件路线创建参数,以收集下单所需的信息。

网页 intent 路由

在默认初始流中创建页面

下面是默认初始流的流程图:

目录关联的页面

我们一起点击以下链接:

  1. 依次点击 Build > Default Start Flow(构建 > 默认初始流)
  2. 点击开始页
  3. 点击路由旁边的 + 图标
  4. 添加了 redirect.artists.overview
  5. 向下滚动到转换,然后转换到目录流程。
  6. 点击保存
  7. redirect.product.overview 以及此表中的其他 11 行重复上述步骤:

网页(在流程中)

路由 > intent

路由 > 转换到

开始

Default Welcome Intent

-

开始

redirect.artists.overview

流程:目录

开始

redirect.product.overview

流程:目录

开始

redirect.shirts

流程:目录

开始

redirect.music

流程:目录

开始

redirect.product

流程:目录

开始

redirect.product.of.artist

流程:目录

开始

redirect.refund.info

流程:客户服务

开始

redirect.shipping.info

流程:客户服务

开始

redirect.swapping.info

流程:客户服务

开始

redirect.my.order

流程:“我的订单”

开始

redirect.my.order.canceled

流程:“我的订单”

开始

redirect.my.order.status

流程:“我的订单”

开始

redirect.end

网页:结束会话

默认的首页路由

默认的开始流程将像致电呼叫中心时的选项菜单一样运作。不过,在此虚拟客服中,它是使用自然语言进行训练的,其中意图中包含训练短语。因此,互动是由对话而非 DTMF 选项驱动的,并且更自然、更人性化。

默认的首页路由

在目录流程中创建页面

以下聊天转写内容属于目录流程:

> "Hi"
"Welcome, I am the virtual agent of G-Records, a fictional rock label.
You can order artists merchandise, ask questions about your order or shipping,
and I can tell you more which artists are currently signed with us. How can I help?"
> "Which bands are signed with this record label?"
"The following bands are signed with G-Records:
Alice Googler, G's N' Roses, The Goo Fighters and The Google Dolls.

From which of these artists would you like to order merchandise?"
> "Alice Googler"
"You want to rock with Alice Googler merchandise. Awesome!

We sell shirts, music or the tour movie.

Which merchandise item do you want?"
"(Suggestion chips: [Shirts] [Music] [Tour Movie])"
> "I would like to buy a Shirt"
"Do you want a longsleeve or a t-shirt?"
"(Suggestion chips: [T-shirt, Longsleeve, Price?])"
> "What's the price difference?"
"A t-shirt costs $25 and a longsleeve costs $30.

Do you want a longsleeve or a t-shirt?"
> "A t-shirt",
"What shirt size do you want?"
"(Suggestion chips: [XS, S, M, L, XL, 2XL, 3XL])"
> "M"
"A T-shirt of Alice Googler size: M costs $25. Shall I continue to order?"

如果您选择音乐导览影片,对话框会有所不同:如果选择音乐,对话框将如下所示:

 > "Music"
"We have a Greatest Hits Album or the Live Album. Which one do you want?"
"(Suggestion chips: [Greatest Hits, Live, Price?])"
> "The Live Album"
"Do you want this album on CD or MP3?"
"(Suggestion chips: [CD, MP3])"
> "What's the price difference?"
"A CD costs $15. The digital album on MP3 costs $10.
Do you want this album on CD or MP3?"
> "Digital Album",
"The Digital Album: Alice Googler - Live costs $10. Shall I continue to order?"

对于导览影片,对话框将如下所示:

 > "Tour Movie"
"The Tour Movie of G's N' Roses costs $25. Shall I continue to order?

以下是目录流程中所有页面的流程图:

目录关联的页面

请注意此流程的复杂性:

  • 我可以跳过“哪些音乐人”问题,直接询问“有哪些商品”
  • 在默认的开始流程中,我可以询问:“我想买 The Google Dolls t 恤”或“我想买点东西”。这意味着,虚拟客服会询问后续问题,以填充这些必需参数的槽位。它会直接跳转到商品页面。
  • “价格”对话框来自将被重复使用的“价格”页面。
  • 虽然导览影片的对话看起来是最简单的对话,但我们实际上会对其进行一些特殊处理。我们将重复使用此对话部分,因此如果最终用户一次性指定所有信息,则也可以直接为其他产品输入此信息:
 > "I want The Goo Fighters longsleeve size S."
"The longsleeve of The Goo Fighters size S costs $30. Shall I continue to order?"

我们先从关联网页开始。

  1. 依次点击 Build > Catalog
  2. 点击开始页
  3. 点击路由旁边的 + 图标
  4. 添加了 redirect.artists.overview
  5. 向下滚动到转场效果,选择页面,然后选择 + 新页面
  6. 使用页面名称 Artist Overview,然后点击保存

现在,我们来完成流程的其余部分:

  1. 您可以使用以下页面、intent 和执行方式重复前面的步骤。接管此表格。页面是您要在流程中选择的页面,路由 > 转换到是您要创建并转换到的新的流或页面。

网页(在流程中)

路由 > intent

路由 > 转换到

目录开始

redirect.artists.overview

音乐人概览

目录开始

redirect.product

产品

目录开始

redirect.product.overview

产品概览

目录开始

redirect.product.of.artist

产品概览

目录开始

redirect.shirts

衬衫

目录开始

redirect.music

音乐

目录开始

redirect.end

结束会话

目录开始

redirect.home

结束流程

音乐人概览

redirect.product.of.artist

产品概览

现在,我们继续添加更多静态执行方式。

  1. 在目录流程中,点击音乐人概览页面。
  2. 点击条目执行方式部分中的修改执行方式
  3. 使用以下静态回答(客服人员的回答):
  • The following bands are signed with G-Records: Alice Googler, G's N' Roses, The Goo Fighters and The Google Dolls.
  1. 点击保存
  2. 在目录流程中,点击商品概览页面。
  3. 点击条目执行方式部分中的修改执行方式
  4. 使用以下静态回答(客服人员说):
  • We sell shirts, music or the tour movie.
  1. 点击保存

页面参数

参数用于捕获和引用最终用户在会话期间提供的值。每个参数都有一个名称和一个实体类型。@Artist@Merch 是我们为创建商品订单而需要收集的最低参数。对于 T 恤或长袖衫,您还需要收集 @ShirtSize;如果您想订购音乐,还需要 @Carrier@Album 名称。

这些参数需要标记为必需。当需要时,您需要提供自定义提示来记住最终用户,以便提供正确的答案,以便收集这些参数。Dialogflow CX 中有一些机制可以帮助您实现这一点。

例如,您可以在参数部分提供自定义静态执行方式消息。如果该参数是必需的,则系统会显示这些参数执行方式。这些响应消息将添加到响应队列中。在代理每轮对话期间,系统可以(且有时需要)调用多个 fulfillment,每个 fulfillment 都可以生成响应消息。Dialogflow 会在响应队列中维护这些响应。如需详细了解页面生命周期以及这些执行方式将被添加到响应队列的顺序,请参阅 Dialogflow CX 页面文档

在“音乐人概览”页面上创建参数

我们来定义一些网页参数:

  1. 目录流程中,点击音乐人概览页面。
  2. 点击 Parameters 块中的 +。添加 artist 参数:
  • 显示名称:artist
  • 实体类型:@Artist
  • 必填:勾选
  • 在日志中隐去:勾选
  1. 现在,我们将添加一些自定义参数执行消息。如果虚拟客服尚未收集 artist 参数,则最终用户会收到将此客服响应添加到响应队列的响应:

From which of these artists would you like to order merchandise?

  1. 添加第二个对话框选项,以提供丰富的建议内容信息卡。点击添加对话框选项,然后使用以下代码(采用 JSON 格式):
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "The Google Dolls"
          },
          {
            "text": "The Goo Fighters"
          },
          {
            "text": "Alice Googler"
          },
          {
            "text": "G's N' Roses"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}

您可以根据最终用户尝试回答这些问题的次数,处理不同的回退执行方式提示。您可以使用参数事件处理脚本来实现此目的。您可以选择各种内置事件处理脚本,例如参数无效语音指令过长无输入第 1 次尝试无输入第 2 次尝试无匹配项。“无输入”与“无匹配”之间的区别在于,如果是“无输入”,则表示用户从未提供过答案;如果是“无匹配”,则表示用户确实提供了答案,但 Dialogflow CX 无法将其与网页进行意图匹配。

  1. 向下滚动到重新提示事件处理程序部分。
  2. 点击添加事件处理脚本,然后选择相应事件:No-match default
  3. 使用以下事件静态文本执行方式

I missed that. Please, specify the artist. You can choose between: Alice Googler, G's N' Roses, The Google Dolls or The Goo Fighters. Which artist do you want to buy merchandise from?

  1. 点击保存
  2. 点击添加事件处理脚本,然后选择相应事件:No-input default
  3. 使用以下事件静态文本执行方式

I am sorry, I could understand the artist's name. You can choose between Alice Googler, G's N' Roses, The Google Dolls or The Goo Fighters. Which artist do you want to buy merchandise from?

  1. 点击保存

网页条件路由

参数与页面条件路由结合使用时非常强大。当某个条件的计算结果为 true 时,系统会调用关联的页面路由。条件可以是某个参数等于特定值某个参数不能缺失某个表单已填写等。如需详细了解参数条件,请参阅 Dialogflow CX 文档。

对于零售虚拟客服人员,我们需要收集一系列参数,因此需要创建一个条件,以检查“表单”是否已填写。表单是应从该页面的最终用户处收集的参数的列表。虚拟客服会与最终用户进行多轮对话,直到收集到所有必需的表单参数(也称为“页面参数”)。

Dialogflow CX 会自动设置最终用户在表单填充期间提供的参数值。如需检查当前页面的整个表单是否已填充,请使用以下条件:$page.params.status = "FINAL"

在“音乐人概览”页面上创建条件路由

我们来创建一个基于条件的路由,该路由会在知道音乐人信息后转到下一页:

  1. 音乐人概览页面中,点击路线部分中的 + 图标。
  2. 向下滚动到状态部分。
  3. 选择至少一项(或)
  4. 接下来,我们将编写一个表达式,用于
  • 参数:$page.params.status
  • 运营商:=
  • 值:"FINAL"
  1. 现在,我们将在该路由上创建特定的静态执行方式消息,以确认最终用户的选择。向下滚动到 Fulfillment 代码块,然后编写以下执行方式消息:
  • $session.params.artist, great choice! Rock on!
  • You want to rock with $session.params.artist merchandise. Awesome!
  1. 当该条件为 true 时,您应转到商品概览页面。向下滚动到转换部分,然后使用以下页面:Product Overview
  2. 点击保存

参数

在“产品概览”页面上创建路线

现在,我们已经了解了如何创建参数和条件路由,接下来为以下页面创建更多参数:

产品概览

  1. 商品概览页面中创建 artist 参数:
  • 显示名称:artist
  • 实体类型:@Artist
  • 必填:勾选
  • 在日志中隐去:勾选
  • 初始提示 fulfillment:From which of these artists would you like to order merchandise?
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "The Google Dolls"
          },
          {
            "text": "The Goo Fighters"
          },
          {
            "text": "Alice Googler"
          },
          {
            "text": "G's N' Roses"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  • 事件处理脚本 > No-match defaultTo buy merchandise you can choose between the following artists: Alice Googler, G's N' Roses, The Google Dolls or The Goo Fighters. Which artist do you want to buy merchandise from?
  • 自定义载荷:
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "The Google Dolls"
          },
          {
            "text": "The Goo Fighters"
          },
          {
            "text": "Alice Googler"
          },
          {
            "text": "G's N' Roses"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  • 事件处理脚本 > No-input defaultTo buy merchandise you can choose between the following artists: Alice Googler, G's N' Roses, The Google Dolls or The Goo Fighters. Which artist were you trying to mention?
  • 自定义载荷:
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "The Google Dolls"
          },
          {
            "text": "The Goo Fighters"
          },
          {
            "text": "Alice Googler"
          },
          {
            "text": "G's N' Roses"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  1. 创建 merch 参数:
  • 显示名称:merch
  • 实体类型:@Merch
  • 必填:勾选
  • 在日志中隐去:勾选
  • 执行方式:Which merchandise item do you want?
  • 依次点击:添加对话选项 > 自定义载荷
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Shirts"
            },
            {
              "text": "Music"
            },
            {
              "text": "Tour movie"
            }
          ]
        }
      ]
    ]
  }
  • 事件处理脚本 > No-match default
  • 事件处理程序执行方式:We sell Shirts, Music or the Tour movie. Which of these items do you want?
  • 自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Shirts"
            },
            {
              "text": "Music"
            },
            {
              "text": "Tour movie"
            }
          ]
        }
      ]
    ]
  }
  • 事件处理脚本 > No-input default
  • 事件处理程序执行方式:I couldn't understand which merchandise item you wanted to buy. You can choose between: Shirts, Music or the Tour movie. Which item do you want?
  • 自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Shirts"
            },
            {
              "text": "Music"
            },
            {
              "text": "Tour movie"
            }
          ]
        }
      ]
    ]
  }
  1. 创建一条路线,当提供 artist 且提供 merch 项时,系统会转到商品页面。
  • 条件:
  • 符合每个规则 (AND)
  • 表达式:$session.params.artist != null
  • 表达式:$session.params.merch != null
  • 执行方式:Alright! $session.params.merch of $session.params.artist, let's go!
  • 转换:网页:Product
  1. 为用户说出“衬衫”时创建路由
  • intent:redirect.shirts
  • 转换:网页:Shirts
  1. 为用户说“音乐”时创建路由
  • intent:redirect.music
  • 转换:网页:Music
  1. 创建在用户询问价格信息时要执行的路线
  • intent:redirect.price
  • 转场效果:创建新页面:Price

设置上述配置后,您会看到类似于下图的可视化结果。请注意,图中 intent 路由为蓝色,条件路由为橙色。虽然未在图中显示,但事件处理程序为绿色,当多个路由类型转换到某个网页时,相应线条将显示为灰色。

目录流程的开始

到目前为止,您已经了解了如何使用状态处理脚本(例如基于参数intent 路由条件路由)创建实体intent页面。在本实验的后面部分,我们将在执行方式中使用条件分支,以根据输入提供不同的对话。

您可以使用以下配置来最终确定虚拟客服人员。

“衬衫”页面:

  1. 衬衫页面中,创建以下配置:
  • 条目履行:Do you want a longsleeve or a t-shirt?
  • 条目执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "T-shirt"
            },
            {
              "text": "Longsleeve"
            },
            {
              "text": "Price?"
            }
          ]
        }
      ]
    ]
  }
  1. 创建意图路由redirect.price,并将其转换到 Price 页面
  2. 创建以下参数:
  • 参数:merch - 实体类型:@MerchRequiredRedact in log
  • 参数 > 事件处理脚本 > No-match default
  • 参数 > 事件处理程序执行方式:You can choose between a t-shirt or a longsleeve. Which of these do you want?
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "T-shirt"
            },
            {
              "text": "Longsleeve"
            }
          ]
        }
      ]
    ]
  }
  • 参数 > 事件处理脚本 > No-input default
  • 参数 > 事件处理程序执行方式:I couldn't understand if you want the t-shirt or the longsleeve. Which of these do you want?
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "T-shirt"
            },
            {
              "text": "Longsleeve"
            }
          ]
        }
      ]
    ]
  }
  1. 点击条目执行方式,然后向下滚动到参数预设值,这样每次“衬衫”页面处于活动状态时,类别参数都会设为衬衫

参数

category

shirts

  1. 添加条件路由:
  • 至少符合一个规则(或)
  • 表达式:$session.params.merch = "T-shirt"
  • 表达式:$session.params.merch = "Longsleeve"
  • 转换到新页面:Shirt Size

价格页面:

由于价格消息将取决于所选的商品或类别(音乐或衬衫),因此我们将在本实验的后面部分修正此部分。目前,只需输入占位符即可。

  1. 价格页面中,创建以下配置:
  • 条目履行:PRICE TODO

由于您可以在对话的不同位置询问价格,因此它应始终为您提供答案,并将您转回对话的前一部分,以便继续下单。在对话树中,有 5 个位置可以分支以获取价格信息。(衬衫、衬衫尺码、音乐、运营商,以及通过 intent 路由的直接购买),因此我们需要一些条件路由来返回:

  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.category = "shirts"
  • 表达式:$session.params.merch = "null"
  • 转换到新页面:Shirts
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.category = "shirts"
  • 表达式:$session.params.size = "null"
  • 转换到新页面:Shirt Size
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.category = "music"
  • 表达式:$session.params.album = "null"
  • 转换到新页面:Music
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.category = "music"
  • 表达式:$session.params.merch = "null"
  • 转换到新页面:Carrier
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.category = "null"
  • 转换到新页面:Product Overview

衬衫尺寸页面:

  1. 衬衫尺寸页面中,创建以下配置:
  • 条目履行:What shirt size do you want?
  • 条目执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "XS"
            },
            {
              "text": "S"
            },
            {
              "text": "M"
            },
            {
              "text": "L"
            },
            {
              "text": "XL"
            },
            {
              "text": "2XL"
            },
            {
              "text": "3XL"
            }
          ]
        }
      ]
    ]
  }
  1. 创建意图路由redirect.price,并将其转换到 Price 页面。
  2. 创建以下参数:
  • 参数:shirtsize - 实体类型:@ShirtSize - RequiredRedact In Log
  • 参数 > 事件处理脚本 > No-match default
  • 参数 > 事件处理程序执行方式:Please tell me the shirt size, such as XL.
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "XS"
            },
            {
              "text": "S"
            },
            {
              "text": "M"
            },
            {
              "text": "L"
            },
            {
              "text": "XL"
            },
            {
              "text": "2XL"
            },
            {
              "text": "3XL"
            }
          ]
        }
      ]
    ]
  }
  • 参数 > 事件处理脚本 > No-input default
  • 参数 > 事件处理程序执行方式:I couldn't understand the shirt size. What size do you want?
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "XS"
            },
            {
              "text": "S"
            },
            {
              "text": "M"
            },
            {
              "text": "L"
            },
            {
              "text": "XL"
            },
            {
              "text": "2XL"
            },
            {
              "text": "3XL"
            }
          ]
        }
      ]
    ]
  }
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$page.params.shirtsize != "null"
  • 转换到页面:Product

音乐页面:

  1. 音乐页面中,创建以下配置:
  • 条目履行:We have a Greatest Hits Album or the Live Album. Which one do you want?
  • 条目执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Greatest Hits"
            },
            {
              "text": "Live"
            },
            {
              "text": "Price?"
            }
          ]
        }
      ]
    ]
  }
  1. 创建intent 路由redirect.price,并将其转换到页面:Price
  2. 创建以下参数:
  • 参数:album - 实体类型:@Album - RequiredRedact In Log
  • 参数 > 事件处理脚本 > No-match default
  • 参数 > 事件处理程序执行方式:You can choose between Greatest Hits and Live Album. Which of these do you want?
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Greatest Hits"
            },
            {
              "text": "Live"
            }
          ]
        }
      ]
    ]
  }
  • 参数 > 事件处理脚本 > No-input default
  • 参数 > 事件处理程序执行方式:I couldn't understand if you want the album: Greatest Hit or Live. Which of these do you want?
  • 参数 > 事件处理脚本执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Greatest Hits"
            },
            {
              "text": "Live"
            }
          ]
        }
      ]
    ]
  }
  1. 点击条目执行方式,然后向下滚动到参数预设,这样每当“音乐”页面处于活动状态时,类别参数都会设为音乐

参数

category

music

  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$page.params.album != "null"
  • 转换到页面:Carrier

运营商页面:

  1. 运营商页面中,创建以下配置:
  • 条目履行:Do you want this album on CD or MP3?
  • 条目执行自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "CD"
            },
            {
              "text": "MP3"
            },
            {
              "text": "Price?"
            }
          ]
        }
      ]
    ]
  }
  1. 创建intent 路由redirect.price,该路由会转换到 Price 页面。
  2. 创建以下参数:
  • 参数:merch - 实体类型:@Merch - RequiredRedact In Log
  • 参数 > 事件处理脚本 > No-match default
  • 参数 > 事件处理程序执行方式:Do you want a physical CD or the digital album?
  • 参数 > 事件处理脚本执行方式:自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "CD"
            },
            {
              "text": "Digital Album"
            }
          ]
        }
      ]
    ]
  }
  • 参数 > 事件处理脚本 > No-input default
  • 参数 > 事件处理程序执行方式:I couldn't understand if you mean CD or MP3. Which one do you want?
  • 参数 > 事件处理脚本执行方式:自定义载荷:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "CD"
            },
            {
              "text": "MP3"
            }
          ]
        }
      ]
    ]
  }
  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$page.params.merch != "null"
  • 转换到页面:Product

商品页面:

  1. 创建以下参数:

参数显示名称

参数实体类型

检查

artist

@Artist

必填,在日志中隐去

merch

@Merch

必填,在日志中隐去

  1. artist 参数需要以下初始提示 fulfillment,该提示将在未知音乐人时显示。You didn't mention which artist you are interested in. You can ask me to buy the $session.params.merch of the artist you like or ask which artists we signed. How can I help?
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "Which artists?"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  • 此外,还要添加一个包含执行方式的 No-input default 事件处理脚本:I couldn't understand what you just said. Ask me which artists are signed.
  • 以及具有 fulfillment 的 No-match default 事件处理脚本:I missed that. Please ask me which artists are signed.
  1. merch 参数也需要重新提示事件处理程序。
  • 添加带有执行方式的 No-input default 事件处理脚本:I couldn't understand what you just said. Which merchandise item do you want?
  • 以及具有 fulfillment 的 No-match default 事件处理脚本:I missed that. Which merchandise item do you want?

当已知音乐人并用户选择“巡回影片”时,下一个路由将转换到确认页面。

  1. 添加条件路由:
  • 符合每个规则 (AND)
  • 表达式:$session.params.artist != null
  • 表达式:$session.params.merch = "Tour Movie"
  • 参数预设 添加参数 > price = 25
  • 转换到新页面:Confirmation

当已知音乐人、用户选择“T 恤”并选择了 T 恤尺码后,下一个路由将转换到确认页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND $session.params.merch = "T-shirt" AND $session.params.shirtsize != null
  • 参数预设 添加参数 > price = 25
  • 转换到页面:Confirmation

当用户选择“长袖”并选择衬衫尺寸后,下一个路由将转换到确认页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND $session.params.merch = "Longsleeve" AND $session.params.shirtsize != null
  • 参数预设 添加参数 > price = 30
  • 转换到页面:Confirmation

当用户选择“CD”并选择专辑名称时,下一个路线将转换到确认页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND $session.params.merch = "CD" AND $session.params.album != null
  • 参数预设 添加参数 > price = 15
  • 转换到页面:Confirmation

当用户选择“数字专辑”并选择专辑名称后,下一个路由将转换到确认页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND $session.params.merch = "Digital Album" AND $session.params.album != null
  • 参数预设 添加参数 > price = 10
  • 转换到页面:Confirmation

接下来,我们将使用一些提示来创建一些高级条件,以检测缺失的信息。如果已知音乐人,并且用户选择了“CD”或“数字专辑”,但未选择专辑名称,则下一个路线将返回到音乐页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND ($session.params.merch = "CD" OR $session.params.merch = "Digital Album") AND $session.params.album = null
  • 执行方式:I would also need to know which album you would like to buy!
  • 转换到页面:Music

最后一种路线是,当用户选择了“T 恤”或“长袖”,但未选择 T 恤尺码时,系统会在已知音乐人的情况下转到确认页面。

  1. 添加条件路由:
  • 自定义表达式:$session.params.artist != null AND ($session.params.merch = "T-shirt" OR $session.params.merch = "Longsleeve") AND $session.params.shirtsize = null
  • 执行方式:I would also need to know which shirt size you need!
  • 转换到页面:Shirt Size

在本实验的下一部分中,我们将使用基于条件的执行方式,根据输入提供不同的执行方式消息。

7. 条件响应

某些回答会根据输入返回不同的对话,对话会分支,我们称之为条件响应。如果您未使用 webhook 执行方式(后端确定条件响应),这可能会很有趣。示例如下:

if [condition]
  [response]
elif [condition]
  [response]
elif [condition]
  [response]
else
  [response]
endif
  • [condition] 的示例如下:$session.params.user-age >= 21。其格式与路由中的条件类似。
  • [response] 接受静态文本响应
  • 条件响应始终以 if 开头
  • elifelse 块是可选的

Dialogflow CX 还可以使用内置的系统函数。例如,设置日期或时间格式,或显示当前时间 ($sys.func.NOW())

我们来修复确认页面和价格页面,以最终完成目录流程。

确认页面:

现在,我们将构建确认页面。它具有以下要求:

  • 如果商品 CD数字专辑。我们会在确认中显示以下字段:音乐人商品专辑价格
  • 商品T 恤长袖衫。我们会在确认中显示以下字段:音乐人商品尺寸价格
  • 否则(即如果 merchTour Movie)。我们会在确认中显示以下字段:音乐人商品价格
  1. 点击确认页面。
  2. 依次点击“修改执行方式”>“客服人员响应”> 添加对话选项 > 条件响应
if ($session.params.merch = "CD" OR $session.params.merch = "Digital Album")
  The $session.params.merch: $session.params.artist - $session.params.album costs $$session.params.price. Shall I continue to order?
elif ($session.params.merch = "T-shirt" OR $session.params.merch = "Longsleeve")
  A $session.params.merch of $session.params.artist size: $session.params.shirtsize costs $$session.params.price. Shall I continue to order?
elif $session.params.merch = "Tour Movie"
  The $session.params.merch of $session.params.artist costs $$session.params.price. Shall I continue to order?
else
  It looks like something went wrong with your order. You can say "Reset", to restart the order process.
endif
  1. Create the following Custom payload:
  • Custom payload:
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "Yes, confirm"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}

Next, create two intent routes:

  1. confirm.proceed.order transitions to: Order Process Flow.
  2. decline.proceed.order transitions to End Flow

When the user declines the order, and does not want to proceed the order process, we will have to transition back to the welcome page, but all the parameters have to be cleared. We can do this by specifically setting null to all the possible parameters. You can do this with Parameter presets.

  1. In the decline.proceed.order intent route, scroll down to Parameter presets and add the following parameters:

Parameter

Value

artist

null

merch

null

shirtsize

null

category

null

album

null

price

null

restart

true

Notice that we have created an additional parameter called restart. If this parameter is present, the Default Start Flow, should know to continue the conversation by showing a customized message.

  1. Click on the Default Start Flow, Start Page, and create another Conditional Route:
  • $session.params.restart = "true"
  • Fulfillment: "Welcome back, as the virtual agent of G-Records, I can help you order artists merchandise, you can ask questions about your order or shipping, and I can tell you more which artists are currently signed with us. How can I help?"
  • Custom payload:
{
    "richContent": [
      [
        {
          "type": "chips",
          "options": [
            {
              "text": "Which artists?"
            },
            {
              "text": "Which products?"
            },
            {
              "text": "About my order..."
            }
          ]
        }
      ]
    ]
  }
  1. Select the Start Page and click on the redirect.end intent. Create the following fulfillment: Thank you for contacting G-Records! Have a nice day!

Price Page:

Let's also fix the Price TODOs. The price information will be static for now. Click on the Price Page in the Catalog Flow, and use the following entry fulfillment:

  • Delete the Agent Says entry fulfillment.
  • Create a new Conditional Response:
if $session.params.category = "shirts"
  A t-shirt costs $25 and a longsleeve costs $30.
elif $session.params.category = "music"
  A CD costs $15. The digital album on MP3 costs $10.
else
  A t-shirt costs $25 and a longsleeve costs $30. A CD costs $15 and a digital album on MP3 $10. In case you are interested in the Tour Movie, that one is $25.
endif

Conditional Responses

Well done, by now you completed the Catalog flow. Your flow should look similar to this diagram:

8. Wrapping up the agent

We are almost at the end of this lab. Let's configure the last flows together, and take in practice all the new things that we have learned.

Creating the My Order Flow

  1. Go to the My Order Flow, and create the following intent transitions:

Page (In Flow)

Routes > Intent

Routes > Transition To

My Order Start

redirect.my.order

My Order

My Order Start

redirect.my.order.status

My Order Status

My Order Start

redirect.my.order.canceled

My Order Cancellation

My Order Start

redirect.end

End Session

My Order Start

redirect.home

End Flow

My Order

redirect.my.order.status

My Order Status

My Order

redirect.my.order.canceled

My Order Cancellation

Default Start Flow

redirect.my.order.canceled

Flow: My Order

Default Start Flow

redirect.my.order.status

Flow: My Order

  1. Let's create the following entry fulfillment for the My Order Page:
  • Entry fulfillment: I can look up the status of your order, or I can cancel an order.
  1. In the My Order Page create the following parameter:
  • Displayname: ordernumber
  • Entity Type: @OrderNumber
  • Required: checked
  • Initial prompt fulfillment: What's the order number? For example ABCD123.
  • Event Handler: No-match default: To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  • Event Handler: No-input default: I missed that. To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  1. Create the following conditional route:
  • Customize Expression: $page.params.status = "FINAL"
  • Fulfillment: And do you want to Cancel your order, or should I look up the status?
  1. Click on Add state handler > Event Handlers and create the Event Handler: No-input default
  • Fulfillment: I'm sorry, what was that? Would you like me to cancel an order or look up the status?
  • Custom payload:
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "Status"
          },
          {
            "text": "Cancel"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  1. Create the Event Handler: No-match default
  • Fulfillment: Would you like me to cancel an order or lookup the status?
  • Custom payload:
{
  "richContent": [
    [
      {
        "options": [
          {
            "text": "Status"
          },
          {
            "text": "Cancel"
          }
        ],
        "type": "chips"
      }
    ]
  ]
}
  1. In the My Order Status Page create the following parameter:
  • Displayname: ordernumber
  • Entity Type: @OrderNumber
  • Required checked
  • Initial prompt fulfillment: What's the order number? For example ABCD123.
  • Event Handler: No-match default: To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  • Event Handler: No-input default: I missed that. To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  1. In the My Order Status Page create the following conditional route:
  • Customize Expression: $session.params.ordernumber != null
  • Fulfillment: Your order $session.params.ordernumber has been shipped, it can take up to approx 2 weeks before you will receive your items.
  • Add dialogue option > Text: Is there anything else I can help you with?
  1. In the My Order Cancelation Page create the following parameter:
  • Displayname: ordernumber
  • Entity Type: @OrderNumber
  • Required checked
  • Initial prompt fulfillment: What's the order number? For example ABCD123.
  • Event Handler: No-match default: To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  • Event Handler: No-input default: I missed that. To proceed with your order I will need an order number. Order numbers start with 4 characters and end with 3 numbers, such as ABCD123. Which order number may I use?
  1. In the My Order Cancelation Page create the following conditional route:
  • Customize Expression: $session.params.ordernumber != null
  • Fulfillment: Your order $session.params.ordernumber has been canceled.
  • Add dialogue option > Text: Is there anything else I can help you with?
  1. Test the flow and create the following two test scenarios:
>"About my order"
>"ABCD123"
>"Status"

And:

>"What's the status of order DEFG222"
  1. Select the Start Page and click on the redirect.end intent. Create the following fulfillment: Thank you for contacting G-Records! Have a nice day!
  2. Select the Start Page and click on the redirect.home intent. Create the following parameter preset: restart = true

Default Negative intents (Fallback)

When you create a virtual agent, a default negative intent is created for you. You can add training phrases to this intent that act as negative examples that will trigger a No-match event. There may be cases where end-user input has a slight resemblance to training phrases in normal intents, but you do not want these inputs to match any normal intents.

  1. Try in the simulator: I don't like Alice Googler.

You will see that the virtual agent answers with the Product Overview Page, to continue ordering Alice Googler merchandise. However, your end user does not like that artist. Let's use the Default Negative Intent for this.

  1. Go to Manage > Intents and select the Default Negative Intent.
  2. Add the following training phrases that will trigger the No-match event.
  • I don't like Alice Googler
  • I am not a fan of G's N' Roses
  • I can't stand the music of the Google Dolls
  1. Hit Save and test the following sentence in the simulator: I am really not a fan of the Goo Fighters

This time the No-match event was triggered, you stayed on the Start Page.

Default Fallback Messages

  1. Click the Default Start Flow, select the sys.no-input-default event handler.

The No-input fallback basically means: No text or speech answers were detected. Likely no answers were given, or the system couldn't hear it. Therefore, let's make the fallback messages more specific. Use the tab key, to create alternative dialogues:

  1. Remove all answers, and add these text dialogues:
  • I'm sorry, I didn't receive an answer. Can you say it again?
  • I missed your answer, can you say it again?
  • Sorry, I didn't hear anything. Can you say it again?
  • I couldn't hear what you were saying, what was that?
  • I'm sorry, I missed your answer. What were you trying to say?

Don't forget to click Save.

  1. Click the Default Start Flow, select the sys.no-match-default event handler.

The No Match fallback basically means: Text or speech answers were detected but nothing in Dialogflow CX got matched.

  1. Remove all answers, and add these text dialogues:
  • Sorry, I didn't get that. Can you please rephrase?
  • I'm sorry, I don't understand. Can you please rephrase?
  • I don't understand, please rephrase.
  • Sorry, I didn't get that. What was that?
  • I didn't get that, can you please rephrase?

Don't forget to click Save.

  1. It's advised to repeat these steps for the Catalog, My Order, Order Process and Customer Care flows.

Here's a tip: when creating fallback messages, make them more explicit, by rephrasing the previous question or by mentioning an example. You could create these type of No-match and No-input events on Page level when creating parameters. In our labs, we have already done this.

Creating the Order Process Flow

  1. Go to the Order Process Flow, and create the following intent transitions:

Page (In Flow)

Routes > Intent

Routes > Transition To

Order Process Start

redirect.end

End Session

Order Process Start

redirect.home

End Flow

Order Process Start

confirm.proceed.order

New Page: Shipping Details

  1. Let's create the following entry fulfillment for the Shipping Details Page:
  • Entry fulfillment: To complete your order I will first need to collect your shipping details.
  1. Create the following parameters:

These parameters will make use of built-in system entities. System entity support differs for each language. See the docs for more information.

Parameter Display name

Entity

Required?

Initial prompt fulfillment

No-match default

No-input default

firstname

@sys.person

Required

What's your first name?

I'm sorry I missed that. What's the first name?

I'm sorry, I didn't understand. What's the first name?

lastname

@sys.person

Required

What's your last name?

I'm sorry I missed that. What's the last name?

I'm sorry, I didn't understand. What's the last name?

address

@sys.address

Required

What's your address?

I missed that. What's the address?

I'm sorry, I didn't understand. What's the address?

zipcode

@sys.any

Required

What postal code or zipcode do you have?

I'm sorry, what's the zip or postal code? For example: 1234AB or 10001.

I'm sorry, I didn't understand. What's the zip or postal code? For example: 1234AB or 10001.

city

@sys.geo-city

Required

What's the name of the city?

I missed that, what's the name of the city?

I'm sorry, I didn't understand. What's the name of the city?

country

@sys.geo-country

Required

What's the name of the country?

I missed that, what's the name of the country?

I'm sorry, I didn't understand. What's the name of the country?

email

@sys.email

Required

Lastly, what's your email address?

I am sorry. What's the email address? For example name@domain.com.

I am sorry, I didn't understand. What's the email address? For example name@domain.com.

  1. Create the following conditional route:
  • Customize Expression: $page.params.status = "FINAL"
  • Transition to new Page: Payment Details
  1. Create the following entry fulfillment.

Let's fake it that this virtual agent makes use of Google Pay. Don't worry this tutorial won't make real transactions. Create the following entry dialogues:

  • Agent Says:
Alright $session.params.firstname! We will make use of Google Pay, that's connected to your email account: $session.params.email.
  • Conditional Response
if $session.params.merch != "Digital Album"
  Shipping costs an additional 5 dollars. This will make the total price $$sys.func.TO_TEXT($sys.func.ADD($session.params.price, 5)).
  Your merchandise will be shipped to:
  $session.params.firstname $session.params.lastname
  $session.params.address
  $session.params.zipcode $session.params.city
  $session.params.country
  To continue the order process please explicitly say "I confirm". Do you want to confirm your $session.params.artist $session.params.merch order?
else
  The total costs will be: $$session.params.price.
  After purchasing the digital album, you will receive an email with the download link.
  To continue the order process please explicitly say "I confirm".
  Do you want to confirm your $session.params.artist $session.params.merch order?
endif
  1. 创建以下intent 路由
  • 意图:confirm.proceed.order
  • 客服人员说:Thank you for your order! Your merchandise will be shipped today!
  • 添加对话选项 > 文本:Here's the order number: ABCD123
  • 添加对话选项 > 文本:Have a good day!
  • 转换:End Session
  1. 选择开始页面,然后点击 redirect.end intent。创建以下执行方式:Thank you for contacting G-Records! Have a nice day!
  2. 选择开始页面,然后点击 redirect.home intent。创建以下参数预设:restart = true

太棒了!到目前为止,我们已经拥有一个完全可用的真实零售商聊天机器人!在下一个实验中,我们将测试虚拟客服人员的表现!

9. 测试您的虚拟客服系统

您可以使用内置模拟器测试虚拟客服人员的对话。在模拟器中测试流程的好处在于,您可以查看模拟器在浏览流程时收集的流程、页面、参数和 (DTMF) 事件的概览。与直接在集成中进行测试相比,这种方式更易于测试,因为这些类型的信息将对最终用户隐藏。您甚至可以创建测试用例,并保存和重复使用这些测试用例。这非常有用,因为当您日后维护或修改流程时,需要确保所做的任何更改都不会破坏之前的工作。

您还可以将测试存储在 Google Cloud Storage 或本地,以便导出和导入之前创建的测试用例。导出测试会下载一个 blob 文件。如需详细了解模拟器和测试用例,请参阅模拟器 / 测试用例文档

在创建一些测试用例之前,我们先完成虚拟客服人员的其余部分:

创建客户服务流程

  1. 前往客户服务流程,然后创建以下 intent 转换:

网页(在流程中)

路由 > intent

路由 > 转换到

Customer Care Start

redirect.shipping.info

运费

Customer Care Start

redirect.refund.info

退款

Customer Care Start

redirect.swapping.info

交换

Customer Care Start

redirect.home

结束流程

Customer Care Start

redirect.end

结束会话

客户服务流程

  1. 配送页面创建以下条目执行方式:
  • Shipping physical merchandise items can take up to 2 weeks.
  • Is there anything else I can help you with?
  1. 退款页面创建以下条目执行方式:
  • We offer free returns and refunds. We provide one free return label for each order. You can use it within 30 days from receiving your order. If your refund is accepted, we will refund the price you paid for your item back to your original payment method.
  • Is there anything else I can help you with?
  1. 换货页面创建以下条目执行方式:
  • If you would like to change your item for a different one, please return your unwanted item and place a new order. If your refund is accepted, we will refund the price you paid for your item back to your original payment method.
  • Is there anything else I can help you with?
  1. 选择开始页面,然后点击 redirect.end intent。创建以下执行方式:Thank you for contacting G-Records! Have a nice day!
  2. 选择开始页面,然后点击 redirect.home intent。创建以下参数预设:restart = true

创建测试用例

  1. 点击屏幕右侧的测试代理按钮。

首次打开模拟器时,您需要选择代理环境和有效流。在大多数情况下,您应该使用草稿环境和默认开始流。

  1. 类型:Hi

客户服务流程

  1. 问题:Which artists are signed with your label?
  2. 请说:The Google Dolls
  3. 请说:I am interested in buying a shirt
  4. 请说:A t-shirt
  5. 请说:Medium
  6. 现在,点击“保存测试用例”按钮。您可以在模拟器顶部找到该图标(位于“重做”箭头和“重置回收站”图标旁边)

客户服务流程

  1. 为其提供以下详细信息:
  • 测试用例名称:Buy Google Dolls t-shirt size M
  • 标签:#catalog、#shirts、#t-shirt、#TheGoogleDolls
  1. 点击保存

我们来创建更多测试用例。

  1. 首先,点击“重置”(回收站)图标清除当前对话框。
  2. 创建以下测试用例:

购买 Alice Googler T 恤:

>"Buy the Alice Googler t-shirt."
>"XL"
  • 测试用例名称:Buy the Alice Googler t-shirt
  • 标记:#catalog, #shirts, #t-shirt, #AliceGoogler

购买尺码为 M 的 T 恤:(请注意,我们并未提及音乐人名称,但您需要跳过乐队概览、商品概览、衬衫和衬衫尺码页面)

>"Buy a t-shirt size M"
>"The Google Fighters"
  • 测试用例名称:Buy a t-shirt size M
  • 标记:#catalog, #shirts, #t-shirt, #TheGoogleFighters
  • 说明:(请注意,我们并未提及音乐人名称,但您确实想跳过乐队概览、商品概览、衬衫和衬衫尺寸页面)

购买 Guns N' Roses 的音乐(请注意,这会跳过乐队概览和商品概览页面)

>"Purchase music of G's N' Roses"
>"Live"
>"CD"
  • 测试用例名称:Purchase music of G's N' Roses
  • 标记:#catalog, #music, #CD, #GsNRoses, #live
  • 说明:(请注意,这会跳过“频段概览”和“产品概览”页面)

查看价格信息:

>"Which products"
>"Shirts"
>"What's the price difference?"
>"Longsleeve"
>"What does it cost?"
>"M"
>"The Google Dolls"
>"No"
>"Which bands"
>"The Gooo Fighters"
>"Music"
>"How much does it cost?"
>"Greatest Hits"
>"What's the price difference?"
>"Mp3"
>"No"
>"I want to buy the tour movie"
>"Alice Googler"
>"Yes"
  • 测试用例名称:Price info
  • 标记:#catalog, #music, #tourmovie, #shirts
  • 说明:测试对话框中各个位置的价格信息

测试预录制的测试用例

  1. 在左侧的 Dialogflow 主菜单中,依次选择管理 > 测试用例
  2. 选择所有测试用例,然后点击表格上方的运行按钮。

Dialogflow CX 会针对保存为“黄金测试用例”的录音运行所有所选测试用例,如果结果与您保存时相同,则测试即为通过。- 流程中是否发生了变化,例如页面配置不正确,或 intent 将您定向到错误的页面,如果发生这种情况,测试将会失败。

测试用例

  1. 在模拟器中,提出以下问题:How long will shipping take?
  2. 记下结果,并将测试用例保存为 Shipping,标记为 #shipping
  3. 前往“管理”>“测试用例”面板,然后按网格的右上角的运行按钮,以仅运行 Shipping 测试用例。

此测试应能通过。

  1. 返回“客户服务流程”,选择开始页面,然后点击路由标题。

系统随即会显示一个屏幕,其中包含一个网格,其中显示了所有路线。

  1. 移除 redirect.shipping.info route
  2. 前往“管理”>“测试用例”面板,然后按网格的右上角的运行按钮,以仅运行 Shipping 测试用例。

此测试应该会失败。

  1. 您可以点击失败的测试,查看失败的详细信息。

在本例中,测试失败并显示以下错误消息:

Page: Page mismatch:
Expected: Shipping
Actual: Start Page

这是因为该页面已不再存在于流程中。我们预期会看到 Shipping 页面,但实际上始终没有离开 Start 页面。(或者,您的最终用户会收到回退消息)。

换句话说,这是一次错失的请求,即假负例测试结果。测试失败。我们预期会看到送货页面,但没有任何反应,或者系统显示了回退消息。

  1. 返回“客户服务流程”,将 redirect.shipping.info 添加为 intent 路线,并将其添加到开始页面。别忘了前往配送页面,然后点击保存
  2. 在模拟器中记录以下测试用例:I want to swap my item,将此测试用例保存为 Swapping #swapping
  3. 依次打开 Manage > Intents > redirect.refund.info,然后添加以下训练短语:I want to swap this item for a refund

如果没有该训练用语,当用户要求换货退款时,系统会触发 redirect.swapping.info intent,但我们不想提供换货信息,而是想提供退款信息。

  1. 在模拟器中创建以下黄金测试用例:I want to swap this item for a refund,并将此测试用例另存为 Swap for Refund #refund
  2. 返回 Manage >Intents > redirect.refund.info intent,然后移除 I want to swap this item for a refund 行。
  3. 返回管理 > 测试用例,选择换货退款测试用例,然后运行该测试用例。

您的最新测试失败,并显示以下错误消息:

If you would like to change your item for a different one, please return your unwanted item and place a new order. If your refund is accepted, we will refund the price you paid for your item back to your original payment method.`
Is there anything else I can help you with?
 Page: Page mismatch:
Expected: Refund
Actual: Swapping

换句话说,这是错过的已识别请求,即假正例测试结果。测试失败。我们预计会看到退款页面,但系统显示的是换货页面。

覆盖率

在 Dialogflow CX 中,测试覆盖率是一种衡量指标,用于描述在运行特定测试套件时虚拟客服人员对话(页面和 intent)的执行程度。测试覆盖率(以百分比表示)较高的虚拟客服人员在测试期间执行了更多对话,这意味着与测试覆盖率较低的虚拟客服人员相比,它包含未检测到的 bug(例如未理解的请求)的可能性较低。

  1. 如需查看所有测试用例的测试覆盖率报告,请点击覆盖率
  2. 点击转场效果标签页。

这将显示所有页面转换的测试覆盖率。

转场效果覆盖率

  1. 点击intent 标签页。

此时,系统会显示所有 intent 的测试覆盖率。

intent 覆盖率

恭喜,到目前为止,您已构建并测试了一个完整的零售商聊天机器人实际示例!我们前往下一页实验内容,查看结论并找到一些实用参考资料!

10. 总结

Dialogflow CX 是一个对话式 AI 平台 (CAIP),用于创建聊天机器人或语音机器人等虚拟客服。Dialogflow CX 可让您的团队通过可视化聊天机器人构建工具、可重复使用的 intent 以及处理多轮对话的能力,更快地打造企业级对话式体验。

在本 Codelab 中,您学习了如何构建真实的零售虚拟客服人员。我们介绍了以下概念:

  • 参数、自定义实体和系统实体
  • 页面
  • 状态处理程序,例如 intent 路由和条件路由
  • 静态执行方式消息和条件响应
  • 回退 intent
  • 模拟器、测试用例和覆盖率

最终结果

参考

如需详细了解 Dialogflow CX,请参阅以下博客和文档!