Skip to content

Your lightweight open-source personal agent.

fix: consistent sender_id for Telegram command allowlist matching

Re-binffbb264a5d41
diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py
index efd009ee6..d2ce74c78 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