fix: rename KV binding to CLAUDE_STATUS and fix threadId nullish check

- Rename KV binding SUBSCRIBERS → CLAUDE_STATUS for consistent naming
- Fix || null → ?? null to preserve threadId 0 (General topic)
- Update KV namespace creation command in README
This commit is contained in:
2026-04-08 23:14:26 +07:00
parent 41bdcf36ef
commit b3d1f5acb4
6 changed files with 8 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ import {
function getChatTarget(ctx) {
return {
chatId: ctx.chat.id,
threadId: ctx.message?.message_thread_id || null,
threadId: ctx.message?.message_thread_id ?? null,
};
}
@@ -27,7 +27,7 @@ function getChatTarget(ctx) {
*/
export async function handleTelegramWebhook(c) {
const bot = new Bot(c.env.BOT_TOKEN);
const kv = c.env.SUBSCRIBERS;
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.SUBSCRIBERS, 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,7 +69,7 @@ export async function handleStatuspageWebhook(c) {
}
// Get filtered subscribers
const subscribers = await getSubscribersByType(c.env.SUBSCRIBERS, 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 }) => ({