-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
51 lines (43 loc) · 1.22 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
'use strict';
/**
* Requires (Custom Modules)
*/
const helper = require('./helper');
const commands = require('./commands');
/**
* Process Commands
*
* @param {object} event AWS Lambda Event
*
* @return {object} Request Promise
*/
function processCommands(event) {
if (event && event.text && event.trigger_word) {
if (!commands[event.trigger_word]) {
return commands.error('Invalid Command');
}
const command = event.trigger_word.toLowerCase();
const commandArguments = helper.parseCommand(event.text.trim());
return commands[command](commandArguments[command]);
}
return commands.error('Event not specified');
}
/**
* Main Lambda function
*
* @param {object} event AWS Lambda uses this parameter to pass in event data to the handler.
* @param {object} context AWS Lambda uses this parameter to provide your handler the runtime information of the Lambda function that is executing.
*
* @return {object} Request Promise
*/
exports.handler = (event, context) => {
const processCommand = processCommands(event);
processCommand
.then((response) => {
context.succeed(response);
})
.catch((error) => {
context.fail({ text: error.message });
});
return processCommand;
};