有一个 Alexa 技能,可以读出一个随机的报价。会话以“shouldEndSession”结束:false。
如何保持会话打开并询问用户是否想听到另一个报价?这会触发 YesIntent。我正在使用 ':askWithCard' 使会话保持打开状态但不会触发 YesIntent
const handlers = {
'LaunchRequest': function () {
this.emit('Introduction');
},
'Introduction': function() {
console.log("Introduction Handler called.");
var speechOutput = "Just say give me an office space quote";
var repromptText = "I did not recieve any input. Thank you and good bye";
this.emit(':askWithCard', speechOutput, repromptText);
},
'RandomQuoteIntent': function() {
const quoteOfficeSpace = data;
const quoteIndex = Math.floor(Math.random() * quoteOfficeSpace.length);
const randomQuote = quoteOfficeSpace[quoteIndex];
const speechOutput = randomQuote;
this.response.cardRenderer(SKILL_NAME);
this.response.speak(speechOutput);
this.emit(':responseReady');
},
'AMAZON.YesIntent': function() {
this.emit(':RandomQuoteIntent');
},
'AMAZON.HelpIntent': function () {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay! Goodbye, just don't forget to fill out your TPS reports");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye ");
},
'Unhandled': function () {
console.log("Unhandled Intent Handler Called.");
this.emit(':tell', "Sorry, I am unable to understand what you said. just say give me an office space quote");
},
};
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
尝试了response.shouldEndSession(false, "would you like to hear another quote ");
RandomQuoteIntent 但会话在读出第一个报价后关闭