Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(telegram): enforce group_policy in _on_message
Sense_wang521217a7f50f
diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.pyindex c290535fd..3702666be 100644--- a/nanobot/channels/telegram.py+++ b/nanobot/channels/telegram.py@@ -341,6 +341,23 @@ class TelegramChannel(BaseChannel):# Store chat_id for repliesself._chat_ids[sender_id] = chat_id+ # Enforce group_policy: in group chats with "mention" policy,+ # only respond when the bot is @mentioned or the message is a reply to the bot.+ is_group = message.chat.type != "private"+ if is_group and getattr(self.config, "group_policy", "open") == "mention":+ bot_username = (await self._app.bot.get_me()).username if self._app else None+ mentioned = False+ # Check if bot is @mentioned in text+ if bot_username and message.text:+ mentioned = f"@{bot_username}" in message.text+ # Check if the message is a reply to the bot+ if not mentioned and message.reply_to_message and message.reply_to_message.from_user:+ bot_id = (await self._app.bot.get_me()).id if self._app else None+ if bot_id and message.reply_to_message.from_user.id == bot_id:+ mentioned = True+ if not mentioned:+ return+# Build content from text and/or mediacontent_parts = []media_paths = []