-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathslack.coffee
53 lines (46 loc) · 1.03 KB
/
slack.coffee
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
{
SLACK_WEBHOOK = 'https://slack.com/api/api.test'
SLACK_CHANNEL = '#events'
} = process.env
axios = require 'axios'
#
# Helpers
#
slack_payload = (events, title)->
channel: SLACK_CHANNEL
username: 'TorontoJS EventBot™'
blocks: slack_blocks events, title
# https://api.slack.com/tools/block-kit-builder
slack_section = (evt)->
ret =
type: 'section'
text:
type: 'mrkdwn'
text: evt.slack_description
if evt.url
ret.accessory =
type: 'button'
text:
type: 'plain_text'
text: 'Learn More'
emoji: true
url: evt.url
ret
slack_blocks = (events, title)->
blocks = [
type: 'section'
text:
type: 'mrkdwn'
text: "*#{title}*"
]
for evt, idx in events
blocks.push type: 'divider' if idx
blocks.push slack_section evt
blocks
post_to_slack = (payload)->
console.log "posting to Slack", "URL length: #{SLACK_WEBHOOK.length}", "Payload: #{payload}"
axios.post SLACK_WEBHOOK, payload
module.exports = {
slack_payload
post_to_slack
}