为什么我的 Alexa 技能没有移动到下一个意图?
Why isn't my Alexa skill moving on to the next intent?
在我的 Alexa 技能中,我基本上是根据用户的请求播放 MP3 文件。
我面临的问题是,当我尝试从我的启动请求转移到我的意向请求时,它不允许我这样做。当我作为用户在启动请求后给出答案以便能够转到意图请求时,我没有得到任何回应。
如果我直接进入意图请求,它确实有效。
'strict mode'
exports.handler = function(event, context) {
// Sounds from s3
var audio_lib = [
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/lxnonBu5-stand-tall-guardian-this-battle-is-lost-but-their-will-be-others+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/jd1RAcCC-guardians-are-measured-by-their-ability-to-come-back-from-defeat-so-stand-fight+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/idzplXpH-you-have-the-fortitude-and-persistance-of-lord-salidin-you-can-tell-him-i-said-that+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/OMsDcbcE-fight-like-a-demon-for-these-zones-bring-your-friends-i-need-more-like-you+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/LVKANDtb-what-where-s-my-catharsis-boo-boooo+(1).mp3\"/>",
"<audio src=\"https://caydedialogues.s3.us-east-2.amazonaws.com/are+you+trying+to+kill+me%2C+just+win.mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/seventh+column+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/you+can+fight+by+my+side+any+time+guardian+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/YEEEEEEEESS+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/you+may+be+defeated+but+you+must+never+surrender+(1)+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/was+that+all+of+them+that+was+all+of+them+(1).mp3\"/>"
];
// Random chooser for one of the sounds
var factIndex = Math.floor(Math.random() * audio_lib.length);
var randomQuote = audio_lib[factIndex];
let dialogues = {};
// Intent management
try {
var request = event.request;
if (request.type === "LaunchRequest") {
dialogues.speechText = "Hey Guardian, try asking me for a quote by your favorite character!";
context.succeed(buildResponse(dialogues));
} else if ( request.type === "IntentRequest") {
let name = request.intent.slots.Names.value;
if (name === "Zavala") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "Cayde" || name === "Cayde six") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "shaxx") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "ikora") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "zavala") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "saladin") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
}
dialogues.repromptText = "Go ahead ask me for a quote.";
context.succeed(buildResponse(dialogues));
dialogues.endSession = false;
}
} catch(e) {
context.fail("Excpetion: " + e);
}
}
// Building response for the alexa using ssml tags as well
function buildResponse(dialogues) {
var response = {
version: 1.0,
response: {
outputSpeech: {
type: "SSML",
ssml: "<speak>" + dialogues.speechText + "</speak>"
},
shouldEndSession: dialogues.endSession
}
};
if (dialogues.repromptText) {
response.response.reprompt = {
outputSpeech: {
type: "SSML",
ssml: "<speak>" + dialogues.repromptText + "</speak>"
}
};
}
return response;
}
这是一个示例,演示了使用 Alexa Skills Kit SDK (v2)、
处理来自 Alexa 技能的意图
有关更多信息,请查看 this
在我的 Alexa 技能中,我基本上是根据用户的请求播放 MP3 文件。
我面临的问题是,当我尝试从我的启动请求转移到我的意向请求时,它不允许我这样做。当我作为用户在启动请求后给出答案以便能够转到意图请求时,我没有得到任何回应。
如果我直接进入意图请求,它确实有效。
'strict mode'
exports.handler = function(event, context) {
// Sounds from s3
var audio_lib = [
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/lxnonBu5-stand-tall-guardian-this-battle-is-lost-but-their-will-be-others+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/jd1RAcCC-guardians-are-measured-by-their-ability-to-come-back-from-defeat-so-stand-fight+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/idzplXpH-you-have-the-fortitude-and-persistance-of-lord-salidin-you-can-tell-him-i-said-that+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/OMsDcbcE-fight-like-a-demon-for-these-zones-bring-your-friends-i-need-more-like-you+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/LVKANDtb-what-where-s-my-catharsis-boo-boooo+(1).mp3\"/>",
"<audio src=\"https://caydedialogues.s3.us-east-2.amazonaws.com/are+you+trying+to+kill+me%2C+just+win.mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/seventh+column+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/you+can+fight+by+my+side+any+time+guardian+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/YEEEEEEEESS+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/you+may+be+defeated+but+you+must+never+surrender+(1)+(1).mp3\"/>",
"<audio src=\"https://shaxxquotes.s3.us-east-2.amazonaws.com/was+that+all+of+them+that+was+all+of+them+(1).mp3\"/>"
];
// Random chooser for one of the sounds
var factIndex = Math.floor(Math.random() * audio_lib.length);
var randomQuote = audio_lib[factIndex];
let dialogues = {};
// Intent management
try {
var request = event.request;
if (request.type === "LaunchRequest") {
dialogues.speechText = "Hey Guardian, try asking me for a quote by your favorite character!";
context.succeed(buildResponse(dialogues));
} else if ( request.type === "IntentRequest") {
let name = request.intent.slots.Names.value;
if (name === "Zavala") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "Cayde" || name === "Cayde six") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "shaxx") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "ikora") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "zavala") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
} else if (name === "saladin") {
dialogues.speechText = randomQuote;
context.succeed(buildResponse(dialogues));
}
dialogues.repromptText = "Go ahead ask me for a quote.";
context.succeed(buildResponse(dialogues));
dialogues.endSession = false;
}
} catch(e) {
context.fail("Excpetion: " + e);
}
}
// Building response for the alexa using ssml tags as well
function buildResponse(dialogues) {
var response = {
version: 1.0,
response: {
outputSpeech: {
type: "SSML",
ssml: "<speak>" + dialogues.speechText + "</speak>"
},
shouldEndSession: dialogues.endSession
}
};
if (dialogues.repromptText) {
response.response.reprompt = {
outputSpeech: {
type: "SSML",
ssml: "<speak>" + dialogues.repromptText + "</speak>"
}
};
}
return response;
}
这是一个示例,演示了使用 Alexa Skills Kit SDK (v2)、
处理来自 Alexa 技能的意图有关更多信息,请查看 this