-
Notifications
You must be signed in to change notification settings - Fork 5
/
express.ts
45 lines (36 loc) · 1.46 KB
/
express.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
import * as express from "express"
import * as bodyParser from "body-parser"
import { SlackConnector } from "botbuilder-slack"
import { createBot, BotCache } from "./bot"
const port = process.env.PORT || 3000
const botsCache: BotCache = {}
const connectorSettings = {
botLookup: (teamId: string) => {
const botEntry = botsCache[teamId]
if (botEntry) {
return Promise.resolve([botEntry.token, botEntry.identity.id] as [string, string])
} else {
return Promise.reject(new Error('Bot not found'))
}
},
botName: process.env.SLACK_BOT_NAME,
verificationToken: process.env.SLACK_VERIFICATION_TOKEN,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
redirectUrl: process.env.SLACK_OAUTH_REDIRECT_URL,
onOAuthSuccessRedirectUrl: process.env.SLACK_OAUTH_ON_SUCCESS_REDIRECT_URL,
onOAuthErrorRedirectUrl: process.env.SLACK_OAUTH_ON_ERROR_REDIRECT_URL,
onOAuthAccessDeniedRedirectUrl: process.env.SLACK_OAUTH_ON_ACCESS_DENIED_REDIRECT_URL
}
const connector = new SlackConnector(connectorSettings)
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded())
app.listen(port, () => {
console.log(`Bot is listening on port ${port}`)
})
app.post('/slack/events', connector.listenEvents())
app.post('/slack/interactive', connector.listenInteractiveMessages())
app.post('/slack/command', connector.listenCommands())
app.get('/slack/oauth', connector.listenOAuth())
createBot(connector, botsCache)