Skip to content

Commit 0be0f0d

Browse files
committed
fix(feishu): reply to direct messages by chat id
1 parent 5e41074 commit 0be0f0d

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎extensions/feishu/src/bot.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,39 @@ describe("handleFeishuMessage ACP routing", () => {
730730
to: "user:ou_sender_1",
731731
accountId: "default",
732732
});
733+
expect(mockCreateFeishuReplyDispatcher).toHaveBeenCalledWith(
734+
expect.objectContaining({
735+
chatId: "oc_dm",
736+
sendTarget: "chat:oc_dm",
737+
}),
738+
);
739+
});
740+
741+
it("keeps synthetic Feishu DM reply targets sender-scoped", async () => {
742+
setFeishuRuntime(createFeishuBotRuntime());
743+
744+
await dispatchMessage({
745+
cfg: {
746+
channels: { feishu: { enabled: true, allowFrom: ["ou_sender_1"], dmPolicy: "open" } },
747+
},
748+
event: {
749+
sender: { sender_id: { open_id: "ou_sender_1" } },
750+
message: {
751+
message_id: "msg-dm-synthetic-target",
752+
chat_id: "p2p:ou_sender_1",
753+
chat_type: "p2p",
754+
message_type: "text",
755+
content: JSON.stringify({ text: "hello" }),
756+
},
757+
},
758+
});
759+
760+
expect(mockCreateFeishuReplyDispatcher).toHaveBeenCalledWith(
761+
expect.objectContaining({
762+
chatId: "p2p:ou_sender_1",
763+
sendTarget: "user:ou_sender_1",
764+
}),
765+
);
733766
});
734767

735768
it("pins shared Feishu DM last-route updates to the configured owner", async () => {

‎extensions/feishu/src/bot.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ export async function handleFeishuMessage(params: {
788788
// Using a group-scoped From causes the agent to treat different users as the same person.
789789
const feishuFrom = `feishu:${ctx.senderOpenId}`;
790790
const feishuTo = isGroup ? `chat:${ctx.chatId}` : `user:${ctx.senderOpenId}`;
791+
// Reply in the inbound conversation while keeping DM routing/session identity sender-scoped.
792+
// Synthetic menu and card-action events do not always carry a real Feishu chat ID.
793+
const feishuReplyTarget = ctx.chatId.startsWith("oc_") ? `chat:${ctx.chatId}` : feishuTo;
791794
const peerId = isGroup ? (groupSession?.peerId ?? ctx.chatId) : ctx.senderOpenId;
792795
const parentPeer = isGroup ? (groupSession?.parentPeer ?? null) : null;
793796
const directThreadReply = !isGroup && Boolean(ctx.threadId?.trim());
@@ -1562,7 +1565,7 @@ export async function handleFeishuMessage(params: {
15621565
agentId,
15631566
runtime: runtime as RuntimeEnv,
15641567
chatId: ctx.chatId,
1565-
sendTarget: feishuTo,
1568+
sendTarget: feishuReplyTarget,
15661569
allowReasoningPreview,
15671570
replyToMessageId: replyTargetMessageId,
15681571
typingTargetMessageId,
@@ -1736,7 +1739,7 @@ export async function handleFeishuMessage(params: {
17361739
agentId: route.agentId,
17371740
runtime: runtime as RuntimeEnv,
17381741
chatId: ctx.chatId,
1739-
sendTarget: feishuTo,
1742+
sendTarget: feishuReplyTarget,
17401743
allowReasoningPreview,
17411744
replyToMessageId: replyTargetMessageId,
17421745
typingTargetMessageId,

0 commit comments

Comments
 (0)