From 500c9c83ee9be568377df44b7df6e5d8bd45f657 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Thu, 9 Apr 2026 12:16:45 +0700 Subject: [PATCH] feat: add /info command to show chat ID and subscription status --- scripts/setup-bot.js | 1 + src/bot-commands.js | 22 ++++++++++++++++++++++ src/bot-info-commands.js | 2 ++ 3 files changed, 25 insertions(+) diff --git a/scripts/setup-bot.js b/scripts/setup-bot.js index 27db724..4e1faa8 100644 --- a/scripts/setup-bot.js +++ b/scripts/setup-bot.js @@ -11,6 +11,7 @@ const BOT_COMMANDS = [ { command: "status", description: "Current system status" }, { command: "subscribe", description: "Set notification preferences" }, { command: "history", description: "Recent incidents" }, + { command: "info", description: "Chat ID & subscription info" }, { command: "uptime", description: "Component health overview" }, ]; diff --git a/src/bot-commands.js b/src/bot-commands.js index 1f8693c..6cd8d0b 100644 --- a/src/bot-commands.js +++ b/src/bot-commands.js @@ -132,6 +132,27 @@ function createBot(token) { }); }); + bot.command("info", async (ctx) => { + const { chatId, threadId } = getChatTarget(ctx); + const idLine = + threadId != null ? `${chatId}:${threadId}` : `${chatId}`; + + const sub = await getSubscriber(kv, chatId, threadId); + let subLine; + if (!sub) { + subLine = "Not subscribed. Use /start to subscribe."; + } else { + const types = sub.types?.join(", ") || "none"; + const components = sub.components?.length ? sub.components.join(", ") : "all"; + subLine = + `Types: ${types}\n` + `Components: ${components}`; + } + + await ctx.reply(`Chat Info\n\nChat ID: ${idLine}\n\n${subLine}`, { + parse_mode: "HTML", + }); + }); + // Info commands: /help, /status, /history, /uptime registerInfoCommands(bot); @@ -141,6 +162,7 @@ function createBot(token) { "/help — Detailed command guide\n" + "/start — Subscribe to notifications\n" + "/stop — Unsubscribe\n" + + "/info — Chat ID & subscription info\n" + "/status — Current system status\n" + "/subscribe — Notification preferences\n" + "/history — Recent incidents\n" + diff --git a/src/bot-info-commands.js b/src/bot-info-commands.js index 6d3d79e..dbc7437 100644 --- a/src/bot-info-commands.js +++ b/src/bot-info-commands.js @@ -26,6 +26,8 @@ export function registerInfoCommands(bot) { `Show current status of all components.\n` + `Add a component name for a specific check.\n` + `Example: /status api\n\n` + + `/info\n` + + `Show chat ID and current subscription status.\n\n` + `/subscribe <type> [component]\n` + `Set what notifications you receive.\n` + `Types: incident, component, all\n` +