2025-12-11 10:40:55 +01:00
|
|
|
/*
|
2026-01-12 15:00:36 +01:00
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
2025-12-11 10:40:55 +01:00
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-03-13 15:05:12 +01:00
|
|
|
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 }) => {
|
2024-03-27 11:19:14 +01:00
|
|
|
const { server } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
|
2024-03-13 15:05:12 +01:00
|
|
|
const job = getJob(jobKey);
|
|
|
|
|
const jobName = job == null ? jobKey : job.name;
|
|
|
|
|
const promises = newListings.map((newListing) => {
|
2024-03-17 08:02:02 +01:00
|
|
|
const title = `${jobName} at ${serviceName}: ${newListing.title}`;
|
2025-09-27 18:07:48 +02:00
|
|
|
const message = `Address: ${newListing.address}\nSize: ${newListing.size}\nPrice: ${newListing.price}\nLink: ${newListing.link}`;
|
2024-03-13 15:05:12 +01:00
|
|
|
return fetch(server, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
body: message,
|
2024-03-17 08:02:02 +01:00
|
|
|
title: title,
|
2024-03-13 15:05:12 +01:00
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
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: {
|
|
|
|
|
server: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
label: 'Server',
|
2024-03-27 11:19:14 +01:00
|
|
|
description: 'The server URL to send the notification to.',
|
2024-03-13 15:05:12 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|