Skip to content

飞书流式卡片更新失败:Agent 回复包含外部图片 URL 时报 invalid image keys #5818

@tianxia3111

Description

@tianxia3111

问题描述

当 MoviePilot Agent 在飞书对话回复中使用 Markdown 图片语法(如 ![海报](https://image.tmdb.org/t/p/original/xxx.jpg))时,飞书流式卡片更新会失败,报错:

飞书流式卡片内容更新失败:card_id=xxx, element_id=mp_stream_body, sequence=7, code=200570, msg=ErrMsg: card contains invalid image keys; ErrorValue: image key https://image.tmdb.org/t/p/original/xxx.jpg

复现步骤

  1. 配置飞书通知渠道,启用 Agent 对话功能
  2. 向 Agent 发送搜索请求(如搜索电影)
  3. Agent 回复中包含 TMDB 海报图片的 Markdown 语法
  4. 飞书流式卡片更新失败

问题原因

飞书卡片 API 不支持直接使用外部 URL 作为图片 key。Agent 回复中的 Markdown 图片语法 ![...](url) 被飞书解析为图片 key,但外部 URL 不是有效的飞书 image key。

临时解决方案

app/modules/feishu/feishu.py_escape_card_text 方法中,添加正则表达式移除 Markdown 图片语法:

@staticmethod
def _escape_card_text(text: Optional[str]) -> str:
    """转义飞书卡片 markdown 中易误触的字符,同时移除外部图片语法。"""
    if not text:
        return ""
    escaped = str(text)
    import re as _re
    escaped = _re.sub(r"!\[[^\]]*\]\([^)]*\)", "", escaped)
    for source, target in {
        "\\": "\",
        "<": "&#60;",
        ">": "&#62;",
    }.items():
        escaped = escaped.replace(source, target)
    return escaped

建议修复

  1. _escape_card_text 方法中自动过滤外部图片语法
  2. 或者在 Agent 回复逻辑中,避免直接使用 Markdown 图片语法,改用飞书的图片上传接口

环境信息

  • MoviePilot 版本:v2 (latest)
  • 部署方式:Docker
  • 飞书模块:app/modules/feishu/feishu.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions