Javascript Alexa技巧:处理ShouldEndSession以保持会话打开
拥有Alexa技能,能读出一段随机引用。会话以“shouldEndSession”结束:false 我如何保持会话打开并询问用户是否希望听到另一个报价?这就触发了元宵节。我正在使用“:askWithCard”,它使会话保持打开状态,但不会触发YesIntJavascript Alexa技巧:处理ShouldEndSession以保持会话打开,javascript,node.js,amazon-web-services,alexa,aws-sdk-nodejs,Javascript,Node.js,Amazon Web Services,Alexa,Aws Sdk Nodejs,拥有Alexa技能,能读出一段随机引用。会话以“shouldEndSession”结束:false 我如何保持会话打开并询问用户是否希望听到另一个报价?这就触发了元宵节。我正在使用“:askWithCard”,它使会话保持打开状态,但不会触发YesInt const handlers = { 'LaunchRequest': function () { this.emit('Introduction'); }, 'Introduction': function() {
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();
};
尝试了
响应。shouldEndSession(false,“您想听到另一个报价吗”)在RandomQuoteContent中的code>,但是在读取第一个quote后会话关闭了有一种黑客方法可以做到这一点:在提示问题后使用无声音频流。由于每个音频不应超过90秒,所以您最多可以有大约180秒的窗口等待用户的下一次输入
唯一需要注意的是,用户必须在实际命令之前中断音频,因此需要额外的“Alexa”或您选择的任何调用名称