Search code examples
alexa-skills-kit

Alexa skill default intent override


Is there a way to override amazon default intents (or any intents really) based on where I am in the dialogue? I want the "help" request be answered by different suggestions at the start of the skill vs. when the user is further along. Currently the amazon default intent is chosen no matter where in the skill the user asks for help.

const HelpIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
    },
    handle(handlerInput) {
        const speakOutput = 'This is a customized help message';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

Solution

  • One idea that I've used before is to set a session attribute that keeps the state of your skill. You could initialize it to something like state = "launched" and set it to state = "inProgress" once the user has engaged in the dialog. In your help intent you could then check for the existence or value of the session attribute:

    handle(handlerInput) {
        // Get session attributes
        const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
        // Get or set default value
        const state = sessionAttributes.favoriteColor || "launched";
        // Set speakOutput accordingly
        ...
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }