我正在撰写Alexa
技能并且遇到AMAZON.CancelIntent
意图问题。
如果我说"退出"或"帮助"相应地调用其他意图。但如果我说"取消"
:我的自定义意图NutriFactsIntent
被调用,当然也有问题,因为插槽没有填充。
为什么会这样?
意图架构
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": [
"Cancel",
"Never mind",
"forget it"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"Open",
"Start",
"what can I say",
"help me"
]
},
{
"name": "AMAZON.StopIntent",
"samples": [
"Quit",
"Exit",
"Leave",
"Off",
"Stop"
]
},
{
"name": "NutriFactsIntent",
"samples": [
"give me the facts on a {Food}",
"give me the facts on an {Food}",
"give me the facts for a {Food}",
"give me the facts for an {Food}",
"give me the facts of a {Food}",
"give me the facts of an {Food}",
"give me the facts for {Food}",
"give me the facts of {Food}",
...
}
抓住意图
function onIntent(intentRequest, session, callback) {
//console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);
const intent = intentRequest.intent;
const intentName = intentRequest.intent.name;
// Dispatch to your skill's intent handlers
if (intentName === 'NutriFactsIntent') {
getFactsFromSession(intent, session, callback);
} else if (intentName === 'AMAZON.HelpIntent') {
getWelcomeResponse(callback);
} else if (intentName === 'AMAZON.StopIntent' || intentName === 'AMAZON.CancelIntent') {
handleSessionEndRequest(callback);
} else {
throw new Error('Invalid intent');
}
}