gramstax 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var h=(u,i)=>v(u,"name",{value:i,configurable:!0});var X=(u,i)=>{for(var e in i)v(u,e,{get:i[e],enumerable:!0})},K=(u,i,e,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of U(i))!q.call(u,s)&&s!==e&&v(u,s,{get:()=>i[s],enumerable:!(t=H(i,s))||t.enumerable});return u};var Y=(u,i,e)=>(e=u!=null?G(J(u)):{},K(i||!u||!u.__esModule?v(e,"default",{value:u,enumerable:!0}):e,u)),Z=u=>K(v({},"__esModule",{value:!0}),u);var ii={};X(ii,{BaseGeneral:()=>x,CacheExternal:()=>T,Ctx:()=>k,Gramstax:()=>A,TemplateEngine:()=>C,TemplateManager:()=>F});module.exports=Z(ii);var N=require("logging-pretty");var x=class{static{h(this,"BaseGeneral")}static log=new N.LoggingPretty;static logError(i,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(i)}`)}logError(i,e,t){this.constructor.log.error(`[${e||this.constructor.name}:${t}] ${String(i)}`)}};var R=require("keyv"),B=Y(require("@keyv/redis"),1);var T=class extends R.Keyv{constructor(e="memory",t,s,n){let o;e.startsWith("redis")&&(o=new B.default(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:t,ttl:s});this.url=e}static{h(this,"CacheExternal")}};var $=require("timers/promises");var S=require("grammy");var k=class extends x{static{h(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,e,t,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:t,...o}),d+1==30&&await(0,$.setTimeout)(1200)}}async reply(i,e,t,s){let n=this.templateManager.getMessage(this.data.name,t,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,e,t,s,n){let{src:o,caption:a}=this.templateManager.getMedia(this.data.name,s,this.languageCode,t),r={parse_mode:"HTML",reply_markup:e,...n};if(i=="photo")return await this.ct.replyWithPhoto(o,{caption:a,...r});if(i=="video")return await this.ct.replyWithVideo(o,{caption:a,...r});if(i=="audio")return await this.ct.replyWithAudio(o,{caption:a,...r});if(i=="document")return await this.ct.replyWithDocument(o,{caption:a,...r});if(i=="animation")return await this.ct.replyWithAnimation(o,{caption:a,...r})}async replyPhoto(i,e,t,s){return this.replyMedia("photo",i,e,t,s)}async replyVideo(i,e,t,s){return this.replyMedia("video",i,e,t,s)}async replyAudio(i,e,t,s){return this.replyMedia("audio",i,e,t,s)}async replyDocument(i,e,t,s){return this.replyMedia("document",i,e,t,s)}async replyAnimation(i,e,t,s){return this.replyMedia("animation",i,e,t,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,e,t,s){try{let n=this.templateManager.getMessage(this.data.name,t,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,e,t,s)}}async editMedia(i,e,t,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,t);return await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,t,s,o)}}async editPhoto(i,e,t,s,n){return await this.editMedia("photo",i,e,t,s,n)}async editVideo(i,e,t,s,n){return await this.editMedia("video",i,e,t,s,n)}async editAudio(i,e,t,s,n){return await this.editMedia("audio",i,e,t,s,n)}async editDocument(i,e,t,s,n){return await this.editMedia("document",i,e,t,s,n)}async editAnimation(i,e,t,s,n){return await this.editMedia("animation",i,e,t,s,n)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,e,t){try{let s={method:i,params:e,...t},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...e){let t=i(...e);return`${this.name}${t===void 0?"":`:${t}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,e){let t=this.data.name;if(e?.cache===!0){let a=`${t}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,l=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"inline",e?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new S.InlineKeyboard,n=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"inline",e?.data);return i(s,n)}buildKeyboard(i,e){let t=this.data.name;if(e?.cache===!0){let a=`${t}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,l=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"default",e?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new S.Keyboard,n=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"default",e?.data),o=i(s,n);return o.resized(),o}validateSessionCallback(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(e)}validateSessionCallbackPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(e)}validateSessionText(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(e)}validateSessionTextPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(e)}validateSessionTextCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(e)}validateSessionTextCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(e)}validateSessionTextFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(e)}validateSessionPhotoCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(e)}validateSessionPhotoCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(e)}validateSessionVideoCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(e)}validateSessionVideoCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(e)}validateSessionVideoFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(e)}validateSessionAudioCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(e)}validateSessionAudioCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(e)}validateSessionAudioFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(e)}validateSessionDocumentCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(e)}validateSessionDocumentCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(e)}validateSessionAnimationCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(e)}validateSessionAnimationCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(e)}validateSessionVoiceCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(e)}validateSessionVoiceCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(e)}validateSessionVideoNoteCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(e)}validateSessionStickerFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(e)}validateSessionLocationFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(e)}validateSessionContactFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(e)}sessionCallback(i,e){return this.sessionSet(this.buildSessionMethodCallback(e),i)}sessionCallbackPayload(i,e){return this.sessionSet(this.buildSessionMethodCallbackPayload(e),i)}sessionText(i,e){return this.sessionSet(this.buildSessionMethodText(e),i)}sessionTextPayload(i,e){return this.sessionSet(this.buildSessionMethodTextPayload(e),i)}sessionTextCommand(i,e){return this.sessionSet(this.buildSessionMethodTextCommand(e),i)}sessionTextCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodTextCommandPayload(e),i)}sessionTextFree(i,e){return this.sessionSet(this.buildSessionMethodTextFree(e),i)}sessionPhotoCaption(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaption(e),i)}sessionPhotoCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(e),i)}sessionPhotoCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(e),i)}sessionPhotoCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(e),i)}sessionPhotoFree(i,e){return this.sessionSet(this.buildSessionMethodPhotoFree(e),i)}sessionVideoCaption(i,e){return this.sessionSet(this.buildSessionMethodVideoCaption(e),i)}sessionVideoCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(e),i)}sessionVideoCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(e),i)}sessionVideoCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(e),i)}sessionVideoFree(i,e){return this.sessionSet(this.buildSessionMethodVideoFree(e),i)}sessionAudioCaption(i,e){return this.sessionSet(this.buildSessionMethodAudioCaption(e),i)}sessionAudioCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(e),i)}sessionAudioCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(e),i)}sessionAudioCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(e),i)}sessionAudioFree(i,e){return this.sessionSet(this.buildSessionMethodAudioFree(e),i)}sessionDocumentCaption(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaption(e),i)}sessionDocumentCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(e),i)}sessionDocumentCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(e),i)}sessionDocumentCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(e),i)}sessionDocumentFree(i,e){return this.sessionSet(this.buildSessionMethodDocumentFree(e),i)}sessionAnimationCaption(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaption(e),i)}sessionAnimationCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(e),i)}sessionAnimationCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(e),i)}sessionAnimationCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(e),i)}sessionAnimationFree(i,e){return this.sessionSet(this.buildSessionMethodAnimationFree(e),i)}sessionVoiceCaption(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaption(e),i)}sessionVoiceCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(e),i)}sessionVoiceCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(e),i)}sessionVoiceCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(e),i)}sessionVoiceFree(i,e){return this.sessionSet(this.buildSessionMethodVoiceFree(e),i)}sessionVideoNoteCaption(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(e),i)}sessionVideoNoteCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(e),i)}sessionVideoNoteCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(e),i)}sessionVideoNoteCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(e),i)}sessionVideoNoteFree(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteFree(e),i)}sessionStickerFree(i,e){return this.sessionSet(this.buildSessionMethodStickerFree(e),i)}sessionLocationFree(i,e){return this.sessionSet(this.buildSessionMethodLocationFree(e),i)}sessionContactFree(i,e){return this.sessionSet(this.buildSessionMethodContactFree(e),i)}sessionToCallback(i,e){return this.sessionCallback({...this.session.params,...i},e)}sessionToCallbackPayload(i,e){return this.sessionCallbackPayload({...this.session.params,...i},e)}sessionToText(i,e){return this.sessionText({...this.session.params,...i},e)}sessionToTextPayload(i,e){return this.sessionTextPayload({...this.session.params,...i},e)}sessionToTextCommand(i,e){return this.sessionTextCommand({...this.session.params,...i},e)}sessionToTextCommandPayload(i,e){return this.sessionTextCommandPayload({...this.session.params,...i},e)}sessionToTextFree(i,e){return this.sessionTextFree({...this.session.params,...i},e)}sessionToPhotoCaption(i,e){return this.sessionPhotoCaption({...this.session.params,...i},e)}sessionToPhotoCaptionPayload(i,e){return this.sessionPhotoCaptionPayload({...this.session.params,...i},e)}sessionToPhotoCaptionCommand(i,e){return this.sessionPhotoCaptionCommand({...this.session.params,...i},e)}sessionToPhotoCaptionCommandPayload(i,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},e)}sessionToPhotoFree(i,e){return this.sessionPhotoFree({...this.session.params,...i},e)}sessionToVideoCaption(i,e){return this.sessionVideoCaption({...this.session.params,...i},e)}sessionToVideoCaptionPayload(i,e){return this.sessionVideoCaptionPayload({...this.session.params,...i},e)}sessionToVideoCaptionCommand(i,e){return this.sessionVideoCaptionCommand({...this.session.params,...i},e)}sessionToVideoCaptionCommandPayload(i,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},e)}sessionToVideoFree(i,e){return this.sessionVideoFree({...this.session.params,...i},e)}sessionToAudioCaption(i,e){return this.sessionAudioCaption({...this.session.params,...i},e)}sessionToAudioCaptionPayload(i,e){return this.sessionAudioCaptionPayload({...this.session.params,...i},e)}sessionToAudioCaptionCommand(i,e){return this.sessionAudioCaptionCommand({...this.session.params,...i},e)}sessionToAudioCaptionCommandPayload(i,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},e)}sessionToAudioFree(i,e){return this.sessionAudioFree({...this.session.params,...i},e)}sessionToDocumentCaption(i,e){return this.sessionDocumentCaption({...this.session.params,...i},e)}sessionToDocumentCaptionPayload(i,e){return this.sessionDocumentCaptionPayload({...this.session.params,...i},e)}sessionToDocumentCaptionCommand(i,e){return this.sessionDocumentCaptionCommand({...this.session.params,...i},e)}sessionToDocumentCaptionCommandPayload(i,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},e)}sessionToDocumentFree(i,e){return this.sessionDocumentFree({...this.session.params,...i},e)}sessionToAnimationCaption(i,e){return this.sessionAnimationCaption({...this.session.params,...i},e)}sessionToAnimationCaptionPayload(i,e){return this.sessionAnimationCaptionPayload({...this.session.params,...i},e)}sessionToAnimationCaptionCommand(i,e){return this.sessionAnimationCaptionCommand({...this.session.params,...i},e)}sessionToAnimationCaptionCommandPayload(i,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},e)}sessionToAnimationFree(i,e){return this.sessionAnimationFree({...this.session.params,...i},e)}sessionToVoiceCaption(i,e){return this.sessionVoiceCaption({...this.session.params,...i},e)}sessionToVoiceCaptionPayload(i,e){return this.sessionVoiceCaptionPayload({...this.session.params,...i},e)}sessionToVoiceCaptionCommand(i,e){return this.sessionVoiceCaptionCommand({...this.session.params,...i},e)}sessionToVoiceCaptionCommandPayload(i,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},e)}sessionToVoiceFree(i,e){return this.sessionVoiceFree({...this.session.params,...i},e)}sessionToVideoNoteCaption(i,e){return this.sessionVideoNoteCaption({...this.session.params,...i},e)}sessionToVideoNoteCaptionPayload(i,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},e)}sessionToVideoNoteCaptionCommand(i,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},e)}sessionToVideoNoteCaptionCommandPayload(i,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},e)}sessionToVideoNoteFree(i,e){return this.sessionVideoNoteFree({...this.session.params,...i},e)}sessionToStickerFree(i,e){return this.sessionStickerFree({...this.session.params,...i},e)}sessionToLocationFree(i,e){return this.sessionLocationFree({...this.session.params,...i},e)}sessionToContactFree(i,e){return this.sessionContactFree({...this.session.params,...i},e)}buildIntent(i,e=!0){i||(i=e?this.data.callbackData():this.data.name);let t=e?":":" ";return i?.indexOf?.(t)!=-1?i?.split?.(t)?.[0]:i}buildSessionMethod(i,e){return`${i}-${e||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};var E=require("bun"),M=require("path");var O=require("logging-pretty");var C=class{static{h(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(e,t)=>`\${(data && data["${t}"]) ?? ""}`)}static _processBaseBlocks(i){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,t={};for(let s of i.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();t[n]=a}return t}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,t)=>{let s=t.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(e,t)=>t.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,t={};for(let s of i.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of n.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),p={type:l};a.src&&(p.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(p.caption=c),l==="location"&&(a.latitude&&(p.latitude=a.latitude),a.longitude&&(p.longitude=a.longitude),c&&(p.caption=c)),l==="contact"&&(a.phone&&(p.phone=a.phone),a.first_name&&(p.first_name=a.first_name),a.last_name&&(p.last_name=a.last_name),a.vcard&&(p.vcard=a.vcard),c&&(p.caption=c)),t[d]=p}return t}static _processMessageBlocks(i){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,t={};for(let[,s,n]of i.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();t[s]=o}return t}static _processKeyboardBlocks(i){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,t={};for(let[,s,n,o]of i.matchAll(e)){let a=n==="default"?"default":"inline",r=o.trim();t[s]||(t[s]={}),t[s][a]=r}return t}static _compileToFunction(i,e){let t;e?t=i.map(o=>`\`${o}\``).join(","):t=`\`${i}\``;let s=t;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let n=`return [${s}]`;return new Function("data",n)}else{let n=`return ${s}`;return new Function("data",n)}}static compileMedia(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);t[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);t[s][a]=c=>({...r,caption:l(c)})}else t[s][a]=()=>r}return t}static compileMessages(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);t[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));t[s][a]=this._compileToFunction(d,!1)}}return t}static compileKeyboards(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);t[s]={};for(let[a,r]of Object.entries(o)){t[s][a]={};for(let[d,l]of Object.entries(r)){let p=l.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));t[s][a][d]=this._compileToFunction(p,!0)}}}return t}};var P=class{static{h(this,"HelperPage")}static _getPage(i,e,t=!0){let n=Object.values(i)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return t===!0&&(n.template=void 0),n}static getPageSync(i,e=!0){let t=require(i);return this._getPage(t,i,e)}static async getPage(i,e=!0){let t=await import(`${i}?t=${Date.now()}`);return this._getPage(t,i,e)}};var L=require("fs/promises"),W=require("chokidar"),f=require("path"),y=require("fs");var F=class{static{h(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:e,enableWatch:t=!1,forceLanguage:s}=i;this._path=e,this._forceLanguage=s,this._isWatchEnabled=t,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let e=this._path[i];if(!(0,y.existsSync)(e))throw new Error(`Template base path is not exists: ${e}`);if(!(0,y.statSync)(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let e=this._path[i],t=(0,W.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=t,t.on("change",this._handleFileChange.bind(this)),t.on("add",this._handleFileAdd.bind(this)),t.on("unlink",this._handleFileDelete.bind(this)),t.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let e=(0,f.basename)(i);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(i){let e=(0,f.basename)(i);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(i){let e=(0,f.basename)(i),t=this._getKey(e);this._map.has(t)&&this._map.delete(t)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let e=this._path[i],s=(0,y.readdirSync)(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(i,e=!0){for(let t=0;t<this._path.length;t++){let s=this._path[t],n=(0,f.join)(s,i),o=this._getExtension(i),a=this._getKey(i);if(o==".html"){let r=e?(0,y.readFileSync)(n,"utf8"):await(0,L.readFile)(n,"utf8");this._compile(a,r)}else if(o==".ts"){let r=await P.getPage(n,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return(0,f.extname)(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,e,t){let s=this._map.get(i),n=s||{},o=!1;(t===void 0||t?.media===!1||s?.media===void 0)&&(n.media=C.compileMedia(e),o=!0),(t===void 0||t?.message===!1||s?.message===void 0)&&(n.message=C.compileMessages(e),o=!0),(t===void 0||t?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=C.compileKeyboards(e),o=!0),o&&this._map.set(i,n)}getMedia(i,e="default",t="en",s){let o=this._map.get(i)?.media?.[e]?.[this._forceLanguage||t];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(i,e="default",t="en",s){let o=this._map.get(i)?.message?.[e]?.[this._forceLanguage||t];if(!o)return"";try{return o(s)}catch{return""}}getKeyboard(i,e="default",t="en",s="inline",n){let a=this._map.get(i)?.keyboard?.[e]?.[this._forceLanguage||t]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(i,e){if(this._getExtension(i)!=".html")return null;for(let t=0;t<this._path.length;t++){let s=(0,f.join)(this._path[t],i);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,e,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};var _=require("fs"),w=require("grammy");var A=class{static{h(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new O.LoggingPretty:i.log,this.cacheSession=i.cacheSession||new T("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new F({path:[(0,M.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,e,t){let{username:s}=i;e=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${t})`)}createBot(i){return new w.Bot(i)}createCtx(i){return new k({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:h(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let e=(0,w.webhookCallback)(this.bot,"bun"),t="/telegram-webhook";(0,E.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===t)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),n=i.endsWith("/")?i.slice(0,-1)+t:i+t;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}pageBuildData(i,e){i?.data===void 0&&(i.data=i.buildData()),i.data.name=(0,M.parse)(e).name}pageSorts(i,e){let t=i.data.name,s=i.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,l=e.dynamicSpesific,c=h(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),p=h(m=>m.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),g=h((m,b)=>s[`buildSessionMethod${c(m)}`](b),"buildSessionMethod");e.all[t]=i;for(let m=0;m<e.lenListFuncStaticSession;m++){let b=e.listFuncStaticSession[m],j=e.static[b],Q=e.staticIntent[b],D=e.staticSession[b],V={name:t,func:b},I=j||Q;if(I!==void 0){let z=b.includes(o)?`/${t}`:t;I[s.buildIntent(z,b.startsWith("callback"))]=V}D!==void 0&&(D[g(b,t)]=V),b.toLowerCase().endsWith("free")&&l[p(b)].push(V)}s.free&&d.push(t)}pageLoads(){this.log?.info?.("Load pages..");let i=(0,M.join)(process.cwd(),"src","pages");if(!(0,_.existsSync)(i))throw new Error(`Directory ${i} is not found, please make it manually`);let e=(0,_.readdirSync)(i),t={},s=t,n=t,o=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=h((p,g)=>Object.fromEntries(p.map(m=>[m,{...g}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:o,photo:o,video:o,audio:o,document:o,animation:o,voice:o,videoNote:o,sticker:o,location:o,contact:o},static:l(a,t),staticIntent:l(r,s),staticSession:l(d,n),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let p of e){let g=(0,M.join)(i,p),m=P.getPageSync(g,!0);this.pageBuildData(m,g),this.pageSorts(m,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,e){let t,s;if(t===void 0){let o=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][o||a||r],s)break}s!==void 0&&(t=this.pages.all[s.name])}if(t===void 0){let o=await i.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(t=this.pages.all[s.name])}}if(t===void 0){let o=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][o||a||r],s)break}s!==void 0&&(t=this.pages.all[s.name])}if(t!==void 0&&s!==void 0)return await new t(i)[s.func]?.();let n=this.pages.dynamicSpesific[e]||[];for(let o=0;o<n.length;o++){let a=n[o];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let o=0;o<this.pages.dynamic.length;o++){let a=this.pages.dynamic[o];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,e){return!0}async hookErrorPage(i,e,t,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,e){let t=this.createCtx(i);try{if(await this.hookBeforeRoute(t,e)===!1)return;await this.pageRoutes(t,e)===null&&await this.hookErrorInputNotFoundPage(t)}catch(s){await this.hookErrorPage(t,e,s,!1)}}async onCallbackQueryData(i){let e=this.createCtx(i);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(t){await this.hookErrorPage(e,"onCallbackQueryData",t,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
1
+ "use strict";var G=Object.create;var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var h=(u,i)=>v(u,"name",{value:i,configurable:!0});var X=(u,i)=>{for(var t in i)v(u,t,{get:i[t],enumerable:!0})},O=(u,i,t,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of U(i))!q.call(u,s)&&s!==t&&v(u,s,{get:()=>i[s],enumerable:!(e=H(i,s))||e.enumerable});return u};var Y=(u,i,t)=>(t=u!=null?G(J(u)):{},O(i||!u||!u.__esModule?v(t,"default",{value:u,enumerable:!0}):t,u)),Z=u=>O(v({},"__esModule",{value:!0}),u);var ii={};X(ii,{BaseGeneral:()=>I,CacheExternal:()=>x,Ctx:()=>T,Gramstax:()=>_,TemplateEngine:()=>C,TemplateManager:()=>k});module.exports=Z(ii);var R=require("logging-pretty");var I=class{static{h(this,"BaseGeneral")}static log=new R.LoggingPretty;static logError(i,t){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${t}]: ${String(i)}`)}logError(i,t,e){this.constructor.log.error(`[${t||this.constructor.name}:${e}] ${String(i)}`)}};var K=require("keyv"),N=Y(require("@keyv/redis"),1);var x=class extends K.Keyv{constructor(t="memory",e,s,o){let n;t.startsWith("redis")&&(n=new N.default(t)),t==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=t}static{h(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var T=class extends I{static{h(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,t,e,s,o,n){let r=t.map(d=>this.templateManager.getMessage(this.data.name,o,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await(0,E.setTimeout)(1200)}}async reply(i,t,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,t,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:t,...o};if(i=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(i=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(i=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(i=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(i=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(i=="voice")return await this.ct.replyWithVoice(n.src,a);if(i=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(i=="sticker")return await this.ct.replyWithSticker(n.src,a);if(i=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(i=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(i,t,e,s){return this.replyMedia("photo",i,t,e,s)}async replyVideo(i,t,e,s){return this.replyMedia("video",i,t,e,s)}async replyAudio(i,t,e,s){return this.replyMedia("audio",i,t,e,s)}async replyDocument(i,t,e,s){return this.replyMedia("document",i,t,e,s)}async replyAnimation(i,t,e,s){return this.replyMedia("animation",i,t,e,s)}async replyVoice(i,t,e,s){return this.replyMedia("voice",i,t,e,s)}async replyVideoNote(i,t,e,s){return this.replyMedia("video_note",i,t,e,s)}async replySticker(i,t,e,s){return this.replyMedia("sticker",i,t,e,s)}async replyLocation(i,t,e,s){return this.replyMedia("location",i,t,e,s)}async replyContact(i,t,e,s){return this.replyMedia("contact",i,t,e,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,t,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,t,e,s)}}async editMedia(i,t,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return i=="voice"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="video_note"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="sticker"?(await this.delete(),await this.replySticker(t,e,s,o)):i=="location"?(await this.delete(),await this.replyLocation(t,e,s,o)):i=="contact"?(await this.delete(),await this.replyContact(t,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...o},{reply_markup:t,...n})}catch{await this.reply(t,e,s,n)}}async editPhoto(i,t,e,s,o){return await this.editMedia("photo",i,t,e,s,o)}async editVideo(i,t,e,s,o){return await this.editMedia("video",i,t,e,s,o)}async editAudio(i,t,e,s,o){return await this.editMedia("audio",i,t,e,s,o)}async editDocument(i,t,e,s,o){return await this.editMedia("document",i,t,e,s,o)}async editAnimation(i,t,e,s,o){return await this.editMedia("animation",i,t,e,s,o)}async editVoice(i,t,e,s){return await this.editMedia("voice",i,t,e,s)}async editVideoNote(i,t,e,s){return await this.editMedia("video_note",i,t,e,s)}async editSticker(i,t,e,s){return await this.editMedia("sticker",i,t,e,s)}async editLocation(i,t,e,s){return await this.editMedia("location",i,t,e,s)}async editContact(i,t,e,s){return await this.editMedia("contact",i,t,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,t,e){try{let s={method:i,params:t,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...t){let e=i(...t);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data);return i(s,o)}buildBottomKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),n=i(s,o);return n.resized(),n}validateSessionCallback(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(t)}validateSessionCallbackPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(t)}validateSessionText(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(t)}validateSessionTextPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(t)}validateSessionTextCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(t)}validateSessionTextCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(t)}validateSessionTextFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(t)}validateSessionPhotoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(t)}validateSessionPhotoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(t)}validateSessionPhotoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(t)}validateSessionPhotoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(t)}validateSessionPhotoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(t)}validateSessionVideoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(t)}validateSessionVideoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(t)}validateSessionVideoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(t)}validateSessionVideoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(t)}validateSessionVideoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(t)}validateSessionAudioCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(t)}validateSessionAudioCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(t)}validateSessionAudioCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(t)}validateSessionAudioCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(t)}validateSessionAudioFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(t)}validateSessionDocumentCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(t)}validateSessionDocumentCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(t)}validateSessionDocumentCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(t)}validateSessionDocumentCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(t)}validateSessionDocumentFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(t)}validateSessionAnimationCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(t)}validateSessionAnimationCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(t)}validateSessionAnimationCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(t)}validateSessionAnimationCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(t)}validateSessionAnimationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(t)}validateSessionVoiceCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(t)}validateSessionVoiceCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(t)}validateSessionVoiceCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(t)}validateSessionVoiceCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(t)}validateSessionVoiceFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(t)}validateSessionVideoNoteCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(t)}validateSessionVideoNoteCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(t)}validateSessionVideoNoteCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(t)}validateSessionVideoNoteCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(t)}validateSessionVideoNoteFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(t)}validateSessionStickerFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(t)}validateSessionLocationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(t)}validateSessionContactFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(t)}sessionCallback(i,t){return this.sessionSet(this.buildSessionMethodCallback(t),i)}sessionCallbackPayload(i,t){return this.sessionSet(this.buildSessionMethodCallbackPayload(t),i)}sessionText(i,t){return this.sessionSet(this.buildSessionMethodText(t),i)}sessionTextPayload(i,t){return this.sessionSet(this.buildSessionMethodTextPayload(t),i)}sessionTextCommand(i,t){return this.sessionSet(this.buildSessionMethodTextCommand(t),i)}sessionTextCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodTextCommandPayload(t),i)}sessionTextFree(i,t){return this.sessionSet(this.buildSessionMethodTextFree(t),i)}sessionPhotoCaption(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaption(t),i)}sessionPhotoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(t),i)}sessionPhotoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(t),i)}sessionPhotoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(t),i)}sessionPhotoFree(i,t){return this.sessionSet(this.buildSessionMethodPhotoFree(t),i)}sessionVideoCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoCaption(t),i)}sessionVideoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(t),i)}sessionVideoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(t),i)}sessionVideoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(t),i)}sessionVideoFree(i,t){return this.sessionSet(this.buildSessionMethodVideoFree(t),i)}sessionAudioCaption(i,t){return this.sessionSet(this.buildSessionMethodAudioCaption(t),i)}sessionAudioCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(t),i)}sessionAudioCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(t),i)}sessionAudioCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(t),i)}sessionAudioFree(i,t){return this.sessionSet(this.buildSessionMethodAudioFree(t),i)}sessionDocumentCaption(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaption(t),i)}sessionDocumentCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(t),i)}sessionDocumentCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(t),i)}sessionDocumentCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(t),i)}sessionDocumentFree(i,t){return this.sessionSet(this.buildSessionMethodDocumentFree(t),i)}sessionAnimationCaption(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaption(t),i)}sessionAnimationCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(t),i)}sessionAnimationCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(t),i)}sessionAnimationCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(t),i)}sessionAnimationFree(i,t){return this.sessionSet(this.buildSessionMethodAnimationFree(t),i)}sessionVoiceCaption(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaption(t),i)}sessionVoiceCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(t),i)}sessionVoiceCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(t),i)}sessionVoiceCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(t),i)}sessionVoiceFree(i,t){return this.sessionSet(this.buildSessionMethodVoiceFree(t),i)}sessionVideoNoteCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(t),i)}sessionVideoNoteCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(t),i)}sessionVideoNoteCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(t),i)}sessionVideoNoteCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(t),i)}sessionVideoNoteFree(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteFree(t),i)}sessionStickerFree(i,t){return this.sessionSet(this.buildSessionMethodStickerFree(t),i)}sessionLocationFree(i,t){return this.sessionSet(this.buildSessionMethodLocationFree(t),i)}sessionContactFree(i,t){return this.sessionSet(this.buildSessionMethodContactFree(t),i)}sessionToCallback(i,t){return this.sessionCallback({...this.session.params,...i},t)}sessionToCallbackPayload(i,t){return this.sessionCallbackPayload({...this.session.params,...i},t)}sessionToText(i,t){return this.sessionText({...this.session.params,...i},t)}sessionToTextPayload(i,t){return this.sessionTextPayload({...this.session.params,...i},t)}sessionToTextCommand(i,t){return this.sessionTextCommand({...this.session.params,...i},t)}sessionToTextCommandPayload(i,t){return this.sessionTextCommandPayload({...this.session.params,...i},t)}sessionToTextFree(i,t){return this.sessionTextFree({...this.session.params,...i},t)}sessionToPhotoCaption(i,t){return this.sessionPhotoCaption({...this.session.params,...i},t)}sessionToPhotoCaptionPayload(i,t){return this.sessionPhotoCaptionPayload({...this.session.params,...i},t)}sessionToPhotoCaptionCommand(i,t){return this.sessionPhotoCaptionCommand({...this.session.params,...i},t)}sessionToPhotoCaptionCommandPayload(i,t){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},t)}sessionToPhotoFree(i,t){return this.sessionPhotoFree({...this.session.params,...i},t)}sessionToVideoCaption(i,t){return this.sessionVideoCaption({...this.session.params,...i},t)}sessionToVideoCaptionPayload(i,t){return this.sessionVideoCaptionPayload({...this.session.params,...i},t)}sessionToVideoCaptionCommand(i,t){return this.sessionVideoCaptionCommand({...this.session.params,...i},t)}sessionToVideoCaptionCommandPayload(i,t){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoFree(i,t){return this.sessionVideoFree({...this.session.params,...i},t)}sessionToAudioCaption(i,t){return this.sessionAudioCaption({...this.session.params,...i},t)}sessionToAudioCaptionPayload(i,t){return this.sessionAudioCaptionPayload({...this.session.params,...i},t)}sessionToAudioCaptionCommand(i,t){return this.sessionAudioCaptionCommand({...this.session.params,...i},t)}sessionToAudioCaptionCommandPayload(i,t){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},t)}sessionToAudioFree(i,t){return this.sessionAudioFree({...this.session.params,...i},t)}sessionToDocumentCaption(i,t){return this.sessionDocumentCaption({...this.session.params,...i},t)}sessionToDocumentCaptionPayload(i,t){return this.sessionDocumentCaptionPayload({...this.session.params,...i},t)}sessionToDocumentCaptionCommand(i,t){return this.sessionDocumentCaptionCommand({...this.session.params,...i},t)}sessionToDocumentCaptionCommandPayload(i,t){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},t)}sessionToDocumentFree(i,t){return this.sessionDocumentFree({...this.session.params,...i},t)}sessionToAnimationCaption(i,t){return this.sessionAnimationCaption({...this.session.params,...i},t)}sessionToAnimationCaptionPayload(i,t){return this.sessionAnimationCaptionPayload({...this.session.params,...i},t)}sessionToAnimationCaptionCommand(i,t){return this.sessionAnimationCaptionCommand({...this.session.params,...i},t)}sessionToAnimationCaptionCommandPayload(i,t){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},t)}sessionToAnimationFree(i,t){return this.sessionAnimationFree({...this.session.params,...i},t)}sessionToVoiceCaption(i,t){return this.sessionVoiceCaption({...this.session.params,...i},t)}sessionToVoiceCaptionPayload(i,t){return this.sessionVoiceCaptionPayload({...this.session.params,...i},t)}sessionToVoiceCaptionCommand(i,t){return this.sessionVoiceCaptionCommand({...this.session.params,...i},t)}sessionToVoiceCaptionCommandPayload(i,t){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},t)}sessionToVoiceFree(i,t){return this.sessionVoiceFree({...this.session.params,...i},t)}sessionToVideoNoteCaption(i,t){return this.sessionVideoNoteCaption({...this.session.params,...i},t)}sessionToVideoNoteCaptionPayload(i,t){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommand(i,t){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommandPayload(i,t){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoNoteFree(i,t){return this.sessionVideoNoteFree({...this.session.params,...i},t)}sessionToStickerFree(i,t){return this.sessionStickerFree({...this.session.params,...i},t)}sessionToLocationFree(i,t){return this.sessionLocationFree({...this.session.params,...i},t)}sessionToContactFree(i,t){return this.sessionContactFree({...this.session.params,...i},t)}buildIntent(i,t=!0){i||(i=t?this.data.callbackData():this.data.name);let e=t?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,t){return`${i}-${t||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};var $=require("bun"),P=require("path");var W=require("logging-pretty");var C=class{static{h(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(t,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of i.matchAll(t)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(t,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let t=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of i.matchAll(t)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let m of o.matchAll(r))a[m[1]]=m[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),p={type:l};a.src&&(p.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(p.caption=c),l==="location"&&(a.latitude&&(p.latitude=a.latitude),a.longitude&&(p.longitude=a.longitude),c&&(p.caption=c)),l==="contact"&&(a.phone&&(p.phone=a.phone),a.first_name&&(p.first_name=a.first_name),a.last_name&&(p.last_name=a.last_name),a.vcard&&(p.vcard=a.vcard),c&&(p.caption=c)),e[d]=p}return e}static _processMessageBlocks(i){let t=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of i.matchAll(t)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(i){let t=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of i.matchAll(t)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(i,t){let e;t?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);e[s][a]=c=>({...r,caption:l(c)})}else e[s][a]=()=>r}return e}static compileMessages(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[d,l]of Object.entries(r)){let p=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[s][a][d]=this._compileToFunction(p,!0)}}}return e}};var M=class{static{h(this,"HelperPage")}static _getPage(i,t,e=!0){let o=Object.values(i)[0];if(o===void 0)throw new Error(`File ${t} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(i,t=!0){let e=require(i);return this._getPage(e,i,t)}static async getPage(i,t=!0){let e=await import(`${i}?t=${Date.now()}`);return this._getPage(e,i,t)}};var B=require("fs/promises"),L=require("chokidar"),f=require("path"),y=require("fs");var k=class{static{h(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:t,enableWatch:e=!1,forceLanguage:s}=i;this._path=t,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let t=this._path[i];if(!(0,y.existsSync)(t))throw new Error(`Template base path is not exists: ${t}`);if(!(0,y.statSync)(t).isDirectory())throw new Error(`Template base path is not a directory: ${t}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let t=this._path[i],e=(0,L.watch)(t,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let t=(0,f.basename)(i);this._isValidFile(t)&&await this._loadFile(t,!1)}async _handleFileAdd(i){let t=(0,f.basename)(i);this._isValidFile(t)&&await this._loadFile(t,!1)}_handleFileDelete(i){let t=(0,f.basename)(i),e=this._getKey(t);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let t=this._path[i],s=(0,y.readdirSync)(t,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(i,t=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=(0,f.join)(s,i),n=this._getExtension(i),a=this._getKey(i);if(n==".html"){let r=t?(0,y.readFileSync)(o,"utf8"):await(0,B.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await M.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return(0,f.extname)(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,t,e){let s=this._map.get(i),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=C.compileMedia(t),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=C.compileMessages(t),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(t),n=!0),n&&this._map.set(i,o)}getMedia(i,t="default",e="en",s){let n=this._map.get(i)?.media?.[t]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(i,t="default",e="en",s){let n=this._map.get(i)?.message?.[t]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(i,t="default",e="en",s="inline",o){let a=this._map.get(i)?.keyboard?.[t]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(i,t){if(this._getExtension(i)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=(0,f.join)(this._path[e],i);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,t,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,t)=>typeof t=="function"?t.toString():t).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};var F=require("fs"),w=require("grammy");var _=class{static{h(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new W.LoggingPretty:i.log,this.cacheSession=i.cacheSession||new x("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new k({path:[(0,P.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,t,e){let{username:s}=i;t=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(i){return new w.Bot(i)}createCtx(i){return new T({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:h(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let t=(0,w.webhookCallback)(this.bot,"bun"),e="/telegram-webhook";(0,$.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?t(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(i,t){i?.data===void 0&&(i.data=i.buildData()),i.data.name=(0,P.parse)(t).name}pageSorts(i,t){let e=i.data.name,s=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=t.dynamic,l=t.dynamicSpesific,c=h(b=>b.charAt(0).toUpperCase()+b.slice(1),"upFirst"),p=h(b=>b.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=h((b,g)=>s[`buildSessionMethod${c(b)}`](g),"buildSessionMethod");t.all[e]=i;for(let b=0;b<t.lenListFuncStaticSession;b++){let g=t.listFuncStaticSession[b],j=t.static[g],Q=t.staticIntent[g],D=t.staticSession[g],V={name:e,func:g},A=j||Q;if(A!==void 0){let z=g.includes(n)?`/${e}`:e;A[s.buildIntent(z,g.startsWith("callback"))]=V}D!==void 0&&(D[m(g,e)]=V),g.toLowerCase().endsWith("free")&&l[p(g)].push(V)}s.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=(0,P.join)(process.cwd(),"src","pages");if(!(0,F.existsSync)(i))throw new Error(`Directory ${i} is not found, please make it manually`);let t=(0,F.readdirSync)(i),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=h((p,m)=>Object.fromEntries(p.map(b=>[b,{...m}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:l(a,e),staticIntent:l(r,s),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let p of t){let m=(0,P.join)(i,p),b=M.getPageSync(m,!0);this.pageBuildData(b,m),this.pageSorts(b,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,t){let e,s;if(e===void 0){let n=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await i.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(i)[s.func]?.();let o=this.pages.dynamicSpesific[t]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,t){return!0}async hookErrorPage(i,t,e,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,t){let e=this.createCtx(i);try{if(await this.hookBeforeRoute(e,t)===!1)return;await this.pageRoutes(e,t)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,t,s,!1)}}async onCallbackQueryData(i){let t=this.createCtx(i);try{if(await t.callbackQueryAnswer(),await this.hookBeforeRoute(t,"onCallbackQueryData")===!1)return;await this.pageRoutes(t,"callback")}catch(e){await this.hookErrorPage(t,"onCallbackQueryData",e,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
@@ -1,7 +1,7 @@
1
1
  import { LoggingPretty } from 'logging-pretty';
2
2
  import { Keyv } from 'keyv';
3
3
  import * as grammy from 'grammy';
4
- import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
4
+ import { Context, InlineKeyboard, Bot, BotError } from 'grammy';
5
5
  import * as grammy_types from 'grammy/types';
6
6
  import { UserFromGetMe } from 'grammy/types';
7
7
  import { FSWatcher } from 'chokidar';
@@ -49,7 +49,7 @@ declare class TemplateEngine {
49
49
  static _processKeyboardBlocks(template: string): {
50
50
  [lang: string]: {
51
51
  inline?: string;
52
- default?: string;
52
+ bottom?: string;
53
53
  };
54
54
  };
55
55
  static _compileToFunction<T extends boolean>(template: T extends true ? string[] : string, isArray: T): T extends true ? (data?: Record<string, any>) => string[] : (data?: Record<string, any>) => string;
@@ -67,7 +67,7 @@ declare class TemplateEngine {
67
67
  [baseId: string]: {
68
68
  [lang: string]: {
69
69
  inline?: (data?: Record<string, any>) => string[];
70
- default?: (data?: Record<string, any>) => string[];
70
+ bottom?: (data?: Record<string, any>) => string[];
71
71
  };
72
72
  };
73
73
  };
@@ -128,17 +128,7 @@ declare class TemplateManager {
128
128
  * @param data Template variables
129
129
  * @returns media object
130
130
  */
131
- getMedia(key: string, baseId?: string, language?: string, data?: Record<string, any>): {
132
- type: `photo` | `video` | `audio` | `document` | `animation` | `voice` | `video_note` | `sticker` | `location` | `contact`;
133
- src?: string;
134
- caption?: string;
135
- latitude?: string;
136
- longitude?: string;
137
- phone?: string;
138
- first_name?: string;
139
- last_name?: string;
140
- vcard?: string;
141
- } | Record<any, any>;
131
+ getMedia(key: string, baseId?: string, language?: string, data?: Record<string, any>): IMediaBlock | Record<any, any>;
142
132
  /**
143
133
  * Get compiled message template
144
134
  * @param key Template identifier (filename without extension)
@@ -156,7 +146,7 @@ declare class TemplateManager {
156
146
  * @param data Template variables
157
147
  * @returns Array of rendered button labels
158
148
  */
159
- getKeyboard(key: string, baseId?: string, language?: string, type?: `inline` | `default`, data?: Record<string, any>): string[];
149
+ getKeyboard(key: string, baseId?: string, language?: string, type?: `inline` | `bottom`, data?: Record<string, any>): string[];
160
150
  /**
161
151
  * Write template to file and update cache
162
152
  * @param filename Target filename (with extension)
@@ -190,7 +180,29 @@ declare class TemplateManager {
190
180
  destroy(): Promise<void>;
191
181
  }
192
182
 
193
- type IData = {
183
+ type IInlineKb = InlineKeyboard
184
+ type IBottomKb = IBottomKb
185
+ type IKb = IBottomKb | IInlineKb
186
+ type ICt = Context
187
+ type IOptReply = Parameters<Context[`reply`]>[1]
188
+ type IOptReplyPhoto = Parameters<Context[`replyWithPhoto`]>[1]
189
+ type IOptReplyVideo = Parameters<Context[`replyWithVideo`]>[1]
190
+ type IOptReplyAudio = Parameters<Context[`replyWithAudio`]>[1]
191
+ type IOptReplyDocument = Parameters<Context[`replyWithDocument`]>[1]
192
+ type IOptReplyAnimation = Parameters<Context[`replyWithAnimation`]>[1]
193
+ type IOptReplyVoice = Parameters<Context[`replyWithVoice`]>[1]
194
+ type IOptReplyVideoNote = Parameters<Context[`replyWithVideoNote`]>[1]
195
+ type IOptReplySticker = Parameters<Context[`replyWithSticker`]>[1]
196
+ type IOptReplyLocation = Parameters<Context[`replyWithLocation`]>[2]
197
+ type IOptReplyContact = Parameters<Context[`replyWithContact`]>[2]
198
+ type IOptEdit = Parameters<Context[`editMessageText`]>[1]
199
+ type IOptEditMedia1 = Parameters<Context[`editMessageMedia`]>[0]
200
+ type IOptEditMedia2 = Parameters<Context[`editMessageMedia`]>[1]
201
+
202
+ type ITypeReplyAction = Parameters<Context[`replyWithChatAction`]>[0]
203
+ type IData = Record<string, any>
204
+
205
+ type IPData = {
194
206
  name: string;
195
207
  callbackData: (...args: any) => string | any;
196
208
  };
@@ -199,13 +211,13 @@ type ITemp = {
199
211
  method?: string;
200
212
  params?: any;
201
213
  };
202
- data: Partial<IData>;
214
+ data: Partial<IPData>;
203
215
  [key: string]: any;
204
216
  };
205
217
  declare class Ctx extends BaseGeneral {
206
218
  static template?: string;
207
- static data: IData;
208
- data: IData;
219
+ static data: IPData;
220
+ data: IPData;
209
221
  get isPremium(): boolean;
210
222
  get isBot(): boolean;
211
223
  get userid(): number;
@@ -231,38 +243,48 @@ declare class Ctx extends BaseGeneral {
231
243
  set languageCode(v: any);
232
244
  set session(v: any);
233
245
  get session(): any;
234
- ct: Context;
246
+ ct: ICt;
235
247
  cacheSession: CacheExternal;
236
248
  cacheKeyboard: Map<any, any>;
237
249
  templateManager: TemplateManager;
238
250
  temp: ITemp;
239
251
  constructor(params: {
240
- ct: Context;
252
+ ct: ICt;
241
253
  cacheSession: CacheExternal;
242
254
  cacheKeyboard: Map<any, any>;
243
255
  templateManager: TemplateManager;
244
256
  temp: ITemp;
245
257
  });
246
- broadcast(ids: any[], languageCode: any[], keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: any): Promise<void>;
247
- reply(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: any): Promise<grammy_types.Message.TextMessage>;
248
- replyMedia<T extends Parameters<typeof this$1.ct.editMessageMedia>[0][`type`]>(type: T, keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: T extends `photo` ? Parameters<typeof this$1.ct.replyWithPhoto>[1] : T extends `video` ? Parameters<typeof this$1.ct.replyWithVideo>[1] : T extends `audio` ? Parameters<typeof this$1.ct.replyWithAudio>[1] : T extends `document` ? Parameters<typeof this$1.ct.replyWithDocument>[1] : T extends `animation` ? Parameters<typeof this$1.ct.replyWithAnimation>[1] : undefined): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
249
- replyPhoto(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithPhoto>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
250
- replyVideo(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithVideo>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
251
- replyAudio(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithAudio>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
252
- replyDocument(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithDocument>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
253
- replyAnimation(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithAnimation>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
254
- replyAction(type: Parameters<typeof this$1.ct.replyWithChatAction>[0]): Promise<true>;
255
- edit(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.editMessageText>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
258
+ broadcast(ids: any[], languageCode: any[], keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<void>;
259
+ reply(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<grammy_types.Message.TextMessage>;
260
+ replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
261
+ replyPhoto(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
262
+ replyVideo(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
263
+ replyAudio(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
264
+ replyDocument(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
265
+ replyAnimation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
266
+ replyVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
267
+ replyVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
268
+ replySticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
269
+ replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
270
+ replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
271
+ replyAction(type: ITypeReplyAction): Promise<true>;
272
+ edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
256
273
  text: string;
257
274
  } & Partial<{
258
275
  entities: grammy_types.MessageEntity[];
259
276
  }>) | undefined>;
260
- editMedia(type: Parameters<typeof this$1.ct.editMessageMedia>[0][`type`], keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
261
- editPhoto(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
262
- editVideo(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
263
- editAudio(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
264
- editDocument(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
265
- editAnimation(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
277
+ editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
278
+ editPhoto(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
279
+ editVideo(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
280
+ editAudio(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
281
+ editDocument(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
282
+ editAnimation(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
283
+ editVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
284
+ editVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
285
+ editSticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
286
+ editLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
287
+ editContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
266
288
  delete(): Promise<true>;
267
289
  callbackQueryAnswer(options?: any): Promise<true | null>;
268
290
  sessionSet(method: string, params: any, moreRoot?: Record<any, any>): Promise<boolean | null>;
@@ -280,16 +302,16 @@ declare class Ctx extends BaseGeneral {
280
302
  name: string;
281
303
  }) => string);
282
304
  };
283
- buildInlineKeyboard(callback: (kb: InlineKeyboard, arr: any[]) => InlineKeyboard, params?: {
305
+ buildInlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
284
306
  baseId?: any;
285
- data?: Record<string, any>;
307
+ data?: IData;
286
308
  cache?: boolean;
287
- }): InlineKeyboard;
288
- buildKeyboard(callback: (kb: Keyboard, arr: any[]) => Keyboard, params?: {
309
+ }): IInlineKb;
310
+ buildBottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
289
311
  baseId?: any;
290
- data?: Record<string, any>;
312
+ data?: IData;
291
313
  cache?: boolean;
292
- }): Keyboard;
314
+ }): IBottomKb;
293
315
  transition?(...args: any): Promise<void>;
294
316
  internal?(...args: any): Promise<void>;
295
317
  notify?(...args: any): Promise<void>;
@@ -944,4 +966,4 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
944
966
  onMessageContact(ct: Context): Promise<void>;
945
967
  }
946
968
 
947
- export { BaseGeneral, CacheExternal, Ctx, Gramstax, TemplateEngine, TemplateManager };
969
+ export { BaseGeneral, CacheExternal, Ctx, Gramstax, type IMediaBlock, TemplateEngine, TemplateManager };
@@ -1,7 +1,7 @@
1
1
  import { LoggingPretty } from 'logging-pretty';
2
2
  import { Keyv } from 'keyv';
3
3
  import * as grammy from 'grammy';
4
- import { Context, Keyboard, InlineKeyboard, Bot, BotError } from 'grammy';
4
+ import { Context, InlineKeyboard, Bot, BotError } from 'grammy';
5
5
  import * as grammy_types from 'grammy/types';
6
6
  import { UserFromGetMe } from 'grammy/types';
7
7
  import { FSWatcher } from 'chokidar';
@@ -49,7 +49,7 @@ declare class TemplateEngine {
49
49
  static _processKeyboardBlocks(template: string): {
50
50
  [lang: string]: {
51
51
  inline?: string;
52
- default?: string;
52
+ bottom?: string;
53
53
  };
54
54
  };
55
55
  static _compileToFunction<T extends boolean>(template: T extends true ? string[] : string, isArray: T): T extends true ? (data?: Record<string, any>) => string[] : (data?: Record<string, any>) => string;
@@ -67,7 +67,7 @@ declare class TemplateEngine {
67
67
  [baseId: string]: {
68
68
  [lang: string]: {
69
69
  inline?: (data?: Record<string, any>) => string[];
70
- default?: (data?: Record<string, any>) => string[];
70
+ bottom?: (data?: Record<string, any>) => string[];
71
71
  };
72
72
  };
73
73
  };
@@ -128,17 +128,7 @@ declare class TemplateManager {
128
128
  * @param data Template variables
129
129
  * @returns media object
130
130
  */
131
- getMedia(key: string, baseId?: string, language?: string, data?: Record<string, any>): {
132
- type: `photo` | `video` | `audio` | `document` | `animation` | `voice` | `video_note` | `sticker` | `location` | `contact`;
133
- src?: string;
134
- caption?: string;
135
- latitude?: string;
136
- longitude?: string;
137
- phone?: string;
138
- first_name?: string;
139
- last_name?: string;
140
- vcard?: string;
141
- } | Record<any, any>;
131
+ getMedia(key: string, baseId?: string, language?: string, data?: Record<string, any>): IMediaBlock | Record<any, any>;
142
132
  /**
143
133
  * Get compiled message template
144
134
  * @param key Template identifier (filename without extension)
@@ -156,7 +146,7 @@ declare class TemplateManager {
156
146
  * @param data Template variables
157
147
  * @returns Array of rendered button labels
158
148
  */
159
- getKeyboard(key: string, baseId?: string, language?: string, type?: `inline` | `default`, data?: Record<string, any>): string[];
149
+ getKeyboard(key: string, baseId?: string, language?: string, type?: `inline` | `bottom`, data?: Record<string, any>): string[];
160
150
  /**
161
151
  * Write template to file and update cache
162
152
  * @param filename Target filename (with extension)
@@ -190,7 +180,29 @@ declare class TemplateManager {
190
180
  destroy(): Promise<void>;
191
181
  }
192
182
 
193
- type IData = {
183
+ type IInlineKb = InlineKeyboard
184
+ type IBottomKb = IBottomKb
185
+ type IKb = IBottomKb | IInlineKb
186
+ type ICt = Context
187
+ type IOptReply = Parameters<Context[`reply`]>[1]
188
+ type IOptReplyPhoto = Parameters<Context[`replyWithPhoto`]>[1]
189
+ type IOptReplyVideo = Parameters<Context[`replyWithVideo`]>[1]
190
+ type IOptReplyAudio = Parameters<Context[`replyWithAudio`]>[1]
191
+ type IOptReplyDocument = Parameters<Context[`replyWithDocument`]>[1]
192
+ type IOptReplyAnimation = Parameters<Context[`replyWithAnimation`]>[1]
193
+ type IOptReplyVoice = Parameters<Context[`replyWithVoice`]>[1]
194
+ type IOptReplyVideoNote = Parameters<Context[`replyWithVideoNote`]>[1]
195
+ type IOptReplySticker = Parameters<Context[`replyWithSticker`]>[1]
196
+ type IOptReplyLocation = Parameters<Context[`replyWithLocation`]>[2]
197
+ type IOptReplyContact = Parameters<Context[`replyWithContact`]>[2]
198
+ type IOptEdit = Parameters<Context[`editMessageText`]>[1]
199
+ type IOptEditMedia1 = Parameters<Context[`editMessageMedia`]>[0]
200
+ type IOptEditMedia2 = Parameters<Context[`editMessageMedia`]>[1]
201
+
202
+ type ITypeReplyAction = Parameters<Context[`replyWithChatAction`]>[0]
203
+ type IData = Record<string, any>
204
+
205
+ type IPData = {
194
206
  name: string;
195
207
  callbackData: (...args: any) => string | any;
196
208
  };
@@ -199,13 +211,13 @@ type ITemp = {
199
211
  method?: string;
200
212
  params?: any;
201
213
  };
202
- data: Partial<IData>;
214
+ data: Partial<IPData>;
203
215
  [key: string]: any;
204
216
  };
205
217
  declare class Ctx extends BaseGeneral {
206
218
  static template?: string;
207
- static data: IData;
208
- data: IData;
219
+ static data: IPData;
220
+ data: IPData;
209
221
  get isPremium(): boolean;
210
222
  get isBot(): boolean;
211
223
  get userid(): number;
@@ -231,38 +243,48 @@ declare class Ctx extends BaseGeneral {
231
243
  set languageCode(v: any);
232
244
  set session(v: any);
233
245
  get session(): any;
234
- ct: Context;
246
+ ct: ICt;
235
247
  cacheSession: CacheExternal;
236
248
  cacheKeyboard: Map<any, any>;
237
249
  templateManager: TemplateManager;
238
250
  temp: ITemp;
239
251
  constructor(params: {
240
- ct: Context;
252
+ ct: ICt;
241
253
  cacheSession: CacheExternal;
242
254
  cacheKeyboard: Map<any, any>;
243
255
  templateManager: TemplateManager;
244
256
  temp: ITemp;
245
257
  });
246
- broadcast(ids: any[], languageCode: any[], keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: any): Promise<void>;
247
- reply(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: any): Promise<grammy_types.Message.TextMessage>;
248
- replyMedia<T extends Parameters<typeof this$1.ct.editMessageMedia>[0][`type`]>(type: T, keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: T extends `photo` ? Parameters<typeof this$1.ct.replyWithPhoto>[1] : T extends `video` ? Parameters<typeof this$1.ct.replyWithVideo>[1] : T extends `audio` ? Parameters<typeof this$1.ct.replyWithAudio>[1] : T extends `document` ? Parameters<typeof this$1.ct.replyWithDocument>[1] : T extends `animation` ? Parameters<typeof this$1.ct.replyWithAnimation>[1] : undefined): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
249
- replyPhoto(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithPhoto>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
250
- replyVideo(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithVideo>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
251
- replyAudio(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithAudio>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
252
- replyDocument(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithDocument>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
253
- replyAnimation(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.replyWithAnimation>[1]): Promise<grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | undefined>;
254
- replyAction(type: Parameters<typeof this$1.ct.replyWithChatAction>[0]): Promise<true>;
255
- edit(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options?: Parameters<typeof this$1.ct.editMessageText>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
258
+ broadcast(ids: any[], languageCode: any[], keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<void>;
259
+ reply(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReply): Promise<grammy_types.Message.TextMessage>;
260
+ replyMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options?: T extends `photo` ? IOptReplyPhoto : T extends `video` ? IOptReplyVideo : T extends `audio` ? IOptReplyAudio : T extends `document` ? IOptReplyDocument : T extends `animation` ? IOptReplyAnimation : T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : undefined): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
261
+ replyPhoto(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyPhoto): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
262
+ replyVideo(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideo): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
263
+ replyAudio(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAudio): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
264
+ replyDocument(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyDocument): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
265
+ replyAnimation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyAnimation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
266
+ replyVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVoice): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
267
+ replyVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyVideoNote): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
268
+ replySticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplySticker): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
269
+ replyLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyLocation): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
270
+ replyContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptReplyContact): Promise<grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | undefined>;
271
+ replyAction(type: ITypeReplyAction): Promise<true>;
272
+ edit(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEdit): Promise<true | (grammy_types.Update.Edited & grammy_types.Message.CommonMessage & {
256
273
  text: string;
257
274
  } & Partial<{
258
275
  entities: grammy_types.MessageEntity[];
259
276
  }>) | undefined>;
260
- editMedia(type: Parameters<typeof this$1.ct.editMessageMedia>[0][`type`], keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
261
- editPhoto(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
262
- editVideo(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
263
- editAudio(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
264
- editDocument(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
265
- editAnimation(keyboard?: Keyboard | InlineKeyboard, data?: Record<string, any>, baseId?: string, options1?: Parameters<typeof this$1.ct.editMessageMedia>[0], options2?: Parameters<typeof this$1.ct.editMessageMedia>[1]): Promise<true | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
277
+ editMedia<T extends IMediaBlock[`type`]>(type: T, keyboard?: IKb, data?: IData, baseId?: string, options1?: T extends `voice` ? IOptReplyVoice : T extends `video_note` ? IOptReplyVideoNote : T extends `sticker` ? IOptReplySticker : T extends `location` ? IOptReplyLocation : T extends `contact` ? IOptReplyContact : IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
278
+ editPhoto(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
279
+ editVideo(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
280
+ editAudio(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
281
+ editDocument(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
282
+ editAnimation(keyboard?: IKb, data?: IData, baseId?: string, options1?: IOptEditMedia1, options2?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
283
+ editVoice(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
284
+ editVideoNote(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
285
+ editSticker(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
286
+ editLocation(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
287
+ editContact(keyboard?: IKb, data?: IData, baseId?: string, options?: IOptEditMedia2): Promise<true | grammy_types.Message.LocationMessage | grammy_types.Message.ContactMessage | grammy_types.Message.PhotoMessage | grammy_types.Message.VideoMessage | grammy_types.Message.AudioMessage | grammy_types.Message.DocumentMessage | grammy_types.Message.VoiceMessage | grammy_types.Message.VideoNoteMessage | grammy_types.Message.StickerMessage | (grammy_types.Update.Edited & grammy_types.Message) | undefined>;
266
288
  delete(): Promise<true>;
267
289
  callbackQueryAnswer(options?: any): Promise<true | null>;
268
290
  sessionSet(method: string, params: any, moreRoot?: Record<any, any>): Promise<boolean | null>;
@@ -280,16 +302,16 @@ declare class Ctx extends BaseGeneral {
280
302
  name: string;
281
303
  }) => string);
282
304
  };
283
- buildInlineKeyboard(callback: (kb: InlineKeyboard, arr: any[]) => InlineKeyboard, params?: {
305
+ buildInlineKeyboard(callback: (kb: IInlineKb, arr: any[]) => IInlineKb, params?: {
284
306
  baseId?: any;
285
- data?: Record<string, any>;
307
+ data?: IData;
286
308
  cache?: boolean;
287
- }): InlineKeyboard;
288
- buildKeyboard(callback: (kb: Keyboard, arr: any[]) => Keyboard, params?: {
309
+ }): IInlineKb;
310
+ buildBottomKeyboard(callback: (kb: IBottomKb, arr: any[]) => IBottomKb, params?: {
289
311
  baseId?: any;
290
- data?: Record<string, any>;
312
+ data?: IData;
291
313
  cache?: boolean;
292
- }): Keyboard;
314
+ }): IBottomKb;
293
315
  transition?(...args: any): Promise<void>;
294
316
  internal?(...args: any): Promise<void>;
295
317
  notify?(...args: any): Promise<void>;
@@ -944,4 +966,4 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
944
966
  onMessageContact(ct: Context): Promise<void>;
945
967
  }
946
968
 
947
- export { BaseGeneral, CacheExternal, Ctx, Gramstax, TemplateEngine, TemplateManager };
969
+ export { BaseGeneral, CacheExternal, Ctx, Gramstax, type IMediaBlock, TemplateEngine, TemplateManager };
package/dist/src/index.js CHANGED
@@ -1 +1 @@
1
- var B=Object.defineProperty;var p=(m,i)=>B(m,"name",{value:i,configurable:!0}),_=(m=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(m,{get:(i,e)=>(typeof require<"u"?require:i)[e]}):m)(function(m){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+m+'" is not supported')});import{LoggingPretty as $}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new $;static logError(i,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(i)}`)}logError(i,e,t){this.constructor.log.error(`[${e||this.constructor.name}:${t}] ${String(i)}`)}};import{Keyv as L}from"keyv";import W from"@keyv/redis";var S=class extends L{constructor(e="memory",t,s,n){let o;e.startsWith("redis")&&(o=new W(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:t,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as E}from"timers/promises";import{InlineKeyboard as w,Keyboard as V}from"grammy";var P=class extends C{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,e,t,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:t,...o}),d+1==30&&await E(1200)}}async reply(i,e,t,s){let n=this.templateManager.getMessage(this.data.name,t,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,e,t,s,n){let{src:o,caption:a}=this.templateManager.getMedia(this.data.name,s,this.languageCode,t),r={parse_mode:"HTML",reply_markup:e,...n};if(i=="photo")return await this.ct.replyWithPhoto(o,{caption:a,...r});if(i=="video")return await this.ct.replyWithVideo(o,{caption:a,...r});if(i=="audio")return await this.ct.replyWithAudio(o,{caption:a,...r});if(i=="document")return await this.ct.replyWithDocument(o,{caption:a,...r});if(i=="animation")return await this.ct.replyWithAnimation(o,{caption:a,...r})}async replyPhoto(i,e,t,s){return this.replyMedia("photo",i,e,t,s)}async replyVideo(i,e,t,s){return this.replyMedia("video",i,e,t,s)}async replyAudio(i,e,t,s){return this.replyMedia("audio",i,e,t,s)}async replyDocument(i,e,t,s){return this.replyMedia("document",i,e,t,s)}async replyAnimation(i,e,t,s){return this.replyMedia("animation",i,e,t,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,e,t,s){try{let n=this.templateManager.getMessage(this.data.name,t,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,e,t,s)}}async editMedia(i,e,t,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,t);return await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,t,s,o)}}async editPhoto(i,e,t,s,n){return await this.editMedia("photo",i,e,t,s,n)}async editVideo(i,e,t,s,n){return await this.editMedia("video",i,e,t,s,n)}async editAudio(i,e,t,s,n){return await this.editMedia("audio",i,e,t,s,n)}async editDocument(i,e,t,s,n){return await this.editMedia("document",i,e,t,s,n)}async editAnimation(i,e,t,s,n){return await this.editMedia("animation",i,e,t,s,n)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,e,t){try{let s={method:i,params:e,...t},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...e){let t=i(...e);return`${this.name}${t===void 0?"":`:${t}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,e){let t=this.data.name;if(e?.cache===!0){let a=`${t}:${this.languageCode}:inline`,r=this.cacheKeyboard.get(a);if(!r){let d=new w,l=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"inline",e?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new w,n=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"inline",e?.data);return i(s,n)}buildKeyboard(i,e){let t=this.data.name;if(e?.cache===!0){let a=`${t}:${this.languageCode}:default`,r=this.cacheKeyboard.get(a);if(!r){let d=new V,l=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"default",e?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new V,n=this.templateManager.getKeyboard(t,e?.baseId,this.languageCode,"default",e?.data),o=i(s,n);return o.resized(),o}validateSessionCallback(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(e)}validateSessionCallbackPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(e)}validateSessionText(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(e)}validateSessionTextPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(e)}validateSessionTextCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(e)}validateSessionTextCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(e)}validateSessionTextFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(e)}validateSessionPhotoCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(e)}validateSessionPhotoCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(e)}validateSessionVideoCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(e)}validateSessionVideoCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(e)}validateSessionVideoFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(e)}validateSessionAudioCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(e)}validateSessionAudioCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(e)}validateSessionAudioFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(e)}validateSessionDocumentCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(e)}validateSessionDocumentCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(e)}validateSessionAnimationCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(e)}validateSessionAnimationCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(e)}validateSessionVoiceCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(e)}validateSessionVoiceCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(e)}validateSessionVideoNoteCaption(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(e)}validateSessionStickerFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(e)}validateSessionLocationFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(e)}validateSessionContactFree(i,e){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(e)}sessionCallback(i,e){return this.sessionSet(this.buildSessionMethodCallback(e),i)}sessionCallbackPayload(i,e){return this.sessionSet(this.buildSessionMethodCallbackPayload(e),i)}sessionText(i,e){return this.sessionSet(this.buildSessionMethodText(e),i)}sessionTextPayload(i,e){return this.sessionSet(this.buildSessionMethodTextPayload(e),i)}sessionTextCommand(i,e){return this.sessionSet(this.buildSessionMethodTextCommand(e),i)}sessionTextCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodTextCommandPayload(e),i)}sessionTextFree(i,e){return this.sessionSet(this.buildSessionMethodTextFree(e),i)}sessionPhotoCaption(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaption(e),i)}sessionPhotoCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(e),i)}sessionPhotoCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(e),i)}sessionPhotoCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(e),i)}sessionPhotoFree(i,e){return this.sessionSet(this.buildSessionMethodPhotoFree(e),i)}sessionVideoCaption(i,e){return this.sessionSet(this.buildSessionMethodVideoCaption(e),i)}sessionVideoCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(e),i)}sessionVideoCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(e),i)}sessionVideoCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(e),i)}sessionVideoFree(i,e){return this.sessionSet(this.buildSessionMethodVideoFree(e),i)}sessionAudioCaption(i,e){return this.sessionSet(this.buildSessionMethodAudioCaption(e),i)}sessionAudioCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(e),i)}sessionAudioCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(e),i)}sessionAudioCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(e),i)}sessionAudioFree(i,e){return this.sessionSet(this.buildSessionMethodAudioFree(e),i)}sessionDocumentCaption(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaption(e),i)}sessionDocumentCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(e),i)}sessionDocumentCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(e),i)}sessionDocumentCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(e),i)}sessionDocumentFree(i,e){return this.sessionSet(this.buildSessionMethodDocumentFree(e),i)}sessionAnimationCaption(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaption(e),i)}sessionAnimationCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(e),i)}sessionAnimationCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(e),i)}sessionAnimationCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(e),i)}sessionAnimationFree(i,e){return this.sessionSet(this.buildSessionMethodAnimationFree(e),i)}sessionVoiceCaption(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaption(e),i)}sessionVoiceCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(e),i)}sessionVoiceCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(e),i)}sessionVoiceCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(e),i)}sessionVoiceFree(i,e){return this.sessionSet(this.buildSessionMethodVoiceFree(e),i)}sessionVideoNoteCaption(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(e),i)}sessionVideoNoteCaptionPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(e),i)}sessionVideoNoteCaptionCommand(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(e),i)}sessionVideoNoteCaptionCommandPayload(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(e),i)}sessionVideoNoteFree(i,e){return this.sessionSet(this.buildSessionMethodVideoNoteFree(e),i)}sessionStickerFree(i,e){return this.sessionSet(this.buildSessionMethodStickerFree(e),i)}sessionLocationFree(i,e){return this.sessionSet(this.buildSessionMethodLocationFree(e),i)}sessionContactFree(i,e){return this.sessionSet(this.buildSessionMethodContactFree(e),i)}sessionToCallback(i,e){return this.sessionCallback({...this.session.params,...i},e)}sessionToCallbackPayload(i,e){return this.sessionCallbackPayload({...this.session.params,...i},e)}sessionToText(i,e){return this.sessionText({...this.session.params,...i},e)}sessionToTextPayload(i,e){return this.sessionTextPayload({...this.session.params,...i},e)}sessionToTextCommand(i,e){return this.sessionTextCommand({...this.session.params,...i},e)}sessionToTextCommandPayload(i,e){return this.sessionTextCommandPayload({...this.session.params,...i},e)}sessionToTextFree(i,e){return this.sessionTextFree({...this.session.params,...i},e)}sessionToPhotoCaption(i,e){return this.sessionPhotoCaption({...this.session.params,...i},e)}sessionToPhotoCaptionPayload(i,e){return this.sessionPhotoCaptionPayload({...this.session.params,...i},e)}sessionToPhotoCaptionCommand(i,e){return this.sessionPhotoCaptionCommand({...this.session.params,...i},e)}sessionToPhotoCaptionCommandPayload(i,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},e)}sessionToPhotoFree(i,e){return this.sessionPhotoFree({...this.session.params,...i},e)}sessionToVideoCaption(i,e){return this.sessionVideoCaption({...this.session.params,...i},e)}sessionToVideoCaptionPayload(i,e){return this.sessionVideoCaptionPayload({...this.session.params,...i},e)}sessionToVideoCaptionCommand(i,e){return this.sessionVideoCaptionCommand({...this.session.params,...i},e)}sessionToVideoCaptionCommandPayload(i,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},e)}sessionToVideoFree(i,e){return this.sessionVideoFree({...this.session.params,...i},e)}sessionToAudioCaption(i,e){return this.sessionAudioCaption({...this.session.params,...i},e)}sessionToAudioCaptionPayload(i,e){return this.sessionAudioCaptionPayload({...this.session.params,...i},e)}sessionToAudioCaptionCommand(i,e){return this.sessionAudioCaptionCommand({...this.session.params,...i},e)}sessionToAudioCaptionCommandPayload(i,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},e)}sessionToAudioFree(i,e){return this.sessionAudioFree({...this.session.params,...i},e)}sessionToDocumentCaption(i,e){return this.sessionDocumentCaption({...this.session.params,...i},e)}sessionToDocumentCaptionPayload(i,e){return this.sessionDocumentCaptionPayload({...this.session.params,...i},e)}sessionToDocumentCaptionCommand(i,e){return this.sessionDocumentCaptionCommand({...this.session.params,...i},e)}sessionToDocumentCaptionCommandPayload(i,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},e)}sessionToDocumentFree(i,e){return this.sessionDocumentFree({...this.session.params,...i},e)}sessionToAnimationCaption(i,e){return this.sessionAnimationCaption({...this.session.params,...i},e)}sessionToAnimationCaptionPayload(i,e){return this.sessionAnimationCaptionPayload({...this.session.params,...i},e)}sessionToAnimationCaptionCommand(i,e){return this.sessionAnimationCaptionCommand({...this.session.params,...i},e)}sessionToAnimationCaptionCommandPayload(i,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},e)}sessionToAnimationFree(i,e){return this.sessionAnimationFree({...this.session.params,...i},e)}sessionToVoiceCaption(i,e){return this.sessionVoiceCaption({...this.session.params,...i},e)}sessionToVoiceCaptionPayload(i,e){return this.sessionVoiceCaptionPayload({...this.session.params,...i},e)}sessionToVoiceCaptionCommand(i,e){return this.sessionVoiceCaptionCommand({...this.session.params,...i},e)}sessionToVoiceCaptionCommandPayload(i,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},e)}sessionToVoiceFree(i,e){return this.sessionVoiceFree({...this.session.params,...i},e)}sessionToVideoNoteCaption(i,e){return this.sessionVideoNoteCaption({...this.session.params,...i},e)}sessionToVideoNoteCaptionPayload(i,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},e)}sessionToVideoNoteCaptionCommand(i,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},e)}sessionToVideoNoteCaptionCommandPayload(i,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},e)}sessionToVideoNoteFree(i,e){return this.sessionVideoNoteFree({...this.session.params,...i},e)}sessionToStickerFree(i,e){return this.sessionStickerFree({...this.session.params,...i},e)}sessionToLocationFree(i,e){return this.sessionLocationFree({...this.session.params,...i},e)}sessionToContactFree(i,e){return this.sessionContactFree({...this.session.params,...i},e)}buildIntent(i,e=!0){i||(i=e?this.data.callbackData():this.data.name);let t=e?":":" ";return i?.indexOf?.(t)!=-1?i?.split?.(t)?.[0]:i}buildSessionMethod(i,e){return`${i}-${e||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};import{serve as J}from"bun";import{join as T,parse as q}from"path";import{LoggingPretty as X}from"logging-pretty";var y=class{static{p(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(e,t)=>`\${(data && data["${t}"]) ?? ""}`)}static _processBaseBlocks(i){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,t={};for(let s of i.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();t[n]=a}return t}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,t)=>{let s=t.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(e,t)=>t.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,t={};for(let s of i.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of n.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:l};a.src&&(u.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(u.caption=c),l==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),c&&(u.caption=c)),l==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),c&&(u.caption=c)),t[d]=u}return t}static _processMessageBlocks(i){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,t={};for(let[,s,n]of i.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();t[s]=o}return t}static _processKeyboardBlocks(i){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,t={};for(let[,s,n,o]of i.matchAll(e)){let a=n==="default"?"default":"inline",r=o.trim();t[s]||(t[s]={}),t[s][a]=r}return t}static _compileToFunction(i,e){let t;e?t=i.map(o=>`\`${o}\``).join(","):t=`\`${i}\``;let s=t;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),e){let n=`return [${s}]`;return new Function("data",n)}else{let n=`return ${s}`;return new Function("data",n)}}static compileMedia(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);t[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);t[s][a]=c=>({...r,caption:l(c)})}else t[s][a]=()=>r}return t}static compileMessages(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);t[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));t[s][a]=this._compileToFunction(d,!1)}}return t}static compileKeyboards(i){let e=this._processBaseBlocks(i),t={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);t[s]={};for(let[a,r]of Object.entries(o)){t[s][a]={};for(let[d,l]of Object.entries(r)){let u=l.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));t[s][a][d]=this._compileToFunction(u,!0)}}}return t}};var f=class{static{p(this,"HelperPage")}static _getPage(i,e,t=!0){let n=Object.values(i)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return t===!0&&(n.template=void 0),n}static getPageSync(i,e=!0){let t=_(i);return this._getPage(t,i,e)}static async getPage(i,e=!0){let t=await import(`${i}?t=${Date.now()}`);return this._getPage(t,i,e)}};import{readFile as O}from"fs/promises";import{watch as j}from"chokidar";import{basename as x,join as A,extname as Q}from"path";import{readdirSync as z,readFileSync as G,existsSync as D,statSync as H,writeFileSync as U}from"fs";var M=class{static{p(this,"TemplateManager")}_map=new Map;_engine=y;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:e,enableWatch:t=!1,forceLanguage:s}=i;this._path=e,this._forceLanguage=s,this._isWatchEnabled=t,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let e=this._path[i];if(!D(e))throw new Error(`Template base path is not exists: ${e}`);if(!H(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let e=this._path[i],t=j(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=t,t.on("change",this._handleFileChange.bind(this)),t.on("add",this._handleFileAdd.bind(this)),t.on("unlink",this._handleFileDelete.bind(this)),t.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let e=x(i);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(i){let e=x(i);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(i){let e=x(i),t=this._getKey(e);this._map.has(t)&&this._map.delete(t)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let e=this._path[i],s=z(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(i,e=!0){for(let t=0;t<this._path.length;t++){let s=this._path[t],n=A(s,i),o=this._getExtension(i),a=this._getKey(i);if(o==".html"){let r=e?G(n,"utf8"):await O(n,"utf8");this._compile(a,r)}else if(o==".ts"){let r=await f.getPage(n,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return Q(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,e,t){let s=this._map.get(i),n=s||{},o=!1;(t===void 0||t?.media===!1||s?.media===void 0)&&(n.media=y.compileMedia(e),o=!0),(t===void 0||t?.message===!1||s?.message===void 0)&&(n.message=y.compileMessages(e),o=!0),(t===void 0||t?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=y.compileKeyboards(e),o=!0),o&&this._map.set(i,n)}getMedia(i,e="default",t="en",s){let o=this._map.get(i)?.media?.[e]?.[this._forceLanguage||t];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(i,e="default",t="en",s){let o=this._map.get(i)?.message?.[e]?.[this._forceLanguage||t];if(!o)return"";try{return o(s)}catch{return""}}getKeyboard(i,e="default",t="en",s="inline",n){let a=this._map.get(i)?.keyboard?.[e]?.[this._forceLanguage||t]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(i,e){if(this._getExtension(i)!=".html")return null;for(let t=0;t<this._path.length;t++){let s=A(this._path[t],i);if(D(s))return U(s,e,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as ii,webhookCallback as ei}from"grammy";var I=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new X:i.log,this.cacheSession=i.cacheSession||new S("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new M({path:[T(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,e,t){let{username:s}=i;e=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${t})`)}createBot(i){return new ii(i)}createCtx(i){return new P({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let e=ei(this.bot,"bun"),t="/telegram-webhook";J({fetch(a){let{pathname:r}=new URL(a.url);if(r===t)return a.method==="POST"?e(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),n=i.endsWith("/")?i.slice(0,-1)+t:i+t;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}pageBuildData(i,e){i?.data===void 0&&(i.data=i.buildData()),i.data.name=q(e).name}pageSorts(i,e){let t=i.data.name,s=i.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,l=e.dynamicSpesific,c=p(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),u=p(h=>h.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),g=p((h,b)=>s[`buildSessionMethod${c(h)}`](b),"buildSessionMethod");e.all[t]=i;for(let h=0;h<e.lenListFuncStaticSession;h++){let b=e.listFuncStaticSession[h],K=e.static[b],N=e.staticIntent[b],k=e.staticSession[b],v={name:t,func:b},F=K||N;if(F!==void 0){let R=b.includes(o)?`/${t}`:t;F[s.buildIntent(R,b.startsWith("callback"))]=v}k!==void 0&&(k[g(b,t)]=v),b.toLowerCase().endsWith("free")&&l[u(b)].push(v)}s.free&&d.push(t)}pageLoads(){this.log?.info?.("Load pages..");let i=T(process.cwd(),"src","pages");if(!Y(i))throw new Error(`Directory ${i} is not found, please make it manually`);let e=Z(i),t={},s=t,n=t,o=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=p((u,g)=>Object.fromEntries(u.map(h=>[h,{...g}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:o,photo:o,video:o,audio:o,document:o,animation:o,voice:o,videoNote:o,sticker:o,location:o,contact:o},static:l(a,t),staticIntent:l(r,s),staticSession:l(d,n),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let u of e){let g=T(i,u),h=f.getPageSync(g,!0);this.pageBuildData(h,g),this.pageSorts(h,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,e){let t,s;if(t===void 0){let o=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][o||a||r],s)break}s!==void 0&&(t=this.pages.all[s.name])}if(t===void 0){let o=await i.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(t=this.pages.all[s.name])}}if(t===void 0){let o=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][o||a||r],s)break}s!==void 0&&(t=this.pages.all[s.name])}if(t!==void 0&&s!==void 0)return await new t(i)[s.func]?.();let n=this.pages.dynamicSpesific[e]||[];for(let o=0;o<n.length;o++){let a=n[o];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let o=0;o<this.pages.dynamic.length;o++){let a=this.pages.dynamic[o];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,e){return!0}async hookErrorPage(i,e,t,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,e){let t=this.createCtx(i);try{if(await this.hookBeforeRoute(t,e)===!1)return;await this.pageRoutes(t,e)===null&&await this.hookErrorInputNotFoundPage(t)}catch(s){await this.hookErrorPage(t,e,s,!1)}}async onCallbackQueryData(i){let e=this.createCtx(i);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(t){await this.hookErrorPage(e,"onCallbackQueryData",t,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,I as Gramstax,y as TemplateEngine,M as TemplateManager};
1
+ var N=Object.defineProperty;var p=(b,i)=>N(b,"name",{value:i,configurable:!0}),F=(b=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(b,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):b)(function(b){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+b+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new E;static logError(i,t){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${t}]: ${String(i)}`)}logError(i,t,e){this.constructor.log.error(`[${t||this.constructor.name}:${e}] ${String(i)}`)}};import{Keyv as B}from"keyv";import L from"@keyv/redis";var S=class extends B{constructor(t="memory",e,s,o){let n;t.startsWith("redis")&&(n=new L(t)),t==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=t}static{p(this,"CacheExternal")}};import{setTimeout as $}from"timers/promises";import{InlineKeyboard as w,Keyboard as V}from"grammy";var M=class extends C{static{p(this,"Ctx")}static template;static data;data=this.constructor.data;get isPremium(){return this.ct.from?.is_premium??!1}get isBot(){return this.ct.from?.is_bot??!1}get userid(){return this.ct.from?.id}get username(){return this.ct.from?.username}get fullname(){return`${this.ct.from?.first_name||""}${this.ct.from?.last_name||""}`}get firstname(){return this.ct.from?.first_name}get lastname(){return this.ct.from?.last_name}get msgText(){return this.ct.message?.text}get msgTextIntent(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ")[0]:""}get msgTextPayloads(){return this.msgText&&this.msgText.indexOf(" ")!=-1?this.msgText.split(" ").slice(1):[]}get msgTextPayload(){return this.msgTextPayloads[0]}get msgCaption(){return this.ct.message?.caption}get msgCaptionIntent(){return this.msgCaption&&this.msgCaption.indexOf(" ")!=-1?this.msgCaption.split(" ")[0]:""}get msgPhoto(){return this.ct.message?.photo}get msgVideo(){return this.ct.message?.video}get msgAudio(){return this.ct.message?.audio}get callbackData(){return this.ct.callbackQuery?.data}get callbackDataIntent(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":")[0]:""}get callbackDataPayloads(){return this.callbackData&&this.callbackData.indexOf(":")!=-1?this.callbackData.split(":").slice(1):[]}get callbackDataPayload(){return this.callbackDataPayloads?.[0]}get callbackDataParts(){return this.callbackDataPayload&&this.callbackDataPayload.indexOf("+")!=-1?this.callbackDataPayload.split("+"):[]}get languageCode(){return this.ct.from?.language_code}set languageCode(i){this.ct.from.language_code=i}set session(i){this.temp.session=i}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(i){super(),this.ct=i.ct,this.cacheSession=i.cacheSession,this.cacheKeyboard=i.cacheKeyboard,this.templateManager=i.templateManager,this.temp=i.temp,i?.data&&(this.temp.data=i.data)}async broadcast(i,t,e,s,o,n){let r=t.map(d=>this.templateManager.getMessage(this.data.name,o,d,s));for(let d=0;d<i.length;d++){let l=i[d],c=r[d];await this.ct.api.sendMessage(l,c,{parse_mode:"HTML",reply_markup:e,...n}),d+1==30&&await $(1200)}}async reply(i,t,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:i,...s})}async replyMedia(i,t,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:t,...o};if(i=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(i=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(i=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(i=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(i=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(i=="voice")return await this.ct.replyWithVoice(n.src,a);if(i=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(i=="sticker")return await this.ct.replyWithSticker(n.src,a);if(i=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(i=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(i,t,e,s){return this.replyMedia("photo",i,t,e,s)}async replyVideo(i,t,e,s){return this.replyMedia("video",i,t,e,s)}async replyAudio(i,t,e,s){return this.replyMedia("audio",i,t,e,s)}async replyDocument(i,t,e,s){return this.replyMedia("document",i,t,e,s)}async replyAnimation(i,t,e,s){return this.replyMedia("animation",i,t,e,s)}async replyVoice(i,t,e,s){return this.replyMedia("voice",i,t,e,s)}async replyVideoNote(i,t,e,s){return this.replyMedia("video_note",i,t,e,s)}async replySticker(i,t,e,s){return this.replyMedia("sticker",i,t,e,s)}async replyLocation(i,t,e,s){return this.replyMedia("location",i,t,e,s)}async replyContact(i,t,e,s){return this.replyMedia("contact",i,t,e,s)}async replyAction(i){return await this.ct.replyWithChatAction(i)}async edit(i,t,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,t);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:i,...s})}catch{await this.reply(i,t,e,s)}}async editMedia(i,t,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return i=="voice"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="video_note"?(await this.delete(),await this.replyVoice(t,e,s,o)):i=="sticker"?(await this.delete(),await this.replySticker(t,e,s,o)):i=="location"?(await this.delete(),await this.replyLocation(t,e,s,o)):i=="contact"?(await this.delete(),await this.replyContact(t,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:i,parse_mode:"HTML",...o},{reply_markup:t,...n})}catch{await this.reply(t,e,s,n)}}async editPhoto(i,t,e,s,o){return await this.editMedia("photo",i,t,e,s,o)}async editVideo(i,t,e,s,o){return await this.editMedia("video",i,t,e,s,o)}async editAudio(i,t,e,s,o){return await this.editMedia("audio",i,t,e,s,o)}async editDocument(i,t,e,s,o){return await this.editMedia("document",i,t,e,s,o)}async editAnimation(i,t,e,s,o){return await this.editMedia("animation",i,t,e,s,o)}async editVoice(i,t,e,s){return await this.editMedia("voice",i,t,e,s)}async editVideoNote(i,t,e,s){return await this.editMedia("video_note",i,t,e,s)}async editSticker(i,t,e,s){return await this.editMedia("sticker",i,t,e,s)}async editLocation(i,t,e,s){return await this.editMedia("location",i,t,e,s)}async editContact(i,t,e,s){return await this.editMedia("contact",i,t,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(i){try{return await this.ct.answerCallbackQuery(i)}catch{return null}}async sessionSet(i,t,e){try{let s={method:i,params:t,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let i=await this.cacheSession.get(`${this.userid}`);return i&&(this.session=i),i||null}catch{return null}}async sessionClear(){try{let i=await this.cacheSession.delete(`${this.userid}`);return i&&(this.session={}),i}catch{return null}}static buildData(i){return{name:"",callbackData:i?function(...t){let e=i(...t);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}buildInlineKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new w,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data),c=i(d,l);return this.cacheKeyboard.set(a,c),c}return r}let s=new w,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"inline",t?.data);return i(s,o)}buildBottomKeyboard(i,t){let e=this.data.name;if(t?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new V,l=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),c=i(d,l);return c.resized(!0),this.cacheKeyboard.set(a,c),c}return r}let s=new V,o=this.templateManager.getKeyboard(e,t?.baseId,this.languageCode,"bottom",t?.data),n=i(s,o);return n.resized(),n}validateSessionCallback(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallback(t)}validateSessionCallbackPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodCallbackPayload(t)}validateSessionText(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodText(t)}validateSessionTextPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextPayload(t)}validateSessionTextCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommand(t)}validateSessionTextCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextCommandPayload(t)}validateSessionTextFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodTextFree(t)}validateSessionPhotoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaption(t)}validateSessionPhotoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionPayload(t)}validateSessionPhotoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommand(t)}validateSessionPhotoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoCaptionCommandPayload(t)}validateSessionPhotoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodPhotoFree(t)}validateSessionVideoCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaption(t)}validateSessionVideoCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionPayload(t)}validateSessionVideoCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommand(t)}validateSessionVideoCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoCaptionCommandPayload(t)}validateSessionVideoFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoFree(t)}validateSessionAudioCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaption(t)}validateSessionAudioCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionPayload(t)}validateSessionAudioCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommand(t)}validateSessionAudioCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioCaptionCommandPayload(t)}validateSessionAudioFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAudioFree(t)}validateSessionDocumentCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaption(t)}validateSessionDocumentCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionPayload(t)}validateSessionDocumentCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommand(t)}validateSessionDocumentCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentCaptionCommandPayload(t)}validateSessionDocumentFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodDocumentFree(t)}validateSessionAnimationCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaption(t)}validateSessionAnimationCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionPayload(t)}validateSessionAnimationCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommand(t)}validateSessionAnimationCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationCaptionCommandPayload(t)}validateSessionAnimationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodAnimationFree(t)}validateSessionVoiceCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaption(t)}validateSessionVoiceCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionPayload(t)}validateSessionVoiceCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommand(t)}validateSessionVoiceCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceCaptionCommandPayload(t)}validateSessionVoiceFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVoiceFree(t)}validateSessionVideoNoteCaption(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaption(t)}validateSessionVideoNoteCaptionPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionPayload(t)}validateSessionVideoNoteCaptionCommand(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommand(t)}validateSessionVideoNoteCaptionCommandPayload(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteCaptionCommandPayload(t)}validateSessionVideoNoteFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodVideoNoteFree(t)}validateSessionStickerFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodStickerFree(t)}validateSessionLocationFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodLocationFree(t)}validateSessionContactFree(i,t){return i===void 0&&(i=this.session.method),i===void 0?!1:i===this.buildSessionMethodContactFree(t)}sessionCallback(i,t){return this.sessionSet(this.buildSessionMethodCallback(t),i)}sessionCallbackPayload(i,t){return this.sessionSet(this.buildSessionMethodCallbackPayload(t),i)}sessionText(i,t){return this.sessionSet(this.buildSessionMethodText(t),i)}sessionTextPayload(i,t){return this.sessionSet(this.buildSessionMethodTextPayload(t),i)}sessionTextCommand(i,t){return this.sessionSet(this.buildSessionMethodTextCommand(t),i)}sessionTextCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodTextCommandPayload(t),i)}sessionTextFree(i,t){return this.sessionSet(this.buildSessionMethodTextFree(t),i)}sessionPhotoCaption(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaption(t),i)}sessionPhotoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionPayload(t),i)}sessionPhotoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommand(t),i)}sessionPhotoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodPhotoCaptionCommandPayload(t),i)}sessionPhotoFree(i,t){return this.sessionSet(this.buildSessionMethodPhotoFree(t),i)}sessionVideoCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoCaption(t),i)}sessionVideoCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionPayload(t),i)}sessionVideoCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommand(t),i)}sessionVideoCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoCaptionCommandPayload(t),i)}sessionVideoFree(i,t){return this.sessionSet(this.buildSessionMethodVideoFree(t),i)}sessionAudioCaption(i,t){return this.sessionSet(this.buildSessionMethodAudioCaption(t),i)}sessionAudioCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionPayload(t),i)}sessionAudioCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommand(t),i)}sessionAudioCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAudioCaptionCommandPayload(t),i)}sessionAudioFree(i,t){return this.sessionSet(this.buildSessionMethodAudioFree(t),i)}sessionDocumentCaption(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaption(t),i)}sessionDocumentCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionPayload(t),i)}sessionDocumentCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommand(t),i)}sessionDocumentCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodDocumentCaptionCommandPayload(t),i)}sessionDocumentFree(i,t){return this.sessionSet(this.buildSessionMethodDocumentFree(t),i)}sessionAnimationCaption(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaption(t),i)}sessionAnimationCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionPayload(t),i)}sessionAnimationCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommand(t),i)}sessionAnimationCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodAnimationCaptionCommandPayload(t),i)}sessionAnimationFree(i,t){return this.sessionSet(this.buildSessionMethodAnimationFree(t),i)}sessionVoiceCaption(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaption(t),i)}sessionVoiceCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionPayload(t),i)}sessionVoiceCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommand(t),i)}sessionVoiceCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVoiceCaptionCommandPayload(t),i)}sessionVoiceFree(i,t){return this.sessionSet(this.buildSessionMethodVoiceFree(t),i)}sessionVideoNoteCaption(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaption(t),i)}sessionVideoNoteCaptionPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionPayload(t),i)}sessionVideoNoteCaptionCommand(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommand(t),i)}sessionVideoNoteCaptionCommandPayload(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteCaptionCommandPayload(t),i)}sessionVideoNoteFree(i,t){return this.sessionSet(this.buildSessionMethodVideoNoteFree(t),i)}sessionStickerFree(i,t){return this.sessionSet(this.buildSessionMethodStickerFree(t),i)}sessionLocationFree(i,t){return this.sessionSet(this.buildSessionMethodLocationFree(t),i)}sessionContactFree(i,t){return this.sessionSet(this.buildSessionMethodContactFree(t),i)}sessionToCallback(i,t){return this.sessionCallback({...this.session.params,...i},t)}sessionToCallbackPayload(i,t){return this.sessionCallbackPayload({...this.session.params,...i},t)}sessionToText(i,t){return this.sessionText({...this.session.params,...i},t)}sessionToTextPayload(i,t){return this.sessionTextPayload({...this.session.params,...i},t)}sessionToTextCommand(i,t){return this.sessionTextCommand({...this.session.params,...i},t)}sessionToTextCommandPayload(i,t){return this.sessionTextCommandPayload({...this.session.params,...i},t)}sessionToTextFree(i,t){return this.sessionTextFree({...this.session.params,...i},t)}sessionToPhotoCaption(i,t){return this.sessionPhotoCaption({...this.session.params,...i},t)}sessionToPhotoCaptionPayload(i,t){return this.sessionPhotoCaptionPayload({...this.session.params,...i},t)}sessionToPhotoCaptionCommand(i,t){return this.sessionPhotoCaptionCommand({...this.session.params,...i},t)}sessionToPhotoCaptionCommandPayload(i,t){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...i},t)}sessionToPhotoFree(i,t){return this.sessionPhotoFree({...this.session.params,...i},t)}sessionToVideoCaption(i,t){return this.sessionVideoCaption({...this.session.params,...i},t)}sessionToVideoCaptionPayload(i,t){return this.sessionVideoCaptionPayload({...this.session.params,...i},t)}sessionToVideoCaptionCommand(i,t){return this.sessionVideoCaptionCommand({...this.session.params,...i},t)}sessionToVideoCaptionCommandPayload(i,t){return this.sessionVideoCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoFree(i,t){return this.sessionVideoFree({...this.session.params,...i},t)}sessionToAudioCaption(i,t){return this.sessionAudioCaption({...this.session.params,...i},t)}sessionToAudioCaptionPayload(i,t){return this.sessionAudioCaptionPayload({...this.session.params,...i},t)}sessionToAudioCaptionCommand(i,t){return this.sessionAudioCaptionCommand({...this.session.params,...i},t)}sessionToAudioCaptionCommandPayload(i,t){return this.sessionAudioCaptionCommandPayload({...this.session.params,...i},t)}sessionToAudioFree(i,t){return this.sessionAudioFree({...this.session.params,...i},t)}sessionToDocumentCaption(i,t){return this.sessionDocumentCaption({...this.session.params,...i},t)}sessionToDocumentCaptionPayload(i,t){return this.sessionDocumentCaptionPayload({...this.session.params,...i},t)}sessionToDocumentCaptionCommand(i,t){return this.sessionDocumentCaptionCommand({...this.session.params,...i},t)}sessionToDocumentCaptionCommandPayload(i,t){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...i},t)}sessionToDocumentFree(i,t){return this.sessionDocumentFree({...this.session.params,...i},t)}sessionToAnimationCaption(i,t){return this.sessionAnimationCaption({...this.session.params,...i},t)}sessionToAnimationCaptionPayload(i,t){return this.sessionAnimationCaptionPayload({...this.session.params,...i},t)}sessionToAnimationCaptionCommand(i,t){return this.sessionAnimationCaptionCommand({...this.session.params,...i},t)}sessionToAnimationCaptionCommandPayload(i,t){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...i},t)}sessionToAnimationFree(i,t){return this.sessionAnimationFree({...this.session.params,...i},t)}sessionToVoiceCaption(i,t){return this.sessionVoiceCaption({...this.session.params,...i},t)}sessionToVoiceCaptionPayload(i,t){return this.sessionVoiceCaptionPayload({...this.session.params,...i},t)}sessionToVoiceCaptionCommand(i,t){return this.sessionVoiceCaptionCommand({...this.session.params,...i},t)}sessionToVoiceCaptionCommandPayload(i,t){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...i},t)}sessionToVoiceFree(i,t){return this.sessionVoiceFree({...this.session.params,...i},t)}sessionToVideoNoteCaption(i,t){return this.sessionVideoNoteCaption({...this.session.params,...i},t)}sessionToVideoNoteCaptionPayload(i,t){return this.sessionVideoNoteCaptionPayload({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommand(i,t){return this.sessionVideoNoteCaptionCommand({...this.session.params,...i},t)}sessionToVideoNoteCaptionCommandPayload(i,t){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...i},t)}sessionToVideoNoteFree(i,t){return this.sessionVideoNoteFree({...this.session.params,...i},t)}sessionToStickerFree(i,t){return this.sessionStickerFree({...this.session.params,...i},t)}sessionToLocationFree(i,t){return this.sessionLocationFree({...this.session.params,...i},t)}sessionToContactFree(i,t){return this.sessionContactFree({...this.session.params,...i},t)}buildIntent(i,t=!0){i||(i=t?this.data.callbackData():this.data.name);let e=t?":":" ";return i?.indexOf?.(e)!=-1?i?.split?.(e)?.[0]:i}buildSessionMethod(i,t){return`${i}-${t||this.data.name}`}buildSessionMethodCallback(i){return this.buildSessionMethod("1",i)}buildSessionMethodCallbackPayload(i){return this.buildSessionMethod("2",i)}buildSessionMethodText(i){return this.buildSessionMethod("3",i)}buildSessionMethodTextPayload(i){return this.buildSessionMethod("4",i)}buildSessionMethodTextCommand(i){return this.buildSessionMethod("5",i)}buildSessionMethodTextCommandPayload(i){return this.buildSessionMethod("6",i)}buildSessionMethodTextFree(i){return this.buildSessionMethod("7",i)}buildSessionMethodPhotoCaption(i){return this.buildSessionMethod("8",i)}buildSessionMethodPhotoCaptionPayload(i){return this.buildSessionMethod("9",i)}buildSessionMethodPhotoCaptionCommand(i){return this.buildSessionMethod("10",i)}buildSessionMethodPhotoCaptionCommandPayload(i){return this.buildSessionMethod("11",i)}buildSessionMethodPhotoFree(i){return this.buildSessionMethod("12",i)}buildSessionMethodVideoCaption(i){return this.buildSessionMethod("13",i)}buildSessionMethodVideoCaptionPayload(i){return this.buildSessionMethod("14",i)}buildSessionMethodVideoCaptionCommand(i){return this.buildSessionMethod("15",i)}buildSessionMethodVideoCaptionCommandPayload(i){return this.buildSessionMethod("16",i)}buildSessionMethodVideoFree(i){return this.buildSessionMethod("17",i)}buildSessionMethodAudioCaption(i){return this.buildSessionMethod("18",i)}buildSessionMethodAudioCaptionPayload(i){return this.buildSessionMethod("19",i)}buildSessionMethodAudioCaptionCommand(i){return this.buildSessionMethod("20",i)}buildSessionMethodAudioCaptionCommandPayload(i){return this.buildSessionMethod("21",i)}buildSessionMethodAudioFree(i){return this.buildSessionMethod("22",i)}buildSessionMethodDocumentCaption(i){return this.buildSessionMethod("23",i)}buildSessionMethodDocumentCaptionPayload(i){return this.buildSessionMethod("24",i)}buildSessionMethodDocumentCaptionCommand(i){return this.buildSessionMethod("25",i)}buildSessionMethodDocumentCaptionCommandPayload(i){return this.buildSessionMethod("26",i)}buildSessionMethodDocumentFree(i){return this.buildSessionMethod("27",i)}buildSessionMethodAnimationCaption(i){return this.buildSessionMethod("28",i)}buildSessionMethodAnimationCaptionPayload(i){return this.buildSessionMethod("29",i)}buildSessionMethodAnimationCaptionCommand(i){return this.buildSessionMethod("30",i)}buildSessionMethodAnimationCaptionCommandPayload(i){return this.buildSessionMethod("31",i)}buildSessionMethodAnimationFree(i){return this.buildSessionMethod("32",i)}buildSessionMethodVoiceCaption(i){return this.buildSessionMethod("33",i)}buildSessionMethodVoiceCaptionPayload(i){return this.buildSessionMethod("34",i)}buildSessionMethodVoiceCaptionCommand(i){return this.buildSessionMethod("35",i)}buildSessionMethodVoiceCaptionCommandPayload(i){return this.buildSessionMethod("36",i)}buildSessionMethodVoiceFree(i){return this.buildSessionMethod("37",i)}buildSessionMethodVideoNoteCaption(i){return this.buildSessionMethod("38",i)}buildSessionMethodVideoNoteCaptionPayload(i){return this.buildSessionMethod("39",i)}buildSessionMethodVideoNoteCaptionCommand(i){return this.buildSessionMethod("40",i)}buildSessionMethodVideoNoteCaptionCommandPayload(i){return this.buildSessionMethod("41",i)}buildSessionMethodVideoNoteFree(i){return this.buildSessionMethod("42",i)}buildSessionMethodStickerFree(i){return this.buildSessionMethod("43",i)}buildSessionMethodLocationFree(i){return this.buildSessionMethod("44",i)}buildSessionMethodContactFree(i){return this.buildSessionMethod("45",i)}};import{serve as J}from"bun";import{join as x,parse as q}from"path";import{LoggingPretty as X}from"logging-pretty";var y=class{static{p(this,"TemplateEngine")}static _escape(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(i){return i.replace(/\{\{(\w+)\}\}/g,(t,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(i){let t=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of i.matchAll(t)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(i){return i.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(t,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(i){return i.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(i){return i.replace(/<div>([\s\S]*?)<\/div>/gi,(t,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(i){let t=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of i.matchAll(t)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let m of o.matchAll(r))a[m[1]]=m[2];if(!a.lang)continue;let d=a.lang,l=a.type,c=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:l};a.src&&(u.src=a.src),c&&l!=="video_note"&&l!=="sticker"&&(u.caption=c),l==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),c&&(u.caption=c)),l==="contact"&&(a.phone&&(u.phone=a.phone),a.first_name&&(u.first_name=a.first_name),a.last_name&&(u.last_name=a.last_name),a.vcard&&(u.vcard=a.vcard),c&&(u.caption=c)),e[d]=u}return e}static _processMessageBlocks(i){let t=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of i.matchAll(t)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(i){let t=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of i.matchAll(t)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(i,t){let e;t?e=i.map(n=>`\`${n}\``).join(","):e=`\`${i}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),t){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),l=this._compileToFunction(d,!1);e[s][a]=c=>({...r,caption:l(c)})}else e[s][a]=()=>r}return e}static compileMessages(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let d=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(d,!1)}}return e}static compileKeyboards(i){let t=this._processBaseBlocks(i),e={};for(let[s,o]of Object.entries(t)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[d,l]of Object.entries(r)){let u=l.split(/(?<!\\),\s*/).map(m=>m.replace(/\\,/g,",").trim()).map(m=>this._processVariables(this._processScriptBlocks(m)));e[s][a][d]=this._compileToFunction(u,!0)}}}return e}};var f=class{static{p(this,"HelperPage")}static _getPage(i,t,e=!0){let o=Object.values(i)[0];if(o===void 0)throw new Error(`File ${t} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(i,t=!0){let e=F(i);return this._getPage(e,i,t)}static async getPage(i,t=!0){let e=await import(`${i}?t=${Date.now()}`);return this._getPage(e,i,t)}};import{readFile as W}from"fs/promises";import{watch as j}from"chokidar";import{basename as I,join as _,extname as Q}from"path";import{readdirSync as z,readFileSync as G,existsSync as D,statSync as H,writeFileSync as U}from"fs";var P=class{static{p(this,"TemplateManager")}_map=new Map;_engine=y;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(i){let{path:t,enableWatch:e=!1,forceLanguage:s}=i;this._path=t,this._forceLanguage=s,this._isWatchEnabled=e,this._validatePath(),this._initializeWatcher(),this._loadAllFiles()}_validatePath(){try{if(!this._path||!Array.isArray(this._path))throw new Error("Path must be set as string array");for(let i=0;i<this._path.length;i++){let t=this._path[i];if(!D(t))throw new Error(`Template base path is not exists: ${t}`);if(!H(t).isDirectory())throw new Error(`Template base path is not a directory: ${t}`)}return!0}catch(i){throw new Error(`Failed to validate Template base path: ${i}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let i=0;i<this._path.length;i++){let t=this._path[i],e=j(t,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[i]=e,e.on("change",this._handleFileChange.bind(this)),e.on("add",this._handleFileAdd.bind(this)),e.on("unlink",this._handleFileDelete.bind(this)),e.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(i){let t=I(i);this._isValidFile(t)&&await this._loadFile(t,!1)}async _handleFileAdd(i){let t=I(i);this._isValidFile(t)&&await this._loadFile(t,!1)}_handleFileDelete(i){let t=I(i),e=this._getKey(t);this._map.has(e)&&this._map.delete(e)}_handleWatchError(i){}_loadAllFiles(){for(let i=0;i<this._path.length;i++){let t=this._path[i],s=z(t,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(i,t=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=_(s,i),n=this._getExtension(i),a=this._getKey(i);if(n==".html"){let r=t?G(o,"utf8"):await W(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await f.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${i} is not support`)}}_getExtension(i){return Q(i).toLowerCase()}_isValidFile(i){return this._supportedExtensions.has(this._getExtension(i))}_getKey(i){return i.replace(/\.[^/.]+$/,"")}_compile(i,t,e){let s=this._map.get(i),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=y.compileMedia(t),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=y.compileMessages(t),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=y.compileKeyboards(t),n=!0),n&&this._map.set(i,o)}getMedia(i,t="default",e="en",s){let n=this._map.get(i)?.media?.[t]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(i,t="default",e="en",s){let n=this._map.get(i)?.message?.[t]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(i,t="default",e="en",s="inline",o){let a=this._map.get(i)?.keyboard?.[t]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(i,t){if(this._getExtension(i)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=_(this._path[e],i);if(D(s))return U(s,t,"utf8"),await this._loadFile(i,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(i){return this._map.has(i)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(i,t)=>typeof t=="function"?t.toString():t).length}}async destroy(){if(this._watcher)for(let i of this._watcher)await i.close();this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as ii,webhookCallback as ti}from"grammy";var A=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(i){if(!i?.token||i?.token?.length==0)throw new Error("Token is not valid or empty");this.log=i.log===null?void 0:i.log===void 0?new X:i.log,this.cacheSession=i.cacheSession||new S("memory","session"),this.cacheKeyboard=i.cacheKeyboard||new Map,this.templateManager=i.templateManager||new P({path:[x(process.cwd(),"src","pages")]}),this.bot=this.createBot(i.token),this.bot.catch(this.onCatch),this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this)),this.bot.on("message:text",this.onMessageText.bind(this)),this.bot.on("message:photo",this.onMessagePhoto.bind(this)),this.bot.on("message:video",this.onMessageVideo.bind(this)),this.bot.on("message:audio",this.onMessageAudio.bind(this)),this.bot.on("message:document",this.onMessageDocument.bind(this)),this.bot.on("message:animation",this.onMessageAnimation.bind(this)),this.bot.on("message:voice",this.onMessageVoice.bind(this)),this.bot.on("message:video_note",this.onMessageVideoNote.bind(this)),this.bot.on("message:sticker",this.onMessageSticker.bind(this)),this.bot.on("message:location",this.onMessageLocation.bind(this)),this.bot.on("message:contact",this.onMessageContact.bind(this)),this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),i.deploy.startsWith("polling")?this.runPolling():i.deploy.startsWith("webhook")&&this.runWebhook(i.deploy.split("webhook:")[1])}onCatch(i){this.log?.error?.(`[Bot.catch]: ${String(i)}`)}onStart(i,t,e){let{username:s}=i;t=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(i){return new ii(i)}createCtx(i){return new M({ct:i,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async i=>{this.onStart(i,"polling",null)},"onStart")})}async runWebhook(i){let t=ti(this.bot,"bun"),e="/telegram-webhook";J({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?t(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let d=new Date().toISOString();return new Response(JSON.stringify({timestamp:d}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=i.endsWith("/")?i.slice(0,-1)+e:i+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(i,t){i?.data===void 0&&(i.data=i.buildData()),i.data.name=q(t).name}pageSorts(i,t){let e=i.data.name,s=i.prototype,o="Payload",n="Command",a="Caption",r="Free",d=t.dynamic,l=t.dynamicSpesific,c=p(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),u=p(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),m=p((h,g)=>s[`buildSessionMethod${c(h)}`](g),"buildSessionMethod");t.all[e]=i;for(let h=0;h<t.lenListFuncStaticSession;h++){let g=t.listFuncStaticSession[h],O=t.static[g],R=t.staticIntent[g],T=t.staticSession[g],v={name:e,func:g},k=O||R;if(k!==void 0){let K=g.includes(n)?`/${e}`:e;k[s.buildIntent(K,g.startsWith("callback"))]=v}T!==void 0&&(T[m(g,e)]=v),g.toLowerCase().endsWith("free")&&l[u(g)].push(v)}s.free&&d.push(e)}pageLoads(){this.log?.info?.("Load pages..");let i=x(process.cwd(),"src","pages");if(!Y(i))throw new Error(`Directory ${i} is not found, please make it manually`);let t=Z(i),e={},s=e,o=e,n=[],a=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],r=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],d=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],l=p((u,m)=>Object.fromEntries(u.map(h=>[h,{...m}])),"makeObject"),c={all:{},dynamic:[],dynamicSpesific:{text:n,photo:n,video:n,audio:n,document:n,animation:n,voice:n,videoNote:n,sticker:n,location:n,contact:n},static:l(a,e),staticIntent:l(r,s),staticSession:l(d,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:d,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:d.length};for(let u of t){let m=x(i,u),h=f.getPageSync(m,!0);this.pageBuildData(h,m),this.pageSorts(h,c)}return this.log?.info?.(`Finish load pages with total (${Object.keys(c.all).length})`),c}async pageRoutes(i,t){let e,s;if(e===void 0){let n=i.callbackData,a=i.msgText,r=i.msgCaption,d=this.pages.static;for(let l=0;l<this.pages.lenListFuncStatic;l++){let c=this.pages.listFuncStatic[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await i.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let l=this.pages.listFuncStaticSession[d];if(s=r[l][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=i.callbackDataIntent,a=i.msgTextIntent,r=i.msgCaptionIntent,d=this.pages.staticIntent;for(let l=0;l<this.pages.lenListFuncStaticIntent;l++){let c=this.pages.listFuncStaticIntent[l];if(s=d[c][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e!==void 0&&s!==void 0)return await new e(i)[s.func]?.();let o=this.pages.dynamicSpesific[t]||[];for(let n=0;n<o.length;n++){let a=o[n];if(a===void 0)continue;let r=this.pages.all[a.func];if(r===void 0)continue;let l=await new r(i)[a.name]?.();if(l!==null)return l}for(let n=0;n<this.pages.dynamic.length;n++){let a=this.pages.dynamic[n];if(a===void 0)continue;let r=this.pages.all[a];if(r===void 0)continue;let l=await new r(i).free?.();if(l!==null)return l}return null}async hookBeforeRoute(i,t){return!0}async hookErrorPage(i,t,e,s){}async hookErrorInputNotFoundPage(i){}async onMessage(i,t){let e=this.createCtx(i);try{if(await this.hookBeforeRoute(e,t)===!1)return;await this.pageRoutes(e,t)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,t,s,!1)}}async onCallbackQueryData(i){let t=this.createCtx(i);try{if(await t.callbackQueryAnswer(),await this.hookBeforeRoute(t,"onCallbackQueryData")===!1)return;await this.pageRoutes(t,"callback")}catch(e){await this.hookErrorPage(t,"onCallbackQueryData",e,!0)}}async onMessageText(i){await this.onMessage(i,"onMessageText")}async onMessagePhoto(i){await this.onMessage(i,"onMessagePhoto")}async onMessageVideo(i){await this.onMessage(i,"onMessageVideo")}async onMessageAudio(i){await this.onMessage(i,"onMessageAudio")}async onMessageDocument(i){await this.onMessage(i,"onMessageDocument")}async onMessageAnimation(i){await this.onMessage(i,"onMessageAnimation")}async onMessageVoice(i){await this.onMessage(i,"onMessageVoice")}async onMessageVideoNote(i){await this.onMessage(i,"onMessageVideoNote")}async onMessageSticker(i){await this.onMessage(i,"onMessageSticker")}async onMessageLocation(i){await this.onMessage(i,"onMessageLocation")}async onMessageContact(i){await this.onMessage(i,"onMessageContact")}};export{C as BaseGeneral,S as CacheExternal,M as Ctx,A as Gramstax,y as TemplateEngine,P as TemplateManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gramstax",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "private": false,
5
5
  "description": "A powerful Telegram bot framework with page-based routing and template system",
6
6
  "keywords": [
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/gramstax/gramstax"
16
+ "url": "git+https://github.com/gramstax/gramstax.git"
17
17
  },
18
18
  "bugs": {
19
19
  "url": "https://github.com/gramstax/gramstax/issues"