Heaven Live — Cloudflare Worker + Discord go-live announcements#1
Heaven Live — Cloudflare Worker + Discord go-live announcements#1RSPNOIZY wants to merge 2 commits into
Conversation
HEAVEN goes LIVE. Adds heaven-live/ Cloudflare Worker with: - POST /go-live → sets KV state + fires Discord webhook - POST /go-offline → clears KV state + fires Discord webhook - GET /status → public stream state - go-live.sh / go-offline.sh — 1-command shell triggers - X-Heaven-Key auth on write endpoints - Updates HEAVEN_PROMPT.md: status BUILT → LIVE
KV namespace 'HEAVEN_KV' already exists in Cloudflare account Fishmusicinc. ID: 1f88de7bc13b4fb9984887bb0d0aa200 Ready to deploy — just set secrets and run wrangler deploy.
There was a problem hiding this comment.
Pull request overview
Introduces a new Cloudflare Worker (“heaven-live”) that tracks live-stream state in KV and posts Discord webhook announcements when the stream goes live/offline, plus updates HEAVEN documentation to reflect the new “LIVE layer”.
Changes:
- Adds
heaven-liveWorker with/status,/go-live, and/go-offlineendpoints (API-key protected for mutating actions). - Implements Discord webhook announcement formatting and KV-backed stream state storage.
- Adds deployment/local trigger tooling (Wrangler config + shell scripts) and updates
HEAVEN_PROMPT.mdto document the live layer.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| wisdom/prompts/HEAVEN_PROMPT.md | Documents the new Live Layer, endpoints, secrets, and deploy/go-live instructions. |
| heaven-live/wrangler.toml | Worker configuration and KV binding for stream state. |
| heaven-live/tsconfig.json | TypeScript config for the Worker project. |
| heaven-live/src/stream.ts | KV read/write helpers for stream state persistence. |
| heaven-live/src/index.ts | Worker routing + auth + live/offline state transitions + Discord notifications. |
| heaven-live/src/discord.ts | Discord webhook payload creation and POST logic. |
| heaven-live/package.json | Wrangler/TypeScript tooling scripts and dev dependencies. |
| heaven-live/go-live.sh | CLI trigger to call /go-live. |
| heaven-live/go-offline.sh | CLI trigger to call /go-offline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const authError = requireApiKey(request, env); | ||
| if (authError) return authError; | ||
|
|
||
| const body = await request.json<{ showName?: string; streamUrl?: string; platform?: string }>(); |
| await setStreamState(env.HEAVEN_KV, state); | ||
| await postDiscordAnnouncement(env.DISCORD_WEBHOOK_URL, { | ||
| showName, | ||
| status: 'LIVE', | ||
| platform, | ||
| streamUrl, | ||
| }); | ||
|
|
| if (method === 'POST' && url.pathname === '/go-live') { | ||
| const authError = requireApiKey(request, env); | ||
| if (authError) return authError; |
| export async function getStreamState(kv: KVNamespace): Promise<StreamState> { | ||
| const raw = await kv.get(STATE_KEY); | ||
| if (!raw) { | ||
| return { isLive: false, showName: '', platform: 'Cloudflare Stream' }; | ||
| } | ||
| return JSON.parse(raw) as StreamState; |
|
|
||
| const content = isLive | ||
| ? `🚀 **LIVE**\n🎛️ **Show:** ${announcement.showName}\n🌐 **Platform:** ${announcement.platform}\n🕒 **Time:** ${time}${announcement.streamUrl ? `\n🔗 **Watch:** ${announcement.streamUrl}` : ''}` | ||
| : `📴 **OFFLINE**\n🎛️ **Show:** ${announcement.showName}\n🌐 **Platform:** ${announcement.platform}\n🕒 **Ended:** ${time}`; | ||
|
|
||
| const response = await fetch(webhookUrl, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| username: 'Noizy.AI', | ||
| avatar_url: 'https://noizy.ai/logo.png', | ||
| content, | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Discord webhook failed: ${response.status} ${await response.text()}`); |
| PAYLOAD=$(cat <<EOF | ||
| { | ||
| "showName": "${SHOW_NAME}", | ||
| "platform": "${PLATFORM}", | ||
| "streamUrl": "${STREAM_URL}" | ||
| } | ||
| EOF |
| #!/usr/bin/env zsh | ||
| # Heaven Live — go-live trigger for Noizy.AI | ||
| # Usage: HEAVEN_API_KEY=xxx [SHOW_NAME="..."] [STREAM_URL="https://..."] ./go-live.sh | ||
|
|
|
|
||
| [[kv_namespaces]] | ||
| binding = "HEAVEN_KV" | ||
| id = "1f88de7bc13b4fb9984887bb0d0aa200" |
| #!/usr/bin/env zsh | ||
| # Heaven Live — go-offline trigger for Noizy.AI | ||
| # Usage: HEAVEN_API_KEY=xxx ./go-offline.sh | ||
|
|
Heaven Live — review & deploy notesThis is a clean, well-scoped implementation. Architecture is solid: KV-backed state, secret-authenticated mutations, public read endpoint, Discord webhook announcements, 1-command shell triggers. The separation into Before marking ready and merging, here's what I'd address: Must-fix before deploy1. 2. No idempotency guard on 3. KV write happens before Discord webhook — divergence risk Should-fix (low effort, high value)4. Wrap 5. 6. Add an 7. Shell scripts: 8. Shell scripts: use Nice-to-have / future
Deploy checklist status
|
What this does
HEAVEN goes from BUILT to LIVE.
Adds
heaven-live/— a Cloudflare Worker that manages stream state and fires Discord webhook announcements when Noizy.AI goes live or offline.New files
heaven-live/src/index.ts/go-live,/go-offline,/statusendpointsheaven-live/src/discord.tsheaven-live/src/stream.tsheaven-live/wrangler.tomlheaven-live/go-live.shheaven-live/go-offline.shwisdom/prompts/HEAVEN_PROMPT.mdAPI surface
GET /status— public, returns current stream statePOST /go-live— sets KV state, fires Discord🚀 LIVEannouncement (auth:X-Heaven-Key)POST /go-offline— clears KV state, fires Discord📴 OFFLINEannouncement (auth:X-Heaven-Key)Deploy checklist
wrangler kv:namespace create HEAVEN_KV→ paste ID intowrangler.tomlwrangler secret put DISCORD_WEBHOOK_URL(your Discord webhook URL)wrangler secret put HEAVEN_API_KEY(pick a strong key)cd heaven-live && wrangler deployHEAVEN_API_KEY=xxx ./heaven-live/go-live.shGo live (after deploy)
GORUNFREE.
Generated by Claude Code