From 8ede43395e0831cb14a1f5b1a7ab0eaccaf9826c Mon Sep 17 00:00:00 2001 From: Mikkel Georgsen Date: Mon, 30 Mar 2026 11:55:32 +0000 Subject: [PATCH] fix: log MCP bot's own outbound messages to database Bot can't see its own messages via Telegram polling. Now logs them directly after sending so they appear in pull_updates. Co-Authored-By: Claude Opus 4.6 (1M context) --- mcp_bridge/telegram_bot.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mcp_bridge/telegram_bot.py b/mcp_bridge/telegram_bot.py index 22f0d4f..78a50c0 100644 --- a/mcp_bridge/telegram_bot.py +++ b/mcp_bridge/telegram_bot.py @@ -196,21 +196,36 @@ class BridgeBot: return None async def send_to_group(self, text: str, attribution: str = "claude.ai"): - """Send an attributed message to the group chat.""" + """Send an attributed message to the group chat and log it.""" formatted = f"*\\[{attribution}\\]* {self._escape_markdown(text)}" + result = None try: - await self.bot.send_message( + result = await self.bot.send_message( chat_id=self.group_chat_id, text=formatted, parse_mode="MarkdownV2", ) except Exception: - # Fallback to plain text if markdown fails plain = f"[{attribution}] {text}" - await self.bot.send_message( + result = await self.bot.send_message( chat_id=self.group_chat_id, text=plain, ) + finally: + # Log the sent message so it appears in pull_updates + if result: + from datetime import datetime, timezone + self.db.insert_message( + telegram_message_id=result.message_id, + chat_id=self.group_chat_id, + sender_type="mcp_bot", + sender_id=self._my_bot_id, + sender_name=f"[{attribution}]", + content=text, + reply_to_message_id=None, + has_attachment=False, + created_at=datetime.now(timezone.utc).isoformat(), + ) @staticmethod def _escape_markdown(text: str) -> str: