This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (68 loc) · 1.92 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { App } = require("@slack/bolt");
const express = require("express");
const databaseOps = require("./repositories/databaseOps");
const webserver = express();
webserver.get("/healthz", async (req, res) => {
const status_checks = {};
// Check Slack API
try {
const slack_api_status = await app.client.api.test();
if (slack_api_status.ok) {
status_checks.slack_api = "OK";
}
} catch (e) {
status_checks.slack_api = e.message;
}
// Check Slack Auth
try {
const slack_auth_status = await app.client.auth.test();
if (slack_auth_status.ok) {
status_checks.slack_auth = "OK";
}
} catch (e) {
status_checks.slack_auth = e.message;
}
status_checks.slack_websocket_connection = app.receiver.client.badConnection
? "Connection Failed"
: "OK";
// Check Database Connection
const pool = databaseOps.getPool();
const con = await pool.getConnection();
try {
con.ping();
status_checks.database = "OK";
} catch (err) {
status_checks.database = "DATABASE ERROR: " + err;
}
con.release();
for (const i in status_checks) {
if (status_checks[i] !== "OK") {
res.status(500).send(status_checks);
return;
}
}
res.send(status_checks);
});
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_USER_OAUTH_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
});
var normalizedPath = require("path").join(__dirname, "features");
require("fs")
.readdirSync(normalizedPath)
.forEach(function (file) {
require("./features/" + file)(app);
});
(async () => {
// Initialize the database
databaseOps.setupPool();
await databaseOps.setupDB();
console.log("Connected!");
// Start your app
await app.start();
webserver.listen(process.env.PORT || 3000);
console.log("⚡️ Bolt app is running!");
})();