【问题标题】:Alexa Nodejs Skill - Second Intent asked always failsAlexa Nodejs Skill - 第二个意图询问总是失败
【发布时间】:2019-07-13 02:59:06
【问题描述】:

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

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

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

// 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】:

    问题是您的 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();
      }
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多