diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b9a562e7..307570976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ This file records the notable changes in each dsh-im release. Its format follows ### Fixed / 修复 +- 飞书受校验的 Bot 回复(回复原消息与发到群聊)使用 Markdown 时,改用与聊天相同的原生 Markdown 卡片发送,加粗、标题、列表、表格不再以星号、井号、竖线原样显示;纯文本和带 `` 提及的回复仍按文本发送,保持其他 Bot 的提及接收与自身 Echo 确认不变([BotHarness #2792](https://github.com/BotHarness/DeepSeekBot/issues/2792))。 + Checked Lark Bot replies, both replies to the source message and posts to a group, are sent as the same native Markdown card as chat when they use Markdown, so bold, headings, lists and tables no longer show as raw asterisks, hashes and pipes. Plain replies and replies carrying a `` mention stay text, so other Bots still receive the mention and own Echo confirmation is unchanged ([BotHarness #2792](https://github.com/BotHarness/DeepSeekBot/issues/2792)). + - 兼容 DSH 0.2.1 Typert Gateway:dsh-im 在每次调用时声明本机 owner Peer,修复只能收消息、无法创建会话并报 `INTERNAL_UNKNOWN` 的问题;Gateway 协议错误现在归类为 Harness 接口不兼容([BotHarness #2896](https://github.com/BotHarness/DeepSeekBot/issues/2896))。 Supports the DSH 0.2.1 Typert Gateway: dsh-im names the local owner Peer on every call, fixing bots that received messages but could not create a session (`INTERNAL_UNKNOWN`). Gateway contract failures now classify as a Harness interface mismatch ([BotHarness #2896](https://github.com/BotHarness/DeepSeekBot/issues/2896)). diff --git a/src/channels/feishu/feishu-runtime.mjs b/src/channels/feishu/feishu-runtime.mjs index e77c250b2..a228bc50e 100644 --- a/src/channels/feishu/feishu-runtime.mjs +++ b/src/channels/feishu/feishu-runtime.mjs @@ -32,6 +32,23 @@ const CALLBACK_PROBE_SEND_FAILURE_NOTICE = '⚠️ 修复验证失败:无法 const CALLBACK_PROBE_ABORT_NOTICE = '⚠️ 修复验证中断:Runtime 已停止,未完成 card.action.trigger 实测,不能确认修复成功。请不要重复授权;先等待机器人恢复连接。'; const REUSABLE_WS_STATES = new Set(['connected', 'connecting', 'reconnecting']); +// Checked Bot replies arrive as Markdown. Lark shows it only inside a card, so +// a reply that uses Markdown goes out as the same native Markdown element as +// chat. Plain replies and replies carrying a text-message stay +// text: cards do not render that mention syntax, and other Bots and own echoes +// are read from text messages only. +const MARKDOWN_SYNTAX = /(^|\n)[ \t]{0,3}(#{1,6}[ \t]|[-*+][ \t]|\d{1,9}[.)][ \t]|>|```|\|.*\|)|\*\*\S|__\S|~~\S|`[^`\n]+`|\[[^\]\n]+\]\([^)\s]+\)/; + +export function checkedTextFormat(text) { + return !text.includes(' { + for (const text of ['**Done**', '# Report', '- one\n- two', '1. first', '| a | b |\n| - | - |', 'see `pnpm test`', '[PR](https://example.com)', '> quoted', 'intro\n```js\nx\n```']) + assert.equal(checkedTextFormat(text), 'markdown', text); + for (const text of ['hello', 'LARK-SETUP-OK', '2 * 3 = 6', 'a-b', 'version 1.6.0', 'B **please review**']) + assert.equal(checkedTextFormat(text), 'plain', text); + + const runtime = new FeishuRuntime({ lark: fakeLark(), appId: 'app', appSecret: 'secret', ownerOpenIds: ['*'], + consumerMode: 'external-consumer', harness: { async ensureRunning() {} }, state: {} }); + const starting = runtime.start(); + await waitFor(() => FakeWSClient.instances.length === 1); + FakeWSClient.instances[0].becomeReady(); await starting; + const client = FakeClient.instances[0]; + client.im.v1.message.get = async () => ({ code: 0, data: { items: [{ message_id: 'message', chat_id: 'chat', + sender: { sender_type: 'user', id_type: 'open_id', id: 'human' } }] } }); + const replies = []; + client.im.v1.message.reply = async request => { replies.push(request.data); return { code: 0, data: { message_id: 'reply' } }; }; + const route = { messageId: 'message', conversationId: 'chat', actorId: 'human' }; + await runtime.replyChecked(route, '## Result\n\n**Bold** and a table:\n\n| a | b |\n| - | - |'); + await runtime.replyChecked(route, 'hello'); + assert.equal(replies[0].msg_type, 'interactive'); + assert.deepEqual(JSON.parse(replies[0].content), { schema: '2.0', body: { elements: [{ tag: 'markdown', + content: '## Result\n\n**Bold** and a table:\n\n| a | b |\n| - | - |' }] } }); + assert.deepEqual(replies[1], { msg_type: 'text', content: JSON.stringify({ text: 'hello' }), reply_in_thread: false }); + await runtime.stop(); +}); + + test('own-account qualification maps the sender without borrowing an ingress app identity and yields a checked reply receipt', async () => { const runtime = new FeishuRuntime({ lark: fakeLark(), appId: 'responder', appSecret: 'secret', ownerOpenIds: ['*'], consumerMode: 'external-consumer', harness: { async ensureRunning() {} }, state: {} }); diff --git a/test/reachable-feishu.test.mjs b/test/reachable-feishu.test.mjs index a5315e2a9..8e0977999 100644 --- a/test/reachable-feishu.test.mjs +++ b/test/reachable-feishu.test.mjs @@ -48,4 +48,8 @@ test('public Lark posting checks the verified Bot in paginated native moderator sent: true, receipt: { version: 1, messageId: 'om_restricted', conversationId: 'oc_restricted' }, }); assert.equal(sends.length, 1); + assert.equal(sends[0].data.msg_type, 'text'); + await service.postConversationChecked('bot_one', 'oc_restricted', '**Weekly report**\n\n- shipped', options); + assert.equal(sends[1].data.msg_type, 'interactive'); + assert.equal(JSON.parse(sends[1].data.content).body.elements[0].content, '**Weekly report**\n\n- shipped'); });