Только что узнал здесь 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);
}
},
};