aktueller stand
This commit is contained in:
@@ -37,6 +37,23 @@ function formatDateOnly(dateInput) {
|
||||
}
|
||||
}
|
||||
|
||||
function extractFirstName(profileName) {
|
||||
if (!profileName || typeof profileName !== 'string') {
|
||||
return null;
|
||||
}
|
||||
const trimmed = profileName.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
if (trimmed.includes(',')) {
|
||||
const parts = trimmed.split(',').map((part) => part.trim()).filter(Boolean);
|
||||
if (parts.length > 1) {
|
||||
return parts[1].split(/\s+/)[0] || null;
|
||||
}
|
||||
}
|
||||
return trimmed.split(/\s+/)[0] || null;
|
||||
}
|
||||
|
||||
async function sendNtfyNotification(adminNtfy, userNtfy, payload) {
|
||||
if (!adminNtfy?.enabled || !userNtfy?.enabled || !userNtfy.topic) {
|
||||
return;
|
||||
@@ -66,12 +83,18 @@ async function sendTelegramNotification(adminTelegram, userTelegram, payload) {
|
||||
return;
|
||||
}
|
||||
const endpoint = `https://api.telegram.org/bot${adminTelegram.botToken}/sendMessage`;
|
||||
const profileLabel = extractFirstName(payload?.profileName);
|
||||
const messageParts = [
|
||||
payload?.title ? `*${payload.title}*` : null,
|
||||
profileLabel ? `Profil: ${profileLabel}` : null,
|
||||
payload?.message || null
|
||||
].filter(Boolean);
|
||||
await axios.post(
|
||||
endpoint,
|
||||
{
|
||||
chat_id: userTelegram.chatId,
|
||||
text: payload.title ? `*${payload.title}*\n${payload.message}` : payload.message,
|
||||
parse_mode: payload.title ? 'Markdown' : undefined,
|
||||
text: messageParts.join('\n'),
|
||||
parse_mode: payload?.title ? 'Markdown' : undefined,
|
||||
disable_web_page_preview: true
|
||||
},
|
||||
{ timeout: 15000 }
|
||||
@@ -104,7 +127,7 @@ async function notifyChannels(profileId, template) {
|
||||
}
|
||||
}
|
||||
|
||||
async function sendSlotNotification({ profileId, storeName, pickupDate, onlyNotify, booked, storeId }) {
|
||||
async function sendSlotNotification({ profileId, profileName, storeName, pickupDate, onlyNotify, booked, storeId }) {
|
||||
const dateLabel = formatDateLabel(pickupDate);
|
||||
const title = onlyNotify
|
||||
? `Slot verfügbar bei ${storeName}`
|
||||
@@ -123,7 +146,8 @@ async function sendSlotNotification({ profileId, storeName, pickupDate, onlyNoti
|
||||
title,
|
||||
message: fullMessage,
|
||||
link: storeLink,
|
||||
priority: booked ? 'high' : 'default'
|
||||
priority: booked ? 'high' : 'default',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
@@ -137,7 +161,7 @@ function formatStoreWatchStatus(status) {
|
||||
return 'Status unbekannt';
|
||||
}
|
||||
|
||||
async function sendStoreWatchNotification({ profileId, storeName, storeId, regionName }) {
|
||||
async function sendStoreWatchNotification({ profileId, profileName, storeName, storeId, regionName }) {
|
||||
const storeLink = storeId ? `https://foodsharing.de/store/${storeId}` : null;
|
||||
const title = `Team sucht Verstärkung: ${storeName}`;
|
||||
const regionText = regionName ? ` (${regionName})` : '';
|
||||
@@ -147,11 +171,12 @@ async function sendStoreWatchNotification({ profileId, storeName, storeId, regio
|
||||
title,
|
||||
message,
|
||||
link: storeLink,
|
||||
priority: 'high'
|
||||
priority: 'high',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
async function sendStoreWatchSummaryNotification({ profileId, entries = [], triggeredBy = 'manual' }) {
|
||||
async function sendStoreWatchSummaryNotification({ profileId, profileName, entries = [], triggeredBy = 'manual' }) {
|
||||
if (!profileId || !Array.isArray(entries) || entries.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -174,11 +199,12 @@ async function sendStoreWatchSummaryNotification({ profileId, entries = [], trig
|
||||
await notifyChannels(profileId, {
|
||||
title,
|
||||
message,
|
||||
priority: 'default'
|
||||
priority: 'default',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
async function sendDesiredWindowMissedNotification({ profileId, storeName, desiredWindowLabel }) {
|
||||
async function sendDesiredWindowMissedNotification({ profileId, profileName, storeName, desiredWindowLabel }) {
|
||||
if (!profileId) {
|
||||
return;
|
||||
}
|
||||
@@ -191,7 +217,8 @@ async function sendDesiredWindowMissedNotification({ profileId, storeName, desir
|
||||
title,
|
||||
message,
|
||||
link: null,
|
||||
priority: 'default'
|
||||
priority: 'default',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
@@ -228,7 +255,7 @@ async function sendTestNotification(profileId, channel) {
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
async function sendDormantPickupWarning({ profileId, storeName, storeId, reasonLines = [] }) {
|
||||
async function sendDormantPickupWarning({ profileId, profileName, storeName, storeId, reasonLines = [] }) {
|
||||
if (!profileId || !Array.isArray(reasonLines) || reasonLines.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -242,12 +269,14 @@ async function sendDormantPickupWarning({ profileId, storeName, storeId, reasonL
|
||||
await sendTelegramNotification(adminSettings.notifications?.telegram, userSettings.notifications?.telegram, {
|
||||
title,
|
||||
message,
|
||||
priority: 'high'
|
||||
priority: 'high',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
async function sendJournalReminderNotification({
|
||||
profileId,
|
||||
profileName,
|
||||
storeName,
|
||||
pickupDate,
|
||||
reminderDate,
|
||||
@@ -270,7 +299,8 @@ async function sendJournalReminderNotification({
|
||||
await sendTelegramNotification(adminSettings.notifications?.telegram, userSettings.notifications?.telegram, {
|
||||
title,
|
||||
message: messageLines.join('\n'),
|
||||
priority: 'default'
|
||||
priority: 'default',
|
||||
profileName
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user