-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-lab-5.js
90 lines (86 loc) · 1.77 KB
/
app-lab-5.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
const { App } = require('@slack/bolt')
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
});
(async () => {
// Start your app
await app.start(process.env.PORT || 3000)
console.log('⚡️Hello World.. Bolt app is running!')
})()
// Custom unfurls
app.event('link_shared', async ({ event, context }) => {
console.log('got a link share event')
const unfurls = {}
event.links.forEach(async (link) => {
// let customText = `:wave: This is a custom unfurl of *url*=${link.url} *domain*=${link.domain}`;
const unfurlBlocks = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'This is a custom unfurl, made possible by calling the Slack `chat.unfurl` API'
}
},
{
type: 'divider'
},
{
type: 'section',
fields: [
{
type: 'mrkdwn',
text: `*Domain:*\n${link.domain}`
},
{
type: 'mrkdwn',
text: `*URL:*\n${link.url}`
}
]
},
{
type: 'divider'
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'Was this unfurl helpful?'
}
},
{
type: 'actions',
elements: [
{
type: 'button',
text: {
type: 'plain_text',
emoji: true,
text: 'Yes :100: '
},
style: 'primary',
value: 'yes_helpful'
},
{
type: 'button',
text: {
type: 'plain_text',
emoji: true,
text: 'Needs work :thumbsdown:'
},
style: 'danger',
value: 'no_needs_work'
}
]
}
]
unfurls[link.url] = { blocks: unfurlBlocks }
})
app.client.chat.unfurl({
token: process.env.SLACK_BOT_TOKEN,
channel: event.channel,
ts: event.message_ts,
unfurls: unfurls
})
})