From 51d22b7ef46cfcd188068422cbc6bb23937382d9 Mon Sep 17 00:00:00 2001 From: Thomas Lisankie Date: Mon, 16 Feb 2026 00:14:34 -0500 Subject: [PATCH 1/2] Fix: _forward_command now builds sender_id with username for allowlist matching --- nanobot/channels/telegram.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py index 32f8c67..efd009e 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -226,8 +226,14 @@ class TelegramChannel(BaseChannel): """Forward slash commands to the bus for unified handling in AgentLoop.""" if not update.message or not update.effective_user: return + + user = update.effective_user + sender_id = str(user.id) + if user.username: + sender_id = f"{sender_id}|{user.username}" + await self._handle_message( - sender_id=str(update.effective_user.id), + sender_id=sender_id, chat_id=str(update.message.chat_id), content=update.message.text, ) From ffbb264a5d41941f793ba4910de26df04874ec26 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Mon, 16 Feb 2026 12:11:03 +0000 Subject: [PATCH 2/2] fix: consistent sender_id for Telegram command allowlist matching --- nanobot/channels/telegram.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py index efd009e..d2ce74c 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -222,18 +222,18 @@ class TelegramChannel(BaseChannel): "Type /help to see available commands." ) + @staticmethod + def _sender_id(user) -> str: + """Build sender_id with username for allowlist matching.""" + sid = str(user.id) + return f"{sid}|{user.username}" if user.username else sid + async def _forward_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Forward slash commands to the bus for unified handling in AgentLoop.""" if not update.message or not update.effective_user: return - - user = update.effective_user - sender_id = str(user.id) - if user.username: - sender_id = f"{sender_id}|{user.username}" - await self._handle_message( - sender_id=sender_id, + sender_id=self._sender_id(update.effective_user), chat_id=str(update.message.chat_id), content=update.message.text, ) @@ -246,11 +246,7 @@ class TelegramChannel(BaseChannel): message = update.message user = update.effective_user chat_id = message.chat_id - - # Use stable numeric ID, but keep username for allowlist compatibility - sender_id = str(user.id) - if user.username: - sender_id = f"{sender_id}|{user.username}" + sender_id = self._sender_id(user) # Store chat_id for replies self._chat_ids[sender_id] = chat_id