diff --git a/telegram/bot.py b/telegram/bot.py index c7c06d4..2edd3cb 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -720,7 +720,28 @@ IMPORTANT: Two special tags you can append at the end of your response (after yo logger.info("Auto-research triggered: %s", query[:80]) # Post response (without LEARNING lines) - await msg.reply_text(display_response) + # Telegram has a 4096 char limit — split long messages + if len(display_response) <= 4096: + await msg.reply_text(display_response) + else: + # Split on paragraph boundaries where possible + chunks = [] + remaining = display_response + while remaining: + if len(remaining) <= 4096: + chunks.append(remaining) + break + # Find a good split point (paragraph break near 4000 chars) + split_at = remaining.rfind("\n\n", 0, 4000) + if split_at == -1: + split_at = remaining.rfind("\n", 0, 4096) + if split_at == -1: + split_at = 4096 + chunks.append(remaining[:split_at]) + remaining = remaining[split_at:].lstrip("\n") + for chunk in chunks: + if chunk.strip(): + await msg.reply_text(chunk) # Update conversation state: reset window, store history (Ganymede+Rhea) if user: