diff --git a/lib/notification/adapter/apprise.js b/lib/notification/adapter/apprise.js new file mode 100644 index 0000000..1047d42 --- /dev/null +++ b/lib/notification/adapter/apprise.js @@ -0,0 +1,40 @@ +import { markdown2Html } from '../../services/markdown.js'; +import { getJob } from '../../services/storage/jobStorage.js'; +import fetch from 'node-fetch'; + +export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => { + const { priority, server } = notificationConfig.find((adapter) => adapter.id === config.id).fields; + const job = getJob(jobKey); + const jobName = job == null ? jobKey : job.name; + const promises = newListings.map((newListing) => { + const message = `Address: ${newListing.address}\nSize: ${newListing.size}\nPrice: ${newListing.price}\nURL: ${newListing.link}`; + return fetch(server, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + body: message, + title: newListing.title, + }), + }); + }); + + return Promise.all(promises); +}; +export const config = { + id: 'apprise', + name: 'Apprise', + readme: markdown2Html('lib/notification/adapter/apprise.md'), + description: 'Fredy will send new listings to your Apprise instance.', + fields: { + priority: { + type: 'number', + label: 'Priority', + description: 'The priority of the send notification.', + }, + server: { + type: 'text', + label: 'Server', + description: 'The server url to send the notification to.', + }, + }, +}; diff --git a/lib/notification/adapter/apprise.md b/lib/notification/adapter/apprise.md new file mode 100644 index 0000000..c744920 --- /dev/null +++ b/lib/notification/adapter/apprise.md @@ -0,0 +1,5 @@ +### Apprise Adapter + +Refer to the [instructions](https://github.com/caronc/apprise-api#installation) on how to set up an Apprise instance and how to configure your preferred notification service. + +In addition to the Apprise instance, the priority must be defined. \ No newline at end of file