【问题标题】:Amazon Alexa - Trying to Understanding Alexa Dialogue Flow; Writing conditions for handlers with YesIntent and NoIntent?Amazon Alexa - 试图了解 Alexa 对话流程;使用 YesIntent 和 NoIntent 为处理程序编写条件?
【发布时间】: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


    【解决方案1】:

    我假设您将游戏状态存储在某个地方,这样您就知道该轮还剩下多少问题。在用户在文学问题回合中的最后一个答案之后,只需将您的问题添加到 Alexa 响应中。

    【讨论】:

      猜你喜欢
      • 2017-08-28
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多