Skip to content

fix(im): 飞书卡片 2.0 与文件/markdown 发送;微信文件上传与打字状态 - #1257

Closed
Frederick1607 wants to merge 1 commit into
Fei2411:devfrom
Frederick1607:fix/im-channels
Closed

Frederick1607 wants to merge 1 commit into
Fei2411:devfrom
Frederick1607:fix/im-channels

Conversation

@Frederick1607

@Frederick1607 Frederick1607 commented Nov 9, 2026 •

Copy link
Copy Markdown

Issue

无对应 Issue,问题与复现如下(三项都是现网可复现的 bug,另两项是随之补齐的发送能力)。

What changed / 改了什么

飞书 (feishu.js)

  • 卡片按钮改用 schema 2.0 允许的结构:button 直挂 body.elements,回调用 behaviors: [{ type: 'callback', value: { v } }]。
    • 复现:审批/提问卡片发送失败,返回 Failed to create card content, ext=ErrCode: 200861; ErrPath: ROOT -> body -> elements -> [1](tag: action); ErrMsg: cards of schema V2 no longer support this capability; ErrorValue: unsupported tag action。修后同一账号发送成功。
  • markdown 回复改走 post(md 元素);此前一律发纯 text,用户看到的是 **加粗**、表格竖线等原始语法。
  • 新增文件发送:im/v1/files 上传 + msg_type=file,按扩展名映射 file_type(pdf/doc/xls/ppt/mp4/stream)。
  • 图片改走 im/v1/images + msg_type=image,直接内联显示,不再当附件。
  • 收到消息时给用户的这条消息打 Typing 表情,回复发出后换成 👍。

宿主 (im/index.js)

  • Bot 回复里单独一行 [[file:/绝对路径]] 会被替换成该文件的发送任务(同一会话、走同一条队列)。

微信 (weixin.js)

  • 新增文件发送:ilink/bot/getuploadurl → AES-128-ECB 加密 → CDN 上传 → sendmessage 的 type: 4 / file_item。
  • 上传地址白名单同时接受 weixin.qq.com 与 wechat.com 两类域名:本账号实际返回的是 novac2c.cdn.wechat.com,原白名单只有 novac2c.cdn.weixin.qq.com,会被判为不可信地址直接失败。
  • 修复打字状态:宿主调用 typing() 时传的是 { key: chat.key ?? chat },而 conn.chats 的 key 存在对象外部,chat.key 永远是 undefined,于是整个 chat 对象被当作 user id 发给 getconfig(日志里是 typing [object Object] ticket=none),拿不到 typing_ticket,微信端永远不显示「正在输入」。
    • 改为从 targetsOf 取真正的 chatKey;getconfig 补上 context_token;工单缓存 10 分钟;发 status=1 后 12 秒内无新动静则发 status=2 停止,避免指示器一直转。

Changelog

飞书和微信都能发文件了,飞书卡片不再发送失败、markdown 正常渲染,微信恢复「正在输入」提示。

How I checked it / 怎么验证的

  • npm test (in ds-bot/)
  • node scripts/build-client.mjs --check
  • npm run lint
  • Smoke test, for changes to index.js or src/host/ / 改了 index.js 或 src/host/ 时跑冒烟测试
  • Screenshot attached, for interface changes / 界面改动已附截图

冒烟验证在真实环境完成:一个 Lark 国际版租户(5 个应用)与一个微信 iLink 账号,改动在本地安装的 0.3.2 上跑通后再整理成本分支。单元测试与 lint 未在本机执行(未安装仓库依赖),交给 CI。

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 未改 src/client/。
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。

Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 6 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

for (const { chatKey, chat } of listeners(conn, { botId })) {
const where = { key: chatKey, kind: chat.kind, title: chat.title }
if (body !== '') sendTo(conn, chatKey, where, body)
for (const path of files) enqueue(conn, chatKey, { chat: where, path })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Files disappear on unsupported chat platforms

When a Bot replies with [[file:...]] to another platform, splitFiles removes the marker and queues a file. Those adapters ignore file, so the attachment never reaches the chat.

Learn more

The outbound listener sends every extracted path through the same queue for all eight adapters. Only the Feishu and WeChat adapters consume a queued job's file; adapters such as Telegram's send receive no text in the file job and cannot deliver the attachment. The marker has already been removed from the text, so the user gets no file and often no indication of failure.

Example: A Telegram-bound Bot replies Here is the report:\n[[file:/tmp/report.pdf]]. Telegram receives the introductory text, but the file job has no usable text or attachment and disappears.

Recommended fix: Check the connected adapter's file capability before removing the marker for that chat. Keep an explicit file reference or send a clear unsupported-attachment notice on platforms without outbound file support.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

if (item.kind !== 'bot' && item.kind !== 'view') continue
const body = item.kind === 'bot' ? item.text : viewCardText({ title: item.title, view: item.view }) || (item.title ?? '')
const raw = item.kind === 'bot' ? item.text : viewCardText({ title: item.title, view: item.view }) || (item.title ?? '')
const { text: body, files } = splitFiles(raw)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Group replies expose raw file markers

When a Bot posts [[file:...]] in a bound group, splitFiles never sees that reply. The room listener sends the raw marker as text instead of the file.

Learn more

Bot messages in a room travel through rt.onRoomLine, not through the own-chat session/event projection. The new file extraction applies only to the latter, while the room listener sends line.text unchanged. Thus the file-marker protocol works in direct Bot chats but fails in bound groups.

Example: A room member posts Done\n[[file:/tmp/report.pdf]]; the bound Feishu group receives the literal file path and no report attachment.

Recommended fix: Apply the same attachment splitting and ordered file-job enqueueing in the room listener, preserving the member label on the remaining text.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

headers: { authorization: `Bearer ${await tokenNow()}` },
body: form,
}).then(response => response.json())
if (uploaded?.code !== 0) throw fail(`Feishu refused the file (${uploaded?.msg ?? 'unknown'})`, { permanent: true })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Transient Feishu upload failures drop files

If Feishu returns a 429 or 503 upload response, sendFile marks its nonzero code permanent. The send queue drops the file instead of retrying after recovery.

Learn more

The new multipart upload bypasses api, which distinguishes transient HTTP failures from permanent 4xx refusals. For either an image or another file, sendFile marks every nonzero JSON code permanent, even if its HTTP status is 429 or 503. The send queue then discards that job rather than scheduling a retry.

Example: A PDF upload returns HTTP 503 with { "code": 500, "msg": "unavailable" }. The job is removed and the PDF never arrives, even after Feishu recovers.

Recommended fix: Inspect response.ok, response.status, and the API code for both multipart uploads. Preserve retryable classification and any retry-after value for 429 and 5xx responses.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +209 to +212
if (job.path !== undefined && job.file === undefined) {
job.file = await readFile(job.path)
.then(data => ({ name: basename(job.path), data }))
.catch(() => undefined)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 Bot replies can disclose host files

A paired user can induce a Bot to emit [[file:/absolute/path]]. The host reads that path without an attachment authorization check and sends its contents to the chat.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +25 to +26
const IM_DEBUG_LOG = '/home/ubuntu/.dsh/bot/workspace/logs/im-file.log'
const imLog = (line) => appendFile(IM_DEBUG_LOG, `${new Date().toISOString()} ${line}\n`).catch(() => {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 Debug logging writes into personal DSH data

On a machine with this home directory, imLog appends to the user's .dsh tree regardless of the active profile. File paths and send errors cross the profile boundary.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

queue.jobs.shift()
} catch (error) {
const how = failClass(error)
imLog(`send failed (${how}; file=${job.file?.name ?? '-'}): ${error?.message ?? error}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 Send errors can persist unredacted tokens

When a platform error quotes a credential, imLog writes the raw message to disk. Unlike setStatus, this path never redacts secrets.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:REQUEST_CHANGES — 请先拆分

几个问题都是真实存在的(schema 2.0 按钮报 200861、Markdown 原样显示、文件发不出去),但这个 PR 现在没法按原样合并:

  1. 冲突且严重落后:与 dev(a95e3af4)在 im/index.js、feishu.js、weixin.js 三处都有文本冲突,落后约 941 个提交。请用 scripts/merge-dev.sh 同步,不要 rebase 或 force-push。
  2. 飞书按钮修复与 #1680 重复:#1680 基于当前 dev,已改成 column_set + behaviors: callback 并通过测试。建议这里删掉卡片按钮部分,以 #1680 为准。
  3. Markdown 渲染与 #1670 重叠:#1670 把每个分块都发成 markdown 卡片。这里改走 post(md)是另一种方案,两者只能选一,建议跟随 #1670 的卡片方案。
  4. 剩下的部分各自单独开 PR:
    • 飞书出站文件/图片上传(im/v1/files + msg_type=file):需要和 #1765(本地回复图片经 markdown-image 端点读取,含工作区/大小检查)协调,避免两套读本地文件的路径。请确认文件读取同样经过工作区与大小校验。
    • 微信文件上传与“正在输入”状态:独立的一件事,单独评审。
  5. 缺少测试:三个文件只改了源码,没有对应的 test/ 改动。拆分后的每个 PR 都请补上单测,并按模板关联 Issue(目前写的是“无对应 Issue”,建议先开 Issue 再用 Fixes #)。

@Fei2411

Fei2411 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

感谢反馈!但本 PR 混入了硬编码本机路径与未立项的本地文件协议外发且审查后未拆分,先关闭本 PR。

@Fei2411 Fei2411 closed this Nov 20, 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.

2 participants