【发布时间】:2018-02-19 21:30:28
【问题描述】:
我正在编写 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');
}
}
【问题讨论】:
-
你能在样本话语而不是样本中输入话语吗?
标签: alexa-skills-kit alexa-skill