-
Notifications
You must be signed in to change notification settings - Fork 394
/
app.ts
55 lines (49 loc) · 1.42 KB
/
app.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
/* eslint-disable no-console */
/* eslint-disable import/no-internal-modules */
import './utils/env';
import { App, LogLevel } from '@slack/bolt';
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
logLevel: LogLevel.DEBUG,
});
app.use(async ({ next }) => {
await next();
});
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// Filter out message events with subtypes (see https://api.slack.com/events/message)
if (message.subtype === undefined || message.subtype === 'bot_message') {
// say() sends a message to the channel where the event was triggered
await say({
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Hey there <@${message.user}>!`,
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Click Me',
},
action_id: 'button_click',
},
},
],
text: `Hey there <@${message.user}>!`,
});
}
});
app.action('button_click', async ({ body, ack, say }) => {
// Acknowledge the action
await ack();
await say(`<@${body.user.id}> clicked the button`);
});
(async () => {
// Start your app
await app.start(Number(process.env.PORT) || 3000);
console.log('⚡️ Bolt app is running!');
})();