如何在多轮中获得AMAZON.QUERY输入
How to get AMAZON.QUERY input in multi turn
我正在尝试创建一个 Intent,其中技能可以从用户那里获取输入,直到用户说“完成”。
您可以在保持 withShouldEndSession(false) 的每一轮使用 addElicitSlotDirective,当用户说“完成”时设置 withShouldEndSession(true)。
这应该适合你。这是我如何在我的技能中实现这一点的示例。
const JournalIntentHandler = {
canHandle(handlerInput) {
console.log(JSON.stringify(handlerInput));
const request = handlerInput.requestEnvelope.request;
return (
request.type === "IntentRequest" && request.intent.name === "Journal" && handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
);
},
async handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
let speechText = { text: "" };
let subtitle = "Journal";
endSession.value = false;
speechText.text = "Continue.";
if (!sessionAttributes.savedSpeech) {
sessionAttributes["savedSpeech"] = "";
}
let oldSpeech = sessionAttributes.savedSpeech;
let newSpeech = handlerInput.requestEnvelope.request.intent.slots.speech
.value
? handlerInput.requestEnvelope.request.intent.slots.speech.value
: "";
sessionAttributes.savedSpeech = oldSpeech + " " + newSpeech;
const request = handlerInput.requestEnvelope.request;
if(newSpeech == 'exit' || newSpeech == 'finish'){
endSession.value = true;
speechText.text = `Saved data is <break time='0.2s'/> ${oldSpeech}`
}
return (
handlerInput.responseBuilder
.addElicitSlotDirective('speech')
.speak(speechText.text)
.reprompt("Continue")
.withStandardCard( subtitle, oldSpeech + " " + newSpeech)
.withShouldEndSession(endSession.value)
.getResponse()
);
},
};
我正在尝试创建一个 Intent,其中技能可以从用户那里获取输入,直到用户说“完成”。
您可以在保持 withShouldEndSession(false) 的每一轮使用 addElicitSlotDirective,当用户说“完成”时设置 withShouldEndSession(true)。
这应该适合你。这是我如何在我的技能中实现这一点的示例。
const JournalIntentHandler = {
canHandle(handlerInput) {
console.log(JSON.stringify(handlerInput));
const request = handlerInput.requestEnvelope.request;
return (
request.type === "IntentRequest" && request.intent.name === "Journal" && handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
);
},
async handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
let speechText = { text: "" };
let subtitle = "Journal";
endSession.value = false;
speechText.text = "Continue.";
if (!sessionAttributes.savedSpeech) {
sessionAttributes["savedSpeech"] = "";
}
let oldSpeech = sessionAttributes.savedSpeech;
let newSpeech = handlerInput.requestEnvelope.request.intent.slots.speech
.value
? handlerInput.requestEnvelope.request.intent.slots.speech.value
: "";
sessionAttributes.savedSpeech = oldSpeech + " " + newSpeech;
const request = handlerInput.requestEnvelope.request;
if(newSpeech == 'exit' || newSpeech == 'finish'){
endSession.value = true;
speechText.text = `Saved data is <break time='0.2s'/> ${oldSpeech}`
}
return (
handlerInput.responseBuilder
.addElicitSlotDirective('speech')
.speak(speechText.text)
.reprompt("Continue")
.withStandardCard( subtitle, oldSpeech + " " + newSpeech)
.withShouldEndSession(endSession.value)
.getResponse()
);
},
};