-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
executable file
·45 lines (37 loc) · 974 Bytes
/
handler.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
'use strict';
// Load env vars
const env = require('./.env.json');
// Load the core app
const app = require('./app/main');
// validation methods all live in here
const validation = {
isValidEvent: event => {
try {
return event.session.application.applicationId === env.applicationId;
} catch (e) {
return false;
}
},
};
module.exports.handler = (event, context, callback) => {
// validate our event first
if (!validation.isValidEvent(event)) {
callback('Request made from invalid application');
return;
}
// grab the request for future use
const request = event.request;
// switch over the various request types Alexa provides
switch (request.type) {
case 'LaunchRequest':
app.launch(callback);
return;
case 'IntentRequest':
app.intent(event, callback);
return;
case 'SessionEndedRequest':
return;
}
// if all else fails, send an empty response
callback(null, {});
};