Search code examples
node.jsaws-lambdaalexa-skills-kit

How to get the YesIntent run after a specific intent is run in Alexa Skill


I've been trying to find out how to make the AMAZON.YesIntent run after another intent is triggered. I have searched around and tried different solutions however they never work.


Solution

  • You can call any handler from another intent handler.

    alexa-nodejs-sdk v1
    For alexa-nodejs-sdk v1 you can use

    'SomeOtherIntent': function() {
       // Do your stuff here
    
       // Now to call AMAZON.YesIntent intent handler
       this.emit('AMAZON.YesIntent');
    }
    

    alexa-nodejs-sdk v2
    For alexa-nodejs-sdk v2 you can import the target handle function (if it's in a different module) or just invoke the it directly and pass in the handlerinput.

    const SomeOtherIntentHandler = {
       canHandle(handlerInput) {
          const request = handlerInput.requestEnvelope.request;
          return request.type === 'IntentRequest'
             && request.intent.name === 'SomeOtherIntent';
       },
    
       handle(handlerInput) {
          // Do your stuff here
    
          // Now to call AMAZON.YesIntent intent handler
          return amazonYesIntentHandler.handle(handlerInput);
       }
    }