Repository navigation
fix(im): 飞书卡片 2.0 与文件/markdown 发送;微信文件上传与打字状态 - #1257
Frederick1607 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Devin Review found 6 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| 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 }) |
There was a problem hiding this comment.
🔴 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.
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) |
There was a problem hiding this comment.
🟡 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.
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 }) |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if (job.path !== undefined && job.file === undefined) { | ||
| job.file = await readFile(job.path) | ||
| .then(data => ({ name: basename(job.path), data })) | ||
| .catch(() => undefined) |
There was a problem hiding this comment.
| 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(() => {}) |
There was a problem hiding this comment.
| queue.jobs.shift() | ||
| } catch (error) { | ||
| const how = failClass(error) | ||
| imLog(`send failed (${how}; file=${job.file?.name ?? '-'}): ${error?.message ?? error}`) |
There was a problem hiding this comment.
🟨 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fei2411
left a comment
There was a problem hiding this comment.
结论:REQUEST_CHANGES — 请先拆分
几个问题都是真实存在的(schema 2.0 按钮报 200861、Markdown 原样显示、文件发不出去),但这个 PR 现在没法按原样合并:
- 冲突且严重落后:与 dev(a95e3af4)在
im/index.js、feishu.js、weixin.js三处都有文本冲突,落后约 941 个提交。请用scripts/merge-dev.sh同步,不要 rebase 或 force-push。 - 飞书按钮修复与 #1680 重复:#1680 基于当前 dev,已改成
column_set+behaviors: callback并通过测试。建议这里删掉卡片按钮部分,以 #1680 为准。 - Markdown 渲染与 #1670 重叠:#1670 把每个分块都发成 markdown 卡片。这里改走
post(md)是另一种方案,两者只能选一,建议跟随 #1670 的卡片方案。 - 剩下的部分各自单独开 PR:
- 飞书出站文件/图片上传(
im/v1/files+msg_type=file):需要和 #1765(本地回复图片经markdown-image端点读取,含工作区/大小检查)协调,避免两套读本地文件的路径。请确认文件读取同样经过工作区与大小校验。 - 微信文件上传与“正在输入”状态:独立的一件事,单独评审。
- 飞书出站文件/图片上传(
- 缺少测试:三个文件只改了源码,没有对应的
test/改动。拆分后的每个 PR 都请补上单测,并按模板关联 Issue(目前写的是“无对应 Issue”,建议先开 Issue 再用Fixes #)。
|
感谢反馈!但本 PR 混入了硬编码本机路径与未立项的本地文件协议外发且审查后未拆分,先关闭本 PR。 |
Issue
无对应 Issue,问题与复现如下(三项都是现网可复现的 bug,另两项是随之补齐的发送能力)。
What changed / 改了什么
飞书 (feishu.js)
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。修后同一账号发送成功。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)
[[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(inds-bot/)node scripts/build-client.mjs --checknpm run lintindex.jsorsrc/host// 改了index.js或src/host/时跑冒烟测试冒烟验证在真实环境完成:一个 Lark 国际版租户(5 个应用)与一个微信 iLink 账号,改动在本地安装的 0.3.2 上跑通后再整理成本分支。单元测试与 lint 未在本机执行(未安装仓库依赖),交给 CI。
Checklist / 检查
src/client/changed →npm run buildran andclient.jsis committed. / 未改src/client/。Co-authored-by. / 没有把 AI 工具写成作者或Co-authored-by。