feat: notify admin via Telegram on webhook errors

Send error details to ADMIN_CHAT_ID (optional secret) whenever the
statuspage webhook handler hits an error path. Uses waitUntil() so
the notification never blocks the 200 response.
This commit is contained in:
2026-04-13 22:50:27 +07:00
parent 3857c1e16f
commit 62bf203c22
6 changed files with 69 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ No linter configured.
- `BOT_TOKEN` — Telegram bot token
- `WEBHOOK_SECRET` — Secret token in Statuspage webhook URL path
- `ADMIN_CHAT_ID` — Telegram chat ID to receive webhook error notifications (optional)
## Architecture
@@ -39,7 +40,7 @@ Cloudflare Workers with two entry points exported from `src/index.js`:
### Data Flow
1. **Statuspage → Worker**: Webhook POST → verify URL secret (timing-safe via `crypto-utils.js`) → parse incident/component event → filter subscribers by type + component → `sendBatch` to CF Queue
1. **Statuspage → Worker**: Webhook POST → verify URL secret (timing-safe via `crypto-utils.js`) → parse incident/component event → filter subscribers by type + component → `sendBatch` to CF Queue. On any error, admin is notified via Telegram (`admin-notifier.js`, non-blocking via `waitUntil`)
2. **Queue → Telegram**: Consumer processes batches of 30 → `sendMessage` via `telegram-api.js` helper → auto-removes blocked subscribers (403/400), retries on 429
3. **User → Bot**: Telegram webhook → grammY handles `/help`, `/start`, `/stop`, `/status`, `/subscribe`, `/history`, `/uptime` commands → reads/writes KV