This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (34 loc) · 1.27 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
const express = require('express');
const request = require('request');
const bodyParser = require('body-parser');
const config = require('./config');
const app = express()
const port = config.port;
const slackSecret = config.slack.secret;
const slackToken = config.slack.verificationToken;
const workspaceToken = config.slack.workspaceToken;
function verifiyToken(token) {
if (token !== slackToken) {
console.error('Token received does not match the token provided by Slack.')
return false;
}
return true;
}
app.use(bodyParser.json());
app.post('/log', (req, res) => {
console.log(`Received logging call of type ${req.body.type} || Token Status: ${req.body.token === slackToken}`);
if (!verifiyToken(req.body.token)) return;
if (req.body.type === 'url_verification') {
console.log("Responding to Slack's Events URL verification request.");
res.json({ challenge: req.body.challenge });
}
else if (req.body.type === 'event_callback') {
res.sendStatus(200);
let event = req.body.event;
console.log(`Received ${event.type} event.`);
if (event.type === 'message') {
console.log(`${event.user} in the ${event.channel} ${event.channel_type} said ${event.text}`);
}
}
});
app.listen(port, () => console.log(`App listening on port ${port}!`))