feat(feishu): support sender/topic-scoped group session routing (openclaw#17798) thanks @yfge

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <1186273+yfge@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
拐爷&&老拐瘦
2026-02-28 09:26:36 +08:00
committed by GitHub
parent ed51796d97
commit 36d69d05e2
5 changed files with 185 additions and 22 deletions

View File

@@ -755,19 +755,39 @@ export async function handleFeishuMessage(params: {
const feishuFrom = `feishu:${ctx.senderOpenId}`;
const feishuTo = isGroup ? `chat:${ctx.chatId}` : `user:${ctx.senderOpenId}`;
// Resolve peer ID for session routing
// When topicSessionMode is enabled, messages within a topic (identified by root_id)
// get a separate session from the main group chat.
// Resolve peer ID for session routing.
// Default is one session per group chat; this can be customized with groupSessionScope.
let peerId = isGroup ? ctx.chatId : ctx.senderOpenId;
let topicSessionMode: "enabled" | "disabled" = "disabled";
if (isGroup && ctx.rootId) {
const groupConfig = resolveFeishuGroupConfig({ cfg: feishuCfg, groupId: ctx.chatId });
topicSessionMode = groupConfig?.topicSessionMode ?? feishuCfg?.topicSessionMode ?? "disabled";
if (topicSessionMode === "enabled") {
// Use chatId:topic:rootId as peer ID for topic-scoped sessions
peerId = `${ctx.chatId}:topic:${ctx.rootId}`;
log(`feishu[${account.accountId}]: topic session isolation enabled, peer=${peerId}`);
let groupSessionScope: "group" | "group_sender" | "group_topic" | "group_topic_sender" =
"group";
if (isGroup) {
const legacyTopicSessionMode =
groupConfig?.topicSessionMode ?? feishuCfg?.topicSessionMode ?? "disabled";
groupSessionScope =
groupConfig?.groupSessionScope ??
feishuCfg?.groupSessionScope ??
(legacyTopicSessionMode === "enabled" ? "group_topic" : "group");
switch (groupSessionScope) {
case "group_sender":
peerId = `${ctx.chatId}:sender:${ctx.senderOpenId}`;
break;
case "group_topic":
peerId = ctx.rootId ? `${ctx.chatId}:topic:${ctx.rootId}` : ctx.chatId;
break;
case "group_topic_sender":
peerId = ctx.rootId
? `${ctx.chatId}:topic:${ctx.rootId}:sender:${ctx.senderOpenId}`
: `${ctx.chatId}:sender:${ctx.senderOpenId}`;
break;
case "group":
default:
peerId = ctx.chatId;
break;
}
log(`feishu[${account.accountId}]: group session scope=${groupSessionScope}, peer=${peerId}`);
}
let route = core.channel.routing.resolveAgentRoute({
@@ -778,9 +798,11 @@ export async function handleFeishuMessage(params: {
kind: isGroup ? "group" : "direct",
id: peerId,
},
// Add parentPeer for binding inheritance in topic mode
// Add parentPeer for binding inheritance in topic-scoped modes.
parentPeer:
isGroup && ctx.rootId && topicSessionMode === "enabled"
isGroup &&
ctx.rootId &&
(groupSessionScope === "group_topic" || groupSessionScope === "group_topic_sender")
? {
kind: "group",
id: ctx.chatId,