如何在 Alexa Skill 中使用之前的插槽值?

How to use previous slot value in Alexa Skill?

我想在 Alexa 技能中构建封闭式对话模型。示例要求是

Man: Alexa, what is the price of product1

Alexa: The price of product1 is 89 USD

Man: What is the size of it?

如果我用 "it" 代替产品名称询问尺寸意图,alexa 将如何理解 "it" 是产品的含义?

在单个session范围内,可以将商品名称持久化为一个session属性,在回复size问题时再次获取。

处理价格意图时,您需要将产品名称保存为 session attribute。让我们调用该属性 'ProductName'。然后在同一会话中处理尺寸意图时,只需检查是否已定义 ProductName 属性,如果没有则提示。


为了使此对话更加稳健,请在您的第二个意图(我们称之为 SizeIntent)中定义以下示例话语以允许 ProductName custom slot:

SizeIntent What is the size of it
SizeIntent What is the size of {ProductName} 

这定义了一个 ProductName 插槽,所以现在您有两种可能的输入方法:

  • ProductName 会话属性,通过对话的前一部分。
  • ProductName 插槽值,通过最近的请求。

决定参考哪个值:

  • 如果 ProductName 插槽不为空,请将其保存到您的 'ProductName' 会话属性中并使用它。
  • 否则,如果 ProductName 属性不为空,则使用它。
  • 否则,提示输入 ProductName。