-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
42 lines (38 loc) · 1.07 KB
/
app.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
if (!process.env.SLACK_TOKEN) {
console.log('Error: Specify token in environment');
process.exit(1);
}
const { controller } = require('./lib/controller');
const commands = require('./lib/commands');
const commBase = './lib/commands/';
const server = require('./lib/server');
const config = require('./config');
const port = (process.env.PORT || config.SERVER_PORT);
const express = require('express');
const bodyParser = require('body-parser');
//Load all commands
commands.forEach(command => {
controller.hears(command.patterns, command.scope, require(commBase + command.handler));
});
//Start webserver
const webserver = express();
webserver.use(bodyParser.json());
webserver.use(bodyParser.urlencoded({ extended: true }));
webserver.listen(port, () => {
console.log(`Listening on port ${port}`);
server(webserver);
});
/**
* Message structure
*
{
type: 'message',
channel: 'D1CFPCPL4',
user: 'U0JNTST1Q',
text: 'hi there',
ts: '1464458078.000012',
team: 'T03J4B99C',
event: 'direct_message',
match: [ 'hi', index: 0, input: 'hi there' ]
}
*/