| const sms = require('../services/sms'); | |
| // In-memory cooldown — don't spam the same alert key more than once per 10 min | |
| const lastSent = {}; | |
| const COOLDOWN_MS = 10 * 60 * 1000; | |
| const ADMIN_ALERT_PHONE = '0769590766'; | |
| async function alertAdmin(key, message) { | |
| console.error(`[SYSTEM ALERT] ${key}: ${message}`); | |
| const now = Date.now(); | |
| if (lastSent[key] && now - lastSent[key] < COOLDOWN_MS) { | |
| return false; | |
| } | |
| lastSent[key] = now; | |
| try { | |
| await sms.sendSMS(ADMIN_ALERT_PHONE, message); | |
| return true; | |
| } catch (err) { | |
| console.error(`[SYSTEM ALERT SMS FAILED] ${key}: ${err.message}`); | |
| return false; | |
| } | |
| } | |
| module.exports = { alertAdmin }; | |