-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.js
36 lines (30 loc) · 1.05 KB
/
install.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
const db = require('./db')
const slack = require('./slack')
const { WebClient } = require('@slack/web-api')
module.exports = async code => {
if (code === undefined) {
throw new Error('OAuth code must be defined!')
}
const clientId = process.env.SLACK_CLIENT_ID
const clientSecret = process.env.SLACK_CLIENT_SECRET
// Use code to get the real OAuth token.
const result = await (new WebClient()).oauth.v2.access({
client_id: clientId,
client_secret: clientSecret,
redirect_uri: process.env.SLACK_REDIRECT_URI,
code
})
// Store stuff in database.
const instance = await db.installInstance({
accessToken: result.access_token,
scope: result.scope,
botUserId: result.bot_user_id,
appId: result.app_id,
team: result.team,
authedUser: result.authed_user
})
// tell user how configuration should be done by sending an IM to the installing user.
await slack.sendImToUser(instance, instance.authedUser.id, {
text: "Hi! I'm wildbutton! To configure me, visit my Home tab under Apps in the menu bar."
})
}