refactor: share config adapter allowFrom and defaultTo helpers

This commit is contained in:
Peter Steinberger
2026-03-07 23:02:59 +00:00
parent feac26c3b7
commit 556aa8a702
17 changed files with 100 additions and 57 deletions

View File

@@ -2,6 +2,8 @@ import {
buildAccountScopedDmSecurityPolicy,
collectOpenGroupPolicyRouteAllowlistWarnings,
formatAllowFromLowercase,
mapAllowFromEntries,
resolveOptionalConfigString,
} from "openclaw/plugin-sdk";
import {
applyAccountNameToChannelSection,
@@ -176,15 +178,11 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProb
tokenSource: account.tokenSource,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
(resolveTelegramAccount({ cfg, accountId }).config.allowFrom ?? []).map((entry) =>
String(entry),
),
mapAllowFromEntries(resolveTelegramAccount({ cfg, accountId }).config.allowFrom),
formatAllowFrom: ({ allowFrom }) =>
formatAllowFromLowercase({ allowFrom, stripPrefixRe: /^(telegram|tg):/i }),
resolveDefaultTo: ({ cfg, accountId }) => {
const val = resolveTelegramAccount({ cfg, accountId }).config.defaultTo;
return val != null ? String(val) : undefined;
},
resolveDefaultTo: ({ cfg, accountId }) =>
resolveOptionalConfigString(resolveTelegramAccount({ cfg, accountId }).config.defaultTo),
},
security: {
resolveDmPolicy: ({ cfg, accountId, account }) => {