-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
60 lines (57 loc) · 1.88 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
const { App, LogLevel } = require('@slack/bolt');
const { registerListeners } = require('./listeners');
const orgInstall = require('./database/auth/store_user_org_install');
const workspaceAuth = require('./database/auth/store_user_workspace_install');
const db = require('./database/db');
const dbQuery = require('./database/find_user');
const customRoutes = require('./utils/custom_routes');
const app = new App({
logLevel: LogLevel.DEBUG,
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: 'horea-is-a-human',
customRoutes: customRoutes.customRoutes,
installerOptions: {
stateVerification: false,
},
installationStore: {
storeInstallation: async (installation) => {
if (
installation.isEnterpriseInstall
&& installation.enterprise !== undefined
) {
return orgInstall.saveUserOrgInstall(installation);
}
if (installation.team !== undefined) {
return workspaceAuth.saveUserWorkspaceInstall(installation);
}
throw new Error('Failed saving installation data to installationStore');
},
fetchInstallation: async (installQuery) => {
if (
installQuery.isEnterpriseInstall
&& installQuery.enterpriseId !== undefined
) {
return dbQuery.findUser(installQuery.enterpriseId);
}
if (installQuery.teamId !== undefined) {
return dbQuery.findUser(installQuery.teamId);
}
throw new Error('Failed fetching installation');
},
},
});
/** Register Listeners */
registerListeners(app);
/** Start Bolt App */
(async () => {
try {
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running! ⚡️');
db.connect();
console.log('DB is connected.');
} catch (error) {
console.error('Unable to start App', error);
}
})();