refactor: update bindings to match CF resource names

KV binding: claude_status, Queue binding: claude-status.
Real KV namespace ID configured with remote flag.
This commit is contained in:
2026-04-08 23:23:32 +07:00
parent b3d1f5acb4
commit 68b9604598
6 changed files with 35 additions and 24 deletions

View File

@@ -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)

View File

@@ -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" }
]
```

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -1,19 +1,30 @@
{
"name": "claude-status-webhook",
"main": "src/index.js",
"compatibility_date": "2024-12-01",
"kv_namespaces": [
{ "binding": "CLAUDE_STATUS", "id": "<KV_NAMESPACE_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
}