fix(feishu): harden routing, parsing, and media delivery

This commit is contained in:
Peter Steinberger
2026-03-02 03:21:44 +00:00
parent cdbed3c9b1
commit 6ea3a47dae
12 changed files with 379 additions and 64 deletions

View File

@@ -68,4 +68,101 @@ describe("getMessageFeishu", () => {
}),
);
});
it("extracts text content from post messages", async () => {
mockClientGet.mockResolvedValueOnce({
code: 0,
data: {
items: [
{
message_id: "om_post",
chat_id: "oc_post",
msg_type: "post",
body: {
content: JSON.stringify({
zh_cn: {
title: "Summary",
content: [[{ tag: "text", text: "post body" }]],
},
}),
},
},
],
},
});
const result = await getMessageFeishu({
cfg: {} as ClawdbotConfig,
messageId: "om_post",
});
expect(result).toEqual(
expect.objectContaining({
messageId: "om_post",
chatId: "oc_post",
contentType: "post",
content: "Summary\n\npost body",
}),
);
});
it("returns text placeholder instead of raw JSON for unsupported message types", async () => {
mockClientGet.mockResolvedValueOnce({
code: 0,
data: {
items: [
{
message_id: "om_file",
chat_id: "oc_file",
msg_type: "file",
body: {
content: JSON.stringify({ file_key: "file_v3_123" }),
},
},
],
},
});
const result = await getMessageFeishu({
cfg: {} as ClawdbotConfig,
messageId: "om_file",
});
expect(result).toEqual(
expect.objectContaining({
messageId: "om_file",
chatId: "oc_file",
contentType: "file",
content: "[file message]",
}),
);
});
it("supports single-object response shape from Feishu API", async () => {
mockClientGet.mockResolvedValueOnce({
code: 0,
data: {
message_id: "om_single",
chat_id: "oc_single",
msg_type: "text",
body: {
content: JSON.stringify({ text: "single payload" }),
},
},
});
const result = await getMessageFeishu({
cfg: {} as ClawdbotConfig,
messageId: "om_single",
});
expect(result).toEqual(
expect.objectContaining({
messageId: "om_single",
chatId: "oc_single",
contentType: "text",
content: "single payload",
}),
);
});
});