Making a simple Alexa Skill

Had a free day today so tried my hand at making an Alexa Skill. It’s a little tricky to get your head around how it works but is actually pretty simple. This is a bare bones tutorial on getting a true/false dialog going – I am by no means an Alexa dev.

I’m going to assume you have already had a look in the developer console.

Set up a basic skill

Choose the hello world template and Node.js AWS provision

Update the invocation name

Choose a name for your skill, then click the “Build Model” button. You have to build for the name change to take effect.

Add an intent

On the left you can see the header “Intent”. Click the add button to make your own intent. Call it “MyIntent”. For the utterance I just chose “Testing intent”.

You’ll need to “Build Model” again so the change is picked up.

Click the code tab

Here you can see the Hello World code. You can modify this so you can have a simple conversation with Alexa.

To add a bool variable:

  • Somewhere outside of a function add a variable like “let saidHello = false”

To add your intent:

  • Make a function to handle your intent e.g.
const MyIntentHandler = {
   canHandle(handlerInput) {
      return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
      && Alexa.getIntentName(handlerInput.requestEnvelope) === 'MyIntent';
   },
   handle(handlerInput) {
      let speakOutput;
      if(saidHello){
         speakOutput = 'Recieving you loud and clear';
      }
      else{
         speakOutput = 'How rude';
       }
   return handlerInput.responseBuilder
      .speak(speakOutput)
      .reprompt(speakOutput)
      .getResponse();
   }
};
  • To get the function to run
    • Add the function name to exports.handler at the bottom of the index file
    • The order of functions here matters, so put yours nearer to the top if you want it executed first
  • To add a condition where saidHello changes to true
    • Simply change the variable in the HelloWorldIntentHandler function
handle(handlerInput) {
   saidHello = true;
   const speakOutput = 'Hello World!';
   return handlerInput.responseBuilder
      .speak(speakOutput)
      .reprompt(speakOutput)//('add a reprompt if you want to keep the session open for the user to respond')
      .getResponse();
}

Make sure your reprompts are not commented out so that users can keep asking stuff, and get the true condition to appear. Just make the text in the brackets for reprompt be the same as the speak parameter and you should be golden.

Test your code

Click deploy, then click test and type in the invocation name into the text box on the left.

I’d post my source code but its in a bit of a state. Anyway this might help you get started on Alexa skill dev.

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 )

Connecting to %s