Files
openclaw/extensions/whatsapp/src/account-config.ts
2026-04-01 23:14:48 +09:00

33 lines
1.0 KiB
TypeScript

import {
DEFAULT_ACCOUNT_ID,
resolveAccountEntry,
resolveMergedAccountConfig,
type OpenClawConfig,
} from "openclaw/plugin-sdk/account-core";
import type { WhatsAppAccountConfig } from "./runtime-api.js";
function resolveWhatsAppAccountConfig(
cfg: OpenClawConfig,
accountId: string,
): WhatsAppAccountConfig | undefined {
return resolveAccountEntry(cfg.channels?.whatsapp?.accounts, accountId);
}
export function resolveMergedWhatsAppAccountConfig(params: {
cfg: OpenClawConfig;
accountId?: string | null;
}): WhatsAppAccountConfig & { accountId: string } {
const rootCfg = params.cfg.channels?.whatsapp;
const accountId = params.accountId?.trim() || rootCfg?.defaultAccount || DEFAULT_ACCOUNT_ID;
const merged = resolveMergedAccountConfig<WhatsAppAccountConfig>({
channelConfig: rootCfg as WhatsAppAccountConfig | undefined,
accounts: rootCfg?.accounts as Record<string, Partial<WhatsAppAccountConfig>> | undefined,
accountId,
omitKeys: ["defaultAccount"],
});
return {
accountId,
...merged,
};
}