-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (53 loc) · 1.82 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
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
wttw = require('./wttw.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");
response.say("I can tell you what's on WTTW HD Chicago — just say Alexa, ask WTTW what's on right now.");
response.say("You can also include the channel and say HD, Prime, Create, or Kids");
});
alexaApp.sessionEnded(function(request, response) {
console.log("In sessionEnded");
console.error('Alexa ended the session due to an error');
});
//Intents
alexaApp.intent("whats_on", {
"slots": {
"channel": "wttwChannel"
},
"utterances": [
"what's playing",
"what's on now",
"what's on",
"what's on {-|channel}",
]
}, function(request, response) {
console.log("In what's on intent");
var channel = request.slot("channel");
if (!channel || !(channel in wttw.schedule.channel)) {
channel = 'hd';
}
return wttw.schedule.getOnNow(channel).then((data) => {
response.say('On WTTW '+ channel +' right now: ' + data.onNow + ". " + data.onNext + " is on next.");
}).catch((ex) => {
wttw.errorResponse(response);
});
});
// connect the alexa-app to AWS Lambda
exports.handler = alexaApp.lambda();