Skip to content

Commit e0a0ba6

Browse files
committed
fix(feishu): reply inside P2P direct-message threads
1 parent 4729e2e commit e0a0ba6

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

extensions/feishu/src/bot.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,41 @@ describe("handleFeishuMessage ACP routing", () => {
435435
);
436436
});
437437

438+
it("keeps configured ACP initialization failures inside Feishu p2p threads", async () => {
439+
mockResolveConfiguredBindingRoute.mockReturnValue(createConfiguredFeishuRoute());
440+
mockEnsureConfiguredBindingRouteReady.mockResolvedValue(
441+
createConfiguredBindingReadiness(false, "runtime unavailable"),
442+
);
443+
444+
await dispatchMessage({
445+
cfg: {
446+
session: { mainKey: "main", scope: "per-sender" },
447+
channels: { feishu: { enabled: true, allowFrom: ["ou_sender_1"], dmPolicy: "open" } },
448+
},
449+
event: {
450+
sender: { sender_id: { open_id: "ou_sender_1" } },
451+
message: {
452+
message_id: "om_acp_failure_dm_thread_reply",
453+
root_id: "om_dm_thread_root",
454+
thread_id: "omt_dm_thread",
455+
chat_id: "oc_dm",
456+
chat_type: "p2p",
457+
message_type: "text",
458+
content: JSON.stringify({ text: "hello in p2p thread" }),
459+
},
460+
},
461+
});
462+
463+
expect(mockSendMessageFeishu).toHaveBeenCalledWith(
464+
expect.objectContaining({
465+
to: "chat:oc_dm",
466+
replyToMessageId: "om_dm_thread_root",
467+
replyInThread: true,
468+
text: expect.stringContaining("runtime unavailable"),
469+
}),
470+
);
471+
});
472+
438473
it("routes Feishu topic messages through active bound conversations", async () => {
439474
mockResolveBoundConversation.mockReturnValue(createBoundConversation());
440475

extensions/feishu/src/bot.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,17 +805,18 @@ export async function handleFeishuMessage(params: {
805805
});
806806
if (!ensured.ok) {
807807
const replyTargetMessageId =
808-
isGroup &&
809-
(groupSession?.groupSessionScope === "group_topic" ||
810-
groupSession?.groupSessionScope === "group_topic_sender")
808+
(isGroup &&
809+
(groupSession?.groupSessionScope === "group_topic" ||
810+
groupSession?.groupSessionScope === "group_topic_sender")) ||
811+
directThreadMessage
811812
? (ctx.rootId ?? ctx.messageId)
812813
: ctx.messageId;
813814
await sendMessageFeishu({
814815
cfg: effectiveCfg,
815816
to: `chat:${ctx.chatId}`,
816817
text: `⚠️ Failed to initialize the configured ACP session for this Feishu conversation: ${ensured.error}`,
817818
replyToMessageId: replyTargetMessageId,
818-
replyInThread: isGroup ? (groupSession?.replyInThread ?? false) : false,
819+
replyInThread: isGroup ? (groupSession?.replyInThread ?? false) : directThreadMessage,
819820
accountId: account.accountId,
820821
}).catch((err) => {
821822
log(`feishu[${account.accountId}]: failed to send ACP init error reply: ${String(err)}`);

0 commit comments

Comments
 (0)