From c399faac691947fd3917a28a55db8433845d1fbf Mon Sep 17 00:00:00 2001 From: Alishahryar1 Date: Wed, 28 Jan 2026 19:00:27 -0800 Subject: [PATCH] Fixed telegram integration --- providers/claude_cli.py | 11 +++++++++-- server.py | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/providers/claude_cli.py b/providers/claude_cli.py index 673d4bc7..c1ebbf09 100644 --- a/providers/claude_cli.py +++ b/providers/claude_cli.py @@ -24,10 +24,12 @@ class CLIParser: elif etype == "result": # Safely get message from result which might be a list or dict res = event.get("result") + logger.debug(f"Parsing result event: res type={type(res)}, keys={res.keys() if isinstance(res, dict) else 'N/A'}") if isinstance(res, dict): msg_obj = res.get("message") if not msg_obj: msg_obj = event.get("message") + logger.debug(f"Result msg_obj: {msg_obj is not None}, type={type(msg_obj) if msg_obj else 'None'}") if msg_obj and isinstance(msg_obj, dict): content = msg_obj.get("content", []) @@ -57,10 +59,15 @@ class CLIParser: return {"type": "subagent_start", "tasks": subagents} return {"type": "tool_start", "tools": tool_calls} + # Return combined result if we have content + result = {} if thinking_parts: - return {"type": "thinking", "text": "\n".join(thinking_parts)} + result["thinking"] = "\n".join(thinking_parts) if parts: - return {"type": "content", "text": "".join(parts)} + result["text"] = "".join(parts) + if result: + result["type"] = "content" + return result # 2. Handle streaming deltas if etype == "content_block_delta": diff --git a/server.py b/server.py index 33b83b03..39ba3636 100644 --- a/server.py +++ b/server.py @@ -373,13 +373,21 @@ def register_bot_handlers(client: "TelegramClient"): continue if parsed["type"] == "thinking": - # Display thinking tokens with special prefix + # Display thinking tokens with special prefix (streaming) thinking_text = parsed["text"] await event.reply(f"💭 **Thinking:**\n```\n{thinking_text[:1500]}{'...' if len(thinking_text) > 1500 else ''}\n```", parse_mode="markdown") elif parsed["type"] == "content": - current_content += parsed["text"] - await update_bot_ui(current_content, "🧠 **Claude is working...**") + # Handle thinking if present in combined event + if parsed.get("thinking"): + thinking_text = parsed["thinking"] + logger.debug(f"BOT: Got thinking: {len(thinking_text)} chars") + await event.reply(f"💭 **Thinking:**\n```\n{thinking_text[:1500]}{'...' if len(thinking_text) > 1500 else ''}\n```", parse_mode="markdown") + # Accumulate text content + if parsed.get("text"): + logger.debug(f"BOT: Got text content: {len(parsed['text'])} chars") + current_content += parsed["text"] + await update_bot_ui(current_content, "🧠 **Claude is working...**") elif parsed["type"] == "tool_start": names = [t.get("name") for t in parsed["tools"]] @@ -394,6 +402,7 @@ def register_bot_handlers(client: "TelegramClient"): await update_bot_ui(current_content, "🔎 **Subagent working...**") elif parsed["type"] == "complete": + logger.debug(f"BOT: Complete event, current_content length: {len(current_content)}") if parsed.get("status") == "failed": await status_msg.edit(f"❌ **Failed**\n\n{current_content}", parse_mode="markdown") else: