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

如何在Alexa技能中获取并使用Yes/No确认触发对应意图

Solution for Handling Yes/No Responses in Your Alexa Skill

Got it, let's get this sorted for you! The core issue here is making sure Alexa properly routes the user's "yes" or "no" response to the right intent after your launch prompt. Here's how to adjust your code and leverage Alexa's built-in tools to make this work smoothly:

Step-by-Step Implementation

First, we'll use Alexa's pre-built AMAZON.YesIntent and AMAZON.NoIntent—these are ready-to-use intents that handle basic yes/no responses without you having to create custom utterances. Here's the updated code:

var handlers = {
    'LaunchRequest': function () {
        const welcomeMsg = this.t("WELCOME_MSG");
        const prompt = this.t("ASK_FOR_SOMETHING"); // Should map to "Do you want to perform something ?"
        const reprompt = this.t("LAUNCH_REPROMPT"); // Example: "I didn't catch that. Do you want to perform something?"

        this.response.speak(`${welcomeMsg} ${prompt}`).listen(reprompt);
        this.emit(':responseReady');
    },

    // Handle user's "yes" response
    'AMAZON.YesIntent': function () {
        // Trigger your custom intent directly
        this.emit('SomethingIntent');
    },

    'SomethingIntent': function () {
        // Your logic for when the user agrees goes here
        this.response.speak("Perfect! Let's dive into that task you wanted.");
        this.emit(':responseReady');
    },

    // Handle user's "no" response
    'AMAZON.NoIntent': function () {
        this.response.speak("No worries at all! Have a fantastic day.");
        this.emit(':responseReady');
    },

    // Gracefully handle unrecognized responses
    'Unhandled': function () {
        const reprompt = this.t("LAUNCH_REPROMPT");
        this.response.speak("Sorry, I didn't get that. " + reprompt).listen(reprompt);
        this.emit(':responseReady');
    }
};

Key Details to Note

  • Built-in Intents: You don't need to create custom intents or utterances for yes/no—AMAZON.YesIntent and AMAZON.NoIntent are enabled by default in most Alexa skill interaction models, but double-check your skill's console to confirm.
  • Intent Redirection: Using this.emit('SomethingIntent') in the yes handler keeps your code clean by reusing your existing intent logic instead of duplicating code.
  • Reprompt & Fallback: The Unhandled handler ensures Alexa stays in the conversation if the user says something unclear, guiding them back to the yes/no prompt.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:26:12