Files
fredy/lib/notification/adapter/slack.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-01-20 20:23:27 +01:00
const Slack = require('slack');
const msg = Slack.chat.postMessage;
/**
* sends a new listing to slack
* @param serviceName e.g immoscout
* @param newListings an array with newly found listings
* @param notificationConfig config of this notification adapter
2020-07-17 16:34:10 +02:00
* * @param jobKey name of the current job that is being executed
2018-01-20 20:23:27 +01:00
* @returns {Promise<Chat.PostMessage.Response> | void}
*/
2020-07-17 16:34:10 +02:00
exports.send = (serviceName, newListings, notificationConfig, jobKey) => {
const { token, channel, enabled } = notificationConfig.slack;
if (!enabled) {
return [Promise.resolve()];
}
2020-07-17 16:34:10 +02:00
return newListings.map((payload) =>
msg({
token,
channel,
2020-07-17 16:34:10 +02:00
text: `*(${serviceName} - ${jobKey})* - ${payload.title}`,
attachments: [
{
fallback: payload.title,
color: '#36a64f',
title: 'Link to Exposé',
title_link: payload.link,
fields: [
{
title: 'Price',
value: payload.price,
2020-07-17 16:34:10 +02:00
short: false,
},
{
title: 'Size',
value: payload.size,
2020-07-17 16:34:10 +02:00
short: false,
},
{
title: 'Address',
value: payload.address,
2020-07-17 16:34:10 +02:00
short: false,
},
],
footer: 'Powered by Fredy',
2020-07-17 16:34:10 +02:00
ts: new Date().getTime() / 1000,
},
],
})
);
2018-01-20 20:23:27 +01:00
};