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

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

Similar projects you might like

Iron-Rich Foods!
Easy
  • 42
  • 3

A necessary skill for all people with iron deficiencies. It's always hard to find foods that are rich in iron. Until now. Just ask Alexa!

Movie Quotes Trivia
Easy
  • 12
  • 1

Full instructions

Test your knowledge of great movies by matching five famous movies quotes. It will be great fun activities among famaly and friends.

Wise Quotes
Easy
  • 131
  • 3

Full instructions

More than 100 wise quotes to empower you everyday.

Wildlife Facts Skill
Easy
  • 50
  • 2

Learn more about wildlife animals with more than 200 interesting facts with this Alexa skill.

Compost Helper Alexa Skill
Easy
  • 147
  • 3

Use Alexa to find out if a household item can be added to your compost.

Ferrari Facts
Easy
  • 263
  • 4

Full instructions

learn about the most expensive cars in the world with Ferrari Facts you you will know some interesting facts that you probably didn't hear a

Add projectSign up / Login