Last active
July 30, 2019 08:39
-
-
Save germanviscuso/c09af10f2da4f9232e99de32d9975d64 to your computer and use it in GitHub Desktop.
Alexa Skill Basics: Intent Confirmation in Dialogue Management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"interactionModel": { | |
"languageModel": { | |
"invocationName": "intent confirmation", | |
"intents": [ | |
{ | |
"name": "AMAZON.CancelIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.HelpIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.StopIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "MyCustomIntent", | |
"slots": [], | |
"samples": [ | |
"i want to do something", | |
"do something", | |
"let's go" | |
] | |
} | |
], | |
"types": [] | |
}, | |
"dialog": { | |
"intents": [ | |
{ | |
"name": "MyCustomIntent", | |
"confirmationRequired": true, | |
"prompts": { | |
"confirmation": "Confirm.Intent.703928482675" | |
}, | |
"slots": [] | |
} | |
] | |
}, | |
"prompts": [ | |
{ | |
"id": "Confirm.Intent.703928482675", | |
"variations": [ | |
{ | |
"type": "PlainText", | |
"value": "Do you confirm?" | |
}, | |
{ | |
"type": "PlainText", | |
"value": "Are you sure?" | |
} | |
] | |
} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Alexa = require('ask-sdk'); | |
const HELP_MESSAGE = 'Please say: let\'s go'; | |
const HELP_REPROMPT = 'You can say let\'s go or I want to do something'; | |
const STOP_MESSAGE = 'Goodbye!'; | |
const InProgressMyCustomIntentHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'MyCustomIntent' | |
&& request.dialogState !== 'COMPLETED'; | |
}, | |
handle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
const responseBuilder = handlerInput.responseBuilder; | |
const intent = request.intent; | |
return responseBuilder | |
.addDelegateDirective(intent) | |
.getResponse(); | |
}, | |
}; | |
const CompletedMyCustomIntentHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'MyCustomIntent'; | |
}, | |
handle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
const responseBuilder = handlerInput.responseBuilder; | |
const intent = request.intent; | |
let speechOutput = 'I didn\'t catch your confirmation'; | |
if(intent.confirmationStatus === 'CONFIRMED') | |
speechOutput = 'I\'m glad you confirm! ' + STOP_MESSAGE; | |
if(intent.confirmationStatus === 'DENIED') | |
speechOutput = 'Too bad you changed your mind! ' + STOP_MESSAGE; | |
return handlerInput.responseBuilder | |
.speak(speechOutput) | |
.getResponse(); | |
}, | |
}; | |
const HelpHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'LaunchRequest' || | |
(request.type === 'IntentRequest' | |
&& request.intent.name === 'AMAZON.HelpIntent'); | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(HELP_MESSAGE) | |
.reprompt(HELP_REPROMPT) | |
.getResponse(); | |
}, | |
}; | |
const ExitHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& (request.intent.name === 'AMAZON.CancelIntent' | |
|| request.intent.name === 'AMAZON.StopIntent'); | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(STOP_MESSAGE) | |
.getResponse(); | |
}, | |
}; | |
const skillBuilder = Alexa.SkillBuilders.standard(); | |
exports.handler = skillBuilder | |
.addRequestHandlers( | |
InProgressMyCustomIntentHandler, | |
CompletedMyCustomIntentHandler, | |
HelpHandler, | |
ExitHandler | |
) | |
.lambda(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment