Alexa Skills: using the session attribute correctly

Why is the Session attribute important for Alexa Skills? This article answers the question and shows how to use the attribute correctly.

The following article is an excerpt from my book “Developing Alexa Skills“. Click on the picture to buy the book on Amazon from 8,99€. It’s worth it for developers and those who want to become developers.

how to develop and build alexa skills book

Alexa Skills: Skill data and the session attribute

A skill does not always have a linear conversation. We may want to ask a question and behave differently depending on the answer we have received. To do this, we need to keep some information in the “memory” of an Alexa skill.

The Alexa Skill SDK gives us the ability to use session attributes to do this, and if you’re having a conversation with someone, you may either miss something they said, or you may not have heard it properly. Usually you ask for a repetition of what he said. Skills also need this ability because people don’t always listen to Alexa perfectly.  For example, if you have your briefing read to you in the morning, you can also say, “Alexa, please repeat that. ”

To implement the repetition functionality for skills, you just need to include the AMAZON.RepeatIntent in the interaction model and then use session attributes in the code to remember the last voice output that was forwarded to the customer.

What is AMAZON.RepeatIntent?

AMAZON.RepeatIntent is one of the standard intents offered by Amazon with which the user can repeat the last action. If the intent is implemented in the skill, the user can ask Alexa to repeat the last action. To include this intent, you need to do the following:

  • In the interaction model, provide the AMAZON.repeatIntent.
  • Extend the session attributes where necessary so that the last spoken response is in the session attributes. This is done with the method setSessionAttributes().
  • Add a handler for the AMAZON.repeatIntent and call the session attributes in it so that they can then be used.  This works with the method getSessionAttributes().

An example for the session attribute in use

On Github I developed a forked version of the Amazon quiz skill: In the game, users can ask for World Cup data. For example, I reference the Sesion attribute in the DefinitionHandler, which is addressed when users don’t play the game, but ask the game a question:

smart home system alexa skills session attribute

As you can see, the attribute object contains the information whether the user has already started the game before. If the game was not started, then the DefinitionHandler will be opened. Here is another video:

The Manual for Alexa Skill Development

If the article interested you, check out the manual for Alexa Skill Development on Amazon, or read the book’s page. On Github you can find all code examples used in the book.

Leave a Reply

Your email address will not be published. Required fields are marked *