Develop your first Alexa skill

Mukul Jain
5 min readNov 9, 2017

--

Alexa skill, voice user-interface, the new big thing in the world. A few years back, something like Alexa or echo must look like some futurist techs. But here we are ordering and asking, almost anything.

If you’re thinking, ok, we know how amazing Alexa is and you don’t need to tell us that. Well, it’s your lucky day, as I’m gonna tell you something even better. That is, building an Alexa skill is even easier than ordering an echo from Amazon (maybe I exaggerated :) )

Before you start, there is a great tutorial already published by AWS on developing Alexa skill. Though, it only tells you the instructions to create a skill, which is why I planned to write a blog on it. In this, I will try to focus on some of the best practices and approaches when developing Alexa skill.

Pre-requisites

First of all, you need a couple of things:

  • Echo or echo dot
  • Amazon developer account
  • AWS account

When creating an account on AWS and Amazon developers portal, make sure that you use the same email address. If you don’t then you won’t be able to test it on your echo device which is registered on developers portal.

Assuming, you’re all set up, let’s try to understand how Alexa skills work.

Using Alexa develop portal

From this image, you can understand the flow. It’s very simple. Let me put it down in steps, let’s say you want to make Alexa skill, how you will start

  • Go to Amazon developers portal, and specify wake keyword and name of Alexa skill
  • Now it’s time for may be the most crucial step, which might decide if your skill gets certified (read, published on Alexa skill store) or not.
  • Here, you have to create a schema for your skill, which tells Alexa kit, what kind of intents your Alexa skill can expect. More on this later.
  • Let’s say you have created the schema, it’s time to add utterances and slots (if any). Utterances are like practice for your skill, which tells what kind of requests it can expect. You can specify 50,000 utterances for one skill. So, “the more the better”.
  • Next, you have to specify the lambda function which will receive the intent and send the response back to Alexa, which Alexa will speak to the user.

That’s it. The skill is ready, which you can test from “test” section, or from your echo device.

Let’s go in detail of some of the above steps.

Understanding Intent Schema

Understand intent as a constant which Alexa will generate, for every request made by the user to Alexa skill.

Let’s understand this by an example. We have an Alexa skill, PizzaSkill, for ordering pizzas. A user can order it form Alexa by saying “Hey PizzaSkill, order 1 pizza”.

So, this skill or any Alexa skill for that matter must have 3 default intents.

{
"intents": [
{
"intent": "AMAZON.CancelIntent",
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.HelpIntent"
}
]
}

So, if a user says either “Stop”, “Thank you”, Alexa will generate AMAZON.StopIntent.
You don’t need to create utterances for Amazon built-in intents.
Check here, for the built-in intents Amazon provides.

But what about the intent, which will generate when the user orders the pizza. Let’s add that one in above schema.

{
"intents": [
{
"intent": "OrderPizza",
"slots": [
{
"name": "Quantity",
"type": "AMAZON.NUMBER"
}
]
},
....
]
}

If you notice, the type of slot is AMAZON.NUMBER, which is built-in slot type. So, if the user says “Hey PizzaSkill, order 10 pizza”, then slot value of Quantity will be 10.
Check here, for the built-in slots Amazon provides.

Now we will train our skill to generate this intent when the user orders a pizza, by adding these utterances.

OrderPizza Hey PizzaSkill, order ${Quantity} pizza
OrderPizza Order ${Quantity} pizza
OrderPizza Please order ${Quantity} pizza

We’re done with schema part. If you test Alexa skill in test section in Alexa developer portal and write some user input, you’ll see it will generate the request object.

Handling Intents in Lambda functions

What is lambda function? How does it work? How to develop it? These questions are not in the scope of this blog. For developing lambda functions in nodejs, read one of my earlier blogs.

Lambda will receive the request object, generated by Alexa, and then you can send a response back based on the Intent.

Here’s a how request object can look like:

{
"session": {
"new": true,
"sessionId": "",
"application": {
"applicationId": ""
},
"attributes": {},
"user": {}
},
"request": {
"type": "IntentRequest",
"requestId": "",
"intent": {
"name": "AMAZON.HelpIntent",
"slots": {}
},
"locale": "en-US",
"timestamp": "2017-10-25T10:47:52Z"
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {}
},
"version": "1.0"
}

Do let me know in comments if you want to go in depth of Lambda functions when developing Alexa skills.

Getting your Alexa skill certified

Before publishing your skill, you have to submit it for review. It usually takes 5–7 days to get it reviewed and once passed, your skill gets published on Alexa store.

There are some pitfalls, because of which your skill might get rejected.

  • Absence of Stop, Cancel and Help built-in intents
  • Session never ends, even if user stops the skill
  • User’s request is misunderstood from Alexa’s end, i.e, lack of sample utterances

Once you get the hang of it, developing Alexa skills is way too easy. Hoping you all have amazing time developing these.

I hope you found this post useful and please do let me know in case of any question or query. If you like this post, you can clap for it or follow me on Medium for my latest posts or on Twitter.

--

--