feat: add ntfy and telegram notification workflows
This commit is contained in:
@@ -2,6 +2,7 @@ const cron = require('node-cron');
|
||||
const foodsharingClient = require('./foodsharingClient');
|
||||
const sessionStore = require('./sessionStore');
|
||||
const { DEFAULT_SETTINGS } = require('./adminConfig');
|
||||
const notificationService = require('./notificationService');
|
||||
|
||||
const weekdayMap = {
|
||||
Montag: 'Monday',
|
||||
@@ -37,7 +38,20 @@ function resolveSettings(settings) {
|
||||
initialDelayMaxSeconds: Number.isFinite(settings.initialDelayMaxSeconds)
|
||||
? settings.initialDelayMaxSeconds
|
||||
: DEFAULT_SETTINGS.initialDelayMaxSeconds,
|
||||
ignoredSlots: Array.isArray(settings.ignoredSlots) ? settings.ignoredSlots : DEFAULT_SETTINGS.ignoredSlots
|
||||
ignoredSlots: Array.isArray(settings.ignoredSlots) ? settings.ignoredSlots : DEFAULT_SETTINGS.ignoredSlots,
|
||||
notifications: {
|
||||
ntfy: {
|
||||
enabled: !!settings.notifications?.ntfy?.enabled,
|
||||
serverUrl: settings.notifications?.ntfy?.serverUrl || DEFAULT_SETTINGS.notifications.ntfy.serverUrl,
|
||||
topicPrefix: settings.notifications?.ntfy?.topicPrefix || DEFAULT_SETTINGS.notifications.ntfy.topicPrefix,
|
||||
username: settings.notifications?.ntfy?.username || DEFAULT_SETTINGS.notifications.ntfy.username,
|
||||
password: settings.notifications?.ntfy?.password || DEFAULT_SETTINGS.notifications.ntfy.password
|
||||
},
|
||||
telegram: {
|
||||
enabled: !!settings.notifications?.telegram?.enabled,
|
||||
botToken: settings.notifications?.telegram?.botToken || DEFAULT_SETTINGS.notifications.telegram.botToken
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -147,6 +161,13 @@ async function processBooking(session, entry, pickup) {
|
||||
|
||||
if (entry.onlyNotify) {
|
||||
console.log(`[INFO] Slot gefunden (nur Hinweis) für ${storeName} am ${readableDate}`);
|
||||
await notificationService.sendSlotNotification({
|
||||
profileId: session.profile.id,
|
||||
storeName,
|
||||
pickupDate: pickup.date,
|
||||
onlyNotify: true,
|
||||
booked: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,6 +180,13 @@ async function processBooking(session, entry, pickup) {
|
||||
}
|
||||
await foodsharingClient.bookSlot(entry.id, utcDate, session.profile.id, session);
|
||||
console.log(`[SUCCESS] Slot gebucht für ${storeName} am ${readableDate}`);
|
||||
await notificationService.sendSlotNotification({
|
||||
profileId: session.profile.id,
|
||||
storeName,
|
||||
pickupDate: pickup.date,
|
||||
onlyNotify: false,
|
||||
booked: true
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[ERROR] Buchung für ${storeName} am ${readableDate} fehlgeschlagen:`, error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user