UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

78 lines (77 loc) • 3.03 kB
import { R as resolveTimerTimeoutMs } from "./number-coercion-D6u-4YD8.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { i as readResponseWithLimit } from "./http-response-body-B-i_0116.mjs"; import { r as fetchWithTimeout } from "./fetch-timeout-D62KciOm.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./text-utility-runtime-Ds8jsG0J.mjs"; import "./number-runtime-W4chuk8B.mjs"; import "./error-runtime-BM740gJj.mjs"; import { n as makeProxyFetch } from "./proxy-fetch-DVhncUsK.mjs"; import "./fetch-runtime-Dz-KqFMb.mjs"; import "./response-limit-runtime-DkiFHsEX.mjs"; import { F as normalizeTelegramApiRoot, n as resolveTelegramTransport } from "./fetch-Credn4zH.mjs"; //#region extensions/telegram/src/audit-membership-runtime.ts const TELEGRAM_BOT_API_MAX_RESPONSE_BYTES = 4194304; async function auditTelegramGroupMembershipImpl(e) { const t = e.proxyUrl ? makeProxyFetch(e.proxyUrl) : void 0; const n = resolveTelegramTransport(t, { network: e.network }); try { const t = `${normalizeTelegramApiRoot(e.apiRoot)}/bot${e.token}`; const r = []; const i = resolveTimerTimeoutMs(e.timeoutMs, 1); const a = performance.now() + i; for (const o of e.groupIds) { const s = { chatId: o, ok: false, status: null, error: null, matchKey: o, matchSource: "id" }; r.push(s); const c = Math.max(0, a - performance.now()); if (c === 0) { s.error = `Telegram membership audit timed out after ${i}ms`; continue; } try { const r = `${t}/getChatMember?chat_id=${encodeURIComponent(o)}&user_id=${encodeURIComponent(String(e.botId))}`; const i = await fetchWithTimeout(r, {}, c, n.fetch); const l = Math.max(1, a - performance.now()); const u = await readResponseWithLimit(i, TELEGRAM_BOT_API_MAX_RESPONSE_BYTES, { timeoutMs: l, chunkTimeoutMs: l / 2, onIdleTimeout: ({ chunkTimeoutMs: e }) => /* @__PURE__ */ new Error(`Telegram membership audit response body stalled for ${e}ms`), onTimeout: ({ timeoutMs: e }) => /* @__PURE__ */ new Error(`Telegram membership audit response body timed out after ${e}ms`) }); const d = JSON.parse(u.toString("utf8")); if (!i.ok || !isRecord(d) || !d.ok) { s.error = isRecord(d) && !d.ok && typeof d.description === "string" ? d.description : `getChatMember failed (${i.status})`; continue; } const f = isRecord(d.result) && typeof d.result.status === "string" ? d.result.status : null; const p = f === "creator" || f === "administrator" || f === "member"; Object.assign(s, { ok: p, status: f, error: p ? null : "bot not in group" }); } catch (e) { s.error = formatErrorMessage(e); } } return { ok: r.every((e) => e.ok), checkedGroups: r.length, unresolvedGroups: 0, hasWildcardUnmentionedGroups: false, groups: r }; } finally { await n.close(); } } //#endregion export { auditTelegramGroupMembershipImpl };