如何实现Alexa技能中用户回答Yes时自动跳转Intent?求排查方案
Alexa技能交互解决方案:营业时间查询流程
问题根源
你当前的实现问题主要出在意图确认指令的误用和技能模型配置缺失:
addConfirmIntentDirective是用于用户触发某个意图后,让Alexa确认是否执行该意图,而非在启动时直接发起确认- 未配置处理用户"No"回答的内置意图,也没给
OperationalHoursIntent设置足够的识别样本
正确的技能模型配置
1. 配置OperationalHoursIntent
- 在Alexa开发者控制台的「Interaction Model」中创建该意图,无需添加任何插槽
- 添加样本Utterances,比如:
- "营业时间"
- "几点开门"
- "你们什么时候营业"
- "查看营业时间"
- 无需开启Intent Confirmation(启动时已主动询问,用户的Yes直接触发查询即可)
2. 启用内置意图
必须添加以下两个内置意图,用于处理用户的Yes/No回答:
AMAZON.YesIntent:识别用户的肯定回复AMAZON.NoIntent:识别用户的否定回复
调整后的代码实现
// 启动请求处理器:欢迎并询问是否需要了解营业时间 const LaunchRequestHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; }, handle(handlerInput) { const speakOutput = 'Welcome to coffee shop! Would you like to know our hours of operation?'; const repromptOutput = 'Would you like to know our hours of operation?'; return handlerInput.responseBuilder .speak(speakOutput) .reprompt(repromptOutput) .getResponse(); } }; // 营业时间意图处理器:回复营业时间 const OperationalHoursHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'OperationalHoursIntent'; }, handle(handlerInput) { return handlerInput.responseBuilder .speak('We are open 9-5.') .getResponse(); } }; // 肯定回复处理器:触发营业时间查询 const YesIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent'; }, handle(handlerInput) { // 直接复用营业时间回复逻辑,或跳转至OperationalHoursIntent return handlerInput.responseBuilder .speak('We are open 9-5.') .getResponse(); } }; // 否定回复处理器:结束对话 const NoIntentHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.NoIntent'; }, handle(handlerInput) { return handlerInput.responseBuilder .speak('Alright, thanks for stopping by! Goodbye.') .withShouldEndSession(true) // 明确结束会话 .getResponse(); } }; // 注册所有处理器 exports.handler = Alexa.SkillBuilders.custom() .addRequestHandlers( LaunchRequestHandler, OperationalHoursHandler, YesIntentHandler, NoIntentHandler // 可添加其他必要处理器如AMAZON.HelpIntent、AMAZON.CancelIntent等 ) .lambda();
关键修正点说明
- 移除启动时的
addConfirmIntentDirective:启动后直接发起询问,让用户的Yes/No触发对应的内置意图 - 添加
AMAZON.YesIntent处理器:用户说Yes时直接回复营业时间 - 添加
AMAZON.NoIntent处理器:用户说No时结束对话 - 确保模型中配置了足够的样本Utterances,让Alexa能正确识别意图
内容的提问来源于stack exchange,提问作者Ryan Shrewsbury
相关产品推荐
相关产品推荐

