【问题标题】:No response from any other intent request except Launch request除 Launch 请求外,其他任何意图请求均无响应
【发布时间】:2019-01-28 04:16:39
【问题描述】:

我是 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();
};

我错过了什么?谢谢你的帮助。

【问题讨论】:

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


    【解决方案1】:

    你有几件事需要纠正。

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

    好处是,您不必手动设置此参数,SDK 会按如下方式处理:

    1. :ask:将“询问”用户并通过保持会话处于活动状态来等待响应。如果您设置了重新提示,则在没有用户交互的 8 秒后触发。
      ask: 将自动包含"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');        
    }
    

    或者使用 :ask

    "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);       
    }
    

    【讨论】:

    • 感谢您的帮助。意图似乎大部分都有效,但未处理的事件出现了很多。有什么原因吗?谢谢。
    • Unhandled 在没有针对特定意图请求的意图处理程序时出现。请检查生成的请求 JSON。
    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 2018-09-18
    • 2023-03-23
    相关资源
    最近更新 更多