-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
228 lines (206 loc) · 5.34 KB
/
index.js
File metadata and controls
228 lines (206 loc) · 5.34 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
const express = require("express"),
alexa = require("alexa-app"),
request = require("request"),
fetch = require('node-fetch'),
PORT = process.env.PORT || 3000,
app = express(),
// Setup the alexa app and attach it to express before anything else.
alexaApp = new alexa.app(""),
//import global config/helper object
wfmt = require('./config.js');
app.set("view engine", "ejs");
// POST calls to / in express will be handled by the app.request() function
alexaApp.express({
expressApp: app,
checkCert: true,
// sets up a GET route when set to true. This is handy for testing in
// development, but not recommended for production.
debug: false
});
alexaApp.launch(function(request, response) {
console.log("App launched");
wfmt.stream.start(response);
});
alexaApp.sessionEnded(function(request, response) {
console.log("In sessionEnded");
console.error('Alexa ended the session due to an error');
});
//Intents
alexaApp.intent("stream", {
"slots": {},
"utterances": [
"stream",
"start",
"open",
"play",
"play the wfmt stream",
"start the wfmt stream",
"open the wfmt stream",
"open the wfmt live stream",
"open wfmt",
"start the wfmt live stream",
"play wfmt",
"stream wfmt"
]
}, function(request, response) {
console.log("In stream intent");
wfmt.stream.start(response);
});
alexaApp.intent("whats_on", {
"slots": {},
"utterances": [
"what is this",
"what this is",
"what is this track",
"what is this song",
"which track is this",
"what track is this",
"which song is this",
"what song is this",
"what's playing",
"what's currently playing",
"current song",
"current track",
"currently playing",
"what's on",
"what's on now",
"what's on right now",
"what's playing now",
"what's playing right now"
]
}, function(req, response) {
console.log("In what's on intent");
return wfmt.schedule.getOnNow().then((data) => {
response.say('Now playing ' + data.title + " by " + data.subtitle + " on " + data.show);
});
});
alexaApp.intent("previous_track", {
"slots": {},
"utterances": [
"what just played",
"what was just on",
"what was the previous track",
"what was the last track",
"what was the previous song",
"what was the last song",
"what song was that",
"what track was that",
"previous track",
"previous song"
]
}, function(req, response) {
console.log("In previous track intent");
return fetch(wfmt.schedule.url).then((json) => {
return json.json()
}).then((json) => {
var previousTrack = "The previous song was " + json.prev_track[0].title + " by " + json.prev_track[0].composer;
response.say(previousTrack);
}).catch((ex) => {
wfmt.errorResponse(response);
});
});
alexaApp.intent("AMAZON.CancelIntent", {
"slots": {},
"utterances": [
'stop',
'cancel',
'stop playing',
'cancel playing'
]
}, function(request, response) {
console.log("In cancel intent");
response.audioPlayerStop();
return;
});
alexaApp.intent("AMAZON.PauseIntent", {
"slots": {},
"utterances": [
'pause'
]
}, function(request, response) {
console.log("In pause intent");
response.audioPlayerStop();
return;
});
alexaApp.intent("AMAZON.ResumeIntent", {
"slots": {},
"utterances": [
'resume',
'start playing again'
]
}, function(request, response) {
console.log("In resume intent");
wfmt.stream.start(response);
return;
});
alexaApp.intent("AMAZON.StopIntent", {
"slots": {},
"utterances": [
'stop',
'cancel',
'stop playing',
'cancel playing'
]
}, function(request, response) {
console.log("In stop intent");
response.audioPlayerStop();
return;
});
alexaApp.intent("AMAZON.LoopOffIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.LoopOnIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.NextIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.PreviousIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.RepeatIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.ShuffleOffIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.ShuffleOnIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
alexaApp.intent("AMAZON.StartOverIntent", {
"slots": {},
"utterances": []
}, function(request, response) {
wfmt.notSupportedResponse(response);
return;
});
// connect the alexa-app to AWS Lambda
exports.handler = alexaApp.lambda();