mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 16:08:37 +00:00
refactor: share config adapter allowFrom and defaultTo helpers
This commit is contained in:
@@ -4,10 +4,26 @@ import { resolveIMessageAccount } from "../imessage/accounts.js";
|
||||
import { normalizeAccountId } from "../routing/session-key.js";
|
||||
import { resolveWhatsAppAccount } from "../web/accounts.js";
|
||||
|
||||
export function mapAllowFromEntries(
|
||||
allowFrom: Array<string | number> | null | undefined,
|
||||
): string[] {
|
||||
return (allowFrom ?? []).map((entry) => String(entry));
|
||||
}
|
||||
|
||||
export function formatTrimmedAllowFromEntries(allowFrom: Array<string | number>): string[] {
|
||||
return allowFrom.map((entry) => String(entry).trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
export function resolveOptionalConfigString(
|
||||
value: string | number | null | undefined,
|
||||
): string | undefined {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
const normalized = String(value).trim();
|
||||
return normalized || undefined;
|
||||
}
|
||||
|
||||
export function resolveWhatsAppConfigAllowFrom(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
@@ -33,12 +49,12 @@ export function resolveIMessageConfigAllowFrom(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}): string[] {
|
||||
return (resolveIMessageAccount(params).config.allowFrom ?? []).map((entry) => String(entry));
|
||||
return mapAllowFromEntries(resolveIMessageAccount(params).config.allowFrom);
|
||||
}
|
||||
|
||||
export function resolveIMessageConfigDefaultTo(params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}): string | undefined {
|
||||
return resolveIMessageAccount(params).config.defaultTo?.trim() || undefined;
|
||||
return resolveOptionalConfigString(resolveIMessageAccount(params).config.defaultTo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user