mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-22 09:01:46 +03:00
2267d58afc
Replace the built-in Feishu SDK with the community-maintained clawdbot-feishu plugin by @m1heng. Changes: - Remove src/feishu/ directory (19 files) - Remove src/channels/plugins/outbound/feishu.ts - Remove src/channels/plugins/normalize/feishu.ts - Remove src/config/types.feishu.ts - Remove feishu exports from plugin-sdk/index.ts - Remove FeishuConfig from types.channels.ts New features in community plugin: - Document tools (read/create/edit Feishu docs) - Wiki tools (navigate/manage knowledge base) - Drive tools (folder/file management) - Bitable tools (read/write table records) - Permission tools (collaborator management) - Emoji reactions support - Typing indicators - Rich media support (bidirectional image/file transfer) - @mention handling - Skills for feishu-doc, feishu-wiki, feishu-drive, feishu-perm Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import type { ChannelGroupContext, GroupToolPolicyConfig } from "openclaw/plugin-sdk";
|
|
import type { FeishuConfig, FeishuGroupConfig } from "./types.js";
|
|
|
|
export type FeishuAllowlistMatch = {
|
|
allowed: boolean;
|
|
matchKey?: string;
|
|
matchSource?: "wildcard" | "id" | "name";
|
|
};
|
|
|
|
export function resolveFeishuAllowlistMatch(params: {
|
|
allowFrom: Array<string | number>;
|
|
senderId: string;
|
|
senderName?: string | null;
|
|
}): FeishuAllowlistMatch {
|
|
const allowFrom = params.allowFrom
|
|
.map((entry) => String(entry).trim().toLowerCase())
|
|
.filter(Boolean);
|
|
|
|
if (allowFrom.length === 0) return { allowed: false };
|
|
if (allowFrom.includes("*")) {
|
|
return { allowed: true, matchKey: "*", matchSource: "wildcard" };
|
|
}
|
|
|
|
const senderId = params.senderId.toLowerCase();
|
|
if (allowFrom.includes(senderId)) {
|
|
return { allowed: true, matchKey: senderId, matchSource: "id" };
|
|
}
|
|
|
|
const senderName = params.senderName?.toLowerCase();
|
|
if (senderName && allowFrom.includes(senderName)) {
|
|
return { allowed: true, matchKey: senderName, matchSource: "name" };
|
|
}
|
|
|
|
return { allowed: false };
|
|
}
|
|
|
|
export function resolveFeishuGroupConfig(params: {
|
|
cfg?: FeishuConfig;
|
|
groupId?: string | null;
|
|
}): FeishuGroupConfig | undefined {
|
|
const groups = params.cfg?.groups ?? {};
|
|
const groupId = params.groupId?.trim();
|
|
if (!groupId) return undefined;
|
|
|
|
const direct = groups[groupId] as FeishuGroupConfig | undefined;
|
|
if (direct) return direct;
|
|
|
|
const lowered = groupId.toLowerCase();
|
|
const matchKey = Object.keys(groups).find((key) => key.toLowerCase() === lowered);
|
|
return matchKey ? (groups[matchKey] as FeishuGroupConfig | undefined) : undefined;
|
|
}
|
|
|
|
export function resolveFeishuGroupToolPolicy(
|
|
params: ChannelGroupContext,
|
|
): GroupToolPolicyConfig | undefined {
|
|
const cfg = params.cfg.channels?.feishu as FeishuConfig | undefined;
|
|
if (!cfg) return undefined;
|
|
|
|
const groupConfig = resolveFeishuGroupConfig({
|
|
cfg,
|
|
groupId: params.groupId,
|
|
});
|
|
|
|
return groupConfig?.tools;
|
|
}
|
|
|
|
export function isFeishuGroupAllowed(params: {
|
|
groupPolicy: "open" | "allowlist" | "disabled";
|
|
allowFrom: Array<string | number>;
|
|
senderId: string;
|
|
senderName?: string | null;
|
|
}): boolean {
|
|
const { groupPolicy } = params;
|
|
if (groupPolicy === "disabled") return false;
|
|
if (groupPolicy === "open") return true;
|
|
return resolveFeishuAllowlistMatch(params).allowed;
|
|
}
|
|
|
|
export function resolveFeishuReplyPolicy(params: {
|
|
isDirectMessage: boolean;
|
|
globalConfig?: FeishuConfig;
|
|
groupConfig?: FeishuGroupConfig;
|
|
}): { requireMention: boolean } {
|
|
if (params.isDirectMessage) {
|
|
return { requireMention: false };
|
|
}
|
|
|
|
const requireMention =
|
|
params.groupConfig?.requireMention ?? params.globalConfig?.requireMention ?? true;
|
|
|
|
return { requireMention };
|
|
}
|