Add ntfy.sh notification support

- Add ntfy_topic and ntfy_enabled columns to database
- Add sendNtfyNotification function with emoji tags
- Add /settings/notifications/test/ntfy endpoint
- Add ntfy section in Settings UI with topic input
- Show ntfy badge in ProductDetail notification status

ntfy.sh is a free, simple notification service - no account needed.
Users just pick a topic name and subscribe in the ntfy app.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-22 21:02:49 -05:00
parent a4da43c127
commit 3d6af13ac4
7 changed files with 231 additions and 4 deletions

View file

@ -195,6 +195,52 @@ export async function sendPushoverNotification(
}
}
export async function sendNtfyNotification(
topic: string,
payload: NotificationPayload
): Promise<boolean> {
try {
const currencySymbol = getCurrencySymbol(payload.currency);
let title: string;
let message: string;
let tags: string[];
if (payload.type === 'price_drop') {
const oldPriceStr = payload.oldPrice ? `${currencySymbol}${payload.oldPrice.toFixed(2)}` : 'N/A';
const newPriceStr = payload.newPrice ? `${currencySymbol}${payload.newPrice.toFixed(2)}` : 'N/A';
title = 'Price Drop Alert!';
message = `${payload.productName}\n\nPrice dropped from ${oldPriceStr} to ${newPriceStr}`;
tags = ['moneybag', 'chart_with_downwards_trend'];
} else if (payload.type === 'target_price') {
const newPriceStr = payload.newPrice ? `${currencySymbol}${payload.newPrice.toFixed(2)}` : 'N/A';
const targetPriceStr = payload.targetPrice ? `${currencySymbol}${payload.targetPrice.toFixed(2)}` : 'N/A';
title = 'Target Price Reached!';
message = `${payload.productName}\n\nPrice is now ${newPriceStr} (your target: ${targetPriceStr})`;
tags = ['dart', 'white_check_mark'];
} else {
const priceStr = payload.newPrice ? ` at ${currencySymbol}${payload.newPrice.toFixed(2)}` : '';
title = 'Back in Stock!';
message = `${payload.productName}\n\nThis item is now available${priceStr}`;
tags = ['package', 'tada'];
}
await axios.post(`https://ntfy.sh/${topic}`, message, {
headers: {
'Title': title,
'Tags': tags.join(','),
'Click': payload.productUrl,
},
});
console.log(`ntfy notification sent to topic ${topic}`);
return true;
} catch (error) {
console.error('Failed to send ntfy notification:', error);
return false;
}
}
export async function sendNotifications(
settings: {
telegram_bot_token: string | null;
@ -205,6 +251,8 @@ export async function sendNotifications(
pushover_user_key: string | null;
pushover_app_token: string | null;
pushover_enabled?: boolean;
ntfy_topic: string | null;
ntfy_enabled?: boolean;
},
payload: NotificationPayload
): Promise<void> {
@ -227,5 +275,9 @@ export async function sendNotifications(
);
}
if (settings.ntfy_topic && settings.ntfy_enabled !== false) {
promises.push(sendNtfyNotification(settings.ntfy_topic, payload));
}
await Promise.allSettled(promises);
}