Alexa skill - how to use variables/attributes, also known as slots!

I recently picked up writing a skill for Alexa. Trying to wrap my head around the terminology I created this post (and some others..) to help others who will go through the same struggle.

One of the things I had to search for was how to pass parameters to my methods. "Keywords" that the user says as input. Such as a date, a city or similar that my code needs to use for lookup or storage. This in "Alexa" terminology is called a slot - or intent slot. A slot is related to an intent, as it is part of the sample utterances. This can be seen below

Alexa intent with slot

In the above image you will see curly braces with a word in between them. This is the slot of this utterance. Meaning the slot can be placed differently among utterances. The {Decision} part in the above will become reachable from my code. However first we must choose a type for the slot. This is known as a "Slot Type". This is found just below the slot:

Alexa Skill Intent Slot

There are many built in slot types. Such as dates, cities and so on. I needed my own "enum" - predefined list of words. In the above image you can see that I have created a slot type called "Decision" and assigned it to the slot "Outcome".

The slot type Decision is created under "Slot types" in the left side menu as seen below. It can be seen that I have created the values A and B for this input.

Alexa skill Slot Type

Alright so we have created an intent (Decision), with a slot (outcome) which has a slot type (Decision). The next obvious step is to get the actual value for this. My example is for NodeJS using Amazon Lambda. In the handler invoked by the Decision intent you can get the letter A, B or whatever the user types in by using the following statement:

var outcome = this.event.request.intent.slots.Outcome.value;

Where "Outcome" is the name of the slot that you wish to access.

I hope this helps someone out there, let me know in the comments down below if it did :)

Do you not yet have an echo? You can easily order one from amazon: