-
Notifications
You must be signed in to change notification settings - Fork 1
/
adapter.js
53 lines (45 loc) · 1.19 KB
/
adapter.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
require('dotenv').config()
const { SlackAdapter, SlackMessageTypeMiddleware, SlackEventMiddleware } = require('botbuilder-adapter-slack')
const { tokenCache, userCache } = require('./cache')
const getTokenForTeam = async (teamId) => {
if (tokenCache[teamId]) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(tokenCache[teamId])
}, 150)
})
}
return console.error('Team not found in tokenCache: ', teamId) // eslint-disable-line no-console
}
const getBotUserByTeam = async (teamId) => {
if (userCache[teamId]) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(userCache[teamId])
}, 150)
})
}
return console.error('Team not found in userCache: ', teamId) // eslint-disable-line no-console
}
const {
verificationToken,
clientSigningSecret,
botToken,
clientId,
clientSecret,
redirectUri,
} = process.env
const adapter = new SlackAdapter({
verificationToken,
clientSigningSecret,
botToken,
clientId,
clientSecret,
scopes: ['bot'],
redirectUri,
getTokenForTeam,
getBotUserByTeam,
})
adapter.use(new SlackEventMiddleware())
adapter.use(new SlackMessageTypeMiddleware())
module.exports = adapter