Alexa Nodejs技能 - 第二个意图总是失败

问题描述 投票:0回答:1

我已经开始使用CodeStar和Nodejs创建一个简单的Alexa技能,我的技能可以告知用户Web系统当前是否仍然可用,是否有任何当前事件或服务输出。我从http://statuspage.io获得了JSON API形式的所有数据。

我遇到的问题是,我的LaunchRequestHandler工作正常,我问的第一个意图也是如此,但是当我问第二个意图时(紧接在第一个意图之后)这是我的技能断裂和输出(在Alexa内部)开发者控制台):<Audio only response>

Alexa Developer Console Screenshot

下面我粘贴了我的技能中的代码。

// model/en-GB.json

"intents": [{
    "name": "QuickStatusIntent",
    "slots": [],
    "samples": [
        "quick status",
        "current status",
        "tell me the current status",
        "what's the current status",
        "tell me the quick status",
        "what's the quick status"
    ]
},
{
    "name": "CurrentIncidentIntent",
    "slots": [],
    "samples": [
        "incidents",
        "current incident",
        "is there a current incident",
        "tell me the current incidents",
        "what are the current incidents",
        "are there any current incidents"
    ]
}]


// lambda/custom/index.js

const QuickStatusIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'QuickStatusIntent';
    },
    async handle(handlerInput) {
      let speechText = await getNetlifyStatus();
      return handlerInput.responseBuilder
        .speak(speechText)
        .getResponse();
    }
};

const CurrentIncidentIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'CurrentIncidentIntent';
  },
  async handle(handlerInput) {
    const result = await getSummary();
    const speechText = `There are currently ${result.incidents.length} system incidents`;
    return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
  }
}

我最初的想法是删除.getResponse(),因为它可能一直在等待响应,但是,似乎没有正常工作。

javascript node.js alexa alexa-skills-kit
1个回答
0
投票

问题是您的CurrentIncidentIntentHandler在将响应传递给用户后立即关闭会话。

如果要保持会话打开并让用户继续进行对话在CurrentIncidentIntentHandler中使用.withShouldEndSession(false).repeat(speechText)使Alexa等待用户的下一个响应。

const CurrentIncidentIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'CurrentIncidentIntent';
  },
  async handle(handlerInput) {
    const result = await getSummary();
    const speechText = `There are currently ${result.incidents.length} system incidents`;
    return handlerInput.responseBuilder
      .speak(speechText)
      .withShouldEndSession(false) //you can also use .repeat(speachText) at this line
      .getResponse();
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.