Things used in this project

Software apps and online services:
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda
Dp image kit 02
Amazon Alexa Alexa Skills Kit

Code

StarDateJavaScript
Deploy to a Lambda function, triggered by Alexa Skills Kit.
'use strict';

const Alexa = require('alexa-sdk');

const APP_ID = 'amzn1.ask.skill.e26e400d-1271-4e97-bf05-e9d1d7980ff3';

const SKILL_NAME = 'Star Date';
const STAR_DATE_MESSAGE = 'The current star date is: ';
const HELP_MESSAGE = 'Do you want to know the current star date?';
const STOP_MESSAGE = 'Goodbye!';

const handlers = {
    'LaunchRequest': function () {
        this.emit('GetStarDate');
    },
    'GetStarDate': function () {
        var date = new Date();

        var year = date.getUTCFullYear();
        var month = date.getUTCMonth() + 1;
        var day = date.getUTCDate();
        var seconds = date.getUTCSeconds() + (60 * date.getUTCMinutes()) + (60 * 60 * date.getUTCHours());
        
        var stardate1 = year;
        var stardate2 = ("0"+month).slice(-2) + ("0" + day).slice(-2);
        var stardate3 = Math.floor(seconds%86400/86400*100000);
        var stardate = "<say-as interpret-as='digits'>"+stardate1+"</say-as>"
                     + "<break/>"
                     + "<say-as interpret-as='digits'>"+stardate2+"</say-as>"
                     + "<break/>"
                     + "dot"
                     + "<break/>"
                     + "<say-as interpret-as='digits'>"+stardate3+"</say-as>";
        
        const speechOutput = STAR_DATE_MESSAGE + stardate;
        
        this.emit(':tellWithCard', speechOutput, SKILL_NAME, STAR_DATE_MESSAGE + stardate1 + stardate2 + '.' + stardate3);
    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_MESSAGE;
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', STOP_MESSAGE);
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', STOP_MESSAGE);
    },
    'SessionEndedRequest': function () {
        this.emit(':tell', STOP_MESSAGE);
    },
};

exports.handler = (event, context) => {
    const alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

Credits

35e551ad67e9da5bea4c5da79268ede8
Swapnil Agarwal
0 projects • 0 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login