除启动请求外,其他任何意图请求均未响应

时间:2018-08-21 22:56:13

标签: aws-lambda alexa alexa-skills-kit alexa-skill

我是Alexa技能创造的新手。我试图在大学里为我的学期项目创建一项技能,并试图完成这项工作。我终于让Lambda和交互模型进行了交流,现在正在测试该工具中的技能。我发现2个问题。
1)调用名称将未处理的响应发送给我,并且
2)启动意图之外的所有意图都没有发送回任何响应。 Lambda代码如下:

"use strict";

var Alexa = require("alexa-sdk");

var handlers = {
  "Invocation": function LaunchIntent() {
    this.response.speak("Hello, Welcome to Family Table.  where would you like to make a reservation today?");
    this.emit(':ask', ':responseReady');
    context.succeed(handlers());
  },
  "LaunchIntent": function LaunchIntent() {
    this.response.speak("Hello, Welcome to Family Table.  where would you like to make a reservation today?");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "FoodIntent": function FoodIntent() {
    this.response.speak("What kind of food would you like today?");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "cityintent": function cityintent() {
    this.response.speak("Where would you like to eat?");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "restaurantintent": function restaurantintent() {
    this.response.speak("Would you like to eat at {RestaurantName}?");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "cofirmintent": function cofirmintent() {
    this.response.speak("You want to eat at {RestaurantName} correct?");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "Amazon.FallbackIntent": function AmazonFallbackIntent() {
    this.response.speak("Sorry I can't do that right now.");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "Amazon.CancelIntent": function AmazonCancelIntent() {
    this.response.speak("Cancelling");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "Amazon.HelpIntent": function AmazonHelpIntent() {
    this.response.speak("I don't know how to help you with that.");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "Amazon.StopIntent": function AmazonStopIntent() {
    this.response.speak("Alright, please come back soon.");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  "Amazon.YesIntent": function AmazonYesIntent() {
    this.response.speak("Thank you for using Family Table.  Your reservation has been made.  Enjoy your meal.");
    this.emit(':responseReady');
    context.succeed(handlers());
  },
  'Unhandled': function () {
        this.emit(':ask', 'I don\'t get it!', 'I don\'t get it!');
        context.succeed(handlers());
  },
};

exports.handler = function (event, context, callback) {
  var alexa = Alexa.handler(event, context);
  alexa.registerHandlers(handlers);
  alexa.execute();
};

我想念什么?谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

您有几件事需要纠正。

  1. 启动请求
    它是LaunchRequest而不是LaunchIntent。当您调用一项技能时,这就是将被调用的处理程序。
  2. context.succeed
    您不需要context.succeed(handlers());,可以将其从所有意图处理程序中删除。
  3. 应该结束会话
    如果未设置此参数或将其设置为true,Alexa将结束当前会话并关闭您的技能。除非您再次调用它,否则后续的用户语音都不会到达您的后端代码。

好处是,您不必手动设置此参数,SDK将按以下方式进行处理:

  1. :询问:将保持会话状态,“询问”用户并等待响应。如果您设置了重新提示,则如果没有用户的互动,则会在8秒后触发。
    询问:将自动包含"shouldEndSession":"false"作为响应。

例如:

'AbcIntent': function () {
   var speech="Your speech here";
   var reprompt="Your re-prompt here";
   this.emit(':ask', speech,reprompt);
}
  1. :tell 只会说出答复并结束会话。当您不希望用户有任何回应时,请使用此选项。例如:将其用于AMAZON.StopIntent
  2. speak()和listen():如果没有listen(),则speak()将被视为:tell ,它只是告诉响应并设置"shouldEndSession":"true"作为响应将结束会话。但是,如果有listen(),则SDK将设置"shouldEndSession":"false"作为响应,并使会话保持活动状态。

像这样进行更改:

"LaunchRequest": function () {
    this.response
       .speak("Hello, Welcome to Family Table.  where would you like to make a reservation today?")
       .listen("where would you like to make a reservation today?");
    this.emit(':responseReady');        
}

或使用:询问

"FoodIntent": function () {
  const speech = "What kind of food would you like today?";
  const reprompt = "What kind of food would you like today?";
  this.emit(':ask',speech,reprompt);       
}