-
Notifications
You must be signed in to change notification settings - Fork 18
/
app-oauth.js
70 lines (65 loc) · 2.33 KB
/
app-oauth.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
62
63
64
65
66
67
68
69
70
const { App, LogLevel } = require('@slack/bolt');
const { config } = require('dotenv');
const { registerListeners } = require('./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) {
return tempDB.set(installation.enterprise.id, installation);
}
// Single team installation
if (installation.team !== undefined) {
return tempDB.set(installation.team.id, installation);
}
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) {
return tempDB.delete(installQuery.enterpriseId);
}
// Single team installation deletion
if (installQuery.teamId !== undefined) {
return tempDB.delete(installQuery.teamId);
}
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);
}
})();