mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 22:10:51 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
108 lines
2.9 KiB
TypeScript
108 lines
2.9 KiB
TypeScript
import type { TelegramGroupConfig } from "../../../src/config/types.js";
|
|
import type { TelegramNetworkConfig } from "../../../src/config/types.telegram.js";
|
|
|
|
export type TelegramGroupMembershipAuditEntry = {
|
|
chatId: string;
|
|
ok: boolean;
|
|
status?: string | null;
|
|
error?: string | null;
|
|
matchKey?: string;
|
|
matchSource?: "id";
|
|
};
|
|
|
|
export type TelegramGroupMembershipAudit = {
|
|
ok: boolean;
|
|
checkedGroups: number;
|
|
unresolvedGroups: number;
|
|
hasWildcardUnmentionedGroups: boolean;
|
|
groups: TelegramGroupMembershipAuditEntry[];
|
|
elapsedMs: number;
|
|
};
|
|
|
|
export function collectTelegramUnmentionedGroupIds(
|
|
groups: Record<string, TelegramGroupConfig> | undefined,
|
|
) {
|
|
if (!groups || typeof groups !== "object") {
|
|
return {
|
|
groupIds: [] as string[],
|
|
unresolvedGroups: 0,
|
|
hasWildcardUnmentionedGroups: false,
|
|
};
|
|
}
|
|
const hasWildcardUnmentionedGroups =
|
|
Boolean(groups["*"]?.requireMention === false) && groups["*"]?.enabled !== false;
|
|
const groupIds: string[] = [];
|
|
let unresolvedGroups = 0;
|
|
for (const [key, value] of Object.entries(groups)) {
|
|
if (key === "*") {
|
|
continue;
|
|
}
|
|
if (!value || typeof value !== "object") {
|
|
continue;
|
|
}
|
|
if (value.enabled === false) {
|
|
continue;
|
|
}
|
|
if (value.requireMention !== false) {
|
|
continue;
|
|
}
|
|
const id = String(key).trim();
|
|
if (!id) {
|
|
continue;
|
|
}
|
|
if (/^-?\d+$/.test(id)) {
|
|
groupIds.push(id);
|
|
} else {
|
|
unresolvedGroups += 1;
|
|
}
|
|
}
|
|
groupIds.sort((a, b) => a.localeCompare(b));
|
|
return { groupIds, unresolvedGroups, hasWildcardUnmentionedGroups };
|
|
}
|
|
|
|
export type AuditTelegramGroupMembershipParams = {
|
|
token: string;
|
|
botId: number;
|
|
groupIds: string[];
|
|
proxyUrl?: string;
|
|
network?: TelegramNetworkConfig;
|
|
timeoutMs: number;
|
|
};
|
|
|
|
let auditMembershipRuntimePromise: Promise<typeof import("./audit-membership-runtime.js")> | null =
|
|
null;
|
|
|
|
function loadAuditMembershipRuntime() {
|
|
auditMembershipRuntimePromise ??= import("./audit-membership-runtime.js");
|
|
return auditMembershipRuntimePromise;
|
|
}
|
|
|
|
export async function auditTelegramGroupMembership(
|
|
params: AuditTelegramGroupMembershipParams,
|
|
): Promise<TelegramGroupMembershipAudit> {
|
|
const started = Date.now();
|
|
const token = params.token?.trim() ?? "";
|
|
if (!token || params.groupIds.length === 0) {
|
|
return {
|
|
ok: true,
|
|
checkedGroups: 0,
|
|
unresolvedGroups: 0,
|
|
hasWildcardUnmentionedGroups: false,
|
|
groups: [],
|
|
elapsedMs: Date.now() - started,
|
|
};
|
|
}
|
|
|
|
// Lazy import to avoid pulling `undici` (ProxyAgent) into cold-path callers that only need
|
|
// `collectTelegramUnmentionedGroupIds` (e.g. config audits).
|
|
const { auditTelegramGroupMembershipImpl } = await loadAuditMembershipRuntime();
|
|
const result = await auditTelegramGroupMembershipImpl({
|
|
...params,
|
|
token,
|
|
});
|
|
return {
|
|
...result,
|
|
elapsedMs: Date.now() - started,
|
|
};
|
|
}
|