2018-01-20 20:23:27 +01:00
|
|
|
const Slack = require('slack');
|
2018-01-21 10:47:17 +01:00
|
|
|
const config = require('../../../conf/config.json');
|
2018-01-20 20:23:27 +01:00
|
|
|
const msg = Slack.chat.postMessage;
|
|
|
|
|
|
|
|
|
|
const {token, channel} = config.notification.slack;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sends a new listing to slack
|
|
|
|
|
* @param serviceName e.g immoscout
|
2018-02-06 13:57:32 +01:00
|
|
|
* @param newListings an array with newly found listings
|
2018-01-20 20:23:27 +01:00
|
|
|
* @returns {Promise<Chat.PostMessage.Response> | void}
|
|
|
|
|
*/
|
2018-02-06 13:57:32 +01:00
|
|
|
exports.send = (serviceName, newListings) => {
|
|
|
|
|
return newListings.map(payload => msg({
|
2018-01-20 20:23:27 +01:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
]
|
2018-02-06 13:57:32 +01:00
|
|
|
})
|
2018-01-20 20:23:27 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* each integration needs to implement this method
|
|
|
|
|
*/
|
|
|
|
|
exports.enabled = () => {
|
2018-02-06 13:57:32 +01:00
|
|
|
return config.notification.slack.enabled;
|
2018-01-20 20:23:27 +01:00
|
|
|
};
|