question

Jonathan Horniblow avatar image
Jonathan Horniblow asked

Conditional intent routing (from cookbook) only works with LaunchRequest, not NewSession?!

Anyone having problems with intent routing? I'm following this section from the cookbook: https://github.com/alexa/alexa-cookbook/blob/master/ingredients/using-new-session-to-short-circuit-incoming-intent-and-launch-requests.md It says:

// This will short-cut any incoming intent or launch requests and route them to this handler.
'NewSession': function() {
      if (this.event.request.type === 'IntentRequest') {
          this.emit(this.event.request.intent.name); 
      } 
      this.emit('LaunchRequest');
}

Seems fair enough. So I tried it, and it's not working. I've console-logged everything, and it definitely is catching the intent.

Here's my code:
'NewSession': function () {
            console.log("In newsession function within menu");
            if (this.event.request.type === 'IntentRequest') {
                console.log("got an intentrequest within newsession in menu of " + this.event.request.intent.name);
                console.log(this.attributes.STATE);
                this.emit(this.event.request.intent.name);
            }
            this.handler.state = constants.states.MENU_MODE;
            this.emit('MenuIntent');
        },

And here's my log output:

  • got an intentrequest within newsession within menu: AMAZON.HelpIntent
  • In menuintent function within menu

So it definitely catches it, but doesn't reroute UNLESS I change NewSession to LaunchRequest. Where am I going wrong?!

alexa skills kitintentssdknodejs
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Anand@Amazon avatar image
Anand@Amazon answered

Hi there,

There are three types of request sent by alexa to your function:

1. LaunchRequest

2. Intent Request

3. SessionEndedRequest

Launch Request :

Your service receives a LaunchRequest when the user invokes the skill with the invocation name, but does not provide any command mapping to an intent

Ex: Alexa open daily quiz

IntentRequest:

Your service receives an IntentRequest when the user speaks a command that maps to an intent. The request object sent to your service includes the specific intent and any defined slot values.

Ex. Alexa, ask daily quiz to ask me a quiz.

SessionEndedRequest:

Your service receives a SessionEndedRequest when a currently open session is closed.

In your case your have created a custom Intent "NewSession" and then jumping it to another "MenuIntent" after checking the state.

For resolving this issue

1. You can change "NewSession" to "LaunchRequest" then whenever you say Alexa open <invocation name> this method get triggered and it will move to "MenuIntent".

2. In interaction model mention utterance phrase like

NewSession to give me menu

so whenever you give command like "Alexa ask <Invocation name> to give me menu

then NewSession intent will triggered and it will jump to another intent "MenuItem".

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.