fix(telegram): preserve control command processing in message handler

Skip native commands in the message handler only if they are NOT control
commands. Control commands like /status need to be processed by the
message handler for proper reply generation.
This commit is contained in:
Naveen Chatlapalli 2026-01-30 09:42:40 -06:00
parent 75366cdade
commit 9296643307
2 changed files with 7 additions and 9 deletions

View File

@ -459,18 +459,18 @@ export const registerTelegramHandlers = ({
if (!msg) return; if (!msg) return;
if (shouldSkipUpdate(ctx)) return; if (shouldSkipUpdate(ctx)) return;
// Skip messages that will be handled by native command handlers. // Skip native commands in DMs - they will be handled by bot.command() handlers.
// Native commands (e.g., /new) are processed by bot.command() handlers first. // In groups, we still process commands through the message handler for access
// Without this check, the regular message handler would also process them, // control validation (groupPolicy, groupAllowFrom, etc.) before reply generation.
// potentially causing duplicate session resets or targeting wrong agents. const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup";
if (nativeEnabled && nativeCommandNames && nativeCommandNames.size > 0) { if (!isGroup && nativeEnabled && nativeCommandNames && nativeCommandNames.size > 0) {
const rawText = (msg.text ?? "").trim(); const rawText = (msg.text ?? "").trim();
if (rawText.startsWith("/")) { if (rawText.startsWith("/")) {
const commandMatch = rawText.match(/^\/([a-z0-9_]+)/i); const commandMatch = rawText.match(/^\/([a-z0-9_]+)/i);
if (commandMatch) { if (commandMatch) {
const commandName = commandMatch[1].toLowerCase(); const commandName = commandMatch[1].toLowerCase();
if (nativeCommandNames.has(commandName)) { if (nativeCommandNames.has(commandName)) {
logVerbose(`telegram: skipping native command /${commandName} in regular handler`); logVerbose(`telegram: skipping native command /${commandName} in DM handler`);
return; return;
} }
} }
@ -478,7 +478,6 @@ export const registerTelegramHandlers = ({
} }
const chatId = msg.chat.id; const chatId = msg.chat.id;
const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup";
const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id; const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id;
const isForum = (msg.chat as { is_forum?: boolean }).is_forum === true; const isForum = (msg.chat as { is_forum?: boolean }).is_forum === true;
const resolvedThreadId = resolveTelegramForumThreadId({ const resolvedThreadId = resolveTelegramForumThreadId({

View File

@ -256,8 +256,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
// This prevents native commands (e.g., /new) from being processed twice. // This prevents native commands (e.g., /new) from being processed twice.
const nativeCommandNames = new Set<string>(); const nativeCommandNames = new Set<string>();
if (nativeEnabled) { if (nativeEnabled) {
const skillCommands = const skillCommands = nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
const nativeSpecs = listNativeCommandSpecsForConfig(cfg, { const nativeSpecs = listNativeCommandSpecsForConfig(cfg, {
skillCommands, skillCommands,
provider: "telegram", provider: "telegram",