Alexa Skill - Part 1

Reading time ~3 minutes

This is the first of a series posts in which I will be building an Alexa Skill. I haven’t pre-written this series, so I don’t know where it’s going to end up, or even the exact steps that will occur along the way. What it will be is something closer to how development would occur in the real world as opposed to a sanitized tutorial.

The skill I’ll be building is one for my church. It will let users ask for the time of the next service or event. You can also ask it for the church address and phone number. And we’ll see what other interesting things we can add. If you dislike church’s for some reason, feel free to substitute your favorite civic organization :wink:.

Getting Started

Here are the prerequisites for the tutorial:

  1. An AWS developer account.
  2. You know or can follow along when explaining code in JavaScript.
  3. You have Node.js installed. Let’s go!
  4. If you would like a tutorial for configuring the environment from scratch, let me know. I’ve found this information easily enough with Google that I didn’t think I needed it here. When I write a complete book, I should probably include it (right?).

Install the Alexa Skill Kit Command Line Interface (ask-cli)

npm install -g ask-cli

Initialize the ask-cli

ask init

Create a new skill with the ask-cli

ask new -n sotv

skill.json

At the top level of the project, a file called skill.json is created. This file contains the skill manifest (Skill Manifest API) and is the JSON representation of the skill.

{
  "manifest": {
    "publishingInformation": {
      ...
    },
    "apis": {
      ...
    },
    "manifestVersion": "1.0"
  }
}

The publishingInformation object describes how the skill is presented to end users in the skill store or Alexa app. The supported locales, description, category (list of categories), and other information is contained as shown below.

...
"publishingInformation": {
      "locales": {
        "en-US": {
          "summary": "Sample Short Description",
          "examplePhrases": [
            "Alexa open hello world",
            "Alexa tell hello world hello",
            "Alexa ask hello world say hello"
          ],
          "name": "base",
          "description": "Sample Full Description"
        }
      },
      "isAvailableWorldwide": true,
      "testingInstructions": "Sample Testing Instructions.",
      "category": "EDUCATION_AND_REFERENCE",
      "distributionCountries": []
    },
.//

The apis object describes the HTTP endpoint that processes the intents that the skill supports. The apis object shown below configures the endpoint to be an AWS Lambda function that is defined in the lambda/custom directory of this project.

...
    "apis": {
      "custom": {
        "endpoint": {
          "sourceDir": "lambda/custom"
        }
      }
    },
...

The manifest can also contain (privacyAndCompliance)[https://developer.amazon.com/docs/smapi/skill-manifest.html#privacyandcompliance], (permissions)[https://developer.amazon.com/docs/smapi/skill-manifest.html#permissions], and (events)[https://developer.amazon.com/docs/smapi/skill-manifest.html#events] which you can read about, but aren’t used yet in this project (if we do end up needing any of them I’ll describe them at that time).

models/en-US.json

The models/en-US.json file contains the Interaction Model ((Interaction Model Schema)[https://developer.amazon.com/docs/smapi/interaction-model-schema.html]) of the skill. The languageModel defines the interactions that Skill supports. The invocationName is the set of words that activates your skill. My Skill is for my church, Shepherd of the Valley, so I went with s.o.t.v. which will open my skill when you say something like, “Alexa, open S-O-T-V.”

Under the intents section are the intents your skill will respond to. I didn’t list all the built in ones, but they are AMAZON.CancelIntent, AMAZON.HelpIntent, and AMAZON.StopIntent. The first non-built-in intent my skill will support is the HelloIntent. The samples is an array of phrases also called utterances. These utterances are what will activate the intent for that skill. For example, “Alexa, tell S-O-T-V to say hello.”

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "s.o.t.v.",
      "types": [],
      "intents": [
        {
          "name": "AMAZON.CancelIntent",
          "samples": []
        },
        ...
        {
          "name": "HelloIntent",
          "samples": [
            "hello",
            "say hello"
          ]
        }
      ]
    }
  }
}

That describes the definition of the skill. In the next post, I’ll walk through the supporting code.

A Tutorial Break - Software Careers

I'm taking a break from the Alexa tutorial this week. I wanted to talk a little bit about software development careers. As I mature, I fi...… Continue reading

Alexa Skill - Part 2

Published on August 27, 2018

Learning Alexa Skill Development

Published on August 09, 2018