Add Pushover notification support

- Add pushover_user_key and pushover_app_token columns to users table
- Add sendPushoverNotification function to notifications service
- Add Pushover test endpoint
- Add Pushover settings UI in Settings page
- User provides both User Key and App Token (self-hosted friendly)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-22 13:48:31 -05:00
parent 3b7dce8bde
commit 3fa913814d
6 changed files with 208 additions and 5 deletions

View file

@ -139,11 +139,57 @@ export async function sendDiscordNotification(
}
}
export async function sendPushoverNotification(
userKey: string,
appToken: string,
payload: NotificationPayload
): Promise<boolean> {
try {
const currencySymbol = payload.currency === 'EUR' ? '€' : payload.currency === 'GBP' ? '£' : '$';
let title: string;
let message: 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}`;
} 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})`;
} 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}`;
}
await axios.post('https://api.pushover.net/1/messages.json', {
token: appToken,
user: userKey,
title,
message,
url: payload.productUrl,
url_title: 'View Product',
});
console.log('Pushover notification sent');
return true;
} catch (error) {
console.error('Failed to send Pushover notification:', error);
return false;
}
}
export async function sendNotifications(
settings: {
telegram_bot_token: string | null;
telegram_chat_id: string | null;
discord_webhook_url: string | null;
pushover_user_key: string | null;
pushover_app_token: string | null;
},
payload: NotificationPayload
): Promise<void> {
@ -159,5 +205,11 @@ export async function sendNotifications(
promises.push(sendDiscordNotification(settings.discord_webhook_url, payload));
}
if (settings.pushover_user_key && settings.pushover_app_token) {
promises.push(
sendPushoverNotification(settings.pushover_user_key, settings.pushover_app_token, payload)
);
}
await Promise.allSettled(promises);
}