问题
I'm new to Alexa skill creation. I tried to create a skill for my term project in college and am trying to finish it. I've finally got the Lambda and interaction model communicating and am now testing the skill in the tool. I'm finding 2 issues.
1) The invocation name is sending me the unhandled response back, and
2) None of the intents outside of the launch intent are sending any response back. The Lambda code is as below:
"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();
};
What am I missing? Thanks for your help.
回答1:
You have a couple of things to be corrected.
- LaunchRequest:
It isLaunchRequest
and notLaunchIntent
. When you invoke a skill, this is the handler which will be called. - context.succeed:
You don't needcontext.succeed(handlers());
, you can remove it from all the intent handlers. - shouldEndSession:
If this parameter is not set or if it is set totrue
, Alexa will end the current session and your skill will be closed. No subsequent user speech will reach your backend code unless you invoke it again.
The good thing is that, you don't have to set this parameter manually and the SDK will take care of it as follows:
- :ask: will 'ask' the user and wait for a response by keeping the session alive. If you set a re-prompt, it will be triggered after 8 seconds if there is no interaction from user.
ask: will automatically include"shouldEndSession":"false"
in response.
Ex:
'AbcIntent': function () {
var speech="Your speech here";
var reprompt="Your re-prompt here";
this.emit(':ask', speech,reprompt);
}
- :tell will just say the response and end the session. Use this when you don't expect any response from user. Ex: use it for
AMAZON.StopIntent
. - speak() and listen(): if there is no
listen()
,speak()
will be treated as :tell, it just tell the response and set"shouldEndSession":"true"
in response which will end the session. But if there is alisten()
, the SDK will set"shouldEndSession":"false"
in response and will keep the session alive.
Make your changes like this:
"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');
}
Or use :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);
}
来源:https://stackoverflow.com/questions/51957763/no-response-from-any-other-intent-request-except-launch-request