Setting up the hello world skills kit sample

Getting to know custom skills by implementing the hello world example.

Advertisements

Now we’ve got the DynamoDB things out of the way (for now), I want to start experimenting with my very own custom skill for Alexa.  My goal is to create my own smart mirror custom skill.  It needs to handle all sorts of stuff, but let’s start with the basics.

Before I start creating my own, I first want to understand how it all works exactly.  That’s why I will start by creating a skill from the samples delivered by Amazon.  Let’s download the samples from GitHub into a new folder.

mkdir alexa-skills-kit-samples
git clone https://github.com/amzn/alexa-skills-kit-js.git ./alexa-skills-kit-samples

The next thing we need to do is log on to the AWS console.  It’s important to choose the correct region in the top right corner.  There are only a few regions where the lambda service is available.  Since I’ve made the DynamoDB table in another region I will probably have to redo the earlier DynamoDB steps, but those are worries for later.  I’ve chosen this region :

Schermafbeelding 2017-02-02 om 20.49.57.png

Navigate to the lambda service, and click “Get Started Now”.  The lambda service lets you create your very own piece of code in the cloud.  It is executed only when it is called, so you only have to pay for the little amount of time it runs.  Furthermore, every one who registers is entitled to 1 million free runs of any lambda function per month.  So, in our case that’s actually free.

Schermafbeelding 2017-02-02 om 20.50.31.png

Next, we are prompted to choose a template.  There are several templates, some of which are intended for Alexa lambda functions.  We won’t be using a template since we’ll be uploading the sample code, so I just chose “Blank Function”.

Schermafbeelding 2017-02-02 om 20.51.52.png

Next, the service asks me which application will trigger the lambda function.  Just choose “Alexa Skills Kit” and click “Next”.

Schermafbeelding 2017-02-02 om 20.52.27.png

Next, we need to configure some stuff, like a descent name and a runtime . In our case, we will be writing the code in NodeJS, so i’ll use this one, but we can choose other runtimes as well.

Schermafbeelding 2017-02-02 om 20.53.46.png

Now, we can specify the code for the lambda function . There are several ways to do so, the simplest of which is probably just typing the code in the browser . The disadvantage here is the lack of highlighting, code completion, etc.  It’s not an IDE.  Instead I will zip the files in the “src” folder of the “helloWorld” sample, and upload it.

Schermafbeelding 2017-02-02 om 20.56.46.png

Choose “Upload a .ZIP file” as the code entry type.  Leave the handler as it is, and make sure “Create new role from template(s)” is selected.  Specify your own rule name.

Schermafbeelding 2017-02-02 om 20.58.47.png

Schermafbeelding 2017-02-02 om 21.04.23.png

Create the function.  In the next screen you should see the ARN (Amazon Resource Name), that looks about like this :

Schermafbeelding 2017-02-02 om 21.08.07.png

Just copy it to the clipboard.

Now for the second part.  We need to make a new Alexa skill to call the lambda function.  In order to do that we need to navigate to the amazon developer console & log in.  In the “Alexa” tab, we can choose to create a new skill by selected the “Alexa Skills Kit”.

Schermafbeelding 2017-02-02 om 21.11.54.png

So now, we start the configuration of the skill.  First of all I’ll choose a custom interaction model.  The Smart Home and Flash Briefing skills are a fixed type of interaction specifically intended for those purposes.  Since we’re creating something custom, we choose the first one.  We’ll choose “English” as a language.  While I’m writing you can also choose for English UK and German.  I hope that in the future, more languages will appear here, specifically dutch as that is my mother tongue.

Anyway.  I’ll give it a fitting name “HelloWorld”, and specify an invocation name.  This is the words Alexa listens for in order for the skill to be recognized.  There are a number of limitations and constraints to what you can specify here.  Carefully read the documentation.

I don’t want the audio player functionality.

Schermafbeelding 2017-02-02 om 21.14.38.png

Click Next.  Now we need to specify 2 things :

  • An intent schema
  • Sample Utterances.

The first one is a specification in JSON format telling Alexa what the skill can do, and what parameters it can expect.  The definition of what Alexa can do in that skill is an intent.  Alexa will interpret the user’s voice and based on the sample utterances, it will deduct what the intent of the user is.  It will then execute the code for that intent.  For the “Hello World” example, Amazon has provided the schema and the utterances for us.

Schermafbeelding 2017-02-02 om 21.15.49.png

Just copy past them in the appropriate boxes.

Notice you can create “slots”.  These slots are kind of parameters you can pass a long.  Such as “show a picture of George Michael”.  George Michael (or any other person or thing you want to see a picture of) will be a slot of string type.  Alexa will then recognize it, and pass it along as a parameter.  For this example we’re not going to use a slot, there aren’t any specified in the schema.

Schermafbeelding 2017-02-02 om 21.18.50.png

In the sample utterances, you can specify how Alexa will recognize a certain intent.  The utterance starts with the name of an intent and is followed with some words Alexa needs to interpret.  Now… Alexa is pretty smart.  You don’t really need to input every single permutation of words here.  For example : if you say “say hello to the world” (with the extra “the” in there), it will probably understand as well.  Alexa uses language models to create a context in which the user is interpreted, and he or she usually speaks.  Depending on that model (which it builds on the fly) it will better recognize your intent.

The last configuration step is linking the lambda function and the skill to each other.  Choose “AWS Lambda ARN” as the endpoint type, and paste in the ARN.  No account linking is necessary here.

Not that you could be specifying different ARN’s for different languages.  Isn’t that the coolest thing?

Schermafbeelding 2017-02-02 om 21.21.16.png

In the next step you can test it.  Just type what you would say to alexa, end you can see how the lambda request is built up, and what the response would be.

Schermafbeelding 2017-02-02 om 21.23.19.png

You could go and certify this thing, but I don’t thing Amazon would be too happy having all the hello world examples on the store, so I suggest you don’t.  Even “uncertified”, the skill should be available to you if you navigate to “alexa.amazon.com”, and log in with your account.

Schermafbeelding 2017-02-03 om 06.48.35.png

So, the last thing we need to do is tell the lambda function what the ID of the calling application is.  That way we ensure that the function can only be called by the Alexa skill we set up.  Doing that is easy.  Just go to the AWS console, and locate the “Hello world” lambda function, and edit the code.

Change the APP_ID to match the application ID of your Alexa skill :

Schermafbeelding 2017-02-03 om 18.42.44.png

You can find it in the definition of the skill :

Schermafbeelding 2017-02-03 om 20.28.22.png

I couldn’t help but add my own personal touch…

Schermafbeelding 2017-02-03 om 20.21.22.png

 

Go ahead and test this.

Good luck!

 

1 thought on “Setting up the hello world skills kit sample”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s