diff --git a/nanobot/channels/feishu.py b/nanobot/channels/feishu.py index 5d6c33b..bc4a2b8 100644 --- a/nanobot/channels/feishu.py +++ b/nanobot/channels/feishu.py @@ -40,15 +40,19 @@ MSG_TYPE_MAP = { def _extract_post_text(content_json: dict) -> str: - """Extract plain text from Feishu post (rich text) message content.""" - for lang_key in ("zh_cn", "en_us", "ja_jp"): - lang_content = content_json.get(lang_key) + """Extract plain text from Feishu post (rich text) message content. + + Supports two formats: + 1. Direct format: {"title": "...", "content": [...]} + 2. Localized format: {"zh_cn": {"title": "...", "content": [...]}} + """ + def extract_from_lang(lang_content: dict) -> str | None: if not isinstance(lang_content, dict): - continue + return None title = lang_content.get("title", "") content_blocks = lang_content.get("content", []) if not isinstance(content_blocks, list): - continue + return None text_parts = [] if title: text_parts.append(title) @@ -64,7 +68,21 @@ def _extract_post_text(content_json: dict) -> str: text_parts.append(element.get("text", "")) elif tag == "at": text_parts.append(f"@{element.get('user_name', 'user')}") - return " ".join(text_parts).strip() + return " ".join(text_parts).strip() if text_parts else None + + # Try direct format first + if "content" in content_json: + result = extract_from_lang(content_json) + if result: + return result + + # Try localized format + for lang_key in ("zh_cn", "en_us", "ja_jp"): + lang_content = content_json.get(lang_key) + result = extract_from_lang(lang_content) + if result: + return result + return ""