Alexa Slots, Part 2

Adding Custom Slot Types to Your Amazon Alexa Skill

May 24, 2020

This is a follow-up post to Alexa Slots, Part 1 where I went over how to add existing slot types to your skill. Today I'll be focusing on adding custom slot types.

If you followed the previous post, you may remember that I set up a slot using one of the existing types that asked a user how many facts they would like to hear. The plan today, is to have Alexa ask a follow-up question that requires the integration of a custom slot.

Testing your skill.

Theoretically, I could, assuming I had incorporated actual facts to respond with into my skill, go ahead and publish this skill now. I'd have a bit of work to do to make sure Alexa handled ending the skill appropriately, but then my skill would be complete and ready for use. But let's say I went to release a second version that gives my users more choice and the opportunity to interact more with my skill. This is where I would need to think about how I could expand upon the current functionality in a way that would make it more beneficial to my users.

One idea that comes to mind is that I may want to create categories of facts and then ask the users what type of fact they would like to hear and prompt them with the options available to them. For instance, after the user has told Alexa how many facts they want to hear, Alexa would reply with something like, 'Great, you would like to hear 3 facts. And what type of facts would you like to hear today? You can choose from space, history, music, or the human body'.

Now that I know how I want to extend my skill, let's go ahead and create our custom slot. In the Alexa developer console, we'll start by creating a new content type. We'll call this TypeOfFactsIntent.

Before adding any sample utterances, we'll want to create our custom slot type as we'll want to include this in each of the utterances we add. I'm going to call this slot type typeOfFact.

Slot type.

From here, I'll need to click on + button near 'Slot Types (1)' in the left-hand panel, type the name of my custom slot, typeOfFact, into the input box under 'Create custom slot type', and then hit the 'Create custom slot type' button.

Adding a slot type.

The next screen is where I'll need to add the options I want my users to be able to choose from: history, music, the human body, and space.

Slot types.

The last thing to do before adding our utterances is to go back to our new intent and map the slot we previously added to the custom slot we just created.

Custom slot type.

Once you've added some utterances, go ahead and save and build your model. That's it as on the Alexa developer console side of things. Now you'll need to update your code with your new intent, grab the custom slot value, have Alexa respond to the user, and deploy your lambda function. If you haven't read any of my previous Alexa skill posts and are unsure of how to do this, I recommend checking them out to help fill in any blanks you may have:

Testing in the dev console.

In the above screenshot you can see, after making code changes and deploying my function, Alexa now asks the user how many facts they would like to hear, followed by asking for the type. Setting up custom types is really that simple!

Share this post: