mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 19:20:22 +00:00
refactor: deduplicate channel config adapters
This commit is contained in:
@@ -55,7 +55,7 @@ import {
|
||||
createTelegramPluginBase,
|
||||
findTelegramTokenOwnerAccountId,
|
||||
formatDuplicateTelegramTokenReason,
|
||||
telegramConfigAccessors,
|
||||
telegramConfigAdapter,
|
||||
} from "./shared.js";
|
||||
import { collectTelegramStatusIssues } from "./status-issues.js";
|
||||
import { parseTelegramTarget } from "./targets.js";
|
||||
@@ -325,7 +325,7 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProb
|
||||
applyConfigEdit: buildAccountScopedAllowlistConfigEditor({
|
||||
channelId: "telegram",
|
||||
normalize: ({ cfg, accountId, values }) =>
|
||||
telegramConfigAccessors.formatAllowFrom!({ cfg, accountId, allowFrom: values }),
|
||||
telegramConfigAdapter.formatAllowFrom!({ cfg, accountId, allowFrom: values }),
|
||||
resolvePaths: (scope) => ({
|
||||
readPaths: [[scope === "dm" ? "allowFrom" : "groupAllowFrom"]],
|
||||
writePath: [scope === "dm" ? "allowFrom" : "groupAllowFrom"],
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
|
||||
import {
|
||||
createScopedAccountConfigAccessors,
|
||||
createScopedChannelConfigBase,
|
||||
} from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
buildChannelConfigSchema,
|
||||
@@ -56,21 +53,17 @@ export function formatDuplicateTelegramTokenReason(params: {
|
||||
);
|
||||
}
|
||||
|
||||
export const telegramConfigAccessors = createScopedAccountConfigAccessors({
|
||||
resolveAccount: ({ cfg, accountId }) => resolveTelegramAccount({ cfg, accountId }),
|
||||
resolveAllowFrom: (account: ResolvedTelegramAccount) => account.config.allowFrom,
|
||||
formatAllowFrom: (allowFrom) =>
|
||||
formatAllowFromLowercase({ allowFrom, stripPrefixRe: /^(telegram|tg):/i }),
|
||||
resolveDefaultTo: (account: ResolvedTelegramAccount) => account.config.defaultTo,
|
||||
});
|
||||
|
||||
export const telegramConfigBase = createScopedChannelConfigBase<ResolvedTelegramAccount>({
|
||||
export const telegramConfigAdapter = createScopedChannelConfigAdapter<ResolvedTelegramAccount>({
|
||||
sectionKey: TELEGRAM_CHANNEL,
|
||||
listAccountIds: listTelegramAccountIds,
|
||||
resolveAccount: (cfg, accountId) => resolveTelegramAccount({ cfg, accountId }),
|
||||
inspectAccount: (cfg, accountId) => inspectTelegramAccount({ cfg, accountId }),
|
||||
defaultAccountId: resolveDefaultTelegramAccountId,
|
||||
clearBaseFields: ["botToken", "tokenFile", "name"],
|
||||
resolveAllowFrom: (account: ResolvedTelegramAccount) => account.config.allowFrom,
|
||||
formatAllowFrom: (allowFrom) =>
|
||||
formatAllowFromLowercase({ allowFrom, stripPrefixRe: /^(telegram|tg):/i }),
|
||||
resolveDefaultTo: (account: ResolvedTelegramAccount) => account.config.defaultTo,
|
||||
});
|
||||
|
||||
export function createTelegramPluginBase(params: {
|
||||
@@ -99,7 +92,7 @@ export function createTelegramPluginBase(params: {
|
||||
reload: { configPrefixes: ["channels.telegram"] },
|
||||
configSchema: buildChannelConfigSchema(TelegramConfigSchema),
|
||||
config: {
|
||||
...telegramConfigBase,
|
||||
...telegramConfigAdapter,
|
||||
isConfigured: (account, cfg) => {
|
||||
if (!account.token?.trim()) {
|
||||
return false;
|
||||
@@ -131,7 +124,6 @@ export function createTelegramPluginBase(params: {
|
||||
!findTelegramTokenOwnerAccountId({ cfg, accountId: account.accountId }),
|
||||
tokenSource: account.tokenSource,
|
||||
}),
|
||||
...telegramConfigAccessors,
|
||||
},
|
||||
setup: params.setup,
|
||||
}) as Pick<
|
||||
|
||||
Reference in New Issue
Block a user