When building a skill for Alexa you need to be able to get input from the user.  All but the most simplistic business logic is going to have variables for completing the users desire.  For Alexa, these variables are called Slots.  Just like a variable in a strongly typed programming language these Slots must be declares and given a type so that the user can provide the data.  This post will talk about how Slots work and how to use them in your skill.

There are basically two types of slots you can use in an Alexa skill.

  • Value types, like numbers, dates, times, etc.
  • Lists of items (i.e. multiple choice)

There is actually a third type called Phrases but Phrases are complicated types of slots that open the door for more responsive skills, such as search queries.  Keep an eye on my blog for a full writeup on Phrase slots in the near future, but we will not be getting into those today.

Value Types

The available Value Types are limited to whole numbers, phone numbers, and several variations on date and time.  Aside from the pick lists, these are all the options you have.  Specifically, the options are

  • Dates – the user can give a specific calendar date or a descriptive phrase like “this Wednesday” or “first of next month”.  Your skill will receive a slot value of the specific date
  • Duration – this is for a span of time, like when you set a kitchen timer with your Echo.
  • Numbers – this supports positive and negative whole numbers, not decimals.  There is also a special type of slot called Four Digit Numbers that is useful for years, PIN codes, and such.
  • Ordinal – if the user says “second”, your skill gets a 2
  • Phone Numbers – many different formats are supported including U. S. local 7 digit numbers, numbers with area code, and numbers with country code
  • Time – you skill gets the time the user stated in 24-hour format where midnight is “00:00”.  It also supports certain terms like “Midnight” or Noon.

Date Types

When I say Alexa supports “date” you may think it’s limited to YYYY-MM-DD, but that would be a mistake.  Alexa supports many different permutations of date so you must be prepared to interpret each because you cannot control what the user says.  When you declare that your slot accepts a date, you can get any one of the formats described here.

If the user says a specific calendar date, the value will be returned to your skill in ISO 8601 format, which is just YYYY-MM-DD except for some special cases when using different languages and locales.

Date slots can also accept descriptive words like “tomorrow” “today”, “next Tuesday”, “Christmas”, etc.  Your skill will just receive the specific date without knowing how they described that date.  If they use a descriptive term for a date then it will always be interpreted as being in the future.  If they say “Monday”, it’s next Monday.  If today is Monday, then you get today’s date.

The user is also allowed to specify a week, such as “this week”.  In that case you will get the week date format instead of calendar date.  The week format is in the form YYYY-WNN where YYYY is the year and NN is the week number.  For example, the first week of 2022 is 2022-W01.  The descriptive terms are limited; for example “last week of the year” will get no response, nor will “the week of February 1”.  However, “this week”, “last week”, and “next week” are reliable.

Weekends work the same way as weeks but you get a “-WE” tacked onto the end.  The first weekend of the year would be 2022-W01-WE.

Asking for a month will return the month in the format YYYY-MM if you are using a form of English or YYYY-MM-XX when using some other languages.  For example February will be either 2022-02 or 2022-02-XX.

Years work the same way as months except you will receive just the year, such as YYYY or YYYY-XX-XX, depending on your language setting.

The user can also specify a decade such as “this 90’s”, in which case you will receive the string 199X or 199X-XX-XX.

Finally the user can specify a season as Spring, Summar, Fall, or Winter.  Your skill will receive the year then a season modifier, like 2022-SP, 2022-SU, 2022-FA, or 2022-WI.

Your skill can never tell what kind of date will be returned, so when you are coding for a date be prepared for any of these options.

Duration Types

Duration slots return a time span in a special format.  An example of duration use is in setting cooking timers on your Echo.

Duration returns a value in the format “PnYnMnDTnHnMnS” where P means “duration” and then the number of years, months, days, hours, minutes and seconds.  Note the “T” in the middle that marks the transition from days to time.  This may seem unnecessary but it is necessary to detect the difference between Months and Minutes.  If your timespan is 9 Months you will receive “P9M”, but for 9 Minutes you will receive PT9M.

In theory if the user says “two years one month eight days four hours nine minutes and three seconds” you should receive the string “P2Y1M8D4TH9M3S”.  However large durations like this can be unpredictable.  When I tried the utterance above I got 4 different values as follows

  • P2Y
  • P1M8DT4H
  • PT9M
  • PT3S

From the point of view of my skill, the user gave me 4 different durations for one slot.

Number Types

There are two number types you can use depending on your purpose – Numbers and Four-Digit-Numbers.  There is very little difference between the two except that the Four-Digit-Numbers is a bit better at recognizing PIN numbers and other types of codes.  It is also better at treating the “oh” as a zero when the user says something like  “six oh nine nine”.

Note that the Four-Digit-Numbers name is a misnomer because it will return any number of digits, not just 4.  If you specify a number in the millions for a Four-Digit-Number slot, you will still get the whole number. Same as for a 1 or 2 digit number, you will get what the person said.  In daily use, I’ve noticed very little difference between the two.

The Number slot type can handle positive and negative whole numbers, but not decimal numbers.  If you try to say “seven point two” you will often get a question mark back, but sometimes just one or the other of the two numbers.  If you need to get a decimal number input, you will need to work at it.

Ordinal Types

Ordinals are “first”, “third”, etc.  When you specify an Ordinal slot your skill will receive the integer representing that word.  There’s not much more so say about ordinals.

Phone Numbers

The phone number recognition can be powerful, recognizing everything from local numbers to overseas.  However, there is no enforcement for phone number format.  If someone speaks a number without enough digits, you will get that incorrect number.  It’s up to you to validate the format and ask for the information again.

The user can specify the country code, area code, and local phone number, including saying “plus” before the country code if they wish (it’s not required).  If they say “plus” your skill will receive the “plus”.  If they do not say it, you will not get it.  Other than the plus, you will not get any punctuation in the number – just the digits.

The phone number slot value seems to be more of a simple regex enforcement for the proper allowable characters of numbers and “plus”.  Beyond that you are on your own to validate the incoming number.

Time Values

Time values are received in 24 hour format where midnight is “00:00”.  The values are always in HH:MM format for all language settings.

The user can also specify a time period like Evening (your skill will receive the string “EV”), Night (“NI”), Morning (“MO”), and Afternoon (“AF”).

Something to keep in mind is when I said “midday” with an en-US locale I was given midnight, not noon.  I have not tested whether this would be recognized properly in a different locale.

List Values

All the rest of the built in slot types, as well as any custom slot types you may create, are all lists.  There are many types of predefined lists, and you can see them all here.   Below is a list of the 90+ items that were available when I wrote this article.

  • Actor names
  • AdministrativeArea
  • AggregateRating
  • Airline Company names
  • Airport
  • Anaphor (“this”, “that”, “those”…)
  • Animal
  • Artist Names (in various media like Music, Literature, Art, etc.)
  • Athlete Name
  • Author Name
  • Book Title
  • Book Series
  • Broadcast Channel (commercial name of TV and Radio stations, such as KEXP or Colorado Public Radio)
  • City Name – Cities in the U. S. and well-known cities world wide
  • Civic Structure – Well known landmarks and local buildings
  • Color
  • Comic
  • Corporation
  • Country
  • Creative Work Type – things an artist would make, like book, soundtrack, thesis, sonnet, song, etc.
  • Day Of Week
  • Dessert
  • Device Type – not just Amazon devices, but also laptop, stereo, TV, etc.
  • Director Names
  • Drink Names – brand names, drink names (including alcoholic drinks)
  • Educational Organization – college and other educational institution names
  • Event Type – such as game, holiday, party, time off, meetup, etc.
  • Festival – specific names of festivals like South by SouthWest, Sundance, Montreux Jazz Festival, etc.
  • Fictional Character
  • Financial Service Business Names
  • First Names common in the U. S.
  • Food
  • Food Establishment
  • Game
  • Genre
  • Landform
  • Landmarks Or Historical Buildings
  • Language
  • Local Business
  • Local Business Type
  • Medical Organization – names of local and national companies
  • Month Names
  • Movie Titles
  • Movie Series
  • Movie Theater
  • Music Album
  • Music Creative Work Type – Words describing different types of musical works, such as songs and tracks.
  • Music Event
  • Music Group
  • Musician names
  • Music Playlist – generic types of music lists, such as Dance, Classic Rock, etc.
  • Music Recording – album names and song names
  • Music Venue
  • Music Video
  • Organization – non-governmental companies
  • Person Names – real and fictional names of people
  • Postal Address
  • Professional – names of well-known people from sports, business, Literature, Music, etc.
  • Professional Type – names of professions
  • Radio Channel
  • Region Names within the U. S.
  • Relative Position – “bottom”, “middle”, “right”, etc.
  • Residence names – well-known residences
  • Room Names – “Living room”, “library”, “nursery”, etc.
  • Screening Event – film festivals
  • Service – services companies provide their clients
  • Social Media Platform – names of the MANY social media platforms available
  • Software Application Names – includes business software, games, etc.
  • Software Game
  • Sport Names
  • Sports Event
  • Sports Team
  • Street Names
  • Television Channel
  • TV Episode – names of individual episodes of popular series
  • TV Season
  • TV Series
  • Video Game
  • Visual Mode Trigger – “show”, “display”, “see”, “view”,…
  • Weather Condition
  • Written Creative Work Type

They also provide a list of country specific terms for certain countries.

  • Australian Cities
  • Australian Regions
  • German City
  • First Names common in Germany
  • German Regions
  • General European City Names
  • UK Cities
  • First Names common in the UK
  • UK Regions
  • U. S. City names
  • First names common in the U. S.
  • U. S. State Names

Just as for the Phone Number and Four-Digit-Number slot types, these lists are not restrictive.  I found that the Actor Names slot would recognize musicians and politicians.  When I tried to make it recognize the actor name “pitt” it returned the name to me but in all lower case.   When I said “Brad Pitt” it returned with proper casing making me think the name was recognized.  Each list appears to favor recognizing words in its topic, but did not enforce it.

For any one of these built in lists you can also add your own values to the list when you configure your skill in the interaction model.

Custom Values

Though these lists are convenient, they are not sufficient for everyones needs.  Therefore you can define your own custom slot value list that your users will choose from.  This is done in the interaction model definition but describing the technical part of that is a whole post of its own.