Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Código de ejemplo en donde se muestra el manejo de SLOTS - FirstSkill - Hola mi nombre es Lucio", intenta decir eso con tu nombre
{
"interactionModel": {
"languageModel": {
"invocationName": "first skill",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": [
"cancela"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"ayudame",
"ayuda"
]
},
{
"name": "AMAZON.StopIntent",
"samples": [
"deten",
"detente",
"para"
]
},
{
"name": "HelloWorldIntent",
"slots": [],
"samples": [
"holi",
"que hay",
"que onda",
"eit",
"hey",
"hola"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "IntroduceYourSelfIntent",
"slots": [
{
"name": "Nombre",
"type": "Names",
"samples": [
"me llamo {Nombre} y comida faovrita es la {Comida}",
"{Nombre}",
"mi nombre es {Nombre}",
"me llamo {Nombre}"
]
},
{
"name": "Comida",
"type": "AMAZON.Food",
"samples": [
"Esta es {Comida}",
"Mi comida favorita es {Comida}",
"Soy {Nombre} y mi comida favorita es {Comida}",
"{Comida}"
]
}
],
"samples": [
"{Nombre} es como me llamo",
"{Nombre} es mi nombre",
"{Comida} es mi comida favorita",
"mi comida favorita es la {Comida}",
"me llamo {Nombre} y mi comida favorita es la {Comida}",
"me llamo {Nombre}",
"holi soy {Nombre}",
"Hola soy {Nombre}",
"{Nombre}",
"mi primer nombre es {Nombre}",
"mi nombre es {Nombre}",
"soy {Nombre}",
"hola mi nombre es {Nombre}"
]
},
{
"name": "favouriteFood",
"slots": [],
"samples": [
"cual es mi comida",
"mi comida favorita por favor",
"cual es mi comida favorita"
]
}
],
"types": [
{
"name": "Names",
"values": [
{
"name": {
"value": "Armando"
}
},
{
"name": {
"value": "Marcos"
}
},
{
"name": {
"value": "Juan"
}
},
{
"name": {
"value": "Ivan"
}
},
{
"name": {
"value": "Gerardo"
}
},
{
"name": {
"value": "Vicente"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "IntroduceYourSelfIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "Nombre",
"type": "Names",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.230302656341.1560002001537"
}
},
{
"name": "Comida",
"type": "AMAZON.Food",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.230302656341.921773706882"
}
}
]
}
],
"delegationStrategy": "ALWAYS"
},
"prompts": [
{
"id": "Elicit.Slot.230302656341.1560002001537",
"variations": [
{
"type": "PlainText",
"value": "¿Cómo te llamas?"
},
{
"type": "PlainText",
"value": "¿Cúal es tu nombre?"
}
]
},
{
"id": "Elicit.Slot.230302656341.921773706882",
"variations": [
{
"type": "PlainText",
"value": "¿Cúal es tu comida favorita?"
}
]
}
]
}
}
// 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 Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Bievenido, you can say Hello or Help. Which would you like to try?';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent';
},
handle(handlerInput) {
const speakOutput = 'Hola y bienvenido!, te invito a que te presentes';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('Tu puedes decir: "Hola mi nombre es Lucio", intenta decir eso con tu nombre.')
.getResponse();
}
};
const InProgressIntroduceYourSelfHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'IntroduceYourSelfIntent'
&& handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
return handlerInput.responseBuilder
.addDelegateDirective(handlerInput.requestEnvelope.request.intent)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
const CompleteIntroduceYourSelfIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'IntroduceYourSelfIntent';
},
handle(handlerInput) {
const userName = handlerInput.requestEnvelope.request.intent.slots.Nombre.value;
const favFood = handlerInput.requestEnvelope.request.intent.slots.Comida.value;
const speakOutput = `Perfecto, recordare que tu nombre es ${userName}, y que tu comida favorita es ${favFood}. Puedes preguntarme sobre tu comida favorita.`;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
sessionAttributes.favouriteFood = favFood
handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('Tu puedes decirme algo como: "¿Cuál es mi comida favorita?')
.getResponse();
}
};
const ComidaFavoritaIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'favouriteFood';
},
handle(handlerInput) {
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
if (sessionAttributes.favouriteFood){
return handlerInput.responseBuilder
.speak(`Tu comida favorita es ${sessionAttributes.favouriteFood}`)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
} else {
return handlerInput.responseBuilder
.speak('No me dijiste nada de tu comida favorita. Para esto solo di: "Mi comida favorita es la Pizza"')
.reprompt('No me dijiste nada de tu comida favorita. Para esto solo di: "Mi comida favorita es la Pizza"')
.getResponse();
}
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speakOutput = 'You can say hello to me! How can I help?';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
|| Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speakOutput = 'Hasta la proóxima!';
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === '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 Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
},
handle(handlerInput) {
const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
const speakOutput = `You just triggered ${intentName}`;
return handlerInput.responseBuilder
.speak(speakOutput)
//.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.stack}`);
const speakOutput = `Sorry, I had trouble doing what you asked. Please try again.`;
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
// The SkillBuilder 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,
HelloWorldIntentHandler,
InProgressIntroduceYourSelfHandler,
CompleteIntroduceYourSelfIntentHandler,
ComidaFavoritaIntentHandler,
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
You can’t perform that action at this time.