Skip to content

fix(feishu): 卡片剔除 markdown 图片,4xx 拒收不再重试 - #153

Merged
PeterBon merged 1 commit into
mainfrom
fix/feishu-card-images
Nov 19, 2026
Merged

PeterBon merged 1 commit into
mainfrom
fix/feishu-card-images

Conversation

@PeterBon

Copy link
Copy Markdown
Owner

问题

turn/end 通知把最终回答原样放进飞书卡片;回答里的 ![alt](本地路径) 会被飞书当作 img_key 解析,而卡片图片只能用 im/v1/images 上传换来的 key,于是整张卡片被拒收:

飞书通知失败: 飞书接口 HTTP 400 msg=Failed to create card content,
ext=ErrCode: 200570; ErrMsg: card contains invalid image keys;
ErrorValue: image key .dsh-tmp/api-key-trend-desktop.png;

实测于会话「审查Web端后端并修复推送」:本地图表 yixin-ai/.dsh-tmp/api-key-trend-desktop.png 被写进回答,通知失败且 retries 会重试一个确定性错误。

改动

  • examples/notify-feishu.mjs:新增 stripCardImages(),把 ![alt](任意目标) / ![alt][ref] 降级为 🖼 alt;buildBody 在截断前剔除,buildCard 对最终卡片正文兜底,--text 模式同样清理。
  • src/feishu-notify.ts:isPermanentFeishuError 解析 飞书接口 HTTP <status>,4xx(408/429 除外)判永久失败;5xx/传输失败仍重试。
  • examples/notify-feishu.d.mts 补声明;两份 README 同步说明;lib/ 随构建更新。
  • 测试:新增 7 条 stripCardImages 用例 + 2 条 buildBody/buildCard 用例 + 2 条重试分类用例。

验证

  • tsc(主 / client / test)全绿;vitest run 548/548 通过;tsc + tsdown 构建通过。
  • 端到端冒烟:用失败场景正文走完整 run(),发出的卡片正文为 … 🖼 桌面端 API Key 用量趋势图 …,不再含 ![](。

turn/end 的最终回答里带 ![alt](本地路径) 时,飞书把路径当成 img_key,整张卡片被 400/200570 拒收。现在 buildBody/buildCard 统一把图片降级为 🖼 alt(截断前先剔除,避免切出半截语法),--text 模式同样清理。isPermanentFeishuError 把 4xx(408/429 除外)判为永久失败,确定性错误不再白重试。
@PeterBon
PeterBon merged commit bb3e32e into main Nov 19, 2026
4 checks passed
@PeterBon
PeterBon deleted the fix/feishu-card-images branch November 19, 2026 01:50
@PeterBon PeterBon mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant