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: