Thomas Desmond Headshot
Thomas Desmond
Sitecore Developer Advocate

The Basics of the Alexa Skill IntentSchema

Amazon Alexa Dot speaker with logos behind

In this post, I will describe the basics of designing and working with the IntentSchema for an Amazon Alexa skill. To provide some context, an Alexa skill can have multiple intents. Each intent is a specific action within the skill.

Imagine we have a calculator skill. The user can ask Alexa to add or subtract two numbers. The skill would be the calculator and the two intents would be adding and subtracting. The intent schema comes into play because we are allowing the user to add or subtract any two numbers. We use the IntentSchema.json to prepare Alexa to accept those two arguments. Note: The programming idea of an argument is referred to as a slot in the Alexa world, I will refer to them as slots for rest of post.

For our addition and subtraction intents, we would need to define two slots for both of them the first number and second number in the calculation. See below the intentSchema.json currently with only the AddIntent slots defined in it.

2   "intents":\[
3      {
4         "intent":"AddIntent",
5         "slots":\[
6            {
7               "name":"firstNumber",
8               "type":"AMAZON.Number"
9            },
10            {
11               "name":"secondNumber",
12               "type":"AMAZON.Number"
13            }
14         \]
15      }
16   \]

You can see in the json that we have two individual slots (firstNumber & secondNumber). Each has a name and a type attribute these are required for every slot that you define.

2	"intents": \[{
3		"intent": "AddIntent",
4		"slots": \[{
5			"name": "firstnum",
6			"type": "AMAZON.NUMBER"
7		}, {
8			"name": "secondnum",
9			"type": "AMAZON.NUMBER"
10		}\]
11	}, {
12		"intent": "SubtractIntent",
13		"slots": \[{
14			"name": "firstnum",
15			"type": "AMAZON.NUMBER"
16		}, {
17			"name": "secondnum",
18			"type": "AMAZON.NUMBER"
19		}\]
20	}\]

Above is an example with both of our intents defined inside of the intentSchema.json Notice slots within the same intent must have unique names but slots inside of a different intent are within a new scope.

All slots must have a defined types. Amazon has some default types that you can use for your apps. These types are the most common:

1|  Slot Type |  Description |
2| --- | --- |
3|  AMAZON.NUMBER |  Able to recognize numbers and convert then to integers. Example: Two converts to 2 |
4|  AMAZON.TIME |  Converts times into programmable values. Example: "Set alarm for seven pm". Converts to 7:00 or 18:00 depending on settings |
5|  AMAZON.DURATION |  Able to change durations into usable values Example: "Set alarm for 45 minutes". Converts to PT45M |
6|  AMAZON.FOUR\_DIGIT\_NUMBER |  Recognizes 4 digit number sequences like years and converts them. Example: "Wikipedia war of eighteen twelve" converts to 1812. |
7|  AMAZON.DATE |  Converts dates into usable formats. Example: "What is the weather today" converts to what is the weather for 2017-3-2 |

If you find yourself struggling with understanding what the above types do and how they handle user input. Make sample apps and look at what Alexa returns as the data. It is useful to see the real world conversions that Alexa does.

The intentSchema makes Alexa powerful because it can make your skills more dynamic, in that you can accept all types of input from the user. It is possible to build custom slots as well as lists to really build out your skill. I will make a post in the future about these advanced topics.