Skip to content

Instantly share code, notes, and snippets.

@JoshuaTheMiller
Created May 10, 2018 03:18
Show Gist options
  • Save JoshuaTheMiller/bf9a1c56440e887199165f45e5c4c6fc to your computer and use it in GitHub Desktop.
Save JoshuaTheMiller/bf9a1c56440e887199165f45e5c4c6fc to your computer and use it in GitHub Desktop.
The Lambda for the DailyGoodJob Flash Briefing tutorial.
// Check out the walkthrough at: https://medium.com/@aflyingcaveman
const phrases = [
"You're doing great!",
"You're awesome!",
"Good job at doing what you do!"
];
exports.handler = (event, context, callback) => {
const todaysDate = getTodayAsDateWithNoTime();
const uniqueId = todaysDate.toString();
const updatedDate = todaysDate;
const whatToSay = getDailyGoodJobString(todaysDate.getDate());
const title = "Alexa's Compliment: " + whatToSay ;
const redirectionUrl = "";
const response = prepareResponseForFlashBriefing(uniqueId, updatedDate, title, whatToSay, redirectionUrl);
callback(null, response);
};
function getTodayAsDateWithNoTime() {
let today = new Date();
today.setHours(0,0,0,0);
return today;
}
function getDailyGoodJobString(todaysDateNumber) {
return phrases[todaysDateNumber % phrases.length];
}
function prepareResponseForFlashBriefing(uniqueId, updatedDate, title, whatToSay, redirectionUrl = "") {
const responseCode = 200;
const responseBody = {
uid: uniqueId,
updateDate: updatedDate,
titleText: title,
mainText: whatToSay
};
if(redirectionUrl == null || redirectionUrl == undefined || redirectionUrl == "") {
return {
statusCode: responseCode,
body: JSON.stringify(responseBody)
};
}
responseBody.redirectionUrl = redirectionUrl;
return {
statusCode: responseCode,
body: JSON.stringify(responseBody)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment