const e=require(`./utils-DyYoKTxM.cjs`),t=require(`./model-auth-B0JUHRHo.cjs`),n=require(`./ir-CZ1NXJrr.cjs`),r=require(`./polls-BuaJuIpV.cjs`),i=require(`./tables-CY3NIvao.cjs`),a=require(`./active-listener-Cj1UM1H3.cjs`),o=`\0FENCE`,s=`\0CODE`;function c(t){if(!t)return t;let n=[],r=t.replace(/```[\s\S]*?```/g,e=>(n.push(e),`${o}${n.length-1}`)),i=[];return r=r.replace(/`[^`\n]+`/g,e=>(i.push(e),`${s}${i.length-1}`)),r=r.replace(/\*\*(.+?)\*\*/g,`*$1*`),r=r.replace(/__(.+?)__/g,`*$1*`),r=r.replace(/~~(.+?)~~/g,`~$1~`),r=r.replace(RegExp(`${e.o(s)}(\\d+)`,`g`),(e,t)=>i[Number(t)]??``),r=r.replace(RegExp(`${e.o(o)}(\\d+)`,`g`),(e,t)=>n[Number(t)]??``),r}const l=e.O(`gateway/channels/whatsapp`).child(`outbound`);async function u(r,o,s){let u=o.trimStart(),d=e.x(r);if(!u&&!s.mediaUrl)return{messageId:``,toJid:d};let f=t.xr(),p=Date.now(),{listener:m,accountId:h}=a.n(s.accountId),g=s.cfg??t.Gi(),_=t.zs({cfg:g,accountId:h??s.accountId}),v=n.s({cfg:g,channel:`whatsapp`,accountId:h??s.accountId});u=i.t(u??``,v),u=c(u);let y=t.Ni(r),b=e.K({module:`web-outbound`,correlationId:f,to:y});try{let e=t.Ni(d),i,a,o;if(s.mediaUrl){let e=await n.a(s.mediaUrl,{maxBytes:t.Bs(_),localRoots:s.mediaLocalRoots}),r=u||void 0;i=e.buffer,a=e.contentType,e.kind===`audio`?a=e.contentType===`audio/ogg`?`audio/ogg; codecs=opus`:e.contentType??`application/octet-stream`:e.kind===`video`||e.kind===`image`?u=r??``:(u=r??``,o=e.fileName)}l.info(`Sending message -> ${e}${s.mediaUrl?` (media)`:``}`),b.info({jid:e,hasMedia:!!s.mediaUrl},`sending message`),await m.sendComposingTo(r);let c=s.accountId?.trim()?h:void 0,f=s.gifPlayback||c||o?{...s.gifPlayback?{gifPlayback:!0}:{},...o?{fileName:o}:{},accountId:c}:void 0,g=(f?await m.sendMessage(r,u,i,a,f):await m.sendMessage(r,u,i,a))?.messageId??`unknown`,v=Date.now()-p;return l.info(`Sent message ${g} -> ${e}${s.mediaUrl?` (media)`:``} (${v}ms)`),b.info({jid:e,messageId:g},`sent message`),{messageId:g,toJid:d}}catch(e){throw b.error({err:String(e),to:y,hasMedia:!!s.mediaUrl},`failed to send via web session`),e}}async function d(n,r,i,o){let s=t.xr(),{listener:c}=a.n(o.accountId),u=t.Ni(n),d=e.K({module:`web-outbound`,correlationId:s,chatJid:u,messageId:r});try{let a=t.Ni(e.x(n));l.info(`Sending reaction "${i}" -> message ${r}`),d.info({chatJid:a,messageId:r,emoji:i},`sending reaction`),await c.sendReaction(n,r,i,o.fromMe??!1,o.participant),l.info(`Sent reaction "${i}" -> message ${r}`),d.info({chatJid:a,messageId:r,emoji:i},`sent reaction`)}catch(e){throw d.error({err:String(e),chatJid:u,messageId:r,emoji:i},`failed to send reaction via web session`),e}}async function f(n,i,o){let s=t.xr(),c=Date.now(),{listener:u}=a.n(o.accountId),d=t.Ni(n),f=e.K({module:`web-outbound`,correlationId:s,to:d});try{let a=e.x(n),o=t.Ni(a),s=r.n(i,{maxOptions:12});l.info(`Sending poll -> ${o}`),f.info({jid:o,optionCount:s.options.length,maxSelections:s.maxSelections},`sending poll`);let d=(await u.sendPoll(n,s))?.messageId??`unknown`,p=Date.now()-c;return l.info(`Sent poll ${d} -> ${o} (${p}ms)`),f.info({jid:o,messageId:d},`sent poll`),{messageId:d,toJid:a}}catch(e){throw f.error({err:String(e),to:d},`failed to send poll via web session`),e}}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return u}});
