【发布时间】:2020-09-20 09:20:27
【问题描述】:
我目前正在使用 Javascript 进行编码,并且是 Amazon Alexa 的新手。
我正在尝试编写一个处理程序,它会在所有问题用完后结束会话并切换到不同的游戏状态。
但是,我无法理解话语。基本上我想写的是:
SpeakOutput = "Would you like to keep playing?" // this is where I'm confused where to write this question in the code
if(Alexa.getIntentName(handlerInput.requestEnvelope) === "AMAZON.YesIntent") {
setGameState(handlerInput, "BiologyQuestions")
return nextBioQuestion(handlerInput)
} else {
return handlerInput.responseBuilder
.speak(" That was fun! Let's play together next time! ")
.withShouldEndSession(true)
.getResponse();
}
用简单的英语应该是:
Alexa:* 完成文学题轮中的所有问题 * 你想继续玩吗?
用户:是的!
Alexa:* 切换到生物学问题 *
我应该写另一个辅助函数来解决这个问题吗?我已经编写了“nextBioSession”函数。我想我很难真正理解如何编写启用“你想继续玩吗?”的条件。问题并得到回答。
这是我目前拥有的代码:
const QuestionCheckHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === "IntentRequest"
&& (Alexa.getIntentName(handlerInput.requestEnvelope) === "AMAZON.YesIntent" || Alexa.getIntentName(handlerInput.requestEnvelope) === "AMAZON.NoIntent")
&& handlerInput.attributesManager.getSessionAttributes().gameState === "LiteratureQuestions";
},
handle(handlerInput) {
if(Alexa.getIntentName(handlerInput.requestEnvelope) === "AMAZON.YesIntent") {
setGameState(handlerInput, "BiologyQuestions")
return nextBiologyQuestion(handlerInput)
} else {
return handlerInput.responseBuilder
.speak(" That was fun. Let's play together next time! ")
.withShouldEndSession(true)
.getResponse();
}
}
};
我不确定在哪里编写 SpeakOutput “您想继续吗?”在条件之前或作为单独的辅助函数......我试图将问题放在条件之前,但似乎它没有识别它。任何帮助将不胜感激!
【问题讨论】:
标签: javascript amazon-web-services alexa alexa-skill