forked from alexa-samples/skill-sample-nodejs-fact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (63 loc) · 3.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var Alexa = require('alexa-sdk');
//=========================================================================================================================================
//TODO: The items below this comment need your attention.
//=========================================================================================================================================
//Replace with your app ID (OPTIONAL). You can find this value at the top of your skill's page on http:https://developer.amazon.com.
//Make sure to enclose your value in quotes, like this: var APP_ID = "amzn1.ask.skill.bb4045e6-b3e8-4133-b650-72923c5980f1";
var APP_ID = undefined;
var SKILL_NAME = "Space Facts";
var GET_FACT_MESSAGE = "Here's your fact: ";
var HELP_MESSAGE = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
var HELP_REPROMPT = "What can I help you with?";
var STOP_MESSAGE = "Goodbye!";
//=========================================================================================================================================
//TODO: Replace this data with your own. You can find translations of this data at http:https://github.com/alexa/skill-sample-node-js-fact/data
//=========================================================================================================================================
var data = [
"A year on Mercury is just 88 days long.",
"Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.",
"Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.",
"On Mars, the Sun appears about half the size as it does on Earth.",
"Earth is the only planet not named after a god.",
"Jupiter has the shortest day of all the planets.",
"The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.",
"The Sun contains 99.86% of the mass in the Solar System.",
"The Sun is an almost perfect sphere.",
"A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.",
"Saturn radiates two and a half times more energy into space than it receives from the sun.",
"The temperature inside the Sun can reach 15 million degrees Celsius.",
"The Moon is moving approximately 3.8 cm away from our planet every year."
];
//=========================================================================================================================================
//Editing anything below this line might break your skill.
//=========================================================================================================================================
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('GetNewFactIntent');
},
'GetNewFactIntent': function () {
var factArr = data;
var factIndex = Math.floor(Math.random() * factArr.length);
var randomFact = factArr[factIndex];
var speechOutput = GET_FACT_MESSAGE + randomFact;
this.emit(':tellWithCard', speechOutput, SKILL_NAME, randomFact)
},
'AMAZON.HelpIntent': function () {
var speechOutput = HELP_MESSAGE;
var reprompt = HELP_REPROMPT;
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', STOP_MESSAGE);
},
'AMAZON.StopIntent': function () {
this.emit(':tell', STOP_MESSAGE);
}
};