Skip to content

Commit d50b177

Browse files
committed
fix(feishu): retain native presentation outbound hooks
1 parent 0dcad82 commit d50b177

2 files changed

Lines changed: 65 additions & 13 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
2+
import { feishuPlugin } from "../channel-plugin-api.js";
3+
4+
const renderPresentation = vi.hoisted(() => vi.fn());
5+
const sendPayload = vi.hoisted(() => vi.fn());
6+
7+
vi.mock("./channel.runtime.js", () => ({
8+
feishuChannelRuntime: { feishuOutbound: { renderPresentation, sendPayload } },
9+
}));
10+
11+
afterAll(() => {
12+
vi.doUnmock("./channel.runtime.js");
13+
vi.resetModules();
14+
});
15+
16+
describe("Feishu public outbound presentation hooks", () => {
17+
beforeEach(() => {
18+
vi.resetAllMocks();
19+
});
20+
21+
const presentation = { title: "Status", blocks: [{ type: "text" as const, text: "Ready" }] };
22+
const payload = { presentation };
23+
const ctx = {
24+
cfg: {},
25+
to: "chat:oc_group",
26+
accountId: "work",
27+
threadId: "om_parent",
28+
text: "",
29+
payload,
30+
};
31+
32+
it("renders and sends native payloads through the advertised plugin capability", async () => {
33+
const rendered = { channelData: { feishu: { card: { schema: "2.0" } } } };
34+
const receipt = { channel: "feishu", messageId: "om_card" };
35+
renderPresentation.mockResolvedValueOnce(rendered);
36+
sendPayload.mockResolvedValueOnce(receipt);
37+
38+
expect(feishuPlugin.outbound?.presentationCapabilities?.supported).toBe(true);
39+
const renderContext = { ctx, payload, presentation };
40+
const result = await feishuPlugin.outbound?.renderPresentation?.(renderContext);
41+
expect(renderPresentation).toHaveBeenCalledExactlyOnceWith(renderContext);
42+
expect(result).toBe(rendered);
43+
44+
const sendContext = { ...ctx, payload: rendered };
45+
await expect(feishuPlugin.outbound?.sendPayload?.(sendContext)).resolves.toBe(receipt);
46+
expect(sendPayload).toHaveBeenCalledExactlyOnceWith(sendContext);
47+
});
48+
49+
it("preserves native renderer and sender failures", async () => {
50+
const renderError = new Error("card rendering failed");
51+
renderPresentation.mockRejectedValueOnce(renderError);
52+
await expect(
53+
feishuPlugin.outbound?.renderPresentation?.({ ctx, payload, presentation }),
54+
).rejects.toBe(renderError);
55+
56+
const sendError = new Error("card delivery failed");
57+
sendPayload.mockRejectedValueOnce(sendError);
58+
await expect(feishuPlugin.outbound?.sendPayload?.(ctx)).rejects.toBe(sendError);
59+
});
60+
});

‎extensions/feishu/src/channel.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,21 +1985,13 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
19851985
},
19861986
},
19871987
},
1988-
renderPresentation: async (ctx) => {
1989-
const runtime = await loadFeishuChannelRuntime();
1990-
const renderPresentation = runtime.feishuOutbound.renderPresentation;
1991-
return renderPresentation ? await renderPresentation(ctx) : null;
1992-
},
1993-
sendPayload: async (ctx) => {
1994-
const runtime = await loadFeishuChannelRuntime();
1995-
const sendPayload = runtime.feishuOutbound.sendPayload;
1996-
if (!sendPayload) {
1997-
throw new Error("Feishu payload sending is not available.");
1998-
}
1999-
return await sendPayload(ctx);
2000-
},
20011988
...createRuntimeOutboundDelegates({
20021989
getRuntime: loadFeishuChannelRuntime,
1990+
renderPresentation: { resolve: (runtime) => runtime.feishuOutbound.renderPresentation },
1991+
sendPayload: {
1992+
resolve: (runtime) => runtime.feishuOutbound.sendPayload,
1993+
unavailableMessage: "Feishu payload sending is not available.",
1994+
},
20031995
sendText: { resolve: (runtime) => runtime.feishuOutbound.sendText },
20041996
sendMedia: { resolve: (runtime) => runtime.feishuOutbound.sendMedia },
20051997
}),

0 commit comments

Comments
 (0)