-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack.js
58 lines (51 loc) · 1.69 KB
/
slack.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
{
const Slack = require('slack-node');
buildEventAttachment = (event) => {
return {
title: event.title,
title_link: event.details_url,
text: `Group: ${event.group}\nLocation: ${event.location}\nDate: ${event.date}\nTime: ${event.time}`
};
};
buildJobAttachment = (job) => {
return {
title: job.title,
title_link: job.url,
text: job.company
};
};
postNewEventsToSlack = (events) => {
_postToSlack(
'#events',
'One or more events were just added to http://dsmwebcollective.com/events!',
events.map((event) => buildEventAttachment(event)),
process.env.SLACK_USERNAME,
process.env.SLACK_EVENTS_WEBHOOK_URI);
};
postNewJobsToSlack = (jobs) => {
_postToSlack(
'#jobs',
'One or more jobs were just added to http://dsmwebcollective.com/jobs!',
jobs.map((job) => buildJobAttachment(job)),
process.env.SLACK_USERNAME,
process.env.SLACK_JOBS_WEBHOOK_URI)
};
_postToSlack = (channel, title, attachments, username, webhookUri) => {
slack = new Slack();
slack.setWebhook(webhookUri);
slack.webhook({
channel: channel,
username: username,
text: title,
attachments: attachments
}, (err, response) => {
if(err) throw err;
});
};
module.exports = {
postNewEventsToSlack: postNewEventsToSlack,
postNewJobsToSlack: postNewJobsToSlack,
buildEventAttachment: buildEventAttachment,
buildJobAttachment: buildJobAttachment
};
}