-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·59 lines (50 loc) · 1.91 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
#!/usr/bin/env node
require('dotenv').config()
const { App } = require('@slack/bolt');
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3000
});
app.message('hello', async ({ message, say }) => {
await say(`Hey there <@${message.user}>!`);
});
app.command('/admin', async ({ command, ack, client, respond, logger }) => {
await ack();
try {
await client.chat.postMessage({
text: `Incoming message for admins from <@${command.user_name}> in <#${command.channel_name}>:\n${command.text}`,
channel: "admin"
});
await respond(`The admins have been messaged, <@${command.user_name}>`);
}
catch (error) {
await respond(`Something went wrong!\n${error}`);
}
})
app.command('/list_private', async ({ command, ack, client, respond }) => {
await ack();
try {
const private_channel_ls = await client.conversations.list({ types: "private_channel" });
const channel_names = private_channel_ls.channels.filter(e => e.name != "admin").map(e => `- ${e.name}`)
await respond(`Current private channels:\n${channel_names.join('\n')}\nUse \`/join_private\` to request membership.`)
}
catch (error) {
await respond(`Something went wrong!\n${error}`);
}
})
app.command('/join_private', async ({ command, ack, client, respond }) => {
await ack();
try {
await client.chat.postMessage({
text: `<@${command.user_name}> wishes to join this channel. Use \`/invite <@${command.user_name}>\` to let them in`,
channel: command.text
})
await respond(`The channel have been messaged, <@${command.user_name}>, your invitation is being reviewed.`);
}
catch (error) {
await respond(`Something went wrong!\n${error}`);
}
})
app.start()