You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现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();

关键修正点说明

  1. 移除启动时的addConfirmIntentDirective:启动后直接发起询问,让用户的Yes/No触发对应的内置意图
  2. 添加AMAZON.YesIntent处理器:用户说Yes时直接回复营业时间
  3. 添加AMAZON.NoIntent处理器:用户说No时结束对话
  4. 确保模型中配置了足够的样本Utterances,让Alexa能正确识别意图

内容的提问来源于stack exchange,提问作者Ryan Shrewsbury

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 22:41:27