mirror of
https://github.com/tiennm99/claude-status-webhook.git
synced 2026-04-17 15:20:37 +00:00
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:
@@ -59,5 +59,5 @@ Bot stores `message_thread_id` from the topic where `/start` was sent. Notificat
|
|||||||
|
|
||||||
## CF Bindings (wrangler.jsonc)
|
## CF Bindings (wrangler.jsonc)
|
||||||
|
|
||||||
- `CLAUDE_STATUS` — KV namespace
|
- `claude_status` — KV namespace
|
||||||
- `STATUS_QUEUE` — Queue producer/consumer (`claude-status`, batch size 30, max retries 3)
|
- `claude-status` — Queue producer/consumer (batch size 30, max retries 3)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ Copy the KV namespace ID from the output and update `wrangler.jsonc`:
|
|||||||
|
|
||||||
```jsonc
|
```jsonc
|
||||||
"kv_namespaces": [
|
"kv_namespaces": [
|
||||||
{ "binding": "CLAUDE_STATUS", "id": "YOUR_KV_NAMESPACE_ID" }
|
{ "binding": "claude_status", "id": "YOUR_KV_NAMESPACE_ID" }
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function getChatTarget(ctx) {
|
|||||||
*/
|
*/
|
||||||
export async function handleTelegramWebhook(c) {
|
export async function handleTelegramWebhook(c) {
|
||||||
const bot = new Bot(c.env.BOT_TOKEN);
|
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) => {
|
bot.command("start", async (ctx) => {
|
||||||
const { chatId, threadId } = getChatTarget(ctx);
|
const { chatId, threadId } = getChatTarget(ctx);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export async function handleQueue(batch, env) {
|
|||||||
msg.ack();
|
msg.ack();
|
||||||
} else if (res.status === 403 || res.status === 400) {
|
} else if (res.status === 403 || res.status === 400) {
|
||||||
// Bot blocked or chat not found — auto-remove subscriber
|
// 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();
|
msg.ack();
|
||||||
} else if (res.status === 429) {
|
} else if (res.status === 429) {
|
||||||
// Rate limited — let queue retry later
|
// Rate limited — let queue retry later
|
||||||
|
|||||||
@@ -69,14 +69,14 @@ export async function handleStatuspageWebhook(c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get filtered subscribers
|
// 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)
|
// Enqueue messages for fan-out via CF Queues (batch for performance)
|
||||||
const messages = subscribers.map(({ chatId, threadId }) => ({
|
const messages = subscribers.map(({ chatId, threadId }) => ({
|
||||||
body: { chatId, threadId, html },
|
body: { chatId, threadId, html },
|
||||||
}));
|
}));
|
||||||
for (let i = 0; i < messages.length; i += 100) {
|
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);
|
return c.text("OK", 200);
|
||||||
|
|||||||
@@ -3,14 +3,25 @@
|
|||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"compatibility_date": "2024-12-01",
|
"compatibility_date": "2024-12-01",
|
||||||
"kv_namespaces": [
|
"kv_namespaces": [
|
||||||
{ "binding": "CLAUDE_STATUS", "id": "<KV_NAMESPACE_ID>" }
|
{
|
||||||
|
"binding": "claude_status",
|
||||||
|
"id": "d026d63d84bf49268364deb27d3dc28a",
|
||||||
|
"remote": true
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"queues": {
|
"queues": {
|
||||||
"producers": [
|
"producers": [
|
||||||
{ "binding": "STATUS_QUEUE", "queue": "claude-status" }
|
{
|
||||||
|
"binding": "claude-status",
|
||||||
|
"queue": "claude-status"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"consumers": [
|
"consumers": [
|
||||||
{ "queue": "claude-status", "max_batch_size": 30, "max_retries": 3 }
|
{
|
||||||
|
"queue": "claude-status",
|
||||||
|
"max_batch_size": 30,
|
||||||
|
"max_retries": 3
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
// Secrets (set via `wrangler secret put`):
|
// Secrets (set via `wrangler secret put`):
|
||||||
|
|||||||
Reference in New Issue
Block a user