refactor: share zalouser account resolution

This commit is contained in:
Peter Steinberger 2026-03-13 21:14:54 +00:00
parent 7235ee55c6
commit a6375a2094
1 changed files with 15 additions and 14 deletions

View File

@ -43,17 +43,24 @@ function resolveProfile(config: ZalouserAccountConfig, accountId: string): strin
return "default";
}
export async function resolveZalouserAccount(params: {
cfg: OpenClawConfig;
accountId?: string | null;
}): Promise<ResolvedZalouserAccount> {
function resolveZalouserAccountBase(params: { cfg: OpenClawConfig; accountId?: string | null }) {
const accountId = normalizeAccountId(params.accountId);
const baseEnabled =
(params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
const profile = resolveProfile(merged, accountId);
return {
accountId,
enabled: baseEnabled && merged.enabled !== false,
merged,
profile: resolveProfile(merged, accountId),
};
}
export async function resolveZalouserAccount(params: {
cfg: OpenClawConfig;
accountId?: string | null;
}): Promise<ResolvedZalouserAccount> {
const { accountId, enabled, merged, profile } = resolveZalouserAccountBase(params);
const authenticated = await checkZaloAuthenticated(profile);
return {
@ -70,13 +77,7 @@ export function resolveZalouserAccountSync(params: {
cfg: OpenClawConfig;
accountId?: string | null;
}): ResolvedZalouserAccount {
const accountId = normalizeAccountId(params.accountId);
const baseEnabled =
(params.cfg.channels?.zalouser as ZalouserConfig | undefined)?.enabled !== false;
const merged = mergeZalouserAccountConfig(params.cfg, accountId);
const accountEnabled = merged.enabled !== false;
const enabled = baseEnabled && accountEnabled;
const profile = resolveProfile(merged, accountId);
const { accountId, enabled, merged, profile } = resolveZalouserAccountBase(params);
return {
accountId,