Fixed telegram integration

This commit is contained in:
Alishahryar1
2026-01-28 19:00:27 -08:00
parent 56635433ba
commit c399faac69
2 changed files with 21 additions and 5 deletions
+9 -2
View File
@@ -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":
+12 -3
View File
@@ -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: