feat: add metrics tracking and remove unsupported HMAC verification

- Add metrics.js tracking webhooks, messages, cron, commands
- Add GET /metrics/:secret endpoint (text + JSON format)
- Remove HMAC verification (Statuspage doesn't support it)
- Extract validateSecret helper in index.js
- Integrate trackMetrics across webhook, queue, cron, bot handlers
This commit is contained in:
2026-04-09 00:48:42 +07:00
parent b728ae7d38
commit d78e761731
9 changed files with 148 additions and 56 deletions

View File

@@ -8,6 +8,7 @@ import {
} from "./kv-store.js";
import { fetchComponentByName, escapeHtml } from "./status-fetcher.js";
import { registerInfoCommands } from "./bot-info-commands.js";
import { trackMetrics } from "./metrics.js";
/**
* Extract chatId and threadId from grammY context
@@ -26,6 +27,12 @@ export async function handleTelegramWebhook(c) {
const bot = new Bot(c.env.BOT_TOKEN);
const kv = c.env.claude_status;
// Track command usage
bot.use(async (ctx, next) => {
await trackMetrics(kv, { commandsProcessed: 1 });
await next();
});
bot.command("start", async (ctx) => {
const { chatId, threadId } = getChatTarget(ctx);
await addSubscriber(kv, chatId, threadId);