openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
82 lines (81 loc) • 3.87 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { n as normalizeAccountId, r as normalizeOptionalAccountId, t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { a as resolveNormalizedAccountEntry } from "./account-lookup-FhQZVFfo.mjs";
import { t as mergeAccountConfig } from "./channel-account-config-BvENCH3O.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { i as hasConfiguredAccountValue, o as resolveListedDefaultAccountId, t as createAccountListHelpers } from "./account-helpers-2ZndtV_R.mjs";
import "./account-core-DMIDUKXd.mjs";
import { r as resolveDefaultAgentBoundAccountId } from "./bindings-BGbnqeha.mjs";
import "./routing-DmgGYTrU.mjs";
import { t as listAgentIdsCompatibility } from "./agent-scope-runtime-CDpr-vor.mjs";
//#region extensions/telegram/src/account-config.ts
function resolveTelegramAccountConfig(e, t) {
const n = normalizeAccountId(t);
return resolveNormalizedAccountEntry(e.channels?.telegram?.accounts, n, normalizeAccountId);
}
function mergeTelegramAccountConfig(e, t) {
const n = e.channels?.telegram;
const r = Object.keys(n?.accounts ?? {}).length > 1;
return mergeAccountConfig({
channelConfig: n,
accountConfig: resolveTelegramAccountConfig(e, t),
omitKeys: ["defaultAccount"],
inheritEmptyKeys: {
capabilities: "array",
...r ? {} : { groups: "object" }
},
preserveRootAllowFrom: true
});
}
function resolveTelegramLegacyWebhookListener(e) {
if (!e) return;
return {
port: e.port,
host: e.host ?? "127.0.0.1"
};
}
//#endregion
//#region extensions/telegram/src/account-selection.ts
function resolveTelegramBindingAccountId(e) {
if (!e || typeof e !== "object") return null;
const t = e;
if (normalizeLowercaseStringOrEmpty(t.match?.channel) !== "telegram") return null;
const n = typeof t.match?.accountId === "string" ? t.match.accountId : "";
if (!n.trim() || n.trim() === "*") return null;
return normalizeAccountId(n);
}
function hasTelegramAccountConfig(e, t) {
const n = normalizeAccountId(t);
if (resolveTelegramAccountConfig(e, n)) return true;
const r = e.channels?.telegram;
if (n !== "default" && (Object.keys(r?.accounts ?? {}).length > 0 || !e.bindings?.some((e) => resolveTelegramBindingAccountId(e) === n))) return false;
return hasConfiguredAccountValue(r?.botToken) || hasConfiguredAccountValue(r?.tokenFile) || n === "default" && hasConfiguredAccountValue(process.env.TELEGRAM_BOT_TOKEN);
}
const { listAccountIds: listTelegramAccountIds } = createAccountListHelpers("telegram", {
normalizeAccountId,
additionalAccountIds: (e) => [...new Set((e.bindings ?? []).map(resolveTelegramBindingAccountId).filter((e) => e !== null))].toSorted((e, t) => e.localeCompare(t)),
hasImplicitDefaultAccount: (e) => hasTelegramAccountConfig(e, DEFAULT_ACCOUNT_ID)
});
function resolveDefaultTelegramAccountSelection(e) {
const t = e.agents?.ownership === "explicit" && listAgentIdsCompatibility(e).length !== 1 ? null : resolveDefaultAgentBoundAccountId(e, "telegram");
if (t) return {
accountId: t,
shouldWarnMissingDefault: false
};
const n = listTelegramAccountIds(e);
const r = normalizeOptionalAccountId(e.channels?.telegram?.defaultAccount) ?? void 0;
const i = r ? n.includes(r) : false;
const a = resolveListedDefaultAccountId({
accountIds: n,
configuredDefaultAccountId: r
});
return {
accountId: a,
shouldWarnMissingDefault: a === n[0] && !i && !n.includes("default") && n.length > 1
};
}
function resolveDefaultTelegramAccountId(e) {
return resolveDefaultTelegramAccountSelection(e).accountId;
}
//#endregion
export { mergeTelegramAccountConfig as a, resolveDefaultTelegramAccountSelection as i, listTelegramAccountIds as n, resolveTelegramAccountConfig as o, resolveDefaultTelegramAccountId as r, resolveTelegramLegacyWebhookListener as s, hasTelegramAccountConfig as t };