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 Dialog to an Alexa Skill

In this lab, you will change the skill to use dialog directives and entity resolution to make the skill a more natural-flowing conversation with the user. Objectives for this lab include creating a dialog directive that asks the user for the information needed for slots, using entity resolution to resolve the breed of the pet to pet type, and testing the slots using `ask simulate`. **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 Intermediate
Duration
Clock icon 1h 0m
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
      
    2. Copy/paste the URL that appears from the terminal to a browser window.

    3. Log in to the developer console when prompted.

    4. Copy/paste the authorization code.

    5. Enter y for Yes to connect to the AWS account already set up on the VM.

    6. Choose the default AWS account.

  2. Challenge

    Clone and Check Out Branch

    1. Use the following to clone the template skill:

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

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

    git checkout lab_dialog
    
    1. To start with the solution to the lab:

      git checkout lab_dialog_solution
      
  3. Challenge

    Develop the Skill

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

    1. Add samples to the RegisterPetIntent slots, and update the intent samples to include those same samples:

         ...},
         {
          "name": "RegisterPetIntent",
          "slots": [
            {
              "name": "pet_type",
              "type": "petType",
              "samples": [
                "i have a {pet_type}"
              ]
            },
            {
              "name": "pet_name",
              "type": "petName",
              "samples": [
                "his name is {pet_name}",
                "her name is {pet_name}"
              ]
            }
          ],
          "samples": [
            "i want to register my pet",
            "i have a {pet_type}",
            "his name is {pet_name}",
            "her name is {pet_name}"
          ]
        },
      ...
      
    2. Update the "types" to include "synonyms":

        ...,
          "types": [
            {
              "name": "petType",
              "values": [
                {
                  "name": {
                    "value": "dog",
                    "synonyms": [
                      "beagle",
                      "greyhound"
                    ]
                  }
                },
                {
                  "name": {
                    "value": "cat",
                    "synonyms": [
                      "ragdoll",
                      "siamese"
                    ]
                  }
                }
              ]
            },
            {
              "name": "petName",
              "values": [
                  {
                    "name": {
                      "value": "pet_name"
                     }
                  }
              ]
            }
          ]
        ...,
      
    3. Add the dialog directive at the same level as the languageModel, and create a directive for the RegisterPetIntent and create a elicitation prompt for each slot:

        ...},
          "dialog": {
            "intents": [
              {
              "name": "RegisterPetIntent",
              "confirmationRequired": false,
              "prompts": {},
              "slots": [
                  {
                    "name": "pet_type",
                    "type": "petType",
                    "elicitationRequired": true,
                    "confirmationRequired": false,
                    "prompts": {
                        "elicitation": "Elicit.Intent-RegisterPetIntent.IntentSlot-pet_type"
                    }
                  },
                  {
                    "name": "pet_name",
                    "type": "petName",
                    "elicitationRequired": true,
                    "confirmationRequired": false,
                    "prompts": {
                        "elicitation": "Elicit.Intent-RegisterPetIntent.IntentSlot-pet_name"
                    }
                  }
                ]
              }
            ]
          },
        ...
      
    4. Add prompts at the same level as dialog, and create the actual prompt for Alexa to speak:

        ...},
          "prompts": [
            {
              "id": "Elicit.Intent-RegisterPetIntent.IntentSlot-pet_type",
              "variations": [
                {
                    "type": "PlainText",
                    "value": "We are limited to beagles, greyhounds, ragdolls, and siamese breeds. Which of these breeds do you want to register?"
                }
              ]
            },
            {
              "id": "Elicit.Intent-RegisterPetIntent.IntentSlot-pet_name",
              "variations": [
                {
                    "type": "PlainText",
                    "value": "We love those. One of our favorite breeds. What is your pet's name?"
                }
              ]
            }
          ]
        ...
      

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

    1. Create an InProgessRegisterPetIntentHandler:

      const InProgressRegisterPetIntentHandler = {
          canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
      
            return request.type === 'IntentRequest'
              && request.intent.name === 'RegisterPetIntent'
              && request.dialogState !== 'COMPLETED';
          },
          handle(handlerInput) {
            const currentIntent = handlerInput.requestEnvelope.request.intent;
      
            return handlerInput.responseBuilder
              .addDelegateDirective(currentIntent)
              .getResponse();
          }
      };
      
    2. Create a CompletedRegisterPetIntentHandler:

      const CompletedRegisterPetIntentHandler = {
          canHandle(handlerInput) {
              const request = handlerInput.requestEnvelope.request;
      
            return request.type === 'IntentRequest'
              && request.intent.name === 'RegisterPetIntent'
              && request.dialogState === 'COMPLETED';
          },
          handle(handlerInput) {
              pet_type = handlerInput.requestEnvelope.request.intent.slots.pet_type.resolutions.resolutionsPerAuthority[0].values[0].value.name
              pet_name = handlerInput.requestEnvelope.request.intent.slots.pet_name.value
              pet_breed = handlerInput.requestEnvelope.request.intent.slots.pet_type.value
              const speakOutput = "We are happy to welcome your " + pet_breed + '. Your ' + pet_type + ' named ' + pet_name + " is registered!";
      
              return handlerInput.responseBuilder
                  .speak(speakOutput)
                  //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
                  .getResponse();
          }
      };
      
    3. Update exports.handler:

      exports.handler = Alexa.SkillBuilders.custom()
          .addRequestHandlers(
              LaunchRequestHandler,
              ExclusiveVetIntentHandler,
              // RegisterPetIntentHandler,
              InProgessRegisterPetIntentHandler,
              CompletedRegisterPetIntentHandler,
              HelpIntentHandler,
              CancelAndStopIntentHandler,
              FallbackIntentHandler,
              SessionEndedRequestHandler)
          .addErrorHandlers(
              ErrorHandler)
          .lambda();
      
  4. Challenge

    Deploy and Test

    1. Deploy the skill:

      ask deploy 
      
    2. Begin performing a test:

      ask simulate --locale en-US --text 'open exclusive vet'
      
    3. Look for the response in the JSON and verify it is Exclusive Veterinary Services welcomes you. You can say I want to register my pet.".

    4. Enter:

      ask simulate --locale en-US --text 'I want to register my pet'
      
    5. Look for "Dialog.Delegate" as the value for "type".

    6. Enter:

      ask simulate --locale en-US --text 'I have a ragdoll'
      
    7. Look at the slots to see that "ragdoll" is the value for "pet_type", and then check that entity resolution worked by scrolling up to the requests and reviewing the "resolutions" under "pet_type" in the "request" section of the JSON object.

    8. Continue in this fashion with the animal name and checking the slots and the final response.

  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 at this link: Alexa Developer 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