Alexa SDK 重定向以设置会话属性

Alexa SDK Redirect to Set Session Attributes

有没有办法暂时从一个意图重定向到另一个意图以填充槽或会话属性,然后 return 到要响应或实现的原始意图?

我的用例是在帐户链接后要求提供帐户 PIN 作为辅助身份验证。例如,如果有人询问 "What are my account details?",我希望该意图在会话属性中更改(如果存在),如果不存在,则暂时重定向到一个意图,提示他们输入 PIN 并设置它……然后返回并回答他们的帐户详细信息请求。类似于下面的例子:

const IntentHandler = {
  canHandle(input) {
    return (
      input.requestEnvelope.request.type === 'IntentRequest' &&
      input.requestEnvelope.request.intent.name === 'MyIntent'
  },
  handle(input) {
    const { accessToken } = input.requestEnvelope.context.System.user
    // ... do stuff with accessToken

    if (!input.attributesManager.getSessionAttributes().pin) {
      // redirect to other intent to set the pin session attribute
    }

    // ...response to intent request
  }
}

我可以使用插槽填充提示使它与单个意图一起工作,但这是多个意图的常见任务,我想将它分开,这样就不必在控制台中为所有需要配置它它。

仅供参考:将 ask-sdk 用于 Node.js

当前版本的 ask-sdk 是否可行?

是的,Alexa 现在可以轻松地在意图之间切换并直接跳转到为新意图引发特定槽。

我会使用 ElicitSlot Dialog Directive 并为新意图包含 updatedIntent 对象。

updatedIntent

Use this to change intents during the dialog or set slot values and confirmation status. See Change the intent or update slot values during the dialog. If you don't need to change the intent, slot values, or confirmation statuses, you can leave this property out of your response.

When you switch intents with this parameter, Alexa attempts to elicit the specified slot value on the new intent. The next IntentRequest to your skill will be the new intent, not the original.

示例:

  1. 意图 A 缺少访问令牌。
  2. 意图 A 将 Alexa 引导至意图 B 的 elicitSlot "pin"。(在 sessionAttributes 中包含信息,例如“previousIntent”或“nextIntent”以用作指向意图 B 的方向)
  3. Alexa 以 Intent B 的引出提示响应用户插槽 "pin"
  4. 用户提供密码。
  5. Alexa 向 Intent B(非 A)提供用户输入,槽 "pin" 已填充,Intent B 在 sessionAttribtues 中设置访问令牌。
  6. 然后 Intent B 检查 sessionAttribtues 哪个意图 return 的方向以及从该意图引出哪个插槽。因此,对于 Intent A,您可以选择 confirmIntentelicitSlot
  7. 意图 A 将接收下一个用户输入,现在检测访问令牌。

请注意,您必须在切换意图之间向用户传达一些信息。如果您使用的是 confirmIntent 那么它可以是一个简单的 Yes/No 确认问题,例如 “感谢您提供个人识别码,您希望我现在检索您的帐户详细信息吗?”。 =52=]。用户说“是”,然后将其发送回 Intent A 以完成它开始的工作。

如果您不想与用户进行这种额外的来回交互,那么据我所知,您必须在每个可能需要引发它的意图中构建 pin 插槽。这样一来,您就只停留在 Intent A 中。代码效率较低,但对话效率更高,因此需要权衡取舍。