Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Adding Slots to an Alexa Skill

In this lab, you will add custom slots to capture two data points and return them as part of the intent response. Objectives for this lab include creating simple custom slots and testing the slots using `ask dialog`. **Note:** You must have your own Amazon Developer account, which you can [sign up](https://developer.amazon.com/) for if you do not already have one.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Dec 05, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Configure Amazon Skills Kit to Use Your AWS Developer Account

    1. Initialize the ASK CLI:
    ask init --no-browser
    
    1. Copy/paste the URL that appears from the terminal to a browser window.
    2. Log in to the developer console when prompted.
    3. Copy/paste the authorization code.
    4. Enter y for Yes to connect to the AWS account already set up on the VM.
    5. Choose the default AWS account.
  2. Challenge

    Clone and Check Out Branch

    1. Clone the template skill:

      ask new --url https://github.com/linuxacademy/content-aws-skill-builder.git
      
    2. Navigate into the directory:

      cd content-aws-skill-builder
      
    3. To start with a template and perform the tasks for this lab yourself:

      git checkout lab_slots
      
    4. To start with the solution to the lab:

      git checkout lab_slots_solution
      
  3. Challenge

    Develop the Skill

    In ../models/en-US.json:

    1. Add custom slots for pet_type and pet_name to RegisterPetIntent.

    2. Change the samples in the same intent to say '"i want to register my {pet_type} names {pet_name}"'.

      {
        ...,
        {
          "name": "RegisterPetIntent",
          "slots": [
            {
              "name": "pet_type",
              "type": "petType"
            },
            {
              "name": "pet_name",
              "type": "petName"
            }
          ],
          "samples": [
            "i want to register my {pet_type} named {pet_name}"
          ]
        },
        ...
      
    3. Add custom slot type "types" at the same level as "intents".

        ...],
        "types": [
          {
            "name": "petType",
            "values": [
              {
                "name": {
                  "value": "pet_type"
                }
              }
            ]
          },
          {
            "name": "petName",
            "values": [
              {
                "name": {
                  "value": "pet_name"
                 }
              }
            ]
          }
        ]
        ...
      

    In ../lambda/custom/index.js:

    1. Change the LaunchRequestHandler message to: "Exclusive Veterinary Services welcomes you. You can say things like I want to register my dog named Scraps or I want to register my cat named Freckles."

        const LaunchRequestHandler = {
          canHandle(handlerInput) {
            return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
          },
          handle(handlerInput) {
            const speakOutput = "Exclusive Veterinary Services welcomes you. You can say things like I want to register my dog named Scraps or I want to register my cat named Freckles.";
      
            return handlerInput.responseBuilder
              .speak(speakOutput)
              .reprompt(speakOutput)
              .getResponse();
          }
        };
      
    2. Change RegisterPetIntentHandler to use custom slots.

        const RegisterPetIntentHandler = {
            canHandle(handlerInput) {
                return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
                    && Alexa.getIntentName(handlerInput.requestEnvelope) === 'RegisterPetIntent';
            },
            handle(handlerInput) {
                pet_type = handlerInput.requestEnvelope.request.intent.slots.pet_type.value
                pet_name = handlerInput.requestEnvelope.request.intent.slots.pet_name.value
                const speakOutput = "We are happy to welcome your " + pet_type + ' ' + pet_name + "!";
      
                return handlerInput.responseBuilder
                    .speak(speakOutput)
                    //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
                    .getResponse();
            }
        };
      
  4. Challenge

    Deploy and Test

    1. Deploy the skill:

      ask deploy 
      
    2. Begin performing a test:

      ask dialog --locale en-US
      
    3. The prompt will change to User >.

    4. Enter open exclusive vet and follow the prompts.

  5. Challenge

    Clean Up Amazon Developer Account Alexa Console

    At this point, the skill you just created should be deleted from your Alexa Developer Console.

    Please do so here: Alexa Console.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans