【发布时间】:2020-04-10 16:52:04
【问题描述】:
我是 Alexa 技能的新手,因此我可能在此处对对话管理采取了错误的方法,但我正在尝试使用 YesIntent 和 NoIntent 处理程序中的条件以下列方式确定用户的响应。我在 Alexa 开发人员控制台中托管和测试所有内容。这是一个基本的快乐路径场景,他们已经说是的,他们对活动感兴趣,我现在问他们是否想通过短信发送信息:
const YesIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent');
},
async handle(handlerInput) {
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
const { askedUserIfTheyWantText, textUser } = sessionAttributes;
let speakOutput;
if (askedUserIfTheyWantText === undefined) { // I have yet to ask
speakOutput = 'Alright, want me to text you the info?';
sessionAttributes.askedUserIfTheyWantText = true;
handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
} else if (askedUserIfTheyWantText) { // I already asked and they said yes
// assume I already have number, so I will now text them
const successfullyTextedUser = await textUserInfo();
if (successfullyTextedUser) speakOutput = 'Texted you the info!';
else speakOutput = 'There was a problem texting you the info.';
}
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
}
问题在于 askedUserIfTheyWantText 永远不会更新为 true(仍未定义),因此 Alexa 一直在询问“好吧,要我给你发短信吗?”。我究竟做错了什么??正如我所说,我正在 Alexa 开发者控制台中进行测试(通过文本)。
【问题讨论】:
标签: alexa alexa-skills-kit alexa-skill