Dustin Coates in Alexa

When does SessionEndedRequest get invoked on the Alexa Skills Kit?

The SessionEndedRequest is important to get right, especially when you want to save the current session to DynamoDB (in essence, persist the state across different sessions). However, like the LaunchRequest, you won’t define this in your intent schema. So when does it get invoked?

There are a few different ways:

  • The user says “quit” or “exit” or something like that
  • If Alexa is waiting for a response and the user doesn’t respond
  • If Alexa is waiting for a response and the user says something that doesn’t correspond to one of your intents
  • There’s an error

In all of these cases, the session will end and the SessionEndedRequest for the current state (if you are leveraging states) will be invoked. This is the time to save the current session to DynamoDB if your skill can be used across multiple sessions:

'SessionEndedRequest' () {
  this.handler.state = '';
  this.emit(':saveState', true);
  this.emit(':tell', 'Catch you on the flip side.');
}

One thing to note: if you force the session to end by setting shouldEndSession to true by using any of the methods off of this.response except this.response.listen, then SessionEndedRequest will not be invoked.