My first Alexa Skill with Node & Typescript.


dronesafe

So I bought an Amazon Echo just before Christmas and I really found it useful for a lot of things like playing music, asking about the weather and general internet lookups for information. Straight away I hooked it up to my Nest thermostat which meant I could control my heating from around the house with voice commands. My next move was to buy a Hive hub and connect up some plugs and wireless bulbs which allowed me to control lamps and lights throughout the house. I extended the usefulness by adding another two Amazon Dots and placed them strategically around the house. I really liked the ability to control things with voice commands and I found Alexa to be on the whole really easy to use.

Being a developer I had to take a peek at the SDK that allows you to build custom skills and publish them to the Skills marketplace. I decided I would jump in and give building a skill a try as a hobby project. I needed an idea for a skill first and as it happens I also run a company called Aerial Focus Technology which does aerial photography with drones. One of the things you must do before flying a drone is to check the weather at the location you are supposed to be flying, making sure that it’s safe to put a drone up in the air. A quick check on the marketplace showed me that there wasn’t already a skill out there to do this so I thought it was a good enough idea to develop a skill and jumped into the SDK to work out what I needed to do.

Web Service

I ended up opting for using Node.js with Express and Typescript for the back end web service. I could have gone with a .NET WebAPI project but I like to expand my skills and use technologies that I won’t necessarily use in my day job (saying that I’m using TypeScript pretty much on every project I do now).

It was really easy to get a web service up and running pretty quickly and I only needed one endpoint that Alexa can call to get the response that will be spoken back to the user.

Documentation

Visit the custom skills documentation and make sure you understand what is expected of your skill in regards to parsing the correct JSON being sent in the request from Alexa and returning the response JSON.

The understanding custom skills page should be your starting point. And you will want to refer to the JSON interface which outlines the correct request and response schemas.

Passing certification.

Before submitting your skill for certification you should make sure you test it against the submission checklist to make sure your skills covers all aspects of the requirements.

There are a number of things to note.

  • Your skill must validate the incoming URL and certificate to check the call is coming from Amazon. I used the very helpful project alexa-verifier-middleware NPM package which you can tell your Node Express router to use and will handle all the validation for you. It builds on top of the alexa-verifier project on GitHub.Heres the code to plug in the verifier.
    
    
  • 
    import verifier = require("alexa-verifier-middleware");
    
    let router: express.Router;
    router = express.Router();
    router.use(verifier);
    
    //use json form parser middlware
    router.use(bodyParser.json());
    
    
  • You must check the Application id passed in the request is the same application id assigned to your skill. You must also check that a valid intent name has been used.
    
    public IsValidRequest(): Boolean {
      if (this.AppId === this.validApplicationId) {
        if (this.IntentName === "" ||
            this.validIntentNames.indexOf(this.IntentName) !== -1) {
            return true;
        }
      }
      returnfalse;
    }
    
    

Hosting

Amazon push you towards hosting your skill on the AWS Lambda platform but I opted to host on the Microsoft Azure App Service platform and use their Web Apps for Linux service to pull down a Docker image from DockerHub. You can read about how I did this in my previous post.

Code

The code is all open source and hosted on GitHub here.

Download the skill

If you fly drones or any model aircraft and want to use the skill with Alexa the link to the skill is here or just type Drone Safe into the search box on your device.

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