diff --git a/extensions/telegram/test-support.ts b/extensions/telegram/test-support.ts new file mode 100644 index 00000000000..4d5b195cdd3 --- /dev/null +++ b/extensions/telegram/test-support.ts @@ -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({ + 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, + "id" | "meta" | "capabilities" | "config" | "auth" | "pairing" | "allowlist" +>; diff --git a/src/auto-reply/reply/commands.test.ts b/src/auto-reply/reply/commands.test.ts index b13b95bc623..efbd8b56275 100644 --- a/src/auto-reply/reply/commands.test.ts +++ b/src/auto-reply/reply/commands.test.ts @@ -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", }, {