fix(feishu): treat single-text-paragraph posts as commands (#57)

Treat attachment-free Feishu rich-text posts containing bot commands like ordinary text commands instead of forwarding them to the Harness.

Co-authored-by: OpenClaw Agent <agent@openclaw.ai>
This commit is contained in:
Evilh2019 2026-08-25 19:28:20 +08:00 • committed by GitHub
parent d33ae50643
commit adeab2dec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 12 deletions

View file

@ -945,7 +945,10 @@ export class FeishuHarnessBridge {
const text = message.content;
const hasImages = hasInboundImages(message);
const hasFiles = hasInboundFiles(message);
const commandText = event.message.message_type === 'text' && !hasImages && !hasFiles ? text : null;
// 命令识别对 text 与纯文本 post 一视同仁:post 富文本若仅含单个
// 文本段落(如复制粘贴的 /new),同样按命令处理;带图片/文件不认。
// accept() 侧已用 nonEmptyString(content) 判定,两侧保持一致。
const commandText = !hasImages && !hasFiles && text ? text.trim() : null;
if (!text && !hasImages && !hasFiles) {
await this.#send(event.message.chat_id, t('目前支持文字、图片和文件消息。'));
return;

View file

@ -1075,7 +1075,7 @@ test('bridge sends Feishu post text and all embedded images as one structured pr
assert.deepEqual(sent, ['两张图片都已收到']);
});
test('text inside a Feishu post is a model prompt rather than a local or batch command', async () => {
test('a single-text-paragraph Feishu post is treated as a command like a text message', async () => {
const fixture = stateFixture([['p2p:ou_user', 'session-post-command']]);
const asked = [];
const sent = [];
@ -1098,18 +1098,12 @@ test('text inside a Feishu post is a model prompt rather than a local or batch c
message_type: 'post',
content: JSON.stringify({ content: [[{ tag: 'text', text: '/new' }]] }),
}));
await bridge.accept(event('om_post_batch_command', '', {
message_type: 'post',
content: JSON.stringify({ content: [[{ tag: 'text', text: '/batch' }]] }),
}));
await bridge.waitForIdle();
assert.equal(fixture.sessions.get('p2p:ou_user'), 'session-post-command');
assert.deepEqual(asked, [
{ sessionId: 'session-post-command', content: '/new' },
{ sessionId: 'session-post-command', content: '/batch' },
]);
assert.deepEqual(sent, ['按普通内容处理', '按普通内容处理']);
// /new 在 post 单文本段落中现在按命令处理:解除会话绑定并回复确认。
assert.equal(fixture.sessions.get('p2p:ou_user'), undefined);
assert.ok(sent.some((line) => /已开启全新/.test(line)));
assert.deepEqual(asked, []);
});
test('a threaded Feishu reply answers a pending Harness question before the original turn queue', async () => {