Thursday, February 4, 2016

first look at the sdk for amazon alexa

Yesterday was all about the existing capabilities of the Amazon Alexa and I ended with an enthusiastic task of reviewing the sdk (software development kit).

It wasn't half bad - and by the end of the day I had delivered the code to my Alexa and had her asking us all what our favorite color was.

Here's how I accomplished that ...

Here's the getting started guide. I started poking around the information.

First, I signed up to watch the on-demand webinar on the ASK (Alexa Skills Kit). It was about an hour long and well worth it. Each capability is called a skill - and you are really just giving Alexa a new skill.

The information is transmitted via REST so either you have you own secured web service (which I do not) then it's best to use Amazon web service. I was able to sign up and get a whole year of free usage. AWS Lambda made it easy to get up and running even providing some templates (or blueprints) giving you sample code with work with.

It's really just javascript functions that parses json data. You have help methods such as onSessionStarted, onSessionEnded, onIntent and onLaunch.

Next you need an account on the developer portal for Amazon. You can set this up here. This is where you'll define the skill and point it to the REST api (where it sits in the cloud). This is also where the utterances and intents (schemas and possible key phrases) are stored.

So in the sample of favorite color - the color schema is defined with an Intent:
 "intent": "MyColorIsIntent"
"slots": [
          "name": "Color",
          "type": "LIST_OF_COLORS"

The slot would be defined LIST_OF_COLORS: green, red, blue, orange, gold, silver, yellow, black, white. So, the array of colors is a slot.

And Utterances would be anything the user could say ...

WhatsMyColorIntent what's my favorite color
WhatsMyColorIntent what is my favorite color
WhatsMyColorIntent what's my color
WhatsMyColorIntent what is my color
WhatsMyColorIntent my color
WhatsMyColorIntent my favorite color
WhatsMyColorIntent get my color
WhatsMyColorIntent get my favorite color
WhatsMyColorIntent give me my favorite color
WhatsMyColorIntent give me my color
WhatsMyColorIntent what my color is
WhatsMyColorIntent what my favorite color is

Things I struggled with ...

I was only interested in getting my sample code to test properly. Right now I'm only interested in publishing to my Alexa - and not to the entire Alexa world. That was one thing not immediately apparent to me - how to "test" on my own device. 

Turns out as long as you have the same login on the developer console in Amazon as what you configured your Alexa works - it's magical when you "test". It's one of the steps identified in the Alexa app console (skill information, interaction model, and test).

I also struggled in AWS Lambda was picking the right test event. Initially I just picked the default - of course would fail. So pick the correct Sample Event Template.

Also, make sure you pick US East (N. Virigina) has your region to even see the Lambda functions.

This article was really helpful too.

My next move ...

Here's what I want to do now. Take my "Mom I'm home" idea and expand it. Currently it's using IFTTT to send me a text when Holly triggers her.

I would like Holly to be able to walk in the door and say "Alexa? Tell Mom I'm home. Alexa would respond with "Will do Holly. How was your day?" Holly would say "Good" or "Bad". Alexa would text me with "Holly is home and had a good (or bad) day.

Never something I would put into the App Services - only used by us. So now I'm looking at integrating with Amazons SNS service which will allow the text messaging.