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

@ -18,11 +18,12 @@ router.get('/notifications', async (req: AuthRequest, res: Response) => {
return;
}
// Don't expose full bot token, just indicate if it's set
// Don't expose full tokens, just indicate if they're set
res.json({
telegram_configured: !!(settings.telegram_bot_token && settings.telegram_chat_id),
telegram_chat_id: settings.telegram_chat_id,
discord_configured: !!settings.discord_webhook_url,
pushover_configured: !!(settings.pushover_user_key && settings.pushover_app_token),
});
} catch (error) {
console.error('Error fetching notification settings:', error);
@ -34,12 +35,14 @@ router.get('/notifications', async (req: AuthRequest, res: Response) => {
router.put('/notifications', async (req: AuthRequest, res: Response) => {
try {
const userId = req.userId!;
const { telegram_bot_token, telegram_chat_id, discord_webhook_url } = req.body;
const { telegram_bot_token, telegram_chat_id, discord_webhook_url, pushover_user_key, pushover_app_token } = req.body;
const settings = await userQueries.updateNotificationSettings(userId, {
telegram_bot_token,
telegram_chat_id,
discord_webhook_url,
pushover_user_key,
pushover_app_token,
});
if (!settings) {
@ -51,6 +54,7 @@ router.put('/notifications', async (req: AuthRequest, res: Response) => {
telegram_configured: !!(settings.telegram_bot_token && settings.telegram_chat_id),
telegram_chat_id: settings.telegram_chat_id,
discord_configured: !!settings.discord_webhook_url,
pushover_configured: !!(settings.pushover_user_key && settings.pushover_app_token),
message: 'Notification settings updated successfully',
});
} catch (error) {
@ -127,6 +131,42 @@ router.post('/notifications/test/discord', async (req: AuthRequest, res: Respons
}
});
// Test Pushover notification
router.post('/notifications/test/pushover', async (req: AuthRequest, res: Response) => {
try {
const userId = req.userId!;
const settings = await userQueries.getNotificationSettings(userId);
if (!settings?.pushover_user_key || !settings?.pushover_app_token) {
res.status(400).json({ error: 'Pushover not configured' });
return;
}
const { sendPushoverNotification } = await import('../services/notifications');
const success = await sendPushoverNotification(
settings.pushover_user_key,
settings.pushover_app_token,
{
productName: 'Test Product',
productUrl: 'https://example.com',
type: 'price_drop',
oldPrice: 29.99,
newPrice: 19.99,
currency: 'USD',
}
);
if (success) {
res.json({ message: 'Test notification sent successfully' });
} else {
res.status(500).json({ error: 'Failed to send test notification' });
}
} catch (error) {
console.error('Error sending test Pushover notification:', error);
res.status(500).json({ error: 'Failed to send test notification' });
}
});
// Get AI settings
router.get('/ai', async (req: AuthRequest, res: Response) => {
try {