-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-oauth.ts
74 lines (69 loc) · 2.34 KB
/
app-oauth.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
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
import { App, LogLevel } from '@slack/bolt';
import { config } from 'dotenv';
import registerListeners from './listeners';
config();
// For development purposes only
const tempDB = new Map();
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: 'my-state-secret',
scopes: ['channels:history', 'chat:write', 'commands'],
installationStore: {
storeInstallation: async (installation) => {
// Org-wide installation
if (installation.isEnterpriseInstall && installation.enterprise !== undefined) {
tempDB.set(installation.enterprise.id, installation);
return;
}
// Single team installation
if (installation.team !== undefined) {
tempDB.set(installation.team.id, installation);
return;
}
throw new Error('Failed saving installation data to installationStore');
},
fetchInstallation: async (installQuery) => {
// Org-wide installation lookup
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) {
return tempDB.get(installQuery.enterpriseId);
}
// Single team installation lookup
if (installQuery.teamId !== undefined) {
return tempDB.get(installQuery.teamId);
}
throw new Error('Failed fetching installation');
},
deleteInstallation: async (installQuery) => {
// Org-wide installation deletion
if (installQuery.isEnterpriseInstall && installQuery.enterpriseId !== undefined) {
tempDB.delete(installQuery.enterpriseId);
return;
}
// Single team installation deletion
if (installQuery.teamId !== undefined) {
tempDB.delete(installQuery.teamId);
return;
}
throw new Error('Failed to delete installation');
},
},
installerOptions: {
// If true, /slack/install redirects installers to the Slack Authorize URL
// without rendering the web page with "Add to Slack" button
directInstall: false,
},
});
/** Register Listeners */
registerListeners(app);
/** Start Bolt App */
(async () => {
try {
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running! ⚡️');
} catch (error) {
console.error('Unable to start App', error);
}
})();