Created
April 14, 2020 13:58
-
-
Save pkarthikr/d2271711fb79027b04a91d2b0d953833 to your computer and use it in GitHub Desktop.
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": "riddle me today", | |
"intents": [ | |
{ | |
"name": "AMAZON.CancelIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.HelpIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.StopIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "RiddleIntent", | |
"slots": [], | |
"samples": [ | |
"bring a riddle", | |
"tell me a riddle", | |
"what is today's riddle", | |
"give me today's riddle" | |
] | |
}, | |
{ | |
"name": "AMAZON.NavigateHomeIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.YesIntent", | |
"samples": [] | |
} | |
], | |
"types": [] | |
} | |
} | |
} |
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": "आज की पहेली", | |
"intents": [ | |
{ | |
"name": "AMAZON.CancelIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.HelpIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.StopIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "RiddleIntent", | |
"slots": [], | |
"samples": [ | |
"पहेली बताओ", | |
"पहेली सुनाओ" | |
] | |
}, | |
{ | |
"name": "AMAZON.NavigateHomeIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.YesIntent", | |
"samples": [] | |
} | |
], | |
"types": [] | |
} | |
} | |
} |
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
// 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 skillData = require('skillData.js'); | |
const LaunchRequestHandler = { | |
canHandle(handlerInput) { | |
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; | |
}, | |
handle(handlerInput) { | |
const data = getLocalizedData(handlerInput.requestEnvelope.request.locale); | |
console.log(data); | |
const speakOutput = data["WELCOME_MESSAGE"]+ data["QUESTION"]; | |
const prompt = data["QUESTION"]; | |
return handlerInput.responseBuilder | |
.speak(speakOutput) | |
.reprompt(prompt) | |
.getResponse(); | |
} | |
}; | |
function getLocalizedData(locale){ | |
return skillData[locale]; | |
} | |
const RiddleIntentHandler = { | |
canHandle(handlerInput) { | |
return (Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'RiddleIntent') || | |
(Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' | |
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.YesIntent') ; | |
}, | |
handle(handlerInput) { | |
const speakOutput = 'Here is the riddle for today'; | |
return handlerInput.responseBuilder | |
.speak(speakOutput) | |
//.reprompt('add a reprompt if you want to keep the session open for the user to respond') | |
.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 = 'Goodbye!'; | |
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, | |
RiddleIntentHandler, | |
HelpIntentHandler, | |
CancelAndStopIntentHandler, | |
SessionEndedRequestHandler, | |
IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers | |
) | |
.addErrorHandlers( | |
ErrorHandler, | |
) | |
.lambda(); |
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
module.exports = { | |
"en-IN": { | |
"WELCOME_MESSAGE":"Welcome to Riddle Me Today. I am going to ask you a riddle every day, and 3 chances to answer it correctly. The Less Chances you Take, the more points you win. All your points count towards our weekly leaderboard.", | |
"QUESTION": "Are you ready for today's riddle?" | |
}, | |
"hi-IN":{ | |
"WELCOME_MESSAGE":"पहेली का खेल मैं आपका स्वागत हैं, और धन्यवाद", | |
"QUESTION": "क्या आप खेलने के लिए तैय्यार हैं?" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment