Introduction: How to Create an Alexa Skill

What's an alexa skill?

Alexa skills are like apps. You can enable and disable skills, using the Alexa app or a web browser, in the same way that you install and uninstall apps on your smart phone or tablet. Skills are voice-driven Alexa capabilities. You can add Alexa skills to your Echo to bring products and services to life. You can view available skills and enable or disable them using your Alexa app.

This tutorial shows you how create an alexa skill.

Goal:

The goal is, to create a skill, that tells the user a funny german word everytime, the user asks.

Demo:

To see, how the skill should work afterwards, you can test it here:

https://www.amazon.com/gp/product/B07ZH9GL9N?ref&r...

Supplies

  • Knowledge in programming
  • Basics in Node.js and Javascript

Step 1: Create an Amazon Developer Account

Provided you don't have an Amazon Developer Account you can sign up here. Otherwise you can sign in here.

Step 2: Create a New Skill

  1. Follow this link: https://developer.amazon.com/alexa/console/ask
  2. Click on Create Skill on the right side. A new page opens afterwards.
  3. Enter the name of your skill (in our case: Funny German Words) in the Skill name field.
  4. Set the language in the Default language Select-Box to English (US)
  5. We are going to create a custom skill, so we choose the Custom model
  6. At Choose a method to host your skill's backend resources we choose Alexa-Hosted (Node.js)
  7. After you are finished click on Create skill
  8. A new window opens

Step 3: Greet the User

The first thing a user does with your skill it opening it. The intent, which opens the skill is already implemented in the sample code and does not need to be added anymore.

  1. Open the Code tab → The code window with the index.js file opens

    Every intent handler has two functions

    • canHandle()
    • handle()

    The canHandle() function includes the request, the handler responds to.

    The handle() function sends a response to the user.

    If a skill receives a request, the canHandle() function of every intent handler is called and checks, if it can send a response to that request.

  2. In the handle() function of the LaunchRequestHandler delete the whole code and paste the following afterwards:
    const speakOutput = 'Welcome to Funny German Words. Find out what funny words the german language has to offer and what they mean. Do you want to hear a funny word?';
    const repromptText = 'Do you want to hear a funny german word?';
    return handlerInput.responseBuilder
        .speak(speakOutput)
        .reprompt(repromptText)
        .getResponse();
    
  3. Click on Save and Deploy.

The help intent handler needs to be changed to match with the skill. Delete the code of the handle() function and insert this:

const speakOutput = 'Find out what funny words the german language has to offer and what they mean. Do you want to hear a funny word?';
const repromptText = 'Do you want to hear a funny german word?';
return handlerInput.responseBuilder
    .speak(speakOutput)
    .reprompt(repromptText)
    .getResponse();

After finishing that click Save and Deploy.

Step 4: Test the Greeting

Everytime you have more functionallity to your skill, test if it really works, to find out in case of an error, where the error could be.

  1. Click on the Test tab → A new window opens.
  2. Activate the testing environment, by selecting Development in the select box.
  3. Write or speak: "oppen funny german words" → The skill should now answer with the greeting.

Step 5: Add Intents

Now we are going to add opportunities how a user can interact with your skill. Intents make it possible to react correctly after special phrases and trigger the corret handler afterwards.

  1. Click on the Build tab → The Build window opens.
  2. The navigation bar on the right shows all the activated intents. First of all, delete the HelloWorldIntent.
  3. Afterwards click on the Add Button next to the intents tab in the navigation bar.

First of all, we add some built in intents from Alexa's built-in library

  1. Click on Use an existing intent from Alexa's built-in library
  2. Search for YesIntent and NoIntent and click add by both.

Now we add our own custom intent.

  1. Click on Create custom intent
  2. Give the name TellAFunnyWordIntent to the intent
  3. Click on Create custom intent

Now we will add some sample phrases to our intent. Sample phrases are phrases the user could maybe say. Just enter those sample phrases:

  • tell me a word
  • tell me a funny german word
  • a word
  • a funny word
  • to tell me a word

Of course there are a lot more phrases the user could say. You can extend the intent if you want, but we are focusing on the functionallity currently.

After adding the phrases, click on Save Model and afterwards on Build Model. After the build has finished, navigate back to the Code tab.

Step 6: Add Funny Words

To make our skill tell funny words, it needs some funny words first.

For that, create a new file called words.json in the lambda folder.

Insert those words to the words.json file:

[
  {
    "word": "Lebensabschnittpartner",
    "explanation": "This word is most described as another option for partner or lover, but with a more transient twist."
  },
  {
    "word": "Unabhängigkeitserklärungen",
    "explanation": "This word describes the declaration of independece."
  },
  {
    "word": "Freundschaftsbezeugung",
    "explanation": "It is the demonstration of friendship."
  },
  {
    "word": "Rechtsschutzversicherungsgesellschaften",
    "explanation": "The Guinness Book of World Records recognizes this cumbersome word as the longest German word in everyday use. It means insurance companies providing legal protection."
  },
  {
    "word": "Kaftfahrzeug-Haftpflichtversicherung",
    "explanation": "It refers to a motor vehicle liability insurance."
  },
  {
    "word": "Donaudampfschiffahrtsgesellschaftskapitän",
    "explanation": "This word continues the theme of transportation, and is four words pieced neatly together to say Danube steamship company captain."
  }
]

Of course you can add more words if you know some. But for testing it should already work.

Click on Save and Deploy again.

Step 7: Add Intent Handlers

The previously created intents now need a handler, which is triggered by an intent. The NoIntentHandler closes the skill. The YesIntentHandler and the TellAFunnyWordIntentHandler answers with a funny word and its explanantion.

Delete the whole HelloWorldIntentHandler from the index.js file and add three new ones instead:

const TellAFunnyWordIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'TellAFunnyWordIntent';
    },
    handle(handlerInput) {
        const words = JSON.parse(fs.readFileSync('./words.json'));
        const word = words[Math.floor(Math.random() * words.length)];
        const speakOutput = word.word + '. ' + word.explanation;
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};
const YesIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent';
    },
    handle(handlerInput) {
        const words = JSON.parse(fs.readFileSync('./words.json'));
        const word = words[Math.floor(Math.random() * words.length)];
        const speakOutput = word.word + '. ' + word.explanation;
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};
const NoIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.NoIntent';
    },
    handle(handlerInput) {
        const speakOutput = 'Okay, maybe another time.';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};

Step 8: Register the Intent Handlers

Now we need to register the new intent handlers. For that, scroll to the end of the index.js file.

Replace this:

exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        HelloWorldIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
    )
    .addErrorHandlers(
        ErrorHandler,
    )
    .lambda();

with that:

exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        TellAFunnyWordIntentHandler,
        YesIntentHandler,
        NoIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
    )
    .addErrorHandlers(
        ErrorHandler,
    )
    .lambda();

Afterwards click on Save and Deploy again. After the deployment has finished test the skill again.

Step 9: Test the Skill

  1. Click on the Test tab → A new window opens.
  2. Write or speak: "oppen funny german words" → The skill should now answer with the greeting.
  3. Write or speak: "tell me a funny german word" → The skill should now tell one of the words.

If everything works, you can already submit your skill.

Step 10: Set Skill Preview and Submit for Review

Fill all required textboxes with your personal description of the skill.

At Example Phrases write:

  • Alexa, open Funny German Words.
  • Alexa, ask Funny German Words to tell me a funny word.

After you filled all the required fields and after you have uploaded the icons, click on Save and continue.

Choose the correct answers at Privacy & Compilance and at Availability.

Please take a look at the submission checklist before submitting!

Now you need to run some tests. This can take a while.

Afterwards you can submit your skill for review. It will take 1 or 2 days until you get feedback for your skill. If you did everything right, your skill will be published right after the review.

If you want to try the skill already, but it is still in certification, you can always use this skill:

https://www.amazon.com/gp/product/B07ZH9GL9N?ref&ref=cm_sw_em_r_as_dp_uCOJljYBKfNx9