-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
27 lines (26 loc) · 1.04 KB
/
index.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
const request = require('request');
module.exports = ({ config, host, app, events }) => {
return {
notify({ page_url }) {
events.on('new-comment', event => {
try {
const postUrl = page_url.replace('%SLUG%', event.slug) + '#comment-' + event.id;
const comment = event.comment
.split(/\n+/)
.map(s => (s ? `> _${s}_` : '>'))
.join('\n>\n');
const text = `A <${postUrl}|new comment> was posted by ${event.user
.display_name || event.user.name} under *${event.slug}*:\n\n${comment}`;
request({
url: config.webhook_url,
method: 'post',
json: true,
body: { text }
});
} catch (error) {
console.error('Error sending slack notification:', error);
}
});
}
};
};