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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Configure Amazon Skills Kit to Use Your AWS Developer Account
Initialize the ASK CLI:
ask init --no-browser
Copy/paste the URL that appears from the terminal to a browser window.
Log in to the developer console when prompted.
Copy/paste the authorization code.
Enter
y
forYes
to connect to the AWS account already set up on the VM.Choose the default AWS account.
- Clone and Check Out Branch
Use the following to clone the template skill:
ask new --url https://github.com/linuxacademy/content-aws-skill-builder.git
Navigate into the directory with:
cd content-aws-skill-builder
To start with a template and perform the tasks for this lab yourself:
git checkout lab_dialog
To start with the solution to the lab:
git checkout lab_dialog_solution
- Develop the Skill
In
../models/en-US.json
: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}" ] }, ...
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" } } ] } ] ...,
Add the
dialog directive
at the same level as thelanguageModel
, and create a directive for theRegisterPetIntent
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" } } ] } ] }, ...
Add
prompts
at the same level asdialog
, 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
: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(); } };
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(); } };
Update
exports.handler
:exports.handler = Alexa.SkillBuilders.custom() .addRequestHandlers( LaunchRequestHandler, ExclusiveVetIntentHandler, // RegisterPetIntentHandler, InProgessRegisterPetIntentHandler, CompletedRegisterPetIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler, FallbackIntentHandler, SessionEndedRequestHandler) .addErrorHandlers( ErrorHandler) .lambda();
- Deploy and Test
Deploy the skill:
ask deploy
Begin performing a test:
ask simulate --locale en-US --text 'open exclusive vet'
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."
.Enter:
ask simulate --locale en-US --text 'I want to register my pet'
Look for
"Dialog.Delegate"
as the value for"type"
.Enter:
ask simulate --locale en-US --text 'I have a ragdoll'
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.Continue in this fashion with the animal name and checking the slots and the final response.
- 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.