-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (60 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
62
63
64
65
66
67
68
69
require('dotenv').config()
const { App, ExpressReceiver } = require('@slack/bolt')
const standup = require('@core/chat/commands/standup')
const home = require('@core/views/home')
const setupJira = require('@core/views/modals/setup-jira')
const homeAuthenticated = require('@core/views/home_authenticated')
const {
EVENTS,
ACTIONS,
VIEWS,
COMMANDS,
SCOPES,
TEXT,
} = require('@root/constants')
const { getConnection } = require('@db')
const { storeInstallation, fetchInstallation } = require('@db/models/Auth')
const { v4: uuidv4 } = require('uuid')
const db = getConnection()
db.on('error', console.error.bind(console, TEXT.DB.MESSAGES.GENERIC_ERROR))
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: uuidv4(),
scopes: [
SCOPES.GROUPS,
SCOPES.CHANNELS,
SCOPES.CHAT,
SCOPES.COMMANDS,
SCOPES.WEBHOOK,
],
installationStore: {
storeInstallation: async installation => {
try {
return await storeInstallation(installation.team.id, installation)
} catch (e) {
console.log(e)
}
},
fetchInstallation: async ({ teamId }) => {
try {
return await fetchInstallation(teamId)
} catch (e) {
console.log(e)
}
},
},
})
try {
const app = new App({
receiver: expressReceiver,
})
app.command(COMMANDS.STANDUP, standup(app))
app.event(EVENTS.APP_HOME_VIEWED, home(app))
app.action(ACTIONS.OPEN_SETUP_JIRA_MODAL, setupJira(app))
app.view(VIEWS.HOME_AUTHENTICATED_VIEW, homeAuthenticated(app))
} catch (e) {
console.error(e)
}
module.exports = expressReceiver