How to Build a Custom Alexa Skill?

21 Mar, 2018 | 4 minutes read

Alexa is an intelligent assistant, developed by Amazon offering the user the ability to read news, information, listen to music and interact with the same by using only the voice. Besides these things, you can also build custom Alexa skill, such as Alexa can answer custom questions. And how can that be done? This blog post demonstrates the implementation of the solution that enables Alexa to answer custom questions. The purpose of the same is a short demonstration of a set of options that Alexa provides for developers. For the purpose of this blog, we are using API that returns Air Quality values.

In order to start, create Alexa developer account on the following link: https://developer.amazon.com. If you already have an AWS account, you can use same root credentials.

Go to the developer console and from the menu choose Alexa. Click Get started with Alexa Skill Kit. Let’s add one new skill:

Get started with Alexa Skills Kit
(Figure 1 – Get started with custom Alexa Skills Kit)
  • Skill type: Custom Interaction Model
  • Language: English
  • Name: This is the name of the Alexa app. Make it more descriptive. For our demonstration we have added techup-meeting.
  • Invocation Name: Be careful here. This is the name that you will use in your invocation sentences addressed to Alexa.
Start building the Skill
(Figure 2 – Start building the Skill)

For example, if we add Invocation name ‘Interworks’, we can construct invoke custom skills with the following sentences:

  • Alexa, ask Interworks to ….
  • Alexa, talk to Interworks ….

You can find more about sentence construction on the following link: https://developer.amazon.com/docs/custom-skills/understanding-how-users-invoke-custom-skills.html

Here we add interworks.

  • Leave Global fields with their default values and then Save the custom skill

After you create the Skill, the next thing that you should do is add Intents that represent the actions of the skill – what the skill can do.

Go to the next screen where you can start Skill Builder for building Interaction model. The Amazon developer platform will navigate you to screen where you can create Intents.

Add Intents to the Skill
(Figure 3 – Add Intents to the Skill)

By default, there are 3 build-in intents: CancelIntent, StopIntent and HelpIntent. Let’s add new one:

  • Add the name of the intent. This is a string without empty spaces. Ex: AirStatus.
  • Create the intent
  • Next, add Utterances. Utterances specify the words and phrases that users can say to invoke the intent. Mapping utterances to the intent forms the interaction model for the skill.
  • Insert several Utterances and save them. Here is an example:
    • about air quality
    • what is the air quality right now
    • what is the air quality
    • about the air quality right now

At first these utterances may look incomplete, but when you combine them with Invocation name they form normal sentences:

  • Alexa, ask Interworks about air quality
  • Alexa, ask Interworks what is the air quality right now
  • Alexa, ask Interworks what is the air quality
  • Alexa, ask Interworks about the air quality right now

Good for now.

  • Now, you have created Interaction model for the Skill that is ready for building. Click Build model.

The last step is to add configuration details to the Skill. This Skill will invoke Lambda function that will process the response and return back as Alexa response.

From Interaction model, navigate to Skill Information and choose Configuration. In the screen below for Endpoint choose AWS Lambda ARN. We’ve already created one Lambda for a particular Skill for the purpose of this blog.

Add Endpoint to the Skill
(Figure 4 – Add Endpoint to the Skill)

Field should be populated with info like this:

arn:aws:lambda:us-east-1:xxxxxxxxxx:function:techup-air

One Skill can be related just to one Lambda function. Leave the sections for Account Linking and Permissions by default.

We will talk in details about Lambda function later, but now let’s test the solution. Go to test simulator and type your question:

Q: ask interworks about air quality.

A: Current air quality, in particular presence of PM 10 particles is 20. The air is clear and you can breathe freely.

Test the Skill
(Figure 5 – Test the Skill)

Lambda function

Let’s dig in into Lambda function itself. The requirement for the Lambda function is to use API endpoint that returns info about air pollution. Taking that info, Lambda function will process the data and return an answer for Alexa, as follows:

———————————————————————————–

Current air quality, in particular presence of PM 10 particles is {VALUE}.

CASE WHEN {VALUE} < 25

The air is clear and you can breathe freely.

CASE WHEN {VALUE} > 25 and {VALUE} < 50

The air is partially clear so my advice is not to stay outside for too long.

CASE WHEN {VALUE} > 50 and {VALUE} < 100

Air pollution is high so if you plan to go out take your gas mask with you.

CASE WHEN {VALUE} > 100

Put your gas mask on. It’s a gas chamber outside.

————————————————————————————

The complete Node js code is available on GitHub: https://github.com/packova/techUp.git

Conclusion

Alexa provides capabilities, or skills, that enable customers to create a more personalized experience of brain behind millions of devices including Amazon Echo.

This is how you can create a simple but complete custom Alexa skill that can run on Amazon Echo or any device with Alexa. Enjoy.