Chris Mendez in alexa, Radio, Javascript, AWS, NodeJS

AWS: How to create your first Alexa skill

Step 1 - Register with Amazon Developer

Register with Amazon Developer to start creating Alexa skills.

aws-develpoer-console


Step 2 - Register with Amazon Web Services

Register with Amazon Web Services to support the skills you want to create. In our case we will be using AWS Lambda to handle all the functionality we want to provide our skills.

aws-create-account


Step 3 - Create a new Skill

What is a skill?

Skills are built-in capabilities for Alexa to give listeners new experiences.

Where do do I create Skills?

We create skills through the Amazon Alexa Developer Console

How do I get started?

Once you log into the the Amazon Alexa Developer Console, select Create Skill to get started.

alexa-create-a-skill

What do I name my Skill?

You can name your skill whatever you want. Skills require two things to successfully work: an invocation name and an utterance. We will discuss these two functions next.

alexa-name-skill


Step 4 - Create an Invocation

After you create your skill, you will be redirected to the main dashboard.

alexa-checklist

It looks really intimidating but don't worry, just click here first.

alexa-step-invocation

Add an invocation

An invocation name identifies what the user wants to do. Invocations are commands such as, "Alexa, ask ninety point five".

I will name my invocation, "ninety one point five".

Next select Save Model.

alexa-invocation-name


Step 5 - Create an Intent + Utterances

Intents

Intents are what a user specifically wants to do. Using the previous invocation, I'm going to help users ask, "Alexa, ask ninety one point five what's playing ?"

The intent is to find out information about what music is playing on 91.5.

alexa-click-add-intent

Utterances

Not everyone is going to ask a radio station "what's playing" in the exact same way so we use utterances to consider other ways to ask for the same data. Utterances are derivatives of your original request but said differently. For example, here are two similar requests for information and what's implied by the user that is they want to know what's playing right now.

  • "Alexa, ask ninety one point five composer".
  • "Alexa, ask ninety one point five the composer's name".

Utterances are useful because they will help you improve the accuracy of Alexa and they can also help you reach new audiences from different age ranges. For example, maybe you want to reach a younger audience and they may be more inclined to ask,

  • "Alexa, ask ninety one point five name".
  • "Alexa, ask ninety one point five title".
  • "Alexa, ask ninety one point five 'da name".

Below are a list of my utterances.

alexa-intents


Step 6 - Create a Slot

A slot is a variable set by the user. It's a condition that will help narrow what the user wants.

Using our previous example, "Alexa, ask ninety one point five what's playing right now". The slot in our case is "right now".

Another example could be "Alexa, ask ninety one point five what was playing yesterday at 2pm." In this example, the user changed two variables, the date and the time.

In my example, the slots I'm adding are variables used to help the user query data by date and time.

alexa-slots


Step 7 - Create an Intent Schema

An intent schema is how you prepare "intents" and "slots" in a JSON format. If you've been following along with the Alexa step-by-step builder, then it will make a schema for you.

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "ninety one point five",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.ChooseAction<object@ScreeningEvent[location]>",
                    "samples": []
                },
                {
                    "name": "WhatsPlaying",
                    "slots": [
                        {
                            "name": "Now",
                            "type": "AMAZON.TIME"
                        },
                        {
                            "name": "Yesterday",
                            "type": "AMAZON.DATE"
                        },
                        {
                            "name": "On",
                            "type": "AMAZON.DATE"
                        },
                        {
                            "name": "At",
                            "type": "AMAZON.TIME"
                        }
                    ],
                    "samples": [
                        "what's the name of this composer",
                        "whats the title of this piece",
                        "what's the name of this piece",
                        "whats the name of this song",
                        "who is playing ",
                        "what's playing"
                    ]
                }
            ],
            "types": []
        }
    }
}

Step 8 - Get Your Alexa Skill ID

You will need your Skill ID for the next steps. You can find it by first selecting on the menu.

alexa-return-to-skills

Select "View Skill ID" to access your Skill ID string.
alexa-get-skill-id


Step 9 - Create your skill response

Once you've configured Alexa to consider your solution to solve a user's request, you'll need to create the actual solution. We are going to use Node on AWS Lambda so that we do not have to meddle with any servers.

Visit AWS Lambda

alexa-aws-lambda

Create a new function.

alexa-aws-create-function

Author a function from scratch.

alexa-aws-author-from-scratch

If you notice, I have a role called role-lambda-basic-execution. This role was created within AWS IAM and looks like this.

alexa-iam-basic-lambda

Connect Alexa to Lambda

After you've completed the inital lambda from, you'll get the chance to connect the Alexa skill to your lambda function.

alexa-lambda-hooks-1

Take note that you will need to paste your skill id that you received from step 6.

alexa-lambda-configure-portal


Step 10 - Build your skill

Here is the Javascript code we'll use to respond to our users request.

const Alexa = require('alexa-sdk');

// Register the handlers
const handlers = {
    // A. This is the first thing that happens when the Alexa is invoked. 
    //    Think of it like a constructor function.
    'LaunchRequest': function() { 
        this.emit('LaunchIntent');
    },
    // B. This will be Alexa's first response.
    'LaunchIntent': function() {
        this.emit(':ask', "How are you today?");
    },
    // C. This will be called throught the intent schema and utterances.
    'HelloIntent': function() {
        this.emit(':tell', "I'm great. You have successfully created your first skill with Amazon Alexa.");
    }
};

exports.handler = (event, context, callback) => {
    var alexa = Alexa.handler(event, context);
        alexa.registerHandlers(handlers);
        alexa.execute();
};

Step 11 - Simulator testing

Now that we've created a skill, created an invocation with utterances and a Javascript solution, it's time to test our app.


Step 12 - Hardware testing