-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (53 loc) · 1.55 KB
/
index.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
const channel = process.env.SLACK_CHANNEL;
const token = process.env.SLACK_TOKEN;
const signingSecret = process.env.SLACK_SIGNING_SECRET;
if (!channel) {
console.error('Set the channel using the SLACK_CHANNEL env var');
process.exit(1);
}
if (!token) {
console.error('Set the token using the SLACK_TOKEN env var');
process.exit(1);
}
if (!signingSecret) {
console.error('Set the signing secret using the SLACK_SIGNING_SECRET env var');
process.exit(1);
}
const { App } = require('@slack/bolt');
const app = new App({
token,
signingSecret,
});
(async () => {
await app.start(process.env.PORT || 3000);
console.log(`connected, listening on port ${process.env.PORT || 3000}`);
app.event('emoji_changed', async ({ event, context}) => {
try {
console.log(`got: ${JSON.stringify(event)}`);
const action = event.subtype == 'add' ? ':heavy_plus_sign: ' : ':heavy_minus_sign: ';
let emojis = [];
event.name && emojis.push(event.name);
event.names && emojis.push(...event.names);
let text = `${action} ` + emojis.map(e => `:${e}:`).join(' ')
console.log(`posting message: ${text}`);
let result = await app.client.chat.postMessage({
token,
channel,
text,
mrkdwn: true,
})
console.log(event.subtype, emojis)
// send emoji names in a separate message
text = emojis.map(e => `:${e}: \`:${e}:\``).join("\n")
console.log(`posting message: ${text}`);
await app.client.chat.postMessage({
token,
channel,
text,
mrkdwn: true,
})
} catch (error) {
console.error(error)
}
});
})();