mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Release v1.0.0 🎉
This commit is contained in:
18
lib/notification/adapter/console.js
Executable file
18
lib/notification/adapter/console.js
Executable file
@@ -0,0 +1,18 @@
|
||||
const config = require('../../../conf/config.json');
|
||||
|
||||
/**
|
||||
* simply prints out the found data to the console
|
||||
* @param serviceName e.g immoscout
|
||||
* @param payload the actual payload that is used to construct the message
|
||||
* @returns {Promise<Void> | void}
|
||||
*/
|
||||
exports.send = (serviceName, payload) => {
|
||||
return Promise.resolve(console.info(`Found entry from service ${serviceName}:`, payload))
|
||||
};
|
||||
|
||||
/**
|
||||
* each integration needs to implement this method
|
||||
*/
|
||||
exports.enabled = () => {
|
||||
return config.notification.console.enabled;
|
||||
};
|
||||
54
lib/notification/adapter/slack.js
Executable file
54
lib/notification/adapter/slack.js
Executable file
@@ -0,0 +1,54 @@
|
||||
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 payload the actual payload that is used to construct the message
|
||||
* @returns {Promise<Chat.PostMessage.Response> | void}
|
||||
*/
|
||||
exports.send = (serviceName, payload) => {
|
||||
return 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;
|
||||
};
|
||||
17
lib/notification/notify.js
Executable file
17
lib/notification/notify.js
Executable file
@@ -0,0 +1,17 @@
|
||||
const fs = require('fs');
|
||||
const path = './adapter';
|
||||
|
||||
/** Read every integration existing in ./adapter **/
|
||||
const adapter = fs
|
||||
.readdirSync('./lib/notification/adapter')
|
||||
.map(integPath => require(`${path}/${integPath}`))
|
||||
.filter(integration => integration.enabled());
|
||||
|
||||
if (adapter.length === 0) {
|
||||
throw new Error('Please specify at least one notification provider');
|
||||
}
|
||||
|
||||
exports.send = (serviceName, payload) => {
|
||||
//this is not being used in tests, therefor adapter are always set
|
||||
return adapter.map(a => a.send(serviceName, payload));
|
||||
};
|
||||
Reference in New Issue
Block a user