Created
December 12, 2018 13:26
-
-
Save muttoni/f75357acf94636b11dca5a95653f1e8d 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
| /* eslint-disable func-names */ | |
| /* eslint-disable no-console */ | |
| const Alexa = require('ask-sdk'); | |
| const LaunchRequestHandler = { | |
| canHandle(handlerInput) { | |
| const request = handlerInput.requestEnvelope.request; | |
| return request.type === 'LaunchRequest'; | |
| }, | |
| handle(handlerInput) { | |
| const speechOutput = 'Welcome to Magic Word! Lets get started. Do you want sweets?'; | |
| return handlerInput.responseBuilder | |
| .speak(speechOutput) | |
| .reprompt('I did not hear that. ' + speechOutput) | |
| .getResponse(); | |
| }, | |
| }; | |
| const AnswerIntentHandler = { | |
| canHandle(handlerInput) { | |
| const request = handlerInput.requestEnvelope.request; | |
| return request.type === 'IntentRequest' | |
| && request.intent.name === 'AnswerIntent'; | |
| }, | |
| handle(handlerInput) { | |
| const request = handlerInput.requestEnvelope.request; | |
| const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); | |
| if(!sessionAttributes.counter) { | |
| sessionAttributes.counter = 0; | |
| } | |
| let speechOutput = ''; | |
| const courtesyWord = request.intent.slots.courtesyWord.value; | |
| if(courtesyWord) { | |
| sessionAttributes.counter += 1; | |
| speechOutput = `<audio src='soundbank://soundlibrary/musical/amzn_sfx_trumpet_bugle_03'/><voice name="Emma"><lang xml:lang="en-GB">Great, you used ${courtesyWord}. You are <emphasis level="strong">well</emphasis> on your way in becoming polite.</lang></voice>` | |
| } else { | |
| speechOutput = `<audio src='soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_negative_response_01'/> What's the magic word?` | |
| } | |
| handlerInput.attributesManager.setSessionAttributes(sessionAttributes); | |
| return handlerInput.responseBuilder | |
| .speak(speechOutput) | |
| .reprompt(speechOutput) | |
| .getResponse(); | |
| }, | |
| }; | |
| const HelpHandler = { | |
| canHandle(handlerInput) { | |
| const request = handlerInput.requestEnvelope.request; | |
| return 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) { | |
| const speechOutput= 'Goodbye'; | |
| return handlerInput.responseBuilder | |
| .speak(speechOutput) | |
| .getResponse(); | |
| }, | |
| }; | |
| const SessionEndedRequestHandler = { | |
| canHandle(handlerInput) { | |
| const request = handlerInput.requestEnvelope.request; | |
| return request.type === 'SessionEndedRequest'; | |
| }, | |
| handle(handlerInput) { | |
| console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`); | |
| return handlerInput.responseBuilder.getResponse(); | |
| }, | |
| }; | |
| const ErrorHandler = { | |
| canHandle() { | |
| return true; | |
| }, | |
| handle(handlerInput, error) { | |
| console.log(`Error handled: ${error.message}`); | |
| return handlerInput.responseBuilder | |
| .speak('Sorry, an error occurred.') | |
| .reprompt('Sorry, an error occurred.') | |
| .getResponse(); | |
| }, | |
| }; | |
| const skillBuilder = Alexa.SkillBuilders.standard(); | |
| exports.handler = skillBuilder | |
| .addRequestHandlers( | |
| LaunchRequestHandler, | |
| AnswerIntentHandler, | |
| HelpHandler, | |
| ExitHandler, | |
| SessionEndedRequestHandler | |
| ) | |
| .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
| { | |
| "interactionModel": { | |
| "languageModel": { | |
| "invocationName": "magic word", | |
| "intents": [ | |
| { | |
| "name": "AMAZON.FallbackIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.CancelIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.HelpIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.StopIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.NavigateHomeIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AnswerIntent", | |
| "slots": [ | |
| { | |
| "name": "courtesyWord", | |
| "type": "COURTESY_WORDS" | |
| } | |
| ], | |
| "samples": [ | |
| "yeah now", | |
| "yeah now {courtesyWord}", | |
| "forget it {courtesyWord}", | |
| "forget it", | |
| "you suck", | |
| "yuck", | |
| "no way", | |
| "thats very kind of you {courtesyWord}", | |
| "maybe {courtesyWord}", | |
| "yes", | |
| "no", | |
| "maybe", | |
| "{courtesyWord} no", | |
| "{courtesyWord} yes", | |
| "great {courtesyWord}", | |
| "no {courtesyWord}", | |
| "yes {courtesyWord}" | |
| ] | |
| } | |
| ], | |
| "types": [ | |
| { | |
| "name": "COURTESY_WORDS", | |
| "values": [ | |
| { | |
| "name": { | |
| "value": "many thanks" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "ta" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "cheers" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "thank you", | |
| "synonyms": [ | |
| "thankee", | |
| "thank ya", | |
| "thanks" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "please" | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment