/**
* Created by Rob Arao on June 29, 2016
*/
/**
* This simple sample has no external dependencies or session management, and shows the most basic
* example of how to create a Lambda function for handling Alexa Skill requests.
*
* Examples:
* One-shot model:
* User: "Alexa, ask daily thought to share something deep "
* Alexa: "Here is something to think about: ..."
*/
/**
* App ID for the skill
*/
var APP_ID = undefined; //replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
/**
* Array containing thought list.
*/
var THOUGHT_LIST = [
"You are an amazing and funny person. Now go shine brightly.",
"You are extremely attractive. And if I were human I'd ask you out.",
"T S Elliot once said we must never cease from exploration. And the end of all our exploring will be to arrive where we began, and to know the place for the first time.",
"Remember the assistance you need will be provided by the universe, as soon as you convert your readiness to willingness.",
"You should remember that the universe will reward you for taking risks on its behalf.",
"The Dali Lama once told me, the purpose of life is to increase the warm heart.",
"You know, the curious paradox is that when I accept myself just as I am, then I can change.",
"People often say that this or that person has not yet found himself, but the self is not something that one finds. It is something that one creates.",
"An open mind is like an open window. It lets the fresh air in.",
"There is only journey. Going inside yourself.",
"I have found that if you love life, life will love you back.",
"When the future becomes far more interesting than the present, the destination holds more importance than the journey.",
"What you are is Gods gift to you. What you make of yourself is your gift to God.",
"There are no mistakes and no coincidences. All events are blessings given to us to learn.",
"Take your hands off the steering wheel. And be able to say to the universe your will be done.",
"Choice is a divine teacher. For when we choose, we learn that nothing is ever put in our path without a reason.",
"The priviledge of a lifetime is being who you are."
];
/**
* The AlexaSkill prototype and helper functions
*/
var AlexaSkill = require('./AlexaSkill');
/**
* DailyThought is a child of AlexaSkill.
* To read more about inheritance in JavaScript, see the link below.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#Inheritance
*/
var DailyThought = function () {
AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
DailyThought.prototype = Object.create(AlexaSkill.prototype);
DailyThought.prototype.constructor = DailyThought;
DailyThought.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {
console.log("DailyThought onSessionStarted requestId: " + sessionStartedRequest.requestId
+ ", sessionId: " + session.sessionId);
// any initialization logic goes here
};
DailyThought.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
console.log("DailyThought onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);
handleNewFactRequest(response);
};
/**
* Overridden to show that a subclass can override this function to teardown session state.
*/
DailyThought.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {
console.log("DailyThought onSessionEnded requestId: " + sessionEndedRequest.requestId
+ ", sessionId: " + session.sessionId);
// any cleanup logic goes here
};
DailyThought.prototype.intentHandlers = {
"GetNewFactIntent": function (intent, session, response) {
handleNewFactRequest(response);
},
"AMAZON.HelpIntent": function (intent, session, response) {
response.ask("You can ask me a fact, or, you can say exit... What can I help you with?", "What can I help you with?");
},
"AMAZON.StopIntent": function (intent, session, response) {
var speechOutput = "Goodbye";
response.tell(speechOutput);
},
"AMAZON.CancelIntent": function (intent, session, response) {
var speechOutput = "Goodbye";
response.tell(speechOutput);
}
};
/**
* Gets a random new thought from the list and returns to the user.
*/
function handleNewFactRequest(response) {
// Get a random thought from the thought list
var factIndex = Math.floor(Math.random() * THOUGHT_LIST.length);
var fact = THOUGHT_LIST[factIndex];
// Create speech output
var speechOutput = "Here is something to think about: " + fact;
response.tellWithCard(speechOutput, "DailyThought", speechOutput);
}
// Create the handler that responds to the Alexa Request.
exports.handler = function (event, context) {
// Create an instance of the DailyThought skill.
var dailyThought = new DailyThought();
dailyThought.execute(event, context);
};
Comments