-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
91 lines (85 loc) · 2.03 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// @ts-nocheck
// Require the Bolt package (github.com/slackapi/bolt)
const { App } = require('@slack/bolt')
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
})
// All the room in the world for your code
app.event('app_home_opened', async ({ event, client, context }) => {
try {
/* view.publish is the method that your app uses to push a view to the Home tab */
const result = await client.views.publish({
/* the user that opened your app's app home */
user_id: event.user,
/* the view object that appears in the app home*/
view: {
type: 'home',
callback_id: 'home_view',
/* body of the view */
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: "*Welcome to your _App's Home_* :tada:",
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: "This button won't do much for now but you can set up a listener for it using the `actions()` method and passing its unique `action_id`. See an example in the `examples` folder within your Bolt app.",
},
},
{
type: 'actions',
elements: [
{
type: 'button',
text: {
type: 'plain_text',
text: 'Click me!',
},
},
],
},
],
},
})
} catch (error) {
console.error(error)
}
})
// Listens to incoming messages that contain "hello"
app.message('hello', async ({ message, say }) => {
// 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}>!`,
})
})
;(async () => {
// Start your app
await app.start(process.env.PORT || 3000)
console.log('⚡️ Bolt app is running!')
})()