Skip to content

Instantly share code, notes, and snippets.

@muttoni
Created August 2, 2017 15:37
Show Gist options
  • Save muttoni/185d563760c009b795e0bcdedc8659de to your computer and use it in GitHub Desktop.
Save muttoni/185d563760c009b795e0bcdedc8659de to your computer and use it in GitHub Desktop.
'use strict';
var Alexa = require("alexa-sdk");
var languageStrings = {
'en-GB': {
'translation': {
'DEFAULT' : '<say-as interpret-as="interjection">uh-huh</say-as>',
'WELCOME' : "Hello there, tell me what's on your mind. I'm a great listener.",
'HELP' : "I love to listen! Just keep talking to me and I'll occasionally show my enthusiasm",
'REPROMPT' : [
"Oh, I'm sorry, was that a question? I wasn't listening.",
"Was that a question? I got distracted.",
"I'm sorry, I was day dreaming. Keep going, I'm listening!"
],
'GOODBYE' : '<say-as interpret-as="interjection">good golly</say-as>, Goodbye'
}
},
'en-US': {
'translation': {
'DEFAULT' : '<say-as interpret-as="interjection">uh-huh</say-as>',
'WELCOME' : "Hello there, tell me what's on your mind. I'm a great listener.",
'HELP' : "I love to listen! Just keep talking to me and I'll occasionally show my enthusiasm",
'REPROMPT' : [
"Oh, I'm sorry, was that a question? I wasn't listening.",
"Was that a question? I got distracted.",
"I'm sorry, I was day dreaming. Keep going, I'm listening!"
],
'GOODBYE' : '<say-as interpret-as="interjection">aw man!</say-as>, Goodbye'
}
},
'de-DE': {
'translation': {
'DEFAULT' : '<say-as interpret-as="interjection">uh-huh</say-as>',
'WELCOME' : "Hello there, tell me what's on your mind. I'm a great listener.",
'HELP' : "I love to listen! Just keep talking to me and I'll occasionally show my enthusiasm",
'REPROMPT' : [
"Oh, I'm sorry, was that a question? I wasn't listening.",
"Was that a question? I got distracted.",
"I'm sorry, I was day dreaming. Keep going, I'm listening!"
],
'GOODBYE' : '<say-as interpret-as="interjection">aw man!</say-as>, Goodbye'
}
}
};
var handlers = {
'NewSession': function () {
this.emit(':ask', this.t('WELCOME'), this.t('HELP') );
},
'allIntent': function () {
this.emit(':ask', this.t('DEFAULT'), random(this.t('REPROMPT')) );
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', this.t('HELP') );
},
'AMAZON.CancelIntent': function () {
this.emit('QuitIntent');
},
'AMAZON.StopIntent': function () {
this.emit('QuitIntent');
},
'SessionEndedRequest': function () {
this.emit('QuitIntent');
},
'QuitIntent': function () {
this.emit(':tell', this.t('GOODBYE'));
},
'Unhandled': function () {
this.emit("allIntent");
}
};
function random(responseArray) {
return responseArray[Math.floor(Math.random() * responseArray.length)];
}
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment