feat: auto-disable store after notification and improve ntfy payloads

This commit is contained in:
2025-11-09 21:25:50 +01:00
parent 7b1e4a1f03
commit e12bba63b9
2 changed files with 50 additions and 8 deletions

View File

@@ -33,7 +33,8 @@ async function sendNtfyNotification(adminNtfy, userNtfy, payload) {
const url = `${server}/${topic}`;
const headers = {
Title: payload.title,
Priority: payload.priority || 'default'
Priority: payload.priority || 'default',
'Content-Type': 'text/plain; charset=utf-8'
};
if (adminNtfy.username && adminNtfy.password) {
const credentials = Buffer.from(`${adminNtfy.username}:${adminNtfy.password}`).toString('base64');
@@ -51,8 +52,8 @@ async function sendTelegramNotification(adminTelegram, userTelegram, payload) {
endpoint,
{
chat_id: userTelegram.chatId,
text: `${payload.title}\n${payload.message}`,
disable_web_page_preview: true
text: payload.message,
disable_web_page_preview: false
},
{ timeout: 15000 }
);
@@ -71,22 +72,25 @@ async function notifyChannels(profileId, template) {
}
}
async function sendSlotNotification({ profileId, storeName, pickupDate, onlyNotify, booked }) {
async function sendSlotNotification({ profileId, storeName, pickupDate, onlyNotify, booked, storeId }) {
const dateLabel = formatDateLabel(pickupDate);
const title = onlyNotify
? `Slot verfügbar bei ${storeName}`
: booked
? `Slot gebucht bei ${storeName}`
: `Slot gefunden bei ${storeName}`;
const message = onlyNotify
const baseMessage = onlyNotify
? `Es wurde ein freier Slot am ${dateLabel} entdeckt.`
: booked
? `Der Slot am ${dateLabel} wurde erfolgreich gebucht.`
: `Es wurde ein Slot am ${dateLabel} gefunden.`;
const storeLink = storeId ? `https://foodsharing.de/store/${storeId}` : null;
const fullMessage = storeLink ? `${title}\n${baseMessage}\n${storeLink}` : `${title}\n${baseMessage}`;
await notifyChannels(profileId, {
title,
message,
message: fullMessage,
link: storeLink,
priority: booked ? 'high' : 'default'
});
}