import{t as e}from"./config-BYRrjYC5.mjs";import{t}from"./config-not-found-B9AOp828.mjs";import{Api as n,TelegramClient as r}from"telegram";import{StringSession as i}from"telegram/sessions/index.js";let a;async function o(n,o){if(!e.telegram.session&&o===void 0)throw new t(`TELEGRAM_SESSION is not configured`);if(a)return a;let s=Number(e.telegram.apiId??4),c=e.telegram.apiHash??`014b35b6184100b085b0d0572f9b5103`;return a=new r(new i(o??e.telegram.session),s,c,{connectionRetries:1/0,autoReconnect:!0,retryDelay:3e3,maxConcurrentDownloads:Number(e.telegram.maxConcurrentDownloads??10),proxy:e.telegram.proxy?.host&&e.telegram.proxy.port&&e.telegram.proxy.secret?{ip:e.telegram.proxy.host,port:Number(e.telegram.proxy.port),MTProxy:!0,secret:e.telegram.proxy.secret}:void 0}),await a.start(Object.assign(n??{},{onError:e=>{throw Error(`Cannot start TG: `+e)}})),a}function s(e){if(e instanceof n.MessageMediaDocument){for(let t of e.document.attributes)if(t instanceof n.DocumentAttributeFilename)return t.fileName}return e.className}function c(e){if(e instanceof n.MessageMediaDocument&&e.document&&!(e.document instanceof n.DocumentEmpty))return e.document;if(e instanceof n.MessageMediaWebPage&&e.webpage instanceof n.WebPage&&e.webpage.document instanceof n.Document)return e.webpage.document}async function l(e,t){return(await(await o()).invoke(new n.stories.GetStoriesByID({id:[t],peer:e}))).stories[0]}async function u(e,t){if(e instanceof n.MessageMediaStory){if(e.story instanceof n.StoryItem&&e.story.media)return e.story.media;let r=await l(e.peer,e.id);return!r?.media&&t&&(r=await l(t,e.id)),r?.media}return e}export{u as a,l as i,c as n,s as r,o as t};