This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
73 lines (58 loc) · 2.32 KB
/
index.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
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
71
72
73
import { App } from '@slack/bolt'
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
})
const outOfContextChannelID = 'C01270P3XFV'
const outOfContextSandboxChannelID = 'C01JXGVB99U'
const neverPing = [
'U01LBQR5Y7Q', // Khushraj 1, for testing purposes
'U017EPB6LE9' // Hugo
]
app.event('message', async ({ event, client }: any) => {
if (
(event.channel === outOfContextChannelID
|| event.channel === outOfContextSandboxChannelID)
&& event.attachments && event.attachments[0].is_share && event.attachments[0].is_msg_unfurl
) {
const messageThreadMatch = event.attachments[0].from_url.match(/thread_ts=(.*)&/)
const inChannel = event.attachments[0].channel_id
const ts = messageThreadMatch ? messageThreadMatch[1].slice(0, -6) + '.' + messageThreadMatch[1].slice(-6) : event.attachments[0].ts
const outOfContexter = event.user
const outOfContexted = event.attachments[0].author_id
const response = await client.chat.getPermalink({
channel: event.channel,
message_ts: event.ts
})
const dontPingOOCed = neverPing.includes(outOfContexted)
const dontPingOOCer = neverPing.includes(outOfContexter)
const outOfContextedName = await (async () => {
const response = await client.users.info({
user: outOfContexted
})
return response.user.real_name as string
})()
const outOfContexterName = await (async () => {
const response = await client.users.info({
user: outOfContexter
})
return response.user.real_name as string
})()
await client.chat.postMessage({
channel: inChannel,
text:
(dontPingOOCed ? `${outOfContextedName}` : `<@${outOfContexted}>`)
+ ` was OOCed by `
+ (dontPingOOCer ? `${outOfContexterName}! ` : `<@${outOfContexter}>! `)
+ `${response.permalink}`,
thread_ts: ts,
unfurl_links: false,
unfurl_media: false
})
}
})
async function main() {
await app.start(process.env.PORT ? parseInt(process.env.PORT) : 3000)
console.log('⚡️ Bolt app is running!')
}
main()