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

WiFi Strength Meter
Easy
  • 499
  • 6

A meter that indicates the Wi-Fi signal strength in an intuitive way, using the parts I had on hand.

Cryptocurrency Price Checker!
Easy
  • 171
  • 2

Full instructions

With the recent rise in cryptocurrencies, this Price Checker will keep you up to date with the most recent market fluctuations!

Trademark Master
Easy
  • 325
  • 10

Work in progress

Trademark Master tells you if any string has already been registered.

Opening Bell
Easy
  • 1,555
  • 23

Full instructions

A simple Alexa voice skill to retrieve the current performance of a publicly traded stock (NASDAQ, NYSE) using the company name.

Brick Bot
Easy
  • 706
  • 14

Protip

A one-stop-skill for your LEGO® needs! Alexa can tell you available sets, themes, and sub-themes and give you details based on set numbers.

Funny Quoter
Easy
  • 328
  • 8

Full instructions

This has some of the weirdest quotes up her sleeve! If you're feeling blue, and need something to cheer you up, just call on Funny Quoter.

Add projectSign up / Login