Feishu: route comment targets through comment replies

This commit is contained in:
wangweiming
2026-04-01 13:14:30 +08:00
committed by George Zhang
parent 4bbce18e99
commit 6d3c59bd79
3 changed files with 56 additions and 2 deletions

View File

@@ -310,7 +310,7 @@ describe("resolveDriveCommentEventTurn", () => {
});
it("skips comment notices when bot open_id is unavailable", async () => {
const synthetic = await resolveDriveCommentSyntheticEvent({
const turn = await resolveDriveCommentEventTurn({
cfg: buildMonitorConfig(),
accountId: "default",
event: makeDriveCommentEvent(),
@@ -318,7 +318,7 @@ describe("resolveDriveCommentEventTurn", () => {
createClient: () => makeOpenApiClient({}) as never,
});
expect(synthetic).toBeNull();
expect(turn).toBeNull();
});
});

View File

@@ -235,6 +235,50 @@ describe("feishuOutbound comment-thread routing", () => {
expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
});
it("routes comment-thread code-block replies through replyComment instead of IM cards", async () => {
const result = await sendText({
cfg: emptyConfig,
to: "comment:docx:doxcn123:7623358762119646411",
text: "```ts\nconst x = 1\n```",
accountId: "main",
});
expect(replyCommentMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
file_token: "doxcn123",
file_type: "docx",
comment_id: "7623358762119646411",
content: "```ts\nconst x = 1\n```",
}),
);
expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
});
it("routes comment-thread replies through replyComment even when renderMode=card", async () => {
const result = await sendText({
cfg: cardRenderConfig,
to: "comment:docx:doxcn123:7623358762119646411",
text: "handled in thread",
accountId: "main",
});
expect(replyCommentMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
file_token: "doxcn123",
file_type: "docx",
comment_id: "7623358762119646411",
content: "handled in thread",
}),
);
expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
});
it("falls back to a text-only comment reply for media payloads", async () => {
const result = await feishuOutbound.sendMedia?.({
cfg: emptyConfig,

View File

@@ -153,6 +153,16 @@ export const feishuOutbound: ChannelOutboundAdapter = {
}
}
if (parseFeishuCommentTarget(to)) {
return await sendOutboundText({
cfg,
to,
text,
accountId: accountId ?? undefined,
replyToMessageId,
});
}
const account = resolveFeishuAccount({ cfg, accountId: accountId ?? undefined });
const renderMode = account.config?.renderMode ?? "auto";
const useCard = renderMode === "card" || (renderMode === "auto" && shouldUseCard(text));