fix: honor account-scoped setup dm policy

This commit is contained in:
Tak Hoffman
2026-04-03 10:30:51 -05:00
parent c6b8109bd8
commit b1026a0b28
4 changed files with 183 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
import {
addWildcardAllowFrom,
createAllowFromSection,
createTopLevelChannelDmPolicy,
createStandardChannelSetupStatus,
type ChannelSetupDmPolicy,
DEFAULT_ACCOUNT_ID,
hasConfiguredSecretInput,
type OpenClawConfig,
@@ -76,14 +77,40 @@ function buildTelegramDmAccessWarningLines(accountId: string): string[] {
];
}
const dmPolicy = createTopLevelChannelDmPolicy({
const dmPolicy: ChannelSetupDmPolicy = {
label: "Telegram",
channel,
policyKey: "channels.telegram.dmPolicy",
allowFromKey: "channels.telegram.allowFrom",
getCurrent: (cfg) => cfg.channels?.telegram?.dmPolicy ?? "pairing",
resolveConfigKeys: (_cfg, accountId) =>
accountId && accountId !== DEFAULT_ACCOUNT_ID
? {
policyKey: `channels.telegram.accounts.${accountId}.dmPolicy`,
allowFromKey: `channels.telegram.accounts.${accountId}.allowFrom`,
}
: {
policyKey: "channels.telegram.dmPolicy",
allowFromKey: "channels.telegram.allowFrom",
},
getCurrent: (cfg, accountId) =>
mergeTelegramAccountConfig(cfg, accountId ?? DEFAULT_ACCOUNT_ID).dmPolicy ?? "pairing",
setPolicy: (cfg, policy, accountId) => {
const resolvedAccountId = accountId ?? DEFAULT_ACCOUNT_ID;
const merged = mergeTelegramAccountConfig(cfg, resolvedAccountId);
return patchChannelConfigForAccount({
cfg,
channel,
accountId: resolvedAccountId,
patch: {
dmPolicy: policy,
...(policy === "open"
? { allowFrom: addWildcardAllowFrom(merged.allowFrom) }
: {}),
},
});
},
promptAllowFrom: promptTelegramAllowFromForAccount,
});
};
export const telegramSetupWizard: ChannelSetupWizard = {
channel,