Skip to content

Commit

Permalink
Add Apprise notification adapter (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomeloy authored Mar 13, 2024
1 parent f5917af commit fd42b57
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/notification/adapter/apprise.js
Original file line number Diff line number Diff line change
@@ -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.',
},
},
};
5 changes: 5 additions & 0 deletions lib/notification/adapter/apprise.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit fd42b57

Please sign in to comment.