Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (72 loc) · 2.02 KB
/
Copy pathindex.js
File metadata and controls
83 lines (72 loc) · 2.02 KB
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
82
83
import "dotenv/config";
import { App, SocketModeReceiver } from "@slack/bolt";
import { WebClient } from "@slack/web-api";
import { registerCommands } from "./lib/commands/index.js";
import { registerShortcuts } from "./lib/shortcuts/index.js";
import { registerListeners } from "./lib/listeners/index.js";
import { registerActions } from "./lib/actions/index.js";
import appHomeHandler, {
actions as homeActions,
views as homeViews,
} from "./lib/listeners/appHome.js";
import { startWebServer } from "./lib/web/server.js";
export const userClient = new WebClient(process.env.SLACK_USER_TOKEN);
let slackConnected = false;
const receiver = new SocketModeReceiver({
appToken: process.env.SLACK_APP_TOKEN,
});
receiver.client.on("connected", () => {
slackConnected = true;
});
receiver.client.on("close", () => {
slackConnected = false;
});
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
receiver,
});
app.use(async ({ context, next }) => {
context.userClient = userClient;
await next();
});
registerCommands(app);
registerShortcuts(app);
registerListeners(app);
registerActions(app);
app.event("app_home_opened", appHomeHandler);
// home tab actions
for (const h of homeActions) {
if (h.actionId) {
app.action(h.actionId, async (args) => {
await args.ack();
await h.execute(args);
});
} else if (h.pattern) {
app.action(h.pattern, async (args) => {
await args.ack();
await h.execute(args);
});
}
}
// home tab modal submissions
for (const v of homeViews) {
app.view(v.callbackId, async (args) => {
await args.ack();
await v.handleView(args);
});
}
(async () => {
const server = startWebServer({
botClient: app.client,
client: userClient,
isHealthy: () => slackConnected && receiver.client.websocket?.isActive(),
});
try {
await app.start();
console.log(`fire stolen, legs broken; web dashboard listening on ${server.url}`);
} catch (error) {
server.stop();
throw error;
}
})();