mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Concurrent-Jobs (#7)
Fredy 2.0.0 introduces the concept of search jobs. You can now configure multiple of these jobs running in the same instance of Fredy. Also a new API has been created 🎉
This commit is contained in:
committed by
GitHub
parent
52a32f7453
commit
770d30af95
@@ -1,54 +1,50 @@
|
||||
const Slack = require('slack');
|
||||
const config = require('../../../conf/config.json');
|
||||
const msg = Slack.chat.postMessage;
|
||||
|
||||
const {token, channel} = config.notification.slack;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @returns {Promise<Chat.PostMessage.Response> | void}
|
||||
*/
|
||||
exports.send = (serviceName, newListings) => {
|
||||
return newListings.map(payload => msg({
|
||||
token,
|
||||
channel,
|
||||
text: `*(${serviceName})* - ${payload.title}`,
|
||||
"attachments": [
|
||||
{
|
||||
"fallback": payload.title,
|
||||
"color": "#36a64f",
|
||||
"title": "Link to Exposé",
|
||||
"title_link": payload.link,
|
||||
"fields": [
|
||||
{
|
||||
"title": "Price",
|
||||
"value": payload.price,
|
||||
"short": false
|
||||
},
|
||||
{
|
||||
"title": "Size",
|
||||
"value": payload.size,
|
||||
"short": false
|
||||
},
|
||||
{
|
||||
"title": "Address",
|
||||
"value": payload.address,
|
||||
"short": false
|
||||
}
|
||||
],
|
||||
"footer": "Powered by Fredy",
|
||||
ts: new Date().getTime() / 1000
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* each integration needs to implement this method
|
||||
*/
|
||||
exports.enabled = () => {
|
||||
return config.notification.slack.enabled;
|
||||
exports.send = (serviceName, newListings, notificationConfig) => {
|
||||
const { token, channel, enabled } = notificationConfig.slack;
|
||||
if (!enabled) {
|
||||
return [Promise.resolve()];
|
||||
}
|
||||
return newListings.map(payload =>
|
||||
msg({
|
||||
token,
|
||||
channel,
|
||||
text: `*(${serviceName})* - ${payload.title}`,
|
||||
attachments: [
|
||||
{
|
||||
fallback: payload.title,
|
||||
color: '#36a64f',
|
||||
title: 'Link to Exposé',
|
||||
title_link: payload.link,
|
||||
fields: [
|
||||
{
|
||||
title: 'Price',
|
||||
value: payload.price,
|
||||
short: false
|
||||
},
|
||||
{
|
||||
title: 'Size',
|
||||
value: payload.size,
|
||||
short: false
|
||||
},
|
||||
{
|
||||
title: 'Address',
|
||||
value: payload.address,
|
||||
short: false
|
||||
}
|
||||
],
|
||||
footer: 'Powered by Fredy',
|
||||
ts: new Date().getTime() / 1000
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user