openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
88 lines (87 loc) • 3.86 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { n as normalizeAccountId, r as normalizeOptionalAccountId } from "./account-id-BqKT3GuY.mjs";
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./runtime-env-D-Pa5lD6.mjs";
import { t as createAccountActionGate } from "./account-action-gate-C9AmtuMA.mjs";
import { t as resolveAccountWithDefaultFallback } from "./account-core-DMIDUKXd.mjs";
import { n as formatSetExplicitDefaultInstruction } from "./default-account-warnings-Bly3xQ0b.mjs";
import "./routing-DmgGYTrU.mjs";
import { a as mergeTelegramAccountConfig, i as resolveDefaultTelegramAccountSelection, n as listTelegramAccountIds, o as resolveTelegramAccountConfig } from "./account-selection-CGYGB8bX.mjs";
import { n as resolveTelegramToken } from "./token-Dmy_LoAW.mjs";
//#region extensions/telegram/src/accounts.ts
const log = createSubsystemLogger("telegram/accounts");
let emittedMissingDefaultWarn = false;
function resolveDefaultTelegramAccountId(e) {
const t = resolveDefaultTelegramAccountSelection(e);
if (t.shouldWarnMissingDefault && !emittedMissingDefaultWarn) {
emittedMissingDefaultWarn = true;
log.warn(`channels.telegram: accounts.default is missing; falling back to "${t.accountId}". ${formatSetExplicitDefaultInstruction("telegram")} to avoid routing surprises in multi-account setups.`);
}
return t.accountId;
}
function createTelegramActionGate(e) {
const t = e.accountId ?? resolveDefaultTelegramAccountId(e.cfg);
return createAccountActionGate({
baseActions: e.cfg.channels?.telegram?.actions,
accountActions: resolveTelegramAccountConfig(e.cfg, t)?.actions
});
}
function resolveTelegramMediaRuntimeOptions(e) {
const t = normalizeOptionalAccountId(e.accountId);
const n = t ? mergeTelegramAccountConfig(e.cfg, t) : e.cfg.channels?.telegram;
return {
token: e.token,
transport: e.transport,
apiRoot: n?.apiRoot,
trustedLocalFileRoots: n?.trustedLocalFileRoots,
dangerouslyAllowPrivateNetwork: n?.network?.dangerouslyAllowPrivateNetwork
};
}
function resolveTelegramPollActionGateState(e) {
const t = e("sendMessage");
const n = e("poll");
return {
sendMessageEnabled: t,
pollEnabled: n,
enabled: t && n
};
}
function resolveTelegramAccountFallback(e, t) {
return resolveAccountWithDefaultFallback({
accountId: e.accountId ?? resolveDefaultTelegramAccountId(e.cfg),
normalizeAccountId,
resolvePrimary: t,
hasCredential: (e) => e.tokenSource !== "none",
resolveDefaultAccountId: () => resolveDefaultTelegramAccountId(e.cfg)
});
}
function resolveTelegramAccount(e) {
const t = e.cfg.channels?.telegram?.enabled !== false;
const resolve = (n) => {
const r = mergeTelegramAccountConfig(e.cfg, n);
const i = r.enabled !== false;
const a = t && i;
const o = resolveTelegramToken(e.cfg, { accountId: n });
return {
accountId: n,
enabled: a,
name: normalizeOptionalString(r.name),
token: o.token,
tokenSource: o.source,
tokenStatus: o.credentialDiagnostics?.length ? "configured_unavailable" : o.token ? "available" : "missing",
...o.credentialDiagnostics ? { credentialDiagnostics: o.credentialDiagnostics } : {},
config: r
};
};
return resolveTelegramAccountFallback(e, resolve);
}
function listEnabledTelegramAccounts(e) {
if (!(e.channels?.telegram?.enabled !== false)) return [];
return listTelegramAccountIds(e).filter((t) => mergeTelegramAccountConfig(e, t).enabled !== false).map((t) => resolveTelegramAccount({
cfg: e,
accountId: t
}));
}
//#endregion
export { resolveTelegramAccountFallback as a, resolveTelegramAccount as i, listEnabledTelegramAccounts as n, resolveTelegramMediaRuntimeOptions as o, resolveDefaultTelegramAccountId as r, resolveTelegramPollActionGateState as s, createTelegramActionGate as t };