UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) 3.19 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js"; import { o as listAgentIds } from "./agent-scope-config-DcbEhP0R.js"; import { n as normalizeAccountId, r as normalizeOptionalAccountId } from "./account-id-CETVCrTz.js"; import { i as resolveDefaultAgentBoundAccountId } from "./bindings-RJ9_sjHk.js"; import { i as hasConfiguredAccountValue, o as resolveListedDefaultAccountId, t as createAccountListHelpers } from "./account-helpers-DlhUvcA7.js"; import "./string-coerce-runtime-GQa0ehRA.js"; import "./account-core-DA6N6mo1.js"; import "./routing-adlWg0R3.js"; import "./agent-scope-runtime-h57Nypqc.js"; //#region extensions/telegram/src/account-selection.ts function resolveBindingAccount(params) { if (!params.binding || typeof params.binding !== "object") return null; const binding = params.binding; if (normalizeLowercaseStringOrEmpty(binding.match?.channel) !== params.channelId) return null; const accountId = typeof binding.match?.accountId === "string" ? binding.match.accountId : ""; if (!accountId.trim() || accountId.trim() === "*") return null; return { accountId: normalizeAccountId(accountId) }; } function listBoundAccountIds(cfg, channelId) { const ids = /* @__PURE__ */ new Set(); for (const binding of cfg.bindings ?? []) { const resolved = resolveBindingAccount({ binding, channelId }); if (resolved) ids.add(resolved.accountId); } return [...ids].toSorted((left, right) => left.localeCompare(right)); } function hasImplicitDefaultTelegramAccount(cfg) { const telegram = cfg.channels?.telegram; if (!telegram) return false; return hasConfiguredAccountValue(telegram.botToken) || hasConfiguredAccountValue(telegram.tokenFile) || hasConfiguredAccountValue(process.env.TELEGRAM_BOT_TOKEN); } const { listAccountIds: listTelegramAccountIds } = createAccountListHelpers("telegram", { normalizeAccountId, additionalAccountIds: (cfg) => listBoundAccountIds(cfg, "telegram"), hasImplicitDefaultAccount: hasImplicitDefaultTelegramAccount }); function resolveDefaultTelegramAccountSelection(cfg) { const boundDefault = cfg.agents?.ownership === "explicit" && listAgentIds(cfg).length !== 1 ? null : resolveDefaultAgentBoundAccountId(cfg, "telegram"); if (boundDefault) return { accountId: boundDefault, accountIds: listTelegramAccountIds(cfg), shouldWarnMissingDefault: false }; const accountIds = listTelegramAccountIds(cfg); const configuredDefaultAccountId = normalizeOptionalAccountId(cfg.channels?.telegram?.defaultAccount) ?? void 0; const hasExplicitDefaultAccount = configuredDefaultAccountId ? accountIds.includes(configuredDefaultAccountId) : false; const resolved = resolveListedDefaultAccountId({ accountIds, configuredDefaultAccountId }); return { accountId: resolved, accountIds, shouldWarnMissingDefault: resolved === accountIds[0] && !hasExplicitDefaultAccount && !accountIds.includes("default") && accountIds.length > 1 }; } function resolveDefaultTelegramAccountId(cfg) { return resolveDefaultTelegramAccountSelection(cfg).accountId; } //#endregion export { resolveDefaultTelegramAccountId as n, resolveDefaultTelegramAccountSelection as r, listTelegramAccountIds as t };