-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.js
34 lines (28 loc) · 867 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
'use strict';
var qs = require('querystring');
var slackToken = require('./configs/slack_token').slackToken;
var Autobot = require('./main/autobot');
module.exports.slack = function(event, context, callback) {
var statusCode, text;
var body = event.body;
var params = qs.parse(body);
var requestToken = params.token;
var success = function(result) {
var response = {
statusCode: 200,
body: JSON.stringify(result)
};
callback(null, response);
};
var failure = function(err) {
context.fail(err);
};
if (requestToken !== slackToken) {
console.error("Request token (%s) does not match exptected", requestToken);
context.fail("Invalid request token");
callback("Invalid request token");
} else {
var autobot = new Autobot('slack');
autobot.receive(params.text).then(success, failure);
}
};