-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
48 lines (44 loc) · 1.55 KB
/
app.ts
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
import { App, ExpressReceiver, LogLevel } from '@slack/bolt';
import { registerHandlers } from './handlers';
import { config } from './lib/env';
import { PrismaClient } from "@prisma/client";
import { env } from 'process';
import { ConsoleLogger } from '@slack/logger';
// Globals
export const prisma = new PrismaClient();
export const logOps = new ConsoleLogger()
export const slackApp = new App({
token: config.slack.botToken,
appToken: config.slack.appToken,
signingSecret: config.slack.sigSecret,
logLevel: env.LOGOPS_DEBUG !== undefined ? LogLevel.DEBUG : LogLevel.INFO,
socketMode: config.slack.socketMode,
customRoutes: [
{
path: "/",
method: ["GET"],
handler(req, res) {
const redirect = "Redirecting to <a href='https://mau.dev/andreijiroh-dev/leeksbot'>https://mau.dev/andreijiroh-dev/leeksbot</a>"
res.writeHead(301, {
"content-length": Buffer.byteLength(redirect),
location: "https://mau.dev/andreijiroh-dev/leeksbot"
}).end(redirect)
},
}
]
});
registerHandlers(slackApp);
(async () => {
logOps.setLevel(env.LOGOPS_DEBUG !== undefined ? LogLevel.DEBUG : LogLevel.INFO)
logOps.setName("leeksbot")
try {
await slackApp.start(config.port);
await prisma.$connect()
logOps.info("slackAppBase", `⚡️ Bolt app now up and running`);
if (config.slack.socketMode !== true) logOps.info("API server now reachable at port", config.port)
} catch (error) {
console.error('Unable to start App', error);
await slackApp.stop()
await prisma.$disconnect()
}
})();