-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (58 loc) · 2.16 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
70
71
72
const { App, subtype } = require('@slack/bolt');
require('dotenv').config();
const NIGEN_URI = process.env.NIGEN_URI
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3000
});
(async () => {
await app.start();
console.log('⚡️ Bolt app is running!');
})();
app.message(/(hello|hi|hey)/i, async ({ message, say }) => {
console.log("[LOG] I am being greated by", message.username)
console.log(message)
await say(`Wassup, <@${message.user}>`);
})
// Snitching on deleted messages
app.message(subtype('message_deleted'), async ({ message, say }) => {
const user = await getUserInfo(message.previous_message.user)
const userInfo = {
name: user ? user.profile.display_name : undefined,
avatar: user ? user.profile.image_72 : undefined,
id: user ? user.id : undefined,
locale: user ? user.locale : undefined,
}
console.log({tz: user.tz, message_ts: message.previous_message.ts})
const compositionDate = new Date(Number(Math.floor(message.previous_message.ts) * 1000)).toLocaleString('en-US', {
timeZone: user.tz,
hour: 'numeric',
minute: 'numeric',
hour12: true
})
const thread_ts = message.previous_message.thread_ts ?? message.previous_message.ts
const reply = await say({
text: `<!channel>, <@${message.previous_message.user}> deleted their message!`,
thread_ts,
})
const screenshotURI = `${NIGEN_URI}?message=${encodeURI(message.previous_message.text)}&username=${encodeURI(userInfo.name)}&time=${encodeURI(compositionDate)}&avatar=${userInfo.avatar}`
await say({
text: ``,
thread_ts: reply.ts,
attachments: [
{
fallback: "Removed message info",
image_url: screenshotURI,
thumb_url: screenshotURI,
text: 'screenshot',
}
]
})
console.log(screenshotURI)
})
async function getUserInfo(userId) {
return (await app.client.users.info({ user: userId })).user ?? null
}