-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (62 loc) · 2.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var Alexa = require("alexa-sdk");
var firebase = require("firebase");
var appId = process.env.apiID;
var config = {
apiKey: " ",
authDomain: "push-the-button-4f2a2.firebaseapp.com",
databaseURL: "https://push-the-button-4f2a2.firebaseio.com",
storageBucket: "push-the-button-4f2a2.appspot.com",
};
var app = firebase.initializeApp(config);
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.applicationId = appId;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function(){
this.emit('GetTheSide');
},
'GetTheSide': function() {
var that = this;
var speechOutput = "";
var fullName = "";
var teamName = "";
//console.log("Inside 'GetTheSide'");
firebase.database().ref("pushes").orderByChild("published_at").limitToLast(1).once('value', function(data){
var info = data.val();
var key = Object.keys(info);
var team = info[key[0]]["data"];
team = team.replace(/'/g, '"');
teamName = JSON.parse(team)['deviceName'];
if(teamName == "westside") {
fullName = "west side track fires";
} else if(teamName == "eastside") {
fullName = "east side grid lox";
}
speechOutput = "The " + fullName + " have the button. Is there anything else I can tell you?";
var reprompt = "Is there anything else I can tell you?";
that.emit(':ask', speechOutput, reprompt);
});
},
'AMAZON.HelpIntent': function() {
var speechOutput = "You can say who has the button or cancel...What can I help you with?";
var reprompt = "What can I help you with?";
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.StopIntent': function () {
var exitPhrases = ["Peace Out!", "See ya later!", "Deuces!", "Adios!"];
var phraseIndex = Math.floor(Math.random() * exitPhrases.length);
var randomPhrase = exitPhrases[phraseIndex];
this.emit(':tell', randomPhrase);
},
'AMAZON.NoIntent': function () {
var exitPhrases = ["Peace Out!", "See ya later!", "Deuces!", "Adios!"];
var phraseIndex = Math.floor(Math.random() * exitPhrases.length);
var randomPhrase = exitPhrases[phraseIndex];
this.emit(':tell', randomPhrase);
},
'AMAZON.CancelIntent': function() {}
};