Skip to content

Instantly share code, notes, and snippets.

@germanviscuso
Created April 3, 2019 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save germanviscuso/a6897fd7596e3fabd939395dade95ab2 to your computer and use it in GitHub Desktop.
Save germanviscuso/a6897fd7596e3fabd939395dade95ab2 to your computer and use it in GitHub Desktop.
Alexa Skills Basic: Intent Chaining
{
"interactionModel": {
"languageModel": {
"invocationName": "feliz cumple",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "RegisterBirthdayIntent",
"slots": [
{
"name": "day",
"type": "AMAZON.NUMBER",
"samples": [
"el día {day}",
"{day}",
"el {day}"
]
},
{
"name": "month",
"type": "TipoMes",
"samples": [
"{month}",
"en {month}"
]
},
{
"name": "year",
"type": "AMAZON.FOUR_DIGIT_NUMBER",
"samples": [
"de {year}",
"del {year}",
"he nacido en el {year}",
"he nacido en el año {year}",
"año {year}",
"en el {year}",
"en el año {year}",
"el año {year}",
"{year}"
]
}
],
"samples": [
"{day}",
"{month}",
"{month} del {year}",
"{month} de {year}",
"{day} del {month}",
"en el año {year}",
"he nacido en {year}",
"para el {day} de {month}",
"con el {day} de {month}",
"para el {day} de {month} de {year}",
"con el {day} de {month} de {year}",
"mi fecha de nacimiento es el {day} de {month} de {year}",
"mi cumpleaños es el {day} de {month} de {year}",
"mi cumple es el {day} de {month} de {year}",
"mi cumpleaños es el {day} de {month}",
"mi cumple es el {day} de {month}",
"he nacido el {day} de {month} de {year}",
"{day} de {month} de {year}",
"cumplo el {day} de {month} de {year}",
"{month} {day}",
"{day} de {month}",
"cumplo el {day} de {month}",
"el {day}",
"en {month}",
"cumplo el {day}",
"cumplo en {month}",
"registra mi cumple",
"graba mi cumple",
"recuerda mi cumple",
"registra mi cumpleaños",
"recordar mi cumple",
"recordar mi cumpleaños",
"apunta mi cumple",
"apunta mi cumpleaños",
"toma nota de mi cumple",
"toma nota de mi cumpleaños",
"anota mi cumple",
"anota mi cumpleaños",
"graba mi cumpleaños",
"recuerda mi cumpleaños"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": [
{
"name": "TipoMes",
"values": [
{
"id": "12",
"name": {
"value": "diciembre"
}
},
{
"id": "11",
"name": {
"value": "noviembre"
}
},
{
"id": "10",
"name": {
"value": "octubre"
}
},
{
"id": "09",
"name": {
"value": "septiembre"
}
},
{
"id": "08",
"name": {
"value": "agosto"
}
},
{
"id": "07",
"name": {
"value": "julio"
}
},
{
"id": "06",
"name": {
"value": "junio"
}
},
{
"id": "05",
"name": {
"value": "mayo"
}
},
{
"id": "04",
"name": {
"value": "abril"
}
},
{
"id": "03",
"name": {
"value": "marzo"
}
},
{
"id": "02",
"name": {
"value": "febrero"
}
},
{
"id": "01",
"name": {
"value": "enero",
"synonyms": [
"primero",
"primer mes del año"
]
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "RegisterBirthdayIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "day",
"type": "AMAZON.NUMBER",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.653974572406.1040382425372"
},
"validations": [
{
"type": "isGreaterThanOrEqualTo",
"prompt": "Slot.Validation.190694681136.1424851421300.1030431910159",
"value": "1"
},
{
"type": "isLessThanOrEqualTo",
"prompt": "Slot.Validation.190694681136.1424851421300.837658517617",
"value": "31"
}
]
},
{
"name": "month",
"type": "TipoMes",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.282358190483.487594834711"
},
"validations": [
{
"type": "hasEntityResolutionMatch",
"prompt": "Slot.Validation.190694681136.463018349705.1461889218555"
}
]
},
{
"name": "year",
"type": "AMAZON.FOUR_DIGIT_NUMBER",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.1253554922892.1358447173887"
},
"validations": [
{
"type": "isGreaterThan",
"prompt": "Slot.Validation.1253554922892.1358447173887.1026742417738",
"value": "1900"
},
{
"type": "isLessThan",
"prompt": "Slot.Validation.1253554922892.1358447173887.176185058059",
"value": "2018"
}
]
}
]
}
],
"delegationStrategy": "ALWAYS"
},
"prompts": [
{
"id": "Elicit.Slot.653974572406.1040382425372",
"variations": [
{
"type": "PlainText",
"value": "vale. me has dicho que cumples en {month} pero que día?"
},
{
"type": "PlainText",
"value": "que día cumples años?"
},
{
"type": "PlainText",
"value": "en que día es tu cumpleaños?"
},
{
"type": "PlainText",
"value": "dime en que día del mes es tu cumpleaños"
}
]
},
{
"id": "Elicit.Slot.282358190483.487594834711",
"variations": [
{
"type": "PlainText",
"value": "dime ahora el mes en que cumples años"
},
{
"type": "PlainText",
"value": "en que mes cumples años?"
},
{
"type": "PlainText",
"value": "en que mes es tu cumpleaños?"
},
{
"type": "PlainText",
"value": "vale, cumples el día {day} .pero en que mes?"
}
]
},
{
"id": "Slot.Validation.190694681136.1424851421300.1030431910159",
"variations": [
{
"type": "PlainText",
"value": "Por favor dime un día mayor o igual que uno"
}
]
},
{
"id": "Slot.Validation.190694681136.1424851421300.837658517617",
"variations": [
{
"type": "PlainText",
"value": "Por favor dime un día menor o igual a treinta y uno"
}
]
},
{
"id": "Slot.Validation.190694681136.463018349705.1461889218555",
"variations": [
{
"type": "PlainText",
"value": "Por favor dime un mes válido"
}
]
},
{
"id": "Elicit.Slot.1253554922892.1358447173887",
"variations": [
{
"type": "PlainText",
"value": "eres de {month} de que año?"
},
{
"type": "PlainText",
"value": "vale. el {day} de {month} . de que año?"
},
{
"type": "PlainText",
"value": "ahora dime el año de tu nacimiento"
},
{
"type": "PlainText",
"value": "en que año has nacido?"
}
]
},
{
"id": "Slot.Validation.1253554922892.1358447173887.1026742417738",
"variations": [
{
"type": "PlainText",
"value": "No creo que tengas tantos años. Inténtalo otra vez"
}
]
},
{
"id": "Slot.Validation.1253554922892.1358447173887.176185058059",
"variations": [
{
"type": "PlainText",
"value": "No creo que tengas tan pocos años. Inténtalo otra vez"
}
]
},
{
"id": "Elicit.Slot.556115415325.557149889298",
"variations": [
{
"type": "PlainText",
"value": "Cual es el mensaje para el recordatorio?"
},
{
"type": "PlainText",
"value": "Genial. Ahora dime el mensaje a leer cuando se active el recordatorio"
},
{
"type": "PlainText",
"value": "Vale. Dime por favor el mensaje para el recordatorio"
}
]
},
{
"id": "Confirm.Intent.556115415325",
"variations": [
{
"type": "PlainText",
"value": "El mensaje. {message} .Será enviado cuando cumplas años. Lo confirmas?"
},
{
"type": "PlainText",
"value": "Te enviaré el siguiente mensaje cuando cumplas años. {message} . De acuerdo?"
}
]
}
]
}
}
// This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).
// Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
// session persistence, api calls, and more.
const Alexa = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Hola!';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.addDelegateDirective({
name: 'RegisterBirthdayIntent',
confirmationStatus: 'NONE',
slots: {
/*month: { //uncomment this to see how slot values are prefilled when reaching the next intent
name: 'month',
value: 'mayo',
confirmationStatus: 'NONE'
}*/
}
})
.getResponse();
}
};
const RegisterBirthdayIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'RegisterBirthdayIntent';
},
handle(handlerInput) {
const {intent} = handlerInput.requestEnvelope.request;
const day = intent.slots.day.value;
const month = intent.slots.month.resolutions.resolutionsPerAuthority[0].values[0].value.id; //MM
const monthName = intent.slots.month.resolutions.resolutionsPerAuthority[0].values[0].value.name;
const year = intent.slots.year.value;
const speechText = 'He registrado tu cumpleaños para el ' + day + ' de ' + monthName + ' de ' + year; // we'll save these values later
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'Solo tienes que decirme tu fecha de cumpleaños';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speechText = 'Adios!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
// Any cleanup logic goes here.
return handlerInput.responseBuilder.getResponse();
}
};
// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest';
},
handle(handlerInput) {
const intentName = handlerInput.requestEnvelope.request.intent.name;
const speechText = `You just triggered ${intentName}`;
return handlerInput.responseBuilder
.speak(speechText)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`~~~~ Error handled: ${error.message}`);
const speechText = `Perdona. Ha habido un error. Inténtalo otra vez.`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
// This handler acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
RegisterBirthdayIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler) // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
.addErrorHandlers(
ErrorHandler)
.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment