Repository navigation
feat(backend): /api/internal/notify endpoint (homelab notifications) - #625
Conversation
Replaces fragile per-channel webhooks with a bot-token-backed REST proxy.
The homelab watchdog and other host-side scripts post {channelId,content}
to http://lucky-backend:3000/api/internal/notify with X-Notify-Key header.
The route forwards to Discord REST API using the bot's existing token,
so messages appear from the Lucky bot user (no webhook expiry).
- New route in packages/backend/src/routes/internalNotify.ts
- Spec file with auth + happy path + Discord 4xx handling
- Wired into setupRoutes(app)
- LUCKY_NOTIFY_API_KEY pass-through in docker-compose.yml + .env.example
- Bot token already in backend env (DISCORD_TOKEN)
Manual follow-up after merge:
1. Set LUCKY_NOTIFY_API_KEY=<random-32-char> in ~/Lucky/.env on homelab
2. Restart lucky-backend
3. Apply matching homelab repo PR that swaps webhook URL for this endpoint
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 23 minutes and 0 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Replaces dead WATCHDOG_DISCORD_WEBHOOK URL with POST to Lucky's new /api/internal/notify (LucasSantana-Dev/Lucky#625). Lucky forwards via the bot identity, eliminating silent webhook-expiry failure mode. - send_discord() in homelab-watchdog.sh now POSTs JSON to Lucky. - New env: LUCKY_NOTIFY_URL / LUCKY_NOTIFY_KEY / LUCKY_NOTIFY_CHANNEL_ID - WUD/Alertmanager/update-containers will migrate next wave. Manual deploy after both PRs merge: 1. Set LUCKY_NOTIFY_API_KEY in ~/Lucky/.env (any 32-char random) 2. docker compose up -d backend in ~/Lucky 3. Set LUCKY_NOTIFY_KEY in ~/homelab/.env to the same value 4. Set LUCKY_NOTIFY_CHANNEL_ID=1480939399922323567 (#homelab) 5. Watchdog picks up new env on next tick
- Add 17 integration tests for POST /api/internal/notify - Cover happy path: valid content + embeds delivery - Cover auth: missing/wrong/unconfigured API key (401) - Cover validation: missing channelId, missing content+embeds (400) - Cover errors: missing Discord token (500), Discord API errors (502) - Cover edge cases: content truncation, special chars, text parsing - All tests pass with 100% endpoint coverage
* feat(notify): route watchdog alerts through Lucky bot internal endpoint Replaces dead WATCHDOG_DISCORD_WEBHOOK URL with POST to Lucky's new /api/internal/notify (LucasSantana-Dev/Lucky#625). Lucky forwards via the bot identity, eliminating silent webhook-expiry failure mode. - send_discord() in homelab-watchdog.sh now POSTs JSON to Lucky. - New env: LUCKY_NOTIFY_URL / LUCKY_NOTIFY_KEY / LUCKY_NOTIFY_CHANNEL_ID - WUD/Alertmanager/update-containers will migrate next wave. Manual deploy after both PRs merge: 1. Set LUCKY_NOTIFY_API_KEY in ~/Lucky/.env (any 32-char random) 2. docker compose up -d backend in ~/Lucky 3. Set LUCKY_NOTIFY_KEY in ~/homelab/.env to the same value 4. Set LUCKY_NOTIFY_CHANNEL_ID=1480939399922323567 (#homelab) 5. Watchdog picks up new env on next tick * fix: remove orphan send_discord tail leftover from regex replace --------- Co-authored-by: LucasSantana-Dev <LucasSantana-Dev@users.noreply.github.com>
|
Seeds the first two specs for Lucky: - 2026-04-15-internal-notify-endpoint (shipped via #625, archived) - 2026-04-15-autoplay-diversity (proposed) Derived docs/roadmap.md generated from spec frontmatters. Generator: ~/.claude/rag-index/specs.py (personal tooling). Future specs land under docs/specs/<date>-<slug>/{spec,tasks}.md; shipped specs auto-archive to docs/specs/archived/ via spec-ship.
Seeds the first two specs for Lucky: - 2026-04-15-internal-notify-endpoint (shipped via #625, archived) - 2026-04-15-autoplay-diversity (proposed) Derived docs/roadmap.md generated from spec frontmatters. Generator: ~/.claude/rag-index/specs.py (personal tooling). Future specs land under docs/specs/<date>-<slug>/{spec,tasks}.md; shipped specs auto-archive to docs/specs/archived/ via spec-ship.
…625) * feat(backend): add /api/internal/notify endpoint for homelab alerts Replaces fragile per-channel webhooks with a bot-token-backed REST proxy. The homelab watchdog and other host-side scripts post {channelId,content} to http://lucky-backend:3000/api/internal/notify with X-Notify-Key header. The route forwards to Discord REST API using the bot's existing token, so messages appear from the Lucky bot user (no webhook expiry). - New route in packages/backend/src/routes/internalNotify.ts - Spec file with auth + happy path + Discord 4xx handling - Wired into setupRoutes(app) - LUCKY_NOTIFY_API_KEY pass-through in docker-compose.yml + .env.example - Bot token already in backend env (DISCORD_TOKEN) Manual follow-up after merge: 1. Set LUCKY_NOTIFY_API_KEY=<random-32-char> in ~/Lucky/.env on homelab 2. Restart lucky-backend 3. Apply matching homelab repo PR that swaps webhook URL for this endpoint * test(backend): drop spec until tsconfig wires jest globals * test(backend): mock setupInternalNotifyRoutes in routes/index.test * test(backend): cover internalNotify route (auth + happy path + Discord errors) * test(backend): cover /api/internal/notify endpoint - Add 17 integration tests for POST /api/internal/notify - Cover happy path: valid content + embeds delivery - Cover auth: missing/wrong/unconfigured API key (401) - Cover validation: missing channelId, missing content+embeds (400) - Cover errors: missing Discord token (500), Discord API errors (502) - Cover edge cases: content truncation, special chars, text parsing - All tests pass with 100% endpoint coverage --------- Co-authored-by: LucasSantana-Dev <LucasSantana-Dev@users.noreply.github.com>
Seeds the first two specs for Lucky: - 2026-04-15-internal-notify-endpoint (shipped via #625, archived) - 2026-04-15-autoplay-diversity (proposed) Derived docs/roadmap.md generated from spec frontmatters. Generator: ~/.claude/rag-index/specs.py (personal tooling). Future specs land under docs/specs/<date>-<slug>/{spec,tasks}.md; shipped specs auto-archive to docs/specs/archived/ via spec-ship.



Summary
Adds a key-gated POST endpoint that proxies messages from the homelab host to Discord using the bot's existing token. Replaces the brittle webhook URL fan-out (4 of 4 webhooks went 404 unnoticed for weeks).
Why
Webhooks expire silently when a Discord admin removes them; messages then disappear without any signal in the homelab logs. Routing through Lucky uses the bot identity, so as long as the bot is in the channel the messages get through.
Endpoint
POST /api/internal/notifyX-Notify-Key: ${LUCKY_NOTIFY_API_KEY}{ channelId: string, content?: string, embeds?: object[] }writeLimiter.Files
packages/backend/src/routes/internalNotify.ts— handlerpackages/backend/src/routes/internalNotify.spec.ts— auth + happy path + Discord 4xxpackages/backend/src/routes/index.ts— wired into setupRoutesdocker-compose.yml+.env.example—LUCKY_NOTIFY_API_KEYpass-throughManual deploy steps
LUCKY_NOTIFY_API_KEY=<32-char random>in~/Lucky/.envon the homelab host.cd ~/Lucky && docker compose up -d backendRisk
None on the bot itself: endpoint is additive, key-gated, rate-limited, and only uses the existing bot token. If the key env is missing, every request 401s.