fix(test): trim telegram command registry imports

This commit is contained in:
Vincent Koc 2026-03-30 19:30:37 +09:00
parent 69916e8082
commit 2fbd5e3f5f
2 changed files with 63 additions and 7 deletions

View File

@ -0,0 +1,61 @@
import { buildDmGroupAccountAllowlistAdapter } from "openclaw/plugin-sdk/allowlist-config-edit";
import { createApproverRestrictedNativeApprovalAdapter } from "openclaw/plugin-sdk/approval-runtime";
import { getChatChannelMeta, type ChannelPlugin } from "openclaw/plugin-sdk/telegram-core";
import type { ResolvedTelegramAccount } from "./src/accounts.js";
import { resolveTelegramAccount } from "./src/accounts.js";
import { listTelegramAccountIds } from "./src/accounts.js";
import {
getTelegramExecApprovalApprovers,
isTelegramExecApprovalAuthorizedSender,
isTelegramExecApprovalApprover,
isTelegramExecApprovalClientEnabled,
resolveTelegramExecApprovalTarget,
} from "./src/exec-approvals.js";
import { telegramConfigAdapter } from "./src/shared.js";
const telegramNativeApprovalAdapter = createApproverRestrictedNativeApprovalAdapter({
channel: "telegram",
channelLabel: "Telegram",
listAccountIds: listTelegramAccountIds,
hasApprovers: ({ cfg, accountId }) =>
getTelegramExecApprovalApprovers({ cfg, accountId }).length > 0,
isExecAuthorizedSender: ({ cfg, accountId, senderId }) =>
isTelegramExecApprovalAuthorizedSender({ cfg, accountId, senderId }),
isPluginAuthorizedSender: ({ cfg, accountId, senderId }) =>
isTelegramExecApprovalApprover({ cfg, accountId, senderId }),
isNativeDeliveryEnabled: ({ cfg, accountId }) =>
isTelegramExecApprovalClientEnabled({ cfg, accountId }),
resolveNativeDeliveryMode: ({ cfg, accountId }) =>
resolveTelegramExecApprovalTarget({ cfg, accountId }),
requireMatchingTurnSourceChannel: true,
});
export const telegramCommandTestPlugin = {
id: "telegram",
meta: getChatChannelMeta("telegram"),
capabilities: {
chatTypes: ["direct", "group", "channel", "thread"],
reactions: true,
threads: true,
media: true,
polls: true,
nativeCommands: true,
blockStreaming: true,
},
config: telegramConfigAdapter,
auth: telegramNativeApprovalAdapter.auth,
pairing: {},
allowlist: buildDmGroupAccountAllowlistAdapter<ResolvedTelegramAccount>({
channelId: "telegram",
resolveAccount: resolveTelegramAccount,
normalize: ({ cfg, accountId, values }) =>
telegramConfigAdapter.formatAllowFrom!({ cfg, accountId, allowFrom: values }),
resolveDmAllowFrom: (account) => account.config.allowFrom,
resolveGroupAllowFrom: (account) => account.config.groupAllowFrom,
resolveDmPolicy: (account) => account.config.dmPolicy,
resolveGroupPolicy: (account) => account.config.groupPolicy,
}),
} satisfies Pick<
ChannelPlugin<ResolvedTelegramAccount>,
"id" | "meta" | "capabilities" | "config" | "auth" | "pairing" | "allowlist"
>;

View File

@ -7,6 +7,7 @@ import type { OpenClawConfig } from "../../config/config.js";
import { updateSessionStore, type SessionEntry } from "../../config/sessions.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import { loadBundledPluginPublicSurfaceSync } from "../../test-utils/bundled-plugin-public-surface.js";
import { telegramCommandTestPlugin } from "../../../extensions/telegram/test-support.js";
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
import { typedCases } from "../../test-utils/typed-cases.js";
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
@ -24,12 +25,6 @@ const { slackPlugin } = loadBundledPluginPublicSurfaceSync<{
pluginId: "slack",
artifactBasename: "index.ts",
});
const { telegramPlugin } = loadBundledPluginPublicSurfaceSync<{
telegramPlugin: ChannelPlugin;
}>({
pluginId: "telegram",
artifactBasename: "index.ts",
});
const { whatsappPlugin } = loadBundledPluginPublicSurfaceSync<{
whatsappPlugin: ChannelPlugin;
}>({
@ -177,7 +172,7 @@ function setMinimalChannelPluginRegistryForTests(): void {
},
{
pluginId: "telegram",
plugin: telegramPlugin,
plugin: telegramCommandTestPlugin,
source: "test",
},
{