Skip to content

Commit 59a211e

Browse files
author
hanhui
committed
fix(feishu): prefer native thread id for topic sessions
1 parent 0c4fc0a commit 59a211e

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

‎extensions/feishu/src/bot-content.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ export function resolveFeishuGroupSession(params: {
6969
replyInThread?: "enabled" | "disabled";
7070
};
7171
}): ResolvedFeishuGroupSession {
72-
const { chatId, senderOpenId, messageId, rootId, threadId, chatType, groupConfig, feishuCfg } =
73-
params;
72+
const { chatId, senderOpenId, messageId, rootId, threadId, groupConfig, feishuCfg } = params;
7473
const normalizedThreadId = threadId?.trim();
7574
const normalizedRootId = rootId?.trim();
7675
const threadReply = Boolean(normalizedThreadId || normalizedRootId);
@@ -83,14 +82,9 @@ export function resolveFeishuGroupSession(params: {
8382
groupConfig?.groupSessionScope ??
8483
feishuCfg?.groupSessionScope ??
8584
(legacyTopicSessionMode === "enabled" ? "group_topic" : "group");
86-
const normalizedTopicGroupThreadId =
87-
chatType === "topic_group" ? (normalizedThreadId ?? normalizedRootId) : undefined;
8885
const topicScope =
8986
groupSessionScope === "group_topic" || groupSessionScope === "group_topic_sender"
90-
? (normalizedTopicGroupThreadId ??
91-
normalizedRootId ??
92-
normalizedThreadId ??
93-
(replyInThread ? messageId : null))
87+
? (normalizedThreadId ?? normalizedRootId ?? (replyInThread ? messageId : null))
9488
: null;
9589

9690
let peerId;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ describe("handleFeishuMessage command authorization", () => {
28522852
expect(routeRequest.parentPeer).toEqual({ kind: "group", id: "oc-group" });
28532853
});
28542854

2855-
it("keeps root_id as topic key when root_id and thread_id both exist", async () => {
2855+
it("prefers thread_id as topic key when root_id and thread_id both exist", async () => {
28562856
mockShouldComputeCommandAuthorized.mockReturnValue(false);
28572857

28582858
const cfg: ClawdbotConfig = {
@@ -2889,7 +2889,7 @@ describe("handleFeishuMessage command authorization", () => {
28892889
}>(mockResolveAgentRoute, 0, 0);
28902890
expect(routeRequest.peer).toEqual({
28912891
kind: "group",
2892-
id: "oc-group:topic:om_root_topic:sender:ou-topic-user",
2892+
id: "oc-group:topic:omt_topic_1:sender:ou-topic-user",
28932893
});
28942894
expect(routeRequest.parentPeer).toEqual({ kind: "group", id: "oc-group" });
28952895
});
@@ -3025,7 +3025,7 @@ describe("handleFeishuMessage command authorization", () => {
30253025
);
30263026
});
30273027

3028-
it("maps legacy topicSessionMode=enabled to root_id when both root_id and thread_id exist", async () => {
3028+
it("maps legacy topicSessionMode=enabled to thread_id when both root_id and thread_id exist", async () => {
30293029
mockShouldComputeCommandAuthorized.mockReturnValue(false);
30303030

30313031
const cfg: ClawdbotConfig = {
@@ -3058,7 +3058,7 @@ describe("handleFeishuMessage command authorization", () => {
30583058

30593059
expectResolvedRouteCall(
30603060
0,
3061-
{ kind: "group", id: "oc-group:topic:om_root_legacy" },
3061+
{ kind: "group", id: "oc-group:topic:omt_topic_legacy" },
30623062
{ kind: "group", id: "oc-group" },
30633063
);
30643064
});
@@ -3100,7 +3100,7 @@ describe("handleFeishuMessage command authorization", () => {
31003100
);
31013101
});
31023102

3103-
it("keeps topic session key stable after first turn creates a thread", async () => {
3103+
it("prefers the Feishu thread_id once a follow-up event includes it", async () => {
31043104
mockShouldComputeCommandAuthorized.mockReturnValue(false);
31053105

31063106
const cfg: ClawdbotConfig = {
@@ -3144,7 +3144,7 @@ describe("handleFeishuMessage command authorization", () => {
31443144
await dispatchMessage({ cfg, event: secondTurn });
31453145

31463146
expectResolvedRouteCall(0, { kind: "group", id: "oc-group:topic:msg-topic-first" });
3147-
expectResolvedRouteCall(1, { kind: "group", id: "oc-group:topic:msg-topic-first" });
3147+
expectResolvedRouteCall(1, { kind: "group", id: "oc-group:topic:omt_topic_created" });
31483148
});
31493149

31503150
it("hydrates missing native topic thread_id before routing starter events", async () => {

0 commit comments

Comments
 (0)