【问题标题】:alexa sdk pass session attributesalexa sdk 传递会话属性
【发布时间】:2018-03-19 06:56:09
【问题描述】:

This Alexa Doc 表明 sessionAttributes 是响应参数之一,而不是在 response 对象内。

我正在使用Alexa SDK,所有emit 响应构建器仅使用response 对象的参数。例如:

this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech, updatedIntent)

那么我怎样才能使用来自 Alexa SDK 的 emit() 并在响应中传递更新的 sessionAttributes 呢?

【问题讨论】:

    标签: node.js alexa alexa-sdk-nodejs


    【解决方案1】:

    Alexa SDK 会在您调用 emit(..) 之前自动序列化并包含您在 attributes 对象上设置的键值对。

    更具体地说,你可以说:

    this.attributes.myAttribute1 = 'some value';
    this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech, updatedIntent);
    

    并且sessionAttributes 对象将在响应中自动更新以包含:

    'myAttribute1': 'some value`
    

    供参考,您可以在SDK中查看elicitSlot的实现,这里:https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/master/lib/response.js#L131-L143

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多