Alexa, add ‘Hack Amazon Echo’ to my TODO list!

So I gave in and got one of those black Pringles cans called Amazon Echo a couple of months ago and I got to say, it’s been an eye opening experience. I’ve played around with Siri, Google Now and lately, Cortana and Project Oxford but I never really felt an emotional connection to any of them like I have with Alexa. Not sure why. It could be that, thru Echo, she virtually sits in my kitchen all day long telling my family jokes and maintaining our shopping list. It could also be her potential to become a great virtual assistant. I’m also not sure why I refer to Alexa as “her” instead of it. Why the immediate bond? I just can’t put my finger on it but for some reason, I actually feel bad when I say “Alexa, shut up!” which is an actual alternate command to “Alexa, stop.”

It could also be that Alexa probably has the simplest SDK and API I was able to play with… what can I say, I love API’s!

I know what you’re thinking… “enough ranting and tell me just how simple!”

First step (after you read this post in it’s entirety of course), is to go to http://developer.amazon.com/alexa and read up on as much of the documentation as you can. Familiarize yourself with all the lingo like “Skills”, “Slots” and “Utterances” for example. Also download the code samples they have for node.js and Java. Try to get those running and take it from there or if you prefer C#, just fire up Visual Studio, create a Web API project and create a new Web API controller called AlexaController.cs for example, then drop in the following code…

[HttpPost, Route("api/alexa/helloworld")]
public dynamic HelloWorld(dynamic request) {
 return new {
  version = "1.0",
  response = new {
   outputSpeech = new {
    type = "PlainText",
    text = "Hello, World!"
   },
   card = new {
    type = "Simple",
    title = "My Alexa Hello World demo app.",
    content = "Hello, World!"
   },
   shouldEndSession = true
  }
 };
}

A quick rant on dynamics, if you don’t like em’, don’t use em! I’m a big fan of dynamics when it comes to creating PoC’s and prototypes. Other than that, strong type to your hearts content!

Once you drop in the code above, build, then go ahead and test your new endpoint using Unit Tests or Fiddler. If working locally (I’m assuming you are somewhat familiar with building Web API’s in C#), upload it to either Azure or another Internet accessible host as Alexa will need to be able to access your endpoint from her end.

Then if you haven’t done so already, you will need to open a free Amazon developers account at http://developer.amazon.com/login. Once logged in, click on the Apps & Services > Alexa. Then get started with the “Alexa Skills Kit”. The ASK is Amazon’s SDK for creating Alexa apps or what they call Alexa Skills. On the following screen, you will click on “Add a New Skill” button. This will take you to the first step in the adding new skill process called, “Skill Information”. There, you have the following fields…

  • Name: This is your friendly Skill (app) name. Something like “My App”.
  • Invocation Name: This is the word users will say to interact with your skill. For example, “Alexa, ask myapp to do something.”
  • Version: Just add 0.1 or 1.0 for now, can worry about versioning once you get serious about deploying an Alexa Skill publicly, for now, we’re just having some fun.
  • Endpoint: This is where you drop in the URL to the new endpoint you’ve created in Azure or other Internet accessible host. Here’s the kicker, HTTPS is required! Cool thing about Azure is, they provide SSL on all their URL’s but if you are on another host, keep that in mind. You can also use AWS Lambda for free, only problem there is, no C# 🙁

Click “Next” once you are done with that initial step of the Add New Skill form. On the following screen titled, “Interaction Model”, you will see the following 3 areas…

  • Intent Schema: This is a JSON structure object that contains your intent schema. Since we are just doing a basic Hello World for now, you can simply paste in the following JSON object…

{“intents”: [{“intent”: “HelloWorldIntent”}]}

  • Add Custom Slot Types: This is a recently added feature, can skip for now, but once you get this hello world demo up and running, I recommend reading more about Slots at Defining The Voice Interface.
  • Sample Utterances: This is basically a list of phrases that map to each of your Intents, since we only have one intent for now, you can simply paste in the following…

HelloWorldIntent say hello world
HelloWorldIntent say hi to everyone in the world
HelloWorldIntent say hi to the world
HelloWorldIntent tell the world hello

Once you are done here, click next and you will end up at “SSL Certificate”, where you have 3 SSL options to select from. If you are testing on Azure, go ahead and select “My development environment is a subdomain…”, if not, select the appropriate option for your service.

NOTE: If you opted for AWS Lambda as your host, then the SSL Certificate step does not appear.

The following steps called “Test” and “Publishing Information” can be skipped for now. Note that in the test step, you can test the connection to your endpoint using the Service Simulator which is extremely helpful in debugging your Skill down the road. The publishing step is self explanatory, if we’re going to go “live” with our Skill and submit for certification to have it published in the Alexa Skills store, then fill out the publishing form. None of this is required however to test it on your actual Echo at home.

At this point your skill is up and running. An important thing to remember, something that actually had me stumped for a few minutes, was that I have 2 accounts linked to Alexa, mine as well as my wife’s account and when I kept asking “Alexa, ask HelloWorld to say hello”, I kept getting an error. But when I said, “Alexa, switch accounts”, I verbalized one of my sample utterances again and it worked just fine. Another thing to remember is whatever account you use for Alexa, it should be the same as your developer account. If you already have 2 separate accounts, one for your developer account and another one for your Alexa account, you can easily add your developer account in the Alexa mobile companion app. Otherwise, just use your Amazon account on both Alexa and the developer account to make life a bit easier.

Well like I mentioned earlier, your skill is up and running so go ahead and ask Alexa to ask your app to say hello world and cross your fingers! It should work, “it works on my machine!” (I wonder how many people will get that QA reference!) If it doesn’t, make sure you are in the correct account and the endpoint works in the Service Simulator. Also, make sure your unit tests all pass and that it’s all working in Fiddler as well. If you have passed all these tests, you should be good to go. If you are still running into any problems after all that, reach out.

Next steps?

Keep building off this basic hello world example in C#. Add session management, add Slots and Custom Slots and multiple Intents then just keep going from there. Once you have mastered the SDK, API and everything it has to offer, start thinking about the user experience and creating a killer Skill for Alexa. Then, AVS… post on that coming soon!

And most importantly… have fun!

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on Reddit