vishnu kumar
Created December 1, 2016

Advice of the day

sometimes an advice can change your day. thus you can ask alexa for an advice which may help you make your day.

34
Advice of the day

Things used in this project

Story

Read more

Code

index.js

JavaScript
'use strict';
var Alexa = require('alexa-sdk');

var APP_ID = 'amzn1.ask.skill.dab4a8db-1c4c-4ab5-989f-0d2dbcff17cc'; //OPTIONAL: replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
var SKILL_NAME = 'Advice for you';

/**
 * Array containing space facts.
 */
var ADVICE = [
    "What you're supposed to do when you don't like a thing is change it. If you can't change it, change the way you think about it. Don't complain.",
    "Try to be a rainbow in someone's cloud.",
    "Never miss a good chance to shut up.",
    "If a man will begin with certainties, he shall end in doubts; but if he will be content to begin with doubts, he shall end in certainties.",
    "Here's some advice. Stay alive.",
    "We cannot change the cards we are dealt, just how we play the hand.",
    "Never ruin an apology with an excuse.",
    "Don't leave a piece of jewelry at his house so you can go back and get it later; he may be with his real girlfriend.",
    "Don't ever take a fence down until you know why it was put up.",
    "Write with the door closed, rewrite with the door open.",
    "Don't take life too seriously. Punch it in the face when it needs a good hit. Laugh at it.",
    "Push your boundaries, that's what they're there for.",
    "Choose your battles, but don't choose very many.","Adapt what is useful, reject what is useless, and add what is specifically your own."
];

exports.handler = function(event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

var handlers = {
    'LaunchRequest': function () {
        this.emit('GetAdvice');
    },
    'GetNewAdviceIntent': function () {
        this.emit('GetAdvice');
    },
    'GetAdvice': function () {
        // Get a random space fact from the space facts list
        var adviceIndex = Math.floor(Math.random() * ADVICE.length);
        var randomAdvice = ADVICE[adviceIndex];

        // Create speech output
        var speechOutput = "Here's your fact: " + randomAdvice;

        this.emit(':tellWithCard', speechOutput, SKILL_NAME, randomAdvice)
    },
    'AMAZON.HelpIntent': function () {
        var speechOutput = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
        var reprompt = "What can I help you with?";
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', 'Goodbye!');
    },
    'AMAZON.PauseIntent': function () {
        this.emit(':tell', 'paused');
    },
    'AMAZON.ResumeIntent': function () {
        this.emit(':tell', 'app is resumed');
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', 'Goodbye!');
    }
};

Credits

vishnu kumar

vishnu kumar

2 projects • 2 followers

Comments