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

59 lines
1.6 KiB
JavaScript
Raw Normal View History

import Slack from 'slack';
import { markdown2Html } from '../../services/markdown.js';
2018-01-20 20:23:27 +01:00
const msg = Slack.chat.postMessage;
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
2023-09-27 17:45:38 +02:00
const { token, channel } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
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,
},
],
2023-09-27 17:45:38 +02:00
}),
);
2018-01-20 20:23:27 +01:00
};
export const config = {
id: 'slack',
name: 'Slack',
readme: markdown2Html('lib/notification/adapter/slack.md'),
description: 'Fredy will send new listings to the slack channel of your choice..',
fields: {
token: {
type: 'text',
label: 'Token',
description: 'The token needed to send notifications to slack.',
},
channel: {
type: 'channel',
label: 'Channel',
description: 'The channel where fredy should send notifications to.',
},
},
};