Learn
Session Attributes
Assigning Slot Values to Session Attributes

One good use of session attributes is to capture and store user input through slots so you can use that information at a later time. This information is sent to your Lambda function as part of the JSON response.

To get a slot value, you first need to figure out how your slot is sent in the JSON request. The following is an example JSON request for a movie recommendation skill:

"request": { "type": "IntentRequest", "requestId": "EdwRequestId.d30fb1fe-8f09-4a80-ab90-b736c2959146", "intent": { "name": "SetGenreIntent", "slots": { "genres": { "name": "genres", "value": "horror" } } }

The structure of the JSON object tells us how to access user input. We can use the following format to set a genre session attribute to the value saved to a user slot input:

this.attributes['genre'] = this.event.request.intent.slots.genres.value;

In this lesson we want Alexa to interpret the utterance, “Test my Ruby knowledge”, recognize “Ruby” as a slot value, and store it in the language session attribute for Alexa to use in later speech intents.

Instructions

1.

In SetMyLanguageIntent, set the language session attribute so that it equals the user’s specified language. Look at the following JSON Request Object to construct your call:

"request": { "type": "IntentRequest", "requestId": "EdwRequestId.d30fb1fe-8f09-4a80-ab90-b736c2959146", "intent": { "name": "SetMyLanguageIntent", "slots": { "languages": { "name": "languages", "value": "ruby" } } },
2.

In AnswerIntent, create a userAnswer variable and set it equal to the user’s answer. Look at the following JSON Request Object to construct your call:

"request": { "type": "IntentRequest", "requestId": "EdwRequestId.494ef95d-29c8-40a8-914c-0cc740058d53", "intent": { "name": "AnswerIntent", "slots": { "answer": { "name": "answer", "value": "length" } } },
Folder Icon

Take this course for free

Already have an account?