This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (54 loc) · 1.7 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
require("dotenv").config();
const debug = require("debug")("starterbot:main");
const { App } = require("@slack/bolt");
const MainMenuBlock = require("./visuals/blocks/mainMenuBlock");
const ActionHandler = require("./actions/handlers/blockActionHandler");
const successHandler = require("./actions/handlers/modalSubmissionHandler");
// Define socket connection (no external site needed)
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
});
// Capture all messages and respond with main modal
app.message(/[^]*/, async ({ message, say }) => {
debug("main block shown");
await say(MainMenuBlock.getBlock());
});
// Capture the modal submit event and pass data to handler
app.view({ type: "view_submission" }, async ({ ack, body, view, client }) =>
successHandler.handleSuccess({ ack, body, view, client })
);
// Capture modal closes (NOT NEEDED CURRENTLY BUT MIGHT BE USEFUL)
app.view({ type: "view_closed" }, async ({ ack, body, view, client, say }) => {
await ack();
debug("modal closed");
});
// Send all actions to action handler
app.action(/[^]*/, async ({ action, ack, respond, context, body, client }) =>
ActionHandler.handleActions({
action,
ack,
respond,
context,
body,
client,
})
);
// Catch all errors
app.error((error) => {
if (process.env.NODE_ENV === "production") {
console.log("Uncaught error: ", error);
} else {
debug("Uncaught error: ", error);
}
});
// Start the app and get user profiles
(async () => {
await app.start(process.env.PORT || 3000);
if (process.env.NODE_ENV === "production") {
console.log("Slack bot is running!");
} else {
debug("Slack bot is running!");
}
})();