From 68b9604598ae0a61f912d02afa526ef6984e2d34 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Wed, 8 Apr 2026 23:23:32 +0700 Subject: [PATCH] refactor: update bindings to match CF resource names KV binding: claude_status, Queue binding: claude-status. Real KV namespace ID configured with remote flag. --- CLAUDE.md | 4 ++-- README.md | 2 +- src/bot-commands.js | 2 +- src/queue-consumer.js | 2 +- src/statuspage-webhook.js | 4 ++-- wrangler.jsonc | 45 ++++++++++++++++++++++++--------------- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index add01e7..d91fb9e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,5 +59,5 @@ Bot stores `message_thread_id` from the topic where `/start` was sent. Notificat ## CF Bindings (wrangler.jsonc) -- `CLAUDE_STATUS` — KV namespace -- `STATUS_QUEUE` — Queue producer/consumer (`claude-status`, batch size 30, max retries 3) +- `claude_status` — KV namespace +- `claude-status` — Queue producer/consumer (batch size 30, max retries 3) diff --git a/README.md b/README.md index 22a914b..8e265bf 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Copy the KV namespace ID from the output and update `wrangler.jsonc`: ```jsonc "kv_namespaces": [ - { "binding": "CLAUDE_STATUS", "id": "YOUR_KV_NAMESPACE_ID" } + { "binding": "claude_status", "id": "YOUR_KV_NAMESPACE_ID" } ] ``` diff --git a/src/bot-commands.js b/src/bot-commands.js index 00783a8..a36d85a 100644 --- a/src/bot-commands.js +++ b/src/bot-commands.js @@ -27,7 +27,7 @@ function getChatTarget(ctx) { */ export async function handleTelegramWebhook(c) { const bot = new Bot(c.env.BOT_TOKEN); - const kv = c.env.CLAUDE_STATUS; + const kv = c.env.claude_status; bot.command("start", async (ctx) => { const { chatId, threadId } = getChatTarget(ctx); diff --git a/src/queue-consumer.js b/src/queue-consumer.js index 3f6c319..f967eb8 100644 --- a/src/queue-consumer.js +++ b/src/queue-consumer.js @@ -36,7 +36,7 @@ export async function handleQueue(batch, env) { msg.ack(); } else if (res.status === 403 || res.status === 400) { // Bot blocked or chat not found — auto-remove subscriber - await removeSubscriber(env.CLAUDE_STATUS, chatId, threadId); + await removeSubscriber(env.claude_status, chatId, threadId); msg.ack(); } else if (res.status === 429) { // Rate limited — let queue retry later diff --git a/src/statuspage-webhook.js b/src/statuspage-webhook.js index b8292c4..8c6b828 100644 --- a/src/statuspage-webhook.js +++ b/src/statuspage-webhook.js @@ -69,14 +69,14 @@ export async function handleStatuspageWebhook(c) { } // Get filtered subscribers - const subscribers = await getSubscribersByType(c.env.CLAUDE_STATUS, category); + const subscribers = await getSubscribersByType(c.env.claude_status, category); // Enqueue messages for fan-out via CF Queues (batch for performance) const messages = subscribers.map(({ chatId, threadId }) => ({ body: { chatId, threadId, html }, })); for (let i = 0; i < messages.length; i += 100) { - await c.env.STATUS_QUEUE.sendBatch(messages.slice(i, i + 100)); + await c.env["claude-status"].sendBatch(messages.slice(i, i + 100)); } return c.text("OK", 200); diff --git a/wrangler.jsonc b/wrangler.jsonc index 6308907..41b4e9b 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -1,19 +1,30 @@ { - "name": "claude-status-webhook", - "main": "src/index.js", - "compatibility_date": "2024-12-01", - "kv_namespaces": [ - { "binding": "CLAUDE_STATUS", "id": "" } - ], - "queues": { - "producers": [ - { "binding": "STATUS_QUEUE", "queue": "claude-status" } - ], - "consumers": [ - { "queue": "claude-status", "max_batch_size": 30, "max_retries": 3 } - ] - } - // Secrets (set via `wrangler secret put`): - // BOT_TOKEN - Telegram bot token - // WEBHOOK_SECRET - Statuspage webhook URL secret + "name": "claude-status-webhook", + "main": "src/index.js", + "compatibility_date": "2024-12-01", + "kv_namespaces": [ + { + "binding": "claude_status", + "id": "d026d63d84bf49268364deb27d3dc28a", + "remote": true + } + ], + "queues": { + "producers": [ + { + "binding": "claude-status", + "queue": "claude-status" + } + ], + "consumers": [ + { + "queue": "claude-status", + "max_batch_size": 30, + "max_retries": 3 + } + ] + } + // Secrets (set via `wrangler secret put`): + // BOT_TOKEN - Telegram bot token + // WEBHOOK_SECRET - Statuspage webhook URL secret }