-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
52 lines (40 loc) · 1.5 KB
/
server.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
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const helmet = require('helmet');
// Loggers
const morgan = require('morgan');
const winston = require('./config/winston');
// Slack SDK
const { WebClient } = require('@slack/web-api');
const { createEventAdapter } = require('@slack/events-api');
const { createMessageAdapter } = require('@slack/interactive-messages');
const app = express();
const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET);
const slackInteractions = createMessageAdapter(process.env.SLACK_SIGNING_SECRET);
const web = new WebClient(process.env.BOTS_TOKEN);
// Middlewares
app.use(helmet());
app.use(morgan('combined', { stream: winston.stream }));
// Listeners for Slack activities
app.use('/events', slackEvents.requestListener());
app.use('/actions', slackInteractions.requestListener());
// Register handlers for Slack activities
require('./slack/listeners/events')(slackEvents, web);
require('./slack/listeners/interactions')(slackInteractions, web);
require('./slack/listeners/slashCommands')(app, web);
app.get('/', (req, res) => res.send('Server is working'));
app.listen(process.env.PORT, () => {
mongoose.connect(process.env.MongoURI, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}, err => {
if(err) console.log(err);
})
.then(() => {
console.log('Database Ready!');
});
console.log(`Server is running on ${process.env.PORT}`);
});