mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-24 16:32:29 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import {
|
|
buildChannelOutboundSessionRoute,
|
|
stripChannelTargetPrefix,
|
|
type ChannelOutboundSessionRouteParams,
|
|
} from "openclaw/plugin-sdk/core";
|
|
|
|
export function resolveFeishuOutboundSessionRoute(params: ChannelOutboundSessionRouteParams) {
|
|
let trimmed = stripChannelTargetPrefix(params.target, "feishu", "lark");
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
|
|
const lower = trimmed.toLowerCase();
|
|
let isGroup = false;
|
|
let typeExplicit = false;
|
|
|
|
if (lower.startsWith("group:") || lower.startsWith("chat:") || lower.startsWith("channel:")) {
|
|
trimmed = trimmed.replace(/^(group|chat|channel):/i, "").trim();
|
|
isGroup = true;
|
|
typeExplicit = true;
|
|
} else if (lower.startsWith("user:") || lower.startsWith("dm:")) {
|
|
trimmed = trimmed.replace(/^(user|dm):/i, "").trim();
|
|
isGroup = false;
|
|
typeExplicit = true;
|
|
}
|
|
|
|
if (!typeExplicit) {
|
|
const idLower = trimmed.toLowerCase();
|
|
if (idLower.startsWith("ou_") || idLower.startsWith("on_")) {
|
|
isGroup = false;
|
|
}
|
|
}
|
|
|
|
return buildChannelOutboundSessionRoute({
|
|
cfg: params.cfg,
|
|
agentId: params.agentId,
|
|
channel: "feishu",
|
|
accountId: params.accountId,
|
|
peer: {
|
|
kind: isGroup ? "group" : "direct",
|
|
id: trimmed,
|
|
},
|
|
chatType: isGroup ? "group" : "direct",
|
|
from: isGroup ? `feishu:group:${trimmed}` : `feishu:${trimmed}`,
|
|
to: trimmed,
|
|
});
|
|
}
|