From e820c255bc79308dd1098246bdbac54a9b16bfe7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 04:52:25 +0000 Subject: [PATCH] refactor(telegram): share plugin base config --- extensions/telegram/src/channel.setup.ts | 68 +++--------------------- extensions/telegram/src/channel.ts | 60 ++------------------- 2 files changed, 11 insertions(+), 117 deletions(-) diff --git a/extensions/telegram/src/channel.setup.ts b/extensions/telegram/src/channel.setup.ts index 09b41cddb0f..4879ef96c09 100644 --- a/extensions/telegram/src/channel.setup.ts +++ b/extensions/telegram/src/channel.setup.ts @@ -1,69 +1,13 @@ -import { - buildChannelConfigSchema, - getChatChannelMeta, - TelegramConfigSchema, - type ChannelPlugin, -} from "openclaw/plugin-sdk/telegram"; +import { type ChannelPlugin } from "openclaw/plugin-sdk/telegram"; import { type ResolvedTelegramAccount } from "./accounts.js"; import type { TelegramProbe } from "./probe.js"; import { telegramSetupAdapter } from "./setup-core.js"; import { telegramSetupWizard } from "./setup-surface.js"; -import { - findTelegramTokenOwnerAccountId, - formatDuplicateTelegramTokenReason, - telegramConfigAccessors, - telegramConfigBase, -} from "./shared.js"; +import { createTelegramPluginBase } from "./shared.js"; export const telegramSetupPlugin: ChannelPlugin = { - id: "telegram", - meta: { - ...getChatChannelMeta("telegram"), - quickstartAllowFrom: true, - }, - setupWizard: telegramSetupWizard, - capabilities: { - chatTypes: ["direct", "group", "channel", "thread"], - reactions: true, - threads: true, - media: true, - polls: true, - nativeCommands: true, - blockStreaming: true, - }, - reload: { configPrefixes: ["channels.telegram"] }, - configSchema: buildChannelConfigSchema(TelegramConfigSchema), - config: { - ...telegramConfigBase, - isConfigured: (account, cfg) => { - if (!account.token?.trim()) { - return false; - } - return !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }); - }, - unconfiguredReason: (account, cfg) => { - if (!account.token?.trim()) { - return "not configured"; - } - const ownerAccountId = findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }); - if (!ownerAccountId) { - return "not configured"; - } - return formatDuplicateTelegramTokenReason({ - accountId: account.accountId, - ownerAccountId, - }); - }, - describeAccount: (account, cfg) => ({ - accountId: account.accountId, - name: account.name, - enabled: account.enabled, - configured: - Boolean(account.token?.trim()) && - !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }), - tokenSource: account.tokenSource, - }), - ...telegramConfigAccessors, - }, - setup: telegramSetupAdapter, + ...createTelegramPluginBase({ + setupWizard: telegramSetupWizard, + setup: telegramSetupAdapter, + }), }; diff --git a/extensions/telegram/src/channel.ts b/extensions/telegram/src/channel.ts index 0054aaba6de..ebd8ddc2c24 100644 --- a/extensions/telegram/src/channel.ts +++ b/extensions/telegram/src/channel.ts @@ -15,11 +15,9 @@ import { resolveExecApprovalCommandDisplay } from "openclaw/plugin-sdk/infra-run import { buildExecApprovalPendingReplyPayload } from "openclaw/plugin-sdk/infra-runtime"; import { parseTelegramTopicConversation } from "openclaw/plugin-sdk/telegram"; import { - buildChannelConfigSchema, buildTokenChannelStatusSummary, clearAccountEntryFields, DEFAULT_ACCOUNT_ID, - getChatChannelMeta, listTelegramDirectoryGroupsFromConfig, listTelegramDirectoryPeersFromConfig, PAIRING_APPROVED_MESSAGE, @@ -27,7 +25,6 @@ import { resolveConfiguredFromCredentialStatuses, resolveTelegramGroupRequireMention, resolveTelegramGroupToolPolicy, - TelegramConfigSchema, type ChannelPlugin, type ChannelMessageActionAdapter, type OpenClawConfig, @@ -54,10 +51,10 @@ import { sendTypingTelegram } from "./send.js"; import { telegramSetupAdapter } from "./setup-core.js"; import { telegramSetupWizard } from "./setup-surface.js"; import { + createTelegramPluginBase, findTelegramTokenOwnerAccountId, formatDuplicateTelegramTokenReason, telegramConfigAccessors, - telegramConfigBase, } from "./shared.js"; import { collectTelegramStatusIssues } from "./status-issues.js"; import { parseTelegramTarget } from "./targets.js"; @@ -66,8 +63,6 @@ type TelegramSendFn = ReturnType< typeof getTelegramRuntime >["channel"]["telegram"]["sendMessageTelegram"]; -const meta = getChatChannelMeta("telegram"); - type TelegramSendOptions = NonNullable[2]>; function buildTelegramSendOptions(params: { @@ -324,12 +319,10 @@ function readTelegramAllowlistConfig(account: ResolvedTelegramAccount) { } export const telegramPlugin: ChannelPlugin = { - id: "telegram", - meta: { - ...meta, - quickstartAllowFrom: true, - }, - setupWizard: telegramSetupWizard, + ...createTelegramPluginBase({ + setupWizard: telegramSetupWizard, + setup: telegramSetupAdapter, + }), pairing: { idLabel: "telegramUserId", normalizeAllowEntry: (entry) => entry.replace(/^(telegram|tg):/i, ""), @@ -347,49 +340,6 @@ export const telegramPlugin: ChannelPlugin { - if (!account.token?.trim()) { - return false; - } - return !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }); - }, - unconfiguredReason: (account, cfg) => { - if (!account.token?.trim()) { - return "not configured"; - } - const ownerAccountId = findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }); - if (!ownerAccountId) { - return "not configured"; - } - return formatDuplicateTelegramTokenReason({ - accountId: account.accountId, - ownerAccountId, - }); - }, - describeAccount: (account, cfg) => ({ - accountId: account.accountId, - name: account.name, - enabled: account.enabled, - configured: - Boolean(account.token?.trim()) && - !findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }), - tokenSource: account.tokenSource, - }), - ...telegramConfigAccessors, - }, allowlist: { supportsScope: ({ scope }) => scope === "dm" || scope === "group" || scope === "all", readConfig: ({ cfg, accountId }) =>