fix(agent-office): Telegram HTML escape + 4096자 제한 + 실패 원인 로깅
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""에이전트 메시지 포맷팅."""
|
||||
from html import escape as _h
|
||||
from typing import Literal, Optional
|
||||
|
||||
from .agent_registry import get_agent_meta
|
||||
@@ -23,9 +24,14 @@ def format_agent_message(
|
||||
) -> str:
|
||||
meta = get_agent_meta(agent_id)
|
||||
icon = KIND_ICONS.get(kind, "")
|
||||
header = f"{icon} <b>[{meta['emoji']} {meta['display_name']}]</b> {title}"
|
||||
header = f"{icon} <b>[{_h(meta['emoji'])} {_h(meta['display_name'])}]</b> {_h(title)}"
|
||||
|
||||
lines = [header, "━" * 20, body]
|
||||
# Telegram 단일 메시지 4096자 제한 대응 (헤더/푸터 여유 512자 확보)
|
||||
safe_body = _h(body)
|
||||
if len(safe_body) > 3500:
|
||||
safe_body = safe_body[:3500] + "\n…(생략)"
|
||||
|
||||
lines = [header, "━" * 20, safe_body]
|
||||
|
||||
if metadata:
|
||||
footer_parts = []
|
||||
@@ -38,6 +44,6 @@ def format_agent_message(
|
||||
footer_parts.append(f"🤖 {metadata['model']}")
|
||||
if footer_parts:
|
||||
lines.append("")
|
||||
lines.append(f"<i>{' · '.join(footer_parts)}</i>")
|
||||
lines.append(f"<i>{_h(' · '.join(footer_parts))}</i>")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -20,9 +20,12 @@ async def send_raw(text: str, reply_markup: Optional[dict] = None) -> dict:
|
||||
if reply_markup:
|
||||
payload["reply_markup"] = reply_markup
|
||||
result = await api_call("sendMessage", payload)
|
||||
ok = result.get("ok", False)
|
||||
return {
|
||||
"ok": result.get("ok", False),
|
||||
"message_id": result.get("result", {}).get("message_id") if result.get("ok") else None,
|
||||
"ok": ok,
|
||||
"message_id": result.get("result", {}).get("message_id") if ok else None,
|
||||
"description": result.get("description") if not ok else None,
|
||||
"error_code": result.get("error_code") if not ok else None,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user