Keep the Session Open

The Input Handler is a component within Alexa that forwards Echo Button presses to your skill. This topic discusses the lifecycle of a typical skill session and how an active Input Handler can affect it. For example, an active Input Handler can lengthen the session and, under certain circumstances, cancel a reprompt.

Skill Session Lifecycle

First let's review the lifecycle of a skill session:

  1. A skill session begins when a user invokes your skill. This causes Alexa to send your skill a request. This is usually a launch request, although a user may invoke your skill with a specific intent also. The request contains a session object that uses a Boolean value called new to indicate that this is a new session.
  2. Your skill receives the request and formulates a response for Alexa to speak to the user.
  3. What happens next depends on the value of the shouldEndSession parameter in your skill's response:
    • true – The session ends. Alexa, not the skill, handles any further speech from the user. If the user re-invokes the skill, Alexa creates a new session (that is, go back to step 1).
    • false – The session stays open and Alexa opens the microphone to indicate that she expects the user to respond. If the user provides a response, their speech is mapped to one of the intents that the skill defined, and the response is sent to the skill. However, if eight seconds elapse without a response from the user, Alexa closes the microphone. If the skill specified a reprompt, Alexa reprompts the user to speak and opens the microphone for eight more seconds. After the microphone closes, the behavior of the session is the same as if the skill had left shouldEndSession undefined, as described next.
    • undefined – In this case, the session's behavior depends on the type of Echo device that the user is interacting with and whether there is an active Input Handler. If the device has a screen, the session stays open for up to 30 more seconds, without opening the microphone to prompt the user for input. If the user speaks and precedes their request with "Alexa", the request is sent to the skill. Otherwise, Alexa ignores the user's speech. If an Input Handler is active, the session continues to stay open until the skill calls StopInputHandler or the Input Handler times out.

How an Input Handler Affects the Skill Session Lifecycle

An active Input Handler affects the skill session as follows:

  • Session lengthening – As long as an Input Handler is active, the skill session remains open for the duration of the Input Handler, unless the skill sets shouldEndSession to true in any of its responses. In other words, even if the user does not provide voice input, the session stays open until the Input Handler times out, the skill calls StopInputHandler, or the skill sets shouldEndSession to true.
  • Button input can open the microphone – When handling button input events, a skill can have Alexa open the microphone and request voice input from the user by setting shouldEndSession to false in its response.
  • The reprompt can be cancelled – When there is an active Input Handler, button activity can cancel a reprompt. An example is when your skill requests voice input by setting shouldEndSession to false in a previous skill response, and is also listening for buttonDown and buttonUp events. If the user presses a button and the skill receives the input event, any pending voice reprompt is cancelled.

    This behavior can be surprising when your skill handles both buttonDown and buttonUp events and the buttonDown event handler sets a reprompt for voice input. Even if the skill does not respond to the buttonUp event, the buttonUp event cancels the reprompt that the buttonDown event handler set.