UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.54 kB
import{R as resolveTimerTimeoutMs}from"./number-coercion-B3CfI447.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{r as fetchWithTimeout}from"./fetch-timeout-ByCuX83h.mjs";import{i as readResponseWithLimit}from"./http-response-body-BJ35MG8h.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./text-utility-runtime-CDtGqkrl.mjs";import"./number-runtime-G0nhUVZu.mjs";import"./error-runtime-DW-sj0iq.mjs";import{n as makeProxyFetch}from"./proxy-fetch-Bt4uz_eh.mjs";import"./fetch-runtime-BnxPLWBI.mjs";import"./response-limit-runtime-uUJhFwkj.mjs";import{F as normalizeTelegramApiRoot,n as resolveTelegramTransport}from"./fetch-DJrvA0Aj.mjs"; //!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()}}export{auditTelegramGroupMembershipImpl};