mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 05:20:22 +00:00
channels: migrate core channel account listing to factory
This commit is contained in:
committed by
Peter Steinberger
parent
5544ab820c
commit
59384001ad
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { DmPolicy, GroupPolicy, WhatsAppAccountConfig } from "../config/types.js";
|
||||
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
import { resolveOAuthDir } from "../config/paths.js";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
@@ -29,13 +30,10 @@ export type ResolvedWhatsAppAccount = {
|
||||
debounceMs?: number;
|
||||
};
|
||||
|
||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
||||
const accounts = cfg.channels?.whatsapp?.accounts;
|
||||
if (!accounts || typeof accounts !== "object") {
|
||||
return [];
|
||||
}
|
||||
return Object.keys(accounts).filter(Boolean);
|
||||
}
|
||||
const { listConfiguredAccountIds, listAccountIds, resolveDefaultAccountId } =
|
||||
createAccountListHelpers("whatsapp");
|
||||
export const listWhatsAppAccountIds = listAccountIds;
|
||||
export const resolveDefaultWhatsAppAccountId = resolveDefaultAccountId;
|
||||
|
||||
export function listWhatsAppAuthDirs(cfg: OpenClawConfig): string[] {
|
||||
const oauthDir = resolveOAuthDir();
|
||||
@@ -66,22 +64,6 @@ export function hasAnyWhatsAppAuth(cfg: OpenClawConfig): boolean {
|
||||
return listWhatsAppAuthDirs(cfg).some((authDir) => hasWebCredsSync(authDir));
|
||||
}
|
||||
|
||||
export function listWhatsAppAccountIds(cfg: OpenClawConfig): string[] {
|
||||
const ids = listConfiguredAccountIds(cfg);
|
||||
if (ids.length === 0) {
|
||||
return [DEFAULT_ACCOUNT_ID];
|
||||
}
|
||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
export function resolveDefaultWhatsAppAccountId(cfg: OpenClawConfig): string {
|
||||
const ids = listWhatsAppAccountIds(cfg);
|
||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
||||
return DEFAULT_ACCOUNT_ID;
|
||||
}
|
||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
||||
}
|
||||
|
||||
function resolveAccountConfig(
|
||||
cfg: OpenClawConfig,
|
||||
accountId: string,
|
||||
|
||||
Reference in New Issue
Block a user