mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
fix(feishu): parse code blocks and share_chat messages (openclaw#28591) thanks @kevinWangSheng
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: kevinWangSheng <118158941+kevinWangSheng@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -36,6 +36,20 @@ function makePostEvent(content: unknown) {
|
||||
};
|
||||
}
|
||||
|
||||
function makeShareChatEvent(content: unknown) {
|
||||
return {
|
||||
sender: { sender_id: { user_id: "u1", open_id: "ou_sender" } },
|
||||
message: {
|
||||
message_id: "msg_1",
|
||||
chat_id: "oc_chat1",
|
||||
chat_type: "group",
|
||||
message_type: "share_chat",
|
||||
content: JSON.stringify(content),
|
||||
mentions: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("parseFeishuMessageEvent – mentionedBot", () => {
|
||||
const BOT_OPEN_ID = "ou_bot_123";
|
||||
|
||||
@@ -127,4 +141,36 @@ describe("parseFeishuMessageEvent – mentionedBot", () => {
|
||||
const ctx = parseFeishuMessageEvent(event as any, "ou_bot_123");
|
||||
expect(ctx.mentionedBot).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves post code and code_block content", () => {
|
||||
const event = makePostEvent({
|
||||
content: [
|
||||
[
|
||||
{ tag: "text", text: "before " },
|
||||
{ tag: "code", text: "inline()" },
|
||||
],
|
||||
[{ tag: "code_block", language: "ts", text: "const x = 1;" }],
|
||||
],
|
||||
});
|
||||
const ctx = parseFeishuMessageEvent(event as any, "ou_bot_123");
|
||||
expect(ctx.content).toContain("before `inline()`");
|
||||
expect(ctx.content).toContain("```ts\nconst x = 1;\n```");
|
||||
});
|
||||
|
||||
it("uses share_chat body when available", () => {
|
||||
const event = makeShareChatEvent({
|
||||
body: "Merged and Forwarded Message",
|
||||
share_chat_id: "sc_abc123",
|
||||
});
|
||||
const ctx = parseFeishuMessageEvent(event as any, "ou_bot_123");
|
||||
expect(ctx.content).toBe("Merged and Forwarded Message");
|
||||
});
|
||||
|
||||
it("falls back to share_chat identifier when body is unavailable", () => {
|
||||
const event = makeShareChatEvent({
|
||||
share_chat_id: "sc_abc123",
|
||||
});
|
||||
const ctx = parseFeishuMessageEvent(event as any, "ou_bot_123");
|
||||
expect(ctx.content).toBe("[Forwarded message: sc_abc123]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user