From fd42b57010662fe46b36752159fa34e31968f811 Mon Sep 17 00:00:00 2001 From: pomeloy <45542782+pomeloy@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:05:12 +0100 Subject: [PATCH] Add Apprise notification adapter (#92) --- lib/notification/adapter/apprise.js | 40 +++++++++++++++++++++++++++++ lib/notification/adapter/apprise.md | 5 ++++ 2 files changed, 45 insertions(+) create mode 100644 lib/notification/adapter/apprise.js create mode 100644 lib/notification/adapter/apprise.md 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