如何在Alexa / Amazon Echo的多个Amazon.NextIntent链中设计和传递信息

问题描述 投票:0回答:3

嗨,目前正在考虑一个良好的设计来管理Alexa技能中的多个输出链。例如,如果我从一个名为“昨天”的意图和另一个名为“今天”的意图开始。我想将这些信息(是“昨天”我用“或今天”开始链接)传递给NextIntent链。

什么是在意图之间传递信息的最佳方式?

node.js alexa alexa-skills-kit
3个回答
0
投票

刚刚在这里找到https://developer.amazon.com/de/blogs/alexa/post/f167aa0f-8abe-4602-b985-65118b3032ca/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js怎么做。

我正在搜索会话属性

这些可以像这样使用

1)我打电话给第一个意图:

    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
          && handlerInput.requestEnvelope.request.intent.name === 'BesterAutorIntent';
    },
    handle(handlerInput) {
      try {
        const speechOutput = "Ich könnte dir sagen wer der beste Autor ist, aber ich muss erst HR fragen ob ich darf";

        const attributes = handlerInput.attributesManager.getSessionAttributes();
        attributes.kaesebrot = "kaesebrot"
        handlerInput.attributesManager.setSessionAttributes(attributes)

        return handlerInput.responseBuilder
          .speak(speechOutput)
          .reprompt()
          .withSimpleCard(defaulttext.SKILL_NAME, speechOutput)
          .getResponse();

      } catch (error) {
        console.error(error);
      }
    },
  };

在那里,您可以将名为kaesebrot的属性设置为会话属性:

const attributes = handlerInput.attributesManager.getSessionAttributes();
attributes.kaesebrot = "kaesebrot"
handlerInput.attributesManager.setSessionAttributes(attributes)

稍后在另一个函数中,你可以像这样得到它

let counter = 0;

const NextIntentHandler = {
    canHandle(handlerInput) {
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest'
        && request.intent.name === 'AMAZON.NextIntent';
    },
    handle(handlerInput) {
        try {
            counter = counter + 1;

            const attributes = handlerInput.attributesManager.getSessionAttributes();
            speechOutput = counter + " TEST " + attributes.kaesebrot;

            return handlerInput.responseBuilder
                .speak(speechOutput)
                .reprompt()
                .withSimpleCard(defaulttext.SKILL_NAME, speechOutput)
                .getResponse();
        } catch (error) {
            console.error(error);
        }
    },
};

0
投票

托比的答案很好。

我正在使用sdk v1和代码来保持dynamoDB上的属性是这样的:

    exports.handler = function( event, context, callback ) {
        const alexa = Alexa.handler( event, context );
        alexa.dynamoDBTableName = "alexaTable";
        alexa.registerHandlers( handlers );
        alexa.execute();
    };
...
    const handlers = {
...
        "AMAZON.NextIntent": function () {
            console.log( "AMAZON.NextIntent: " + this.attributes.index );
         }
...
}

将在第一次调用lambda函数时创建dynamodb表“alexaTable”,并自动存储和检索属性。在上面的示例中,“索引”是从先前意图中携带的属性。

表模式由键和字段组成。

  1. 密钥:userId,alexa技能用户ID
  2. 字段:mapAttr,JSON结构化属性,但它由alexa-sdk自行管理。

这篇文章可以帮助进一步https://developer.amazon.com/blogs/alexa/post/648c46a1-b491-49bc-902d-d05ecf5c65b4/tips-on-state-management-at-three-different-levels


0
投票

SessionAttributes是一种在整个意图中保持状态的方法,但是在烤箱中有一个新功能,可以专门链接意图并传递插槽值。

它叫做Intent Chaining,你可以在这里看到更多:https://developer.amazon.com/blogs/alexa/post/9ffdbddb-948a-4eff-8408-7e210282ed38/intent-chaining-for-alexa-skill

Intent链接允许您的技能代码从任何意图开始对话管理,包括LaunchRequest。只要交互模型具有对话模型,您就可以链接到任何自定义意图。

例如,从YesterdayIntent,在响应构建器中,您将执行以下操作:

handlerInput.responseBuilder.addDelegateDirective({
    name: 'TodayIntent',
    confirmationStatus: 'NONE',
    slots: {} // the slot values to pass go here
 })
© www.soinside.com 2019 - 2024. All rights reserved.