gramstax 0.0.22 → 0.0.24

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 I=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var h=(p,t)=>I(p,"name",{value:t,configurable:!0});var X=(p,t)=>{for(var i in t)I(p,i,{get:t[i],enumerable:!0})},O=(p,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of U(t))!q.call(p,s)&&s!==i&&I(p,s,{get:()=>t[s],enumerable:!(e=H(t,s))||e.enumerable});return p};var Y=(p,t,i)=>(i=p!=null?G(J(p)):{},O(t||!p||!p.__esModule?I(i,"default",{value:p,enumerable:!0}):i,p)),Z=p=>O(I({},"__esModule",{value:!0}),p);var tt={};X(tt,{BaseGeneral:()=>x,CacheExternal:()=>T,Ctx:()=>k,Gramstax:()=>_,TemplateEngine:()=>C,TemplateManager:()=>F});module.exports=Z(tt);var R=require("logging-pretty");var x=class{static{h(this,"BaseGeneral")}static log=new R.LoggingPretty;static logError(t,i){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${i}]: ${String(t)}`)}logError(t,i,e){this.constructor.log.error(`[${i||this.constructor.name}:${e}] ${String(t)}`)}};var K=require("keyv"),N=Y(require("@keyv/redis"),1);var T=class extends K.Keyv{constructor(i="memory",e,s,o){let n;i.startsWith("redis")&&(n=new N.default(i)),i==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=i}static{h(this,"CacheExternal")}};var E=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(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,i,e,s,o,n){let r=i.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:e,...n}),c+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,i,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,i,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:i,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,i,e,s){return this.replyMedia("photo",t,i,e,s)}async replyVideo(t,i,e,s){return this.replyMedia("video",t,i,e,s)}async replyAudio(t,i,e,s){return this.replyMedia("audio",t,i,e,s)}async replyDocument(t,i,e,s){return this.replyMedia("document",t,i,e,s)}async replyAnimation(t,i,e,s){return this.replyMedia("animation",t,i,e,s)}async replyVoice(t,i,e,s){return this.replyMedia("voice",t,i,e,s)}async replyVideoNote(t,i,e,s){return this.replyMedia("video_note",t,i,e,s)}async replySticker(t,i,e,s){return this.replyMedia("sticker",t,i,e,s)}async replyLocation(t,i,e,s){return this.replyMedia("location",t,i,e,s)}async replyContact(t,i,e,s){return this.replyMedia("contact",t,i,e,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,i,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,i,e,s)}}async editMedia(t,i,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return t=="voice"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(i,e,s,o)):t=="location"?(await this.delete(),await this.replyLocation(i,e,s,o)):t=="contact"?(await this.delete(),await this.replyContact(i,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...o},{reply_markup:i,...n})}catch{await this.reply(i,e,s,n)}}async editPhoto(t,i,e,s,o){return await this.editMedia("photo",t,i,e,s,o)}async editVideo(t,i,e,s,o){return await this.editMedia("video",t,i,e,s,o)}async editAudio(t,i,e,s,o){return await this.editMedia("audio",t,i,e,s,o)}async editDocument(t,i,e,s,o){return await this.editMedia("document",t,i,e,s,o)}async editAnimation(t,i,e,s,o){return await this.editMedia("animation",t,i,e,s,o)}async editVoice(t,i,e,s){return await this.editMedia("voice",t,i,e,s)}async editVideoNote(t,i,e,s){return await this.editMedia("video_note",t,i,e,s)}async editSticker(t,i,e,s){return await this.editMedia("sticker",t,i,e,s)}async editLocation(t,i,e,s){return await this.editMedia("location",t,i,e,s)}async editContact(t,i,e,s){return await this.editMedia("contact",t,i,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,i,e){try{let s={method:t,params:i,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...i){let e=t(...i);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}inlineKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.InlineKeyboard,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data);return t(s,o)}bottomKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new S.Keyboard,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(i)}validateSessionCallbackPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(i)}validateSessionText(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(i)}validateSessionTextPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(i)}validateSessionTextCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(i)}validateSessionTextCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(i)}validateSessionTextFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(i)}validateSessionPhotoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(i)}validateSessionPhotoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(i)}validateSessionPhotoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(i)}validateSessionPhotoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(i)}validateSessionPhotoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(i)}validateSessionVideoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(i)}validateSessionVideoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(i)}validateSessionVideoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(i)}validateSessionVideoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(i)}validateSessionVideoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(i)}validateSessionAudioCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(i)}validateSessionAudioCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(i)}validateSessionAudioCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(i)}validateSessionAudioCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(i)}validateSessionAudioFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(i)}validateSessionDocumentCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(i)}validateSessionDocumentCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(i)}validateSessionDocumentCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(i)}validateSessionDocumentCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(i)}validateSessionDocumentFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(i)}validateSessionAnimationCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(i)}validateSessionAnimationCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(i)}validateSessionAnimationCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(i)}validateSessionAnimationCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(i)}validateSessionAnimationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(i)}validateSessionVoiceCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(i)}validateSessionVoiceCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(i)}validateSessionVoiceCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(i)}validateSessionVoiceCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(i)}validateSessionVoiceFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(i)}validateSessionVideoNoteCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(i)}validateSessionVideoNoteCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(i)}validateSessionVideoNoteCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(i)}validateSessionVideoNoteCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(i)}validateSessionVideoNoteFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(i)}validateSessionStickerFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(i)}validateSessionLocationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(i)}validateSessionContactFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(i)}sessionCallback(t,i){return this.sessionSet(this.methodSessionCallback(i),t)}sessionCallbackPayload(t,i){return this.sessionSet(this.methodSessionCallbackPayload(i),t)}sessionText(t,i){return this.sessionSet(this.methodSessionText(i),t)}sessionTextPayload(t,i){return this.sessionSet(this.methodSessionTextPayload(i),t)}sessionTextCommand(t,i){return this.sessionSet(this.methodSessionTextCommand(i),t)}sessionTextCommandPayload(t,i){return this.sessionSet(this.methodSessionTextCommandPayload(i),t)}sessionTextFree(t,i){return this.sessionSet(this.methodSessionTextFree(i),t)}sessionPhotoCaption(t,i){return this.sessionSet(this.methodSessionPhotoCaption(i),t)}sessionPhotoCaptionPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionPayload(i),t)}sessionPhotoCaptionCommand(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommand(i),t)}sessionPhotoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(i),t)}sessionPhotoFree(t,i){return this.sessionSet(this.methodSessionPhotoFree(i),t)}sessionVideoCaption(t,i){return this.sessionSet(this.methodSessionVideoCaption(i),t)}sessionVideoCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionPayload(i),t)}sessionVideoCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommand(i),t)}sessionVideoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(i),t)}sessionVideoFree(t,i){return this.sessionSet(this.methodSessionVideoFree(i),t)}sessionAudioCaption(t,i){return this.sessionSet(this.methodSessionAudioCaption(i),t)}sessionAudioCaptionPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionPayload(i),t)}sessionAudioCaptionCommand(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommand(i),t)}sessionAudioCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(i),t)}sessionAudioFree(t,i){return this.sessionSet(this.methodSessionAudioFree(i),t)}sessionDocumentCaption(t,i){return this.sessionSet(this.methodSessionDocumentCaption(i),t)}sessionDocumentCaptionPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionPayload(i),t)}sessionDocumentCaptionCommand(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommand(i),t)}sessionDocumentCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(i),t)}sessionDocumentFree(t,i){return this.sessionSet(this.methodSessionDocumentFree(i),t)}sessionAnimationCaption(t,i){return this.sessionSet(this.methodSessionAnimationCaption(i),t)}sessionAnimationCaptionPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionPayload(i),t)}sessionAnimationCaptionCommand(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommand(i),t)}sessionAnimationCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(i),t)}sessionAnimationFree(t,i){return this.sessionSet(this.methodSessionAnimationFree(i),t)}sessionVoiceCaption(t,i){return this.sessionSet(this.methodSessionVoiceCaption(i),t)}sessionVoiceCaptionPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionPayload(i),t)}sessionVoiceCaptionCommand(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommand(i),t)}sessionVoiceCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(i),t)}sessionVoiceFree(t,i){return this.sessionSet(this.methodSessionVoiceFree(i),t)}sessionVideoNoteCaption(t,i){return this.sessionSet(this.methodSessionVideoNoteCaption(i),t)}sessionVideoNoteCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(i),t)}sessionVideoNoteCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(i),t)}sessionVideoNoteCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(i),t)}sessionVideoNoteFree(t,i){return this.sessionSet(this.methodSessionVideoNoteFree(i),t)}sessionStickerFree(t,i){return this.sessionSet(this.methodSessionStickerFree(i),t)}sessionLocationFree(t,i){return this.sessionSet(this.methodSessionLocationFree(i),t)}sessionContactFree(t,i){return this.sessionSet(this.methodSessionContactFree(i),t)}sessionToCallback(t,i){return this.sessionCallback({...this.session.params,...t},i)}sessionToCallbackPayload(t,i){return this.sessionCallbackPayload({...this.session.params,...t},i)}sessionToText(t,i){return this.sessionText({...this.session.params,...t},i)}sessionToTextPayload(t,i){return this.sessionTextPayload({...this.session.params,...t},i)}sessionToTextCommand(t,i){return this.sessionTextCommand({...this.session.params,...t},i)}sessionToTextCommandPayload(t,i){return this.sessionTextCommandPayload({...this.session.params,...t},i)}sessionToTextFree(t,i){return this.sessionTextFree({...this.session.params,...t},i)}sessionToPhotoCaption(t,i){return this.sessionPhotoCaption({...this.session.params,...t},i)}sessionToPhotoCaptionPayload(t,i){return this.sessionPhotoCaptionPayload({...this.session.params,...t},i)}sessionToPhotoCaptionCommand(t,i){return this.sessionPhotoCaptionCommand({...this.session.params,...t},i)}sessionToPhotoCaptionCommandPayload(t,i){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},i)}sessionToPhotoFree(t,i){return this.sessionPhotoFree({...this.session.params,...t},i)}sessionToVideoCaption(t,i){return this.sessionVideoCaption({...this.session.params,...t},i)}sessionToVideoCaptionPayload(t,i){return this.sessionVideoCaptionPayload({...this.session.params,...t},i)}sessionToVideoCaptionCommand(t,i){return this.sessionVideoCaptionCommand({...this.session.params,...t},i)}sessionToVideoCaptionCommandPayload(t,i){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoFree(t,i){return this.sessionVideoFree({...this.session.params,...t},i)}sessionToAudioCaption(t,i){return this.sessionAudioCaption({...this.session.params,...t},i)}sessionToAudioCaptionPayload(t,i){return this.sessionAudioCaptionPayload({...this.session.params,...t},i)}sessionToAudioCaptionCommand(t,i){return this.sessionAudioCaptionCommand({...this.session.params,...t},i)}sessionToAudioCaptionCommandPayload(t,i){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},i)}sessionToAudioFree(t,i){return this.sessionAudioFree({...this.session.params,...t},i)}sessionToDocumentCaption(t,i){return this.sessionDocumentCaption({...this.session.params,...t},i)}sessionToDocumentCaptionPayload(t,i){return this.sessionDocumentCaptionPayload({...this.session.params,...t},i)}sessionToDocumentCaptionCommand(t,i){return this.sessionDocumentCaptionCommand({...this.session.params,...t},i)}sessionToDocumentCaptionCommandPayload(t,i){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},i)}sessionToDocumentFree(t,i){return this.sessionDocumentFree({...this.session.params,...t},i)}sessionToAnimationCaption(t,i){return this.sessionAnimationCaption({...this.session.params,...t},i)}sessionToAnimationCaptionPayload(t,i){return this.sessionAnimationCaptionPayload({...this.session.params,...t},i)}sessionToAnimationCaptionCommand(t,i){return this.sessionAnimationCaptionCommand({...this.session.params,...t},i)}sessionToAnimationCaptionCommandPayload(t,i){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},i)}sessionToAnimationFree(t,i){return this.sessionAnimationFree({...this.session.params,...t},i)}sessionToVoiceCaption(t,i){return this.sessionVoiceCaption({...this.session.params,...t},i)}sessionToVoiceCaptionPayload(t,i){return this.sessionVoiceCaptionPayload({...this.session.params,...t},i)}sessionToVoiceCaptionCommand(t,i){return this.sessionVoiceCaptionCommand({...this.session.params,...t},i)}sessionToVoiceCaptionCommandPayload(t,i){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},i)}sessionToVoiceFree(t,i){return this.sessionVoiceFree({...this.session.params,...t},i)}sessionToVideoNoteCaption(t,i){return this.sessionVideoNoteCaption({...this.session.params,...t},i)}sessionToVideoNoteCaptionPayload(t,i){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommand(t,i){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommandPayload(t,i){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoNoteFree(t,i){return this.sessionVideoNoteFree({...this.session.params,...t},i)}sessionToStickerFree(t,i){return this.sessionStickerFree({...this.session.params,...t},i)}sessionToLocationFree(t,i){return this.sessionLocationFree({...this.session.params,...t},i)}sessionToContactFree(t,i){return this.sessionContactFree({...this.session.params,...t},i)}buildIntent(t,i=!0){t||(t=i?this.data.callbackData():this.data.name);let e=i?":":" ";return t?.indexOf?.(e)!=-1?t?.split?.(e)?.[0]:t}methodSession(t,i){return`${t}-${i||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var $=require("bun"),v=require("path");var W=require("logging-pretty");var C=class{static{h(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(i,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(t){let i=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of t.matchAll(i)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(i,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(i,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let i=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of t.matchAll(i)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of o.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let c=a.lang,d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:d};a.src&&(u.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(u.caption=l),d==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),d==="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),l&&(u.caption=l)),e[c]=u}return e}static _processMessageBlocks(t){let i=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of t.matchAll(i)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(t){let i=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of t.matchAll(i)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(t,i){let e;i?e=t.map(n=>`\`${n}\``).join(","):e=`\`${t}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),i){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);e[s][a]=l=>({...r,caption:d(l)})}else e[s][a]=()=>r}return e}static compileMessages(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(c,!1)}}return e}static compileKeyboards(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[c,d]of Object.entries(r)){let u=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));e[s][a][c]=this._compileToFunction(u,!0)}}}return e}};var P=class{static{h(this,"HelperPage")}static _getPage(t,i,e=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${i} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(t,i=!0){let e=require(t);return this._getPage(e,t,i)}static async getPage(t,i=!0){let e=await import(`${t}?t=${Date.now()}`);return this._getPage(e,t,i)}};var B=require("fs/promises"),L=require("chokidar"),f=require("path"),b=require("fs");var F=class{static{h(this,"TemplateManager")}_map=new Map;_engine=C;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:i,enableWatch:e=!1,forceLanguage:s}=t;this._path=i,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 t=0;t<this._path.length;t++){let i=this._path[t];if(!(0,b.existsSync)(i))throw new Error(`Template base path is not exists: ${i}`);if(!(0,b.statSync)(i).isDirectory())throw new Error(`Template base path is not a directory: ${i}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let i=this._path[t],e=(0,L.watch)(i,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=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(t){let i=(0,f.basename)(t);this._isValidFile(i)&&await this._loadFile(i,!1)}async _handleFileAdd(t){let i=(0,f.basename)(t);this._isValidFile(i)&&await this._loadFile(i,!1)}_handleFileDelete(t){let i=(0,f.basename)(t),e=this._getKey(i);this._map.has(e)&&this._map.delete(e)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let i=this._path[t],s=(0,b.readdirSync)(i,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,i=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=(0,f.join)(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=i?(0,b.readFileSync)(o,"utf8"):await(0,B.readFile)(o,"utf8");this._compile(a,r)}else if(n==".ts"){let r=await P.getPage(o,!1);r?.template!==void 0&&this._compile(a,r.template),r.template=void 0}else throw new Error(`File ${t} is not support`)}}_getExtension(t){return(0,f.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,i,e){let s=this._map.get(t),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=C.compileMedia(i),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=C.compileMessages(i),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=C.compileKeyboards(i),n=!0),n&&this._map.set(t,o)}getMedia(t,i="default",e="en",s){let n=this._map.get(t)?.media?.[i]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(t,i="default",e="en",s){let n=this._map.get(t)?.message?.[i]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(t,i="default",e="en",s="inline",o){let a=this._map.get(t)?.keyboard?.[i]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(t,i){if(this._getExtension(t)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=(0,f.join)(this._path[e],t);if((0,b.existsSync)(s))return(0,b.writeFileSync)(s,i,"utf8"),await this._loadFile(t,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,i)=>typeof i=="function"?i.toString():i).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var M=require("fs"),w=require("grammy");var _=class{static{h(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===null?void 0:t.log===void 0?new W.LoggingPretty:t.log,this.cacheSession=t.cacheSession||new T("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new F({path:[(0,v.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.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()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook")&&this.runWebhook(t.deploy.split("webhook:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,i,e){let{username:s}=t;i=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(t){return new w.Bot(t)}createCtx(t){return new k({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:h(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let i=(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"?i(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+e:t+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(t,i){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,v.parse)(i).name}pageSorts(t,i){let e=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=i.dynamic,d=i.dynamicSpesific,l=h(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),u=h(m=>m.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),g=h((m,y)=>s[`methodSession${l(m)}`](y),"methodSession");i.all[e]=t;for(let m=0;m<i.lenListFuncStaticSession;m++){let y=i.listFuncStaticSession[m],j=i.static[y],Q=i.staticIntent[y],D=i.staticSession[y],V={name:e,func:y},A=j||Q;if(A!==void 0){let z=y.includes(n)?`/${e}`:e;A[s.buildIntent(z,y.startsWith("callback"))]=V}D!==void 0&&(D[g(y,e)]=V),y.toLowerCase().endsWith("free")&&d[u(y)].push(V)}s.free&&c.push(e)}pageLoads(){this.log?.info?.("Load pages..");let t=(0,v.join)(process.cwd(),"src","pages");if(!(0,M.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);let i=(0,M.readdirSync)(t),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"],c=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],d=h((u,g)=>Object.fromEntries(u.map(m=>[m,{...g}])),"makeObject"),l={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:d(a,e),staticIntent:d(r,s),staticSession:d(c,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:c,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:c.length};for(let u of i){let g=(0,v.join)(t,u),m=P.getPageSync(g,!0);this.pageBuildData(m,g),this.pageSorts(m,l)}return this.log?.info?.(`Finish load pages with total (${Object.keys(l.all).length})`),l}async pageRoutes(t,i){let e,s;if(e===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][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(t)[s.func]?.();let o=this.pages.dynamicSpesific[i]||[];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 d=await new r(t)[a.name]?.();if(d!==null)return d}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 d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,i){return!0}async hookErrorPage(t,i,e,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,i){let e=this.createCtx(t);try{if(await this.hookBeforeRoute(e,i)===!1)return;await this.pageRoutes(e,i)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,i,s,!1)}}async onCallbackQueryData(t){let i=this.createCtx(t);try{if(await i.callbackQueryAnswer(),await this.hookBeforeRoute(i,"onCallbackQueryData")===!1)return;await this.pageRoutes(i,"callback")}catch(e){await this.hookErrorPage(i,"onCallbackQueryData",e,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"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 J=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var u=(p,t)=>v(p,"name",{value:t,configurable:!0});var Y=(p,t)=>{for(var e in t)v(p,e,{get:t[e],enumerable:!0})},R=(p,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of J(t))!X.call(p,s)&&s!==e&&v(p,s,{get:()=>t[s],enumerable:!(i=H(t,s))||i.enumerable});return p};var Z=(p,t,e)=>(e=p!=null?G(q(p)):{},R(t||!p||!p.__esModule?v(e,"default",{value:p,enumerable:!0}):e,p)),tt=p=>R(v({},"__esModule",{value:!0}),p);var et={};Y(et,{BaseGeneral:()=>I,CacheExternal:()=>M,Ctx:()=>x,Gramstax:()=>D,TemplateEngine:()=>f,TemplateManager:()=>T});module.exports=tt(et);var N=require("logging-pretty");var I=class{static{u(this,"BaseGeneral")}static log=new N.LoggingPretty;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};var K=require("keyv"),B=Z(require("@keyv/redis"),1);var M=class extends K.Keyv{constructor(e="memory",i,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:i,ttl:s});this.url=e}static{u(this,"CacheExternal")}};var E=require("timers/promises");var S=require("grammy");var x=class extends I{static{u(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(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<t.length;d++){let c=t[d],l=r[d];await this.ct.api.sendMessage(c,l,{parse_mode:"HTML",reply_markup:i,...o}),d+1==30&&await(0,E.setTimeout)(1200)}}async reply(t,e,i,s){let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,n){let o=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...n};if(t=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(t=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(t=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(o.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(t=="sticker")return await this.ct.replyWithSticker(o.src,a);if(t=="location")return await this.ct.replyWithLocation(o.latitude,o.longitude,a);if(t=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,e,i,s)}}async editMedia(t,e,i,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,n)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,n)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,n)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,i,s,o)}}async editPhoto(t,e,i,s,n){return await this.editMedia("photo",t,e,i,s,n)}async editVideo(t,e,i,s,n){return await this.editMedia("video",t,e,i,s,n)}async editAudio(t,e,i,s,n){return await this.editMedia("audio",t,e,i,s,n)}async editDocument(t,e,i,s,n){return await this.editMedia("document",t,e,i,s,n)}async editAnimation(t,e,i,s,n){return await this.editMedia("animation",t,e,i,s,n)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.InlineKeyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(d,c);return this.cacheKeyboard.set(a,l),l}return r}let s=new S.InlineKeyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,n)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new S.Keyboard,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(d,c);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new S.Keyboard,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),o=t(s,n);return o.resized(),o}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};var W=require("bun");var V=require("path"),F=require("fs");var P=class{static{u(this,"HelperPage")}static getPath(){return(0,V.join)(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let n=Object.values(t)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getPageSync(t,e=!0){t||(t=this.getPath());let i=require(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!(0,F.existsSync)(t))throw new Error(`Directory ${t} is not found, please make it manually`);return(0,F.readdirSync)(t).map(s=>{let n=(0,V.join)(t,s);return{path:n,page:this.getPageSync(n,e)}})}};var w=require("path");var j=require("logging-pretty");var f=class{static{u(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[n]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let b of n.matchAll(r))a[b[1]]=b[2];if(!a.lang)continue;let d=a.lang,c=a.type,l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),m={type:c};a.src&&(m.src=a.src),l&&c!=="video_note"&&c!=="sticker"&&(m.caption=l),c==="location"&&(a.latitude&&(m.latitude=a.latitude),a.longitude&&(m.longitude=a.longitude),l&&(m.caption=l)),c==="contact"&&(a.phone&&(m.phone=a.phone),a.first_name&&(m.first_name=a.first_name),a.last_name&&(m.last_name=a.last_name),a.vcard&&(m.vcard=a.vcard),l&&(m.caption=l)),i[d]=m}return i}static _processMessageBlocks(t){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]=o}return i}static _processDescriptionBlocks(t){let e=/<description\b[^>]*\blang="([^"]*)"[^>]*\bscope="([^"]*)"[^>]*>([\s\S]*?)<\/description>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]||(i[s]={}),i[s][n]=a}return i}static _processKeyboardBlocks(t){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=n==="bottom"?"bottom":"inline",r=o.trim();i[s]||(i[s]={}),i[s][a]=r}return i}static _compileToFunction(t,e){let i;e?i=t.map(o=>`\`${o}\``).join(","):i=`\`${t}\``;let s=i;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(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),c=this._compileToFunction(d,!1);i[s][a]=l=>({...r,caption:c(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(d,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processDescriptionBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))for(let[d,c]of Object.entries(r))i[s][d]||(i[s][d]={}),i[s][d][a]=this._compileToFunction(c,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){i[s][a]={};for(let[d,c]of Object.entries(r)){let m=c.split(/(?<!\\),\s*/).map(b=>b.replace(/\\,/g,",").trim()).map(b=>this._processVariables(this._processScriptBlocks(b)));i[s][a][d]=this._compileToFunction(m,!0)}}}return i}};var $=require("fs/promises"),L=require("chokidar"),C=require("path"),y=require("fs");var T=class{static{u(this,"TemplateManager")}_map=new Map;_engine=f;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1,forceLanguage:s}=t;this._path=e,this._forceLanguage=s,this._isWatchEnabled=i,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 t=0;t<this._path.length;t++){let e=this._path[t];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(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=(0,L.watch)(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=(0,C.basename)(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=(0,C.basename)(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=(0,y.readdirSync)(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],n=(0,C.join)(s,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let r=e?(0,y.readFileSync)(n,"utf8"):await(0,$.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 ${t} is not support`)}}_getExtension(t){return(0,C.extname)(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),n=s||{},o=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(n.media=f.compileMedia(e),o=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(n.message=f.compileMessages(e),o=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=f.compileKeyboards(e),o=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(n.description=f.compileDescription(e),o=!0),o&&this._map.set(t,n)}getMedia(t,e="default",i="en",s){let o=this._map.get(t)?.media?.[e]?.[this._forceLanguage||i];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(t,e="default",i="en",s){let o=this._map.get(t)?.message?.[e]?.[this._forceLanguage||i];if(!o)return"";try{return o(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",n){let a=this._map.get(t)?.description?.[e]?.[s]?.[this._forceLanguage||i];if(!a)return"";try{return a(n)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let n=this._map.get(t)?.description?.[e]?.[i];return n?Object.keys(n):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="en",s="inline",n){let a=this._map.get(t)?.keyboard?.[e]?.[this._forceLanguage||i]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=(0,C.join)(this._path[i],t);if((0,y.existsSync)(s))return(0,y.writeFileSync)(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};var k=require("grammy");var D=class{static{u(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new j.LoggingPretty:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new M("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new T({path:[(0,w.join)(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new k.Bot(t)}createCtx(t){return new x({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:u(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=(0,k.webhookCallback)(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,(0,W.serve)({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)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=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}async runServerless(t){this.handlerBotUpdate=(0,k.webhookCallback)(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=(0,w.parse)(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,c=e.dynamicSpesific,l=u(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),m=u(h=>h.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),b=u((h,g)=>s[`methodSession${l(h)}`](g),"methodSession");e.all[i]=t;for(let h=0;h<e.lenListFuncStaticSession;h++){let g=e.listFuncStaticSession[h],Q=e.static[g],U=e.staticIntent[g],O=e.staticSession[g],_={name:i,func:g},A=Q||U;if(A!==void 0){let z=g.includes(o)?`/${i}`:i;A[s.intent(z,g.startsWith("callback"))]=_}O!==void 0&&(O[b(g,i)]=_),g.toLowerCase().endsWith("free")&&c[m(g)].push(_)}s.free&&d.push(i)}async pageSyncDescription(t){let e=new Map,i=u((n,o,a,r)=>{e.has(o)||e.set(o,new Map);let d=e.get(o);d.has(a)||d.set(a,[]);let c=d.get(a);c.some(l=>l.command===n)||c.push({command:n,description:r})},"addCommand"),s=t.static.textCommand;for(let[,n]of Object.entries(s)){let o=n.name,a=this.templateManager.getDescriptionScopes(o);for(let r of a){let d=this.templateManager.getDescriptionLanguage(o,"default",r);for(let c of d){let l=this.templateManager.getDescription(o,"default",c,r);l&&i(o,r,c,l)}}}for(let[n,o]of e)for(let[a,r]of o){let d={type:n},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:d,language_code:c}),m=JSON.stringify(l.map(h=>({command:h.command,description:h.description})).sort((h,g)=>h.command.localeCompare(g.command))),b=JSON.stringify(r.sort((h,g)=>h.command.localeCompare(g.command)));m!==b&&(await this.bot.api.setMyCommands(r,{scope:d,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${n},${c?` lang: ${c}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${n},${c?` lang: ${c}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],n=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],o=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...n,...o,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=u((c,l)=>Object.fromEntries(c.map(m=>[m,{...l}])),"makeObject"),d={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(n,t),staticIntent:r(o,e),staticSession:r(a,i),listFuncStatic:n,listFuncStaticIntent:o,listFuncStaticSession:a,lenListFuncStatic:n.length,lenListFuncStaticIntent:o.length,lenListFuncStaticSession:a.length};return P.getPagesSync(void 0,!0).forEach(({path:c,page:l})=>{this.pageBuildData(l,c),this.pageSorts(l,d)}),this.log?.info?.(`Finish load pages with total (${Object.keys(d.all).length})`),this.pageSyncDescription(d),d}async pageRoutes(t,e){let i,s;if(i===void 0){let o=t.callbackData,a=t.msgText,r=t.msgCaption,d=this.pages.static;for(let c=0;c<this.pages.lenListFuncStatic;c++){let l=this.pages.listFuncStatic[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let o=await t.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let c=this.pages.listFuncStaticSession[d];if(s=r[c][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let o=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,d=this.pages.staticIntent;for(let c=0;c<this.pages.lenListFuncStaticIntent;c++){let l=this.pages.listFuncStaticIntent[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[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 c=await new r(t)[a.name]?.();if(c!==null)return c}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 c=await new r(t).free?.();if(c!==null)return c}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};0&&(module.exports={BaseGeneral,CacheExternal,Ctx,Gramstax,TemplateEngine,TemplateManager});
@@ -46,6 +46,11 @@ declare class TemplateEngine {
46
46
  static _processMessageBlocks(template: string): {
47
47
  [lang: string]: string;
48
48
  };
49
+ static _processDescriptionBlocks(template: string): {
50
+ [lang: string]: {
51
+ [scope: string]: string;
52
+ };
53
+ };
49
54
  static _processKeyboardBlocks(template: string): {
50
55
  [lang: string]: {
51
56
  inline?: string;
@@ -63,6 +68,13 @@ declare class TemplateEngine {
63
68
  [lang: string]: (data?: Record<string, any>) => string;
64
69
  };
65
70
  };
71
+ static compileDescription(template: string): {
72
+ [baseId: string]: {
73
+ [scope: string]: {
74
+ [lang: string]: (data?: Record<string, any>) => string;
75
+ };
76
+ };
77
+ };
66
78
  static compileKeyboards(template: string): {
67
79
  [baseId: string]: {
68
80
  [lang: string]: {
@@ -78,6 +90,7 @@ type ICompiledTemplate = {
78
90
  media: ReturnType<typeof TemplateEngine.compileMedia>;
79
91
  message: ReturnType<typeof TemplateEngine.compileMessages>;
80
92
  keyboard: ReturnType<typeof TemplateEngine.compileKeyboards>;
93
+ description: ReturnType<typeof TemplateEngine.compileDescription>;
81
94
  };
82
95
  /** Template loading options */
83
96
  type ITemplateOptions = {
@@ -138,6 +151,16 @@ declare class TemplateManager {
138
151
  * @returns Rendered message string
139
152
  */
140
153
  getMessage(key: string, baseId?: string, language?: string, data?: Record<string, any>): string;
154
+ /**
155
+ * @param key Template identifier (filename without extension)
156
+ * @param baseId Base id attr from block
157
+ * @param language Target language code
158
+ * @param scope Scope of the command
159
+ * @returns Description string
160
+ */
161
+ getDescription(key: string, baseId?: string, language?: string, scope?: string, data?: Record<string, any>): string;
162
+ getDescriptionLanguage(key: string, baseId?: string, scope?: string): string[];
163
+ getDescriptionScopes(key: string, baseId?: string): string[];
141
164
  /**
142
165
  * Get compiled keyboard template
143
166
  * @param key Template identifier (filename without extension)
@@ -154,11 +177,6 @@ declare class TemplateManager {
154
177
  * @returns Promise that resolves when file is written
155
178
  */
156
179
  write(filename: string, template: string): Promise<boolean | null>;
157
- /**
158
- * Get list of available template
159
- * @returns Array of template names
160
- */
161
- getAvailable(): string[];
162
180
  /**
163
181
  * Check if template exists
164
182
  * @param key Template identifier
@@ -202,7 +220,7 @@ type IOptEditMedia2 = Parameters<Context[`editMessageMedia`]>[1]
202
220
  type ITypeReplyAction = Parameters<Context[`replyWithChatAction`]>[0]
203
221
  type IData = Record<string, any>
204
222
 
205
- type IPData = {
223
+ type IPageData = {
206
224
  name: string;
207
225
  callbackData: (...args: any) => string | any;
208
226
  };
@@ -211,13 +229,13 @@ type ITemp = {
211
229
  method?: string;
212
230
  params?: any;
213
231
  };
214
- data: Partial<IPData>;
232
+ data: Partial<IPageData>;
215
233
  [key: string]: any;
216
234
  };
217
235
  declare class Ctx extends BaseGeneral {
218
236
  static template?: string;
219
- static data: IPData;
220
- data: IPData;
237
+ static data: IPageData;
238
+ data: IPageData;
221
239
  get isPremium(): boolean;
222
240
  get isBot(): boolean;
223
241
  get userid(): number;
@@ -496,7 +514,7 @@ declare class Ctx extends BaseGeneral {
496
514
  sessionToStickerFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
497
515
  sessionToLocationFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
498
516
  sessionToContactFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
499
- buildIntent(str?: string, fbCallbackData?: boolean): string;
517
+ intent(str?: string, fbCallbackData?: boolean): string;
500
518
  methodSession(prefix: string, name: string | undefined): string;
501
519
  methodSessionCallback(name?: string): string;
502
520
  methodSessionCallbackPayload(name?: string): string;
@@ -550,25 +568,28 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
550
568
  cacheKeyboard: Map<any, any>;
551
569
  cacheSession: CacheExternal;
552
570
  pages: ReturnType<typeof this.pageLoads>;
553
- log: LoggingPretty | undefined | null;
571
+ log: LoggingPretty | undefined;
554
572
  bot: IBot;
573
+ handlerBotUpdate: any;
555
574
  constructor(params: {
556
575
  token: string;
557
576
  deploy: string;
558
- log?: LoggingPretty;
577
+ log?: LoggingPretty | boolean | null;
559
578
  cacheData?: CacheExternal;
560
579
  cacheSession?: CacheExternal;
561
580
  cacheKeyboard?: Map<any, any>;
562
581
  templateManager?: TemplateManager;
563
582
  });
564
583
  onCatch(error: BotError<Context>): void;
565
- onStart(botInfo: UserFromGetMe, method: `polling` | `webhook`, data: string | null): void;
584
+ onStart(botInfo: UserFromGetMe, method: `polling` | `webhook` | `serverless`, data: string | null): void;
566
585
  createBot(token: string): Bot<Context, grammy.Api<grammy.RawApi>>;
567
586
  createCtx(ct: Context): ICtx;
568
587
  runPolling(): Promise<void>;
569
588
  runWebhook(baseUrl: string): Promise<void>;
589
+ runServerless(adapter: string): Promise<void>;
570
590
  pageBuildData(Page: typeof Ctx, filePath: string): void;
571
591
  pageSorts(Page: typeof Ctx, pages: typeof this.pages): void;
592
+ pageSyncDescription(pages: typeof this.pages): Promise<void>;
572
593
  pageLoads(): {
573
594
  all: Record<string, typeof Ctx>;
574
595
  dynamic: string[];
@@ -964,6 +985,18 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
964
985
  onMessageSticker(ct: Context): Promise<void>;
965
986
  onMessageLocation(ct: Context): Promise<void>;
966
987
  onMessageContact(ct: Context): Promise<void>;
988
+ registerOnCallbackQueryData(): void;
989
+ registerOnMessageText(): void;
990
+ registerOnMessagePhoto(): void;
991
+ registerOnMessageVideo(): void;
992
+ registerOnMessageAudio(): void;
993
+ registerOnMessageDocument(): void;
994
+ registerOnMessageAnimation(): void;
995
+ registerOnMessageVoice(): void;
996
+ registerOnMessageVideoNote(): void;
997
+ registerOnMessageSticker(): void;
998
+ registerOnMessageLocation(): void;
999
+ registerOnMessageContact(): void;
967
1000
  }
968
1001
 
969
1002
  export { BaseGeneral, CacheExternal, Ctx, Gramstax, type IMediaBlock, TemplateEngine, TemplateManager };
@@ -46,6 +46,11 @@ declare class TemplateEngine {
46
46
  static _processMessageBlocks(template: string): {
47
47
  [lang: string]: string;
48
48
  };
49
+ static _processDescriptionBlocks(template: string): {
50
+ [lang: string]: {
51
+ [scope: string]: string;
52
+ };
53
+ };
49
54
  static _processKeyboardBlocks(template: string): {
50
55
  [lang: string]: {
51
56
  inline?: string;
@@ -63,6 +68,13 @@ declare class TemplateEngine {
63
68
  [lang: string]: (data?: Record<string, any>) => string;
64
69
  };
65
70
  };
71
+ static compileDescription(template: string): {
72
+ [baseId: string]: {
73
+ [scope: string]: {
74
+ [lang: string]: (data?: Record<string, any>) => string;
75
+ };
76
+ };
77
+ };
66
78
  static compileKeyboards(template: string): {
67
79
  [baseId: string]: {
68
80
  [lang: string]: {
@@ -78,6 +90,7 @@ type ICompiledTemplate = {
78
90
  media: ReturnType<typeof TemplateEngine.compileMedia>;
79
91
  message: ReturnType<typeof TemplateEngine.compileMessages>;
80
92
  keyboard: ReturnType<typeof TemplateEngine.compileKeyboards>;
93
+ description: ReturnType<typeof TemplateEngine.compileDescription>;
81
94
  };
82
95
  /** Template loading options */
83
96
  type ITemplateOptions = {
@@ -138,6 +151,16 @@ declare class TemplateManager {
138
151
  * @returns Rendered message string
139
152
  */
140
153
  getMessage(key: string, baseId?: string, language?: string, data?: Record<string, any>): string;
154
+ /**
155
+ * @param key Template identifier (filename without extension)
156
+ * @param baseId Base id attr from block
157
+ * @param language Target language code
158
+ * @param scope Scope of the command
159
+ * @returns Description string
160
+ */
161
+ getDescription(key: string, baseId?: string, language?: string, scope?: string, data?: Record<string, any>): string;
162
+ getDescriptionLanguage(key: string, baseId?: string, scope?: string): string[];
163
+ getDescriptionScopes(key: string, baseId?: string): string[];
141
164
  /**
142
165
  * Get compiled keyboard template
143
166
  * @param key Template identifier (filename without extension)
@@ -154,11 +177,6 @@ declare class TemplateManager {
154
177
  * @returns Promise that resolves when file is written
155
178
  */
156
179
  write(filename: string, template: string): Promise<boolean | null>;
157
- /**
158
- * Get list of available template
159
- * @returns Array of template names
160
- */
161
- getAvailable(): string[];
162
180
  /**
163
181
  * Check if template exists
164
182
  * @param key Template identifier
@@ -202,7 +220,7 @@ type IOptEditMedia2 = Parameters<Context[`editMessageMedia`]>[1]
202
220
  type ITypeReplyAction = Parameters<Context[`replyWithChatAction`]>[0]
203
221
  type IData = Record<string, any>
204
222
 
205
- type IPData = {
223
+ type IPageData = {
206
224
  name: string;
207
225
  callbackData: (...args: any) => string | any;
208
226
  };
@@ -211,13 +229,13 @@ type ITemp = {
211
229
  method?: string;
212
230
  params?: any;
213
231
  };
214
- data: Partial<IPData>;
232
+ data: Partial<IPageData>;
215
233
  [key: string]: any;
216
234
  };
217
235
  declare class Ctx extends BaseGeneral {
218
236
  static template?: string;
219
- static data: IPData;
220
- data: IPData;
237
+ static data: IPageData;
238
+ data: IPageData;
221
239
  get isPremium(): boolean;
222
240
  get isBot(): boolean;
223
241
  get userid(): number;
@@ -496,7 +514,7 @@ declare class Ctx extends BaseGeneral {
496
514
  sessionToStickerFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
497
515
  sessionToLocationFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
498
516
  sessionToContactFree(paramsAdd?: any, name?: string): Promise<boolean | null>;
499
- buildIntent(str?: string, fbCallbackData?: boolean): string;
517
+ intent(str?: string, fbCallbackData?: boolean): string;
500
518
  methodSession(prefix: string, name: string | undefined): string;
501
519
  methodSessionCallback(name?: string): string;
502
520
  methodSessionCallbackPayload(name?: string): string;
@@ -550,25 +568,28 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
550
568
  cacheKeyboard: Map<any, any>;
551
569
  cacheSession: CacheExternal;
552
570
  pages: ReturnType<typeof this.pageLoads>;
553
- log: LoggingPretty | undefined | null;
571
+ log: LoggingPretty | undefined;
554
572
  bot: IBot;
573
+ handlerBotUpdate: any;
555
574
  constructor(params: {
556
575
  token: string;
557
576
  deploy: string;
558
- log?: LoggingPretty;
577
+ log?: LoggingPretty | boolean | null;
559
578
  cacheData?: CacheExternal;
560
579
  cacheSession?: CacheExternal;
561
580
  cacheKeyboard?: Map<any, any>;
562
581
  templateManager?: TemplateManager;
563
582
  });
564
583
  onCatch(error: BotError<Context>): void;
565
- onStart(botInfo: UserFromGetMe, method: `polling` | `webhook`, data: string | null): void;
584
+ onStart(botInfo: UserFromGetMe, method: `polling` | `webhook` | `serverless`, data: string | null): void;
566
585
  createBot(token: string): Bot<Context, grammy.Api<grammy.RawApi>>;
567
586
  createCtx(ct: Context): ICtx;
568
587
  runPolling(): Promise<void>;
569
588
  runWebhook(baseUrl: string): Promise<void>;
589
+ runServerless(adapter: string): Promise<void>;
570
590
  pageBuildData(Page: typeof Ctx, filePath: string): void;
571
591
  pageSorts(Page: typeof Ctx, pages: typeof this.pages): void;
592
+ pageSyncDescription(pages: typeof this.pages): Promise<void>;
572
593
  pageLoads(): {
573
594
  all: Record<string, typeof Ctx>;
574
595
  dynamic: string[];
@@ -964,6 +985,18 @@ declare class Gramstax<ICtx extends Ctx = Ctx, IBot extends Bot = Bot> {
964
985
  onMessageSticker(ct: Context): Promise<void>;
965
986
  onMessageLocation(ct: Context): Promise<void>;
966
987
  onMessageContact(ct: Context): Promise<void>;
988
+ registerOnCallbackQueryData(): void;
989
+ registerOnMessageText(): void;
990
+ registerOnMessagePhoto(): void;
991
+ registerOnMessageVideo(): void;
992
+ registerOnMessageAudio(): void;
993
+ registerOnMessageDocument(): void;
994
+ registerOnMessageAnimation(): void;
995
+ registerOnMessageVoice(): void;
996
+ registerOnMessageVideoNote(): void;
997
+ registerOnMessageSticker(): void;
998
+ registerOnMessageLocation(): void;
999
+ registerOnMessageContact(): void;
967
1000
  }
968
1001
 
969
1002
  export { BaseGeneral, CacheExternal, Ctx, Gramstax, type IMediaBlock, TemplateEngine, TemplateManager };
package/dist/src/index.js CHANGED
@@ -1 +1 @@
1
- var N=Object.defineProperty;var u=(m,t)=>N(m,"name",{value:t,configurable:!0}),M=(m=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(m,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):m)(function(m){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+m+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{u(this,"BaseGeneral")}static log=new E;static logError(t,i){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${i}]: ${String(t)}`)}logError(t,i,e){this.constructor.log.error(`[${i||this.constructor.name}:${e}] ${String(t)}`)}};import{Keyv as B}from"keyv";import L from"@keyv/redis";var S=class extends B{constructor(i="memory",e,s,o){let n;i.startsWith("redis")&&(n=new L(i)),i==="memory"&&(n=new Map),o?.forceStore&&(n=o.forceStore);super({store:n,namespace:e,ttl:s});this.url=i}static{u(this,"CacheExternal")}};import{setTimeout as $}from"timers/promises";import{InlineKeyboard as w,Keyboard as V}from"grammy";var P=class extends C{static{u(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(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,i,e,s,o,n){let r=i.map(c=>this.templateManager.getMessage(this.data.name,o,c,s));for(let c=0;c<t.length;c++){let d=t[c],l=r[c];await this.ct.api.sendMessage(d,l,{parse_mode:"HTML",reply_markup:e,...n}),c+1==30&&await $(1200)}}async reply(t,i,e,s){let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.reply(o,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,i,e,s,o){let n=this.templateManager.getMedia(this.data.name,s,this.languageCode,e),a={parse_mode:"HTML",reply_markup:i,...o};if(t=="photo")return await this.ct.replyWithPhoto(n.src,{caption:n.caption,...a});if(t=="video")return await this.ct.replyWithVideo(n.src,{caption:n.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(n.src,{caption:n.caption,...a});if(t=="document")return await this.ct.replyWithDocument(n.src,{caption:n.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(n.src,{caption:n.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(n.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(n.src,a);if(t=="sticker")return await this.ct.replyWithSticker(n.src,a);if(t=="location")return await this.ct.replyWithLocation(n.latitude,n.longitude,a);if(t=="contact")return await this.ct.replyWithContact(n.phone,n.first_name,{vcard:n.vcard,...a})}async replyPhoto(t,i,e,s){return this.replyMedia("photo",t,i,e,s)}async replyVideo(t,i,e,s){return this.replyMedia("video",t,i,e,s)}async replyAudio(t,i,e,s){return this.replyMedia("audio",t,i,e,s)}async replyDocument(t,i,e,s){return this.replyMedia("document",t,i,e,s)}async replyAnimation(t,i,e,s){return this.replyMedia("animation",t,i,e,s)}async replyVoice(t,i,e,s){return this.replyMedia("voice",t,i,e,s)}async replyVideoNote(t,i,e,s){return this.replyMedia("video_note",t,i,e,s)}async replySticker(t,i,e,s){return this.replyMedia("sticker",t,i,e,s)}async replyLocation(t,i,e,s){return this.replyMedia("location",t,i,e,s)}async replyContact(t,i,e,s){return this.replyMedia("contact",t,i,e,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,i,e,s){try{let o=this.templateManager.getMessage(this.data.name,e,this.languageCode,i);return await this.ct.editMessageText(o,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,i,e,s)}}async editMedia(t,i,e,s,o,n){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,e);return t=="voice"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="video_note"?(await this.delete(),await this.replyVoice(i,e,s,o)):t=="sticker"?(await this.delete(),await this.replySticker(i,e,s,o)):t=="location"?(await this.delete(),await this.replyLocation(i,e,s,o)):t=="contact"?(await this.delete(),await this.replyContact(i,e,s,o)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...o},{reply_markup:i,...n})}catch{await this.reply(i,e,s,n)}}async editPhoto(t,i,e,s,o){return await this.editMedia("photo",t,i,e,s,o)}async editVideo(t,i,e,s,o){return await this.editMedia("video",t,i,e,s,o)}async editAudio(t,i,e,s,o){return await this.editMedia("audio",t,i,e,s,o)}async editDocument(t,i,e,s,o){return await this.editMedia("document",t,i,e,s,o)}async editAnimation(t,i,e,s,o){return await this.editMedia("animation",t,i,e,s,o)}async editVoice(t,i,e,s){return await this.editMedia("voice",t,i,e,s)}async editVideoNote(t,i,e,s){return await this.editMedia("video_note",t,i,e,s)}async editSticker(t,i,e,s){return await this.editMedia("sticker",t,i,e,s)}async editLocation(t,i,e,s){return await this.editMedia("location",t,i,e,s)}async editContact(t,i,e,s){return await this.editMedia("contact",t,i,e,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,i,e){try{let s={method:t,params:i,...e},o=await this.cacheSession.set(`${this.userid}`,s);return o&&(this.session=s),o}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...i){let e=t(...i);return`${this.name}${e===void 0?"":`:${e}`}`}:function(){return this?.name}}}inlineKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let c=new w,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data),l=t(c,d);return this.cacheKeyboard.set(a,l),l}return r}let s=new w,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"inline",i?.data);return t(s,o)}bottomKeyboard(t,i){let e=this.data.name;if(i?.cache===!0){let a=`${e}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let c=new V,d=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),l=t(c,d);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new V,o=this.templateManager.getKeyboard(e,i?.baseId,this.languageCode,"bottom",i?.data),n=t(s,o);return n.resized(),n}validateSessionCallback(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(i)}validateSessionCallbackPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(i)}validateSessionText(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(i)}validateSessionTextPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(i)}validateSessionTextCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(i)}validateSessionTextCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(i)}validateSessionTextFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(i)}validateSessionPhotoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(i)}validateSessionPhotoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(i)}validateSessionPhotoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(i)}validateSessionPhotoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(i)}validateSessionPhotoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(i)}validateSessionVideoCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(i)}validateSessionVideoCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(i)}validateSessionVideoCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(i)}validateSessionVideoCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(i)}validateSessionVideoFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(i)}validateSessionAudioCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(i)}validateSessionAudioCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(i)}validateSessionAudioCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(i)}validateSessionAudioCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(i)}validateSessionAudioFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(i)}validateSessionDocumentCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(i)}validateSessionDocumentCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(i)}validateSessionDocumentCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(i)}validateSessionDocumentCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(i)}validateSessionDocumentFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(i)}validateSessionAnimationCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(i)}validateSessionAnimationCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(i)}validateSessionAnimationCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(i)}validateSessionAnimationCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(i)}validateSessionAnimationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(i)}validateSessionVoiceCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(i)}validateSessionVoiceCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(i)}validateSessionVoiceCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(i)}validateSessionVoiceCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(i)}validateSessionVoiceFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(i)}validateSessionVideoNoteCaption(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(i)}validateSessionVideoNoteCaptionPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(i)}validateSessionVideoNoteCaptionCommand(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(i)}validateSessionVideoNoteCaptionCommandPayload(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(i)}validateSessionVideoNoteFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(i)}validateSessionStickerFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(i)}validateSessionLocationFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(i)}validateSessionContactFree(t,i){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(i)}sessionCallback(t,i){return this.sessionSet(this.methodSessionCallback(i),t)}sessionCallbackPayload(t,i){return this.sessionSet(this.methodSessionCallbackPayload(i),t)}sessionText(t,i){return this.sessionSet(this.methodSessionText(i),t)}sessionTextPayload(t,i){return this.sessionSet(this.methodSessionTextPayload(i),t)}sessionTextCommand(t,i){return this.sessionSet(this.methodSessionTextCommand(i),t)}sessionTextCommandPayload(t,i){return this.sessionSet(this.methodSessionTextCommandPayload(i),t)}sessionTextFree(t,i){return this.sessionSet(this.methodSessionTextFree(i),t)}sessionPhotoCaption(t,i){return this.sessionSet(this.methodSessionPhotoCaption(i),t)}sessionPhotoCaptionPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionPayload(i),t)}sessionPhotoCaptionCommand(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommand(i),t)}sessionPhotoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(i),t)}sessionPhotoFree(t,i){return this.sessionSet(this.methodSessionPhotoFree(i),t)}sessionVideoCaption(t,i){return this.sessionSet(this.methodSessionVideoCaption(i),t)}sessionVideoCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionPayload(i),t)}sessionVideoCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommand(i),t)}sessionVideoCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(i),t)}sessionVideoFree(t,i){return this.sessionSet(this.methodSessionVideoFree(i),t)}sessionAudioCaption(t,i){return this.sessionSet(this.methodSessionAudioCaption(i),t)}sessionAudioCaptionPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionPayload(i),t)}sessionAudioCaptionCommand(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommand(i),t)}sessionAudioCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(i),t)}sessionAudioFree(t,i){return this.sessionSet(this.methodSessionAudioFree(i),t)}sessionDocumentCaption(t,i){return this.sessionSet(this.methodSessionDocumentCaption(i),t)}sessionDocumentCaptionPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionPayload(i),t)}sessionDocumentCaptionCommand(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommand(i),t)}sessionDocumentCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(i),t)}sessionDocumentFree(t,i){return this.sessionSet(this.methodSessionDocumentFree(i),t)}sessionAnimationCaption(t,i){return this.sessionSet(this.methodSessionAnimationCaption(i),t)}sessionAnimationCaptionPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionPayload(i),t)}sessionAnimationCaptionCommand(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommand(i),t)}sessionAnimationCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(i),t)}sessionAnimationFree(t,i){return this.sessionSet(this.methodSessionAnimationFree(i),t)}sessionVoiceCaption(t,i){return this.sessionSet(this.methodSessionVoiceCaption(i),t)}sessionVoiceCaptionPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionPayload(i),t)}sessionVoiceCaptionCommand(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommand(i),t)}sessionVoiceCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(i),t)}sessionVoiceFree(t,i){return this.sessionSet(this.methodSessionVoiceFree(i),t)}sessionVideoNoteCaption(t,i){return this.sessionSet(this.methodSessionVideoNoteCaption(i),t)}sessionVideoNoteCaptionPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(i),t)}sessionVideoNoteCaptionCommand(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(i),t)}sessionVideoNoteCaptionCommandPayload(t,i){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(i),t)}sessionVideoNoteFree(t,i){return this.sessionSet(this.methodSessionVideoNoteFree(i),t)}sessionStickerFree(t,i){return this.sessionSet(this.methodSessionStickerFree(i),t)}sessionLocationFree(t,i){return this.sessionSet(this.methodSessionLocationFree(i),t)}sessionContactFree(t,i){return this.sessionSet(this.methodSessionContactFree(i),t)}sessionToCallback(t,i){return this.sessionCallback({...this.session.params,...t},i)}sessionToCallbackPayload(t,i){return this.sessionCallbackPayload({...this.session.params,...t},i)}sessionToText(t,i){return this.sessionText({...this.session.params,...t},i)}sessionToTextPayload(t,i){return this.sessionTextPayload({...this.session.params,...t},i)}sessionToTextCommand(t,i){return this.sessionTextCommand({...this.session.params,...t},i)}sessionToTextCommandPayload(t,i){return this.sessionTextCommandPayload({...this.session.params,...t},i)}sessionToTextFree(t,i){return this.sessionTextFree({...this.session.params,...t},i)}sessionToPhotoCaption(t,i){return this.sessionPhotoCaption({...this.session.params,...t},i)}sessionToPhotoCaptionPayload(t,i){return this.sessionPhotoCaptionPayload({...this.session.params,...t},i)}sessionToPhotoCaptionCommand(t,i){return this.sessionPhotoCaptionCommand({...this.session.params,...t},i)}sessionToPhotoCaptionCommandPayload(t,i){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},i)}sessionToPhotoFree(t,i){return this.sessionPhotoFree({...this.session.params,...t},i)}sessionToVideoCaption(t,i){return this.sessionVideoCaption({...this.session.params,...t},i)}sessionToVideoCaptionPayload(t,i){return this.sessionVideoCaptionPayload({...this.session.params,...t},i)}sessionToVideoCaptionCommand(t,i){return this.sessionVideoCaptionCommand({...this.session.params,...t},i)}sessionToVideoCaptionCommandPayload(t,i){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoFree(t,i){return this.sessionVideoFree({...this.session.params,...t},i)}sessionToAudioCaption(t,i){return this.sessionAudioCaption({...this.session.params,...t},i)}sessionToAudioCaptionPayload(t,i){return this.sessionAudioCaptionPayload({...this.session.params,...t},i)}sessionToAudioCaptionCommand(t,i){return this.sessionAudioCaptionCommand({...this.session.params,...t},i)}sessionToAudioCaptionCommandPayload(t,i){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},i)}sessionToAudioFree(t,i){return this.sessionAudioFree({...this.session.params,...t},i)}sessionToDocumentCaption(t,i){return this.sessionDocumentCaption({...this.session.params,...t},i)}sessionToDocumentCaptionPayload(t,i){return this.sessionDocumentCaptionPayload({...this.session.params,...t},i)}sessionToDocumentCaptionCommand(t,i){return this.sessionDocumentCaptionCommand({...this.session.params,...t},i)}sessionToDocumentCaptionCommandPayload(t,i){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},i)}sessionToDocumentFree(t,i){return this.sessionDocumentFree({...this.session.params,...t},i)}sessionToAnimationCaption(t,i){return this.sessionAnimationCaption({...this.session.params,...t},i)}sessionToAnimationCaptionPayload(t,i){return this.sessionAnimationCaptionPayload({...this.session.params,...t},i)}sessionToAnimationCaptionCommand(t,i){return this.sessionAnimationCaptionCommand({...this.session.params,...t},i)}sessionToAnimationCaptionCommandPayload(t,i){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},i)}sessionToAnimationFree(t,i){return this.sessionAnimationFree({...this.session.params,...t},i)}sessionToVoiceCaption(t,i){return this.sessionVoiceCaption({...this.session.params,...t},i)}sessionToVoiceCaptionPayload(t,i){return this.sessionVoiceCaptionPayload({...this.session.params,...t},i)}sessionToVoiceCaptionCommand(t,i){return this.sessionVoiceCaptionCommand({...this.session.params,...t},i)}sessionToVoiceCaptionCommandPayload(t,i){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},i)}sessionToVoiceFree(t,i){return this.sessionVoiceFree({...this.session.params,...t},i)}sessionToVideoNoteCaption(t,i){return this.sessionVideoNoteCaption({...this.session.params,...t},i)}sessionToVideoNoteCaptionPayload(t,i){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommand(t,i){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},i)}sessionToVideoNoteCaptionCommandPayload(t,i){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},i)}sessionToVideoNoteFree(t,i){return this.sessionVideoNoteFree({...this.session.params,...t},i)}sessionToStickerFree(t,i){return this.sessionStickerFree({...this.session.params,...t},i)}sessionToLocationFree(t,i){return this.sessionLocationFree({...this.session.params,...t},i)}sessionToContactFree(t,i){return this.sessionContactFree({...this.session.params,...t},i)}buildIntent(t,i=!0){t||(t=i?this.data.callbackData():this.data.name);let e=i?":":" ";return t?.indexOf?.(e)!=-1?t?.split?.(e)?.[0]:t}methodSession(t,i){return`${t}-${i||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};import{serve as J}from"bun";import{join as T,parse as q}from"path";import{LoggingPretty as X}from"logging-pretty";var b=class{static{u(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(i,e)=>`\${(data && data["${e}"]) ?? ""}`)}static _processBaseBlocks(t){let i=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,e={};for(let s of t.matchAll(i)){let o=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[o]=a}return e}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(i,e)=>{let s=e.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(i,e)=>e.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let i=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,e={};for(let s of t.matchAll(i)){let o=s[1],n=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let g of o.matchAll(r))a[g[1]]=g[2];if(!a.lang)continue;let c=a.lang,d=a.type,l=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),p={type:d};a.src&&(p.src=a.src),l&&d!=="video_note"&&d!=="sticker"&&(p.caption=l),d==="location"&&(a.latitude&&(p.latitude=a.latitude),a.longitude&&(p.longitude=a.longitude),l&&(p.caption=l)),d==="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),l&&(p.caption=l)),e[c]=p}return e}static _processMessageBlocks(t){let i=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,e={};for(let[,s,o]of t.matchAll(i)){let n=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();e[s]=n}return e}static _processKeyboardBlocks(t){let i=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,e={};for(let[,s,o,n]of t.matchAll(i)){let a=o==="bottom"?"bottom":"inline",r=n.trim();e[s]||(e[s]={}),e[s][a]=r}return e}static _compileToFunction(t,i){let e;i?e=t.map(n=>`\`${n}\``).join(","):e=`\`${t}\``;let s=e;if(s=this._processScriptBlocks(this._processDivBlocks(this._processSpaceBlocks(s))),i){let o=`return [${s}]`;return new Function("data",o)}else{let o=`return ${s}`;return new Function("data",o)}}static compileMedia(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMediaBlocks(o);e[s]={};for(let[a,r]of Object.entries(n))if(r.caption){let c=this._processVariables(this._processScriptBlocks(r.caption)),d=this._compileToFunction(c,!1);e[s][a]=l=>({...r,caption:d(l)})}else e[s][a]=()=>r}return e}static compileMessages(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processMessageBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){let c=this._processVariables(this._processScriptBlocks(r));e[s][a]=this._compileToFunction(c,!1)}}return e}static compileKeyboards(t){let i=this._processBaseBlocks(t),e={};for(let[s,o]of Object.entries(i)){let n=this._processKeyboardBlocks(o);e[s]={};for(let[a,r]of Object.entries(n)){e[s][a]={};for(let[c,d]of Object.entries(r)){let p=d.split(/(?<!\\),\s*/).map(g=>g.replace(/\\,/g,",").trim()).map(g=>this._processVariables(this._processScriptBlocks(g)));e[s][a][c]=this._compileToFunction(p,!0)}}}return e}};var f=class{static{u(this,"HelperPage")}static _getPage(t,i,e=!0){let o=Object.values(t)[0];if(o===void 0)throw new Error(`File ${i} must have export (not default) class page`);return e===!0&&(o.template=void 0),o}static getPageSync(t,i=!0){let e=M(t);return this._getPage(e,t,i)}static async getPage(t,i=!0){let e=await import(`${t}?t=${Date.now()}`);return this._getPage(e,t,i)}};import{readFile as W}from"fs/promises";import{watch as j}from"chokidar";import{basename as x,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 v=class{static{u(this,"TemplateManager")}_map=new Map;_engine=b;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:i,enableWatch:e=!1,forceLanguage:s}=t;this._path=i,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 t=0;t<this._path.length;t++){let i=this._path[t];if(!D(i))throw new Error(`Template base path is not exists: ${i}`);if(!H(i).isDirectory())throw new Error(`Template base path is not a directory: ${i}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let i=this._path[t],e=j(i,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=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(t){let i=x(t);this._isValidFile(i)&&await this._loadFile(i,!1)}async _handleFileAdd(t){let i=x(t);this._isValidFile(i)&&await this._loadFile(i,!1)}_handleFileDelete(t){let i=x(t),e=this._getKey(i);this._map.has(e)&&this._map.delete(e)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let i=this._path[t],s=z(i,"utf8").filter(o=>this._isValidFile(o));for(let o of s)this._loadFile(o,!0)}}async _loadFile(t,i=!0){for(let e=0;e<this._path.length;e++){let s=this._path[e],o=_(s,t),n=this._getExtension(t),a=this._getKey(t);if(n==".html"){let r=i?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 ${t} is not support`)}}_getExtension(t){return Q(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,i,e){let s=this._map.get(t),o=s||{},n=!1;(e===void 0||e?.media===!1||s?.media===void 0)&&(o.media=b.compileMedia(i),n=!0),(e===void 0||e?.message===!1||s?.message===void 0)&&(o.message=b.compileMessages(i),n=!0),(e===void 0||e?.keyboard===!1||s?.keyboard===void 0)&&(o.keyboard=b.compileKeyboards(i),n=!0),n&&this._map.set(t,o)}getMedia(t,i="default",e="en",s){let n=this._map.get(t)?.media?.[i]?.[this._forceLanguage||e];if(!n)return{};try{return n(s)}catch{return{}}}getMessage(t,i="default",e="en",s){let n=this._map.get(t)?.message?.[i]?.[this._forceLanguage||e];if(!n)return"";try{return n(s)}catch{return""}}getKeyboard(t,i="default",e="en",s="inline",o){let a=this._map.get(t)?.keyboard?.[i]?.[this._forceLanguage||e]?.[s];if(!a)return[];try{return a(o)}catch{return[]}}async write(t,i){if(this._getExtension(t)!=".html")return null;for(let e=0;e<this._path.length;e++){let s=_(this._path[e],t);if(D(s))return U(s,i,"utf8"),await this._loadFile(t,!1),!0}return null}getAvailable(){return Array.from(this._map.keys())}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,i)=>typeof i=="function"?i.toString():i).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{existsSync as Y,readdirSync as Z}from"fs";import{Bot as tt,webhookCallback as it}from"grammy";var A=class{static{u(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===null?void 0:t.log===void 0?new X:t.log,this.cacheSession=t.cacheSession||new S("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new v({path:[T(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.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()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook")&&this.runWebhook(t.deploy.split("webhook:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,i,e){let{username:s}=t;i=="polling"?this.log?.success?.(`Telegram bot polling started: ${s}`):this.log?.success?.(`Telegram bot webhook started: ${s} (${e})`)}createBot(t){return new tt(t)}createCtx(t){return new P({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:u(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let i=it(this.bot,"bun"),e="/telegram-webhook";J({fetch(a){let{pathname:r}=new URL(a.url);if(r===e)return a.method==="POST"?i(a):new Response("OK",{status:200});if(r==="/"&&a.method==="GET"){let c=new Date().toISOString();return new Response(JSON.stringify({timestamp:c}),{status:200,headers:{"Content-Type":"application/json"}})}return new Response("Not found",{status:404})}});let s=await this.bot.api.getWebhookInfo(),o=t.endsWith("/")?t.slice(0,-1)+e:t+e;s.url!=o&&await this.bot.api.setWebhook(o);let n=await this.bot.api.getMe();this.onStart(n,"webhook",o)}pageBuildData(t,i){t?.data===void 0&&(t.data=t.buildData()),t.data.name=q(i).name}pageSorts(t,i){let e=t.data.name,s=t.prototype,o="Payload",n="Command",a="Caption",r="Free",c=i.dynamic,d=i.dynamicSpesific,l=u(h=>h.charAt(0).toUpperCase()+h.slice(1),"upFirst"),p=u(h=>h.replace(o,"").replace(n,"").replace(a,"").replace(r,""),"getPureFuncName"),g=u((h,y)=>s[`methodSession${l(h)}`](y),"methodSession");i.all[e]=t;for(let h=0;h<i.lenListFuncStaticSession;h++){let y=i.listFuncStaticSession[h],O=i.static[y],R=i.staticIntent[y],k=i.staticSession[y],I={name:e,func:y},F=O||R;if(F!==void 0){let K=y.includes(n)?`/${e}`:e;F[s.buildIntent(K,y.startsWith("callback"))]=I}k!==void 0&&(k[g(y,e)]=I),y.toLowerCase().endsWith("free")&&d[p(y)].push(I)}s.free&&c.push(e)}pageLoads(){this.log?.info?.("Load pages..");let t=T(process.cwd(),"src","pages");if(!Y(t))throw new Error(`Directory ${t} is not found, please make it manually`);let i=Z(t),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"],c=[...a,...r,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],d=u((p,g)=>Object.fromEntries(p.map(h=>[h,{...g}])),"makeObject"),l={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:d(a,e),staticIntent:d(r,s),staticSession:d(c,o),listFuncStatic:a,listFuncStaticIntent:r,listFuncStaticSession:c,lenListFuncStatic:a.length,lenListFuncStaticIntent:r.length,lenListFuncStaticSession:c.length};for(let p of i){let g=T(t,p),h=f.getPageSync(g,!0);this.pageBuildData(h,g),this.pageSorts(h,l)}return this.log?.info?.(`Finish load pages with total (${Object.keys(l.all).length})`),l}async pageRoutes(t,i){let e,s;if(e===void 0){let n=t.callbackData,a=t.msgText,r=t.msgCaption,c=this.pages.static;for(let d=0;d<this.pages.lenListFuncStatic;d++){let l=this.pages.listFuncStatic[d];if(s=c[l][n||a||r],s)break}s!==void 0&&(e=this.pages.all[s.name])}if(e===void 0){let n=await t.sessionGet();if(n){let a=n.method,r=this.pages.staticSession;for(let c=0;c<this.pages.lenListFuncStaticSession;c++){let d=this.pages.listFuncStaticSession[c];if(s=r[d][a],s)break}s!==void 0&&(e=this.pages.all[s.name])}}if(e===void 0){let n=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,c=this.pages.staticIntent;for(let d=0;d<this.pages.lenListFuncStaticIntent;d++){let l=this.pages.listFuncStaticIntent[d];if(s=c[l][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(t)[s.func]?.();let o=this.pages.dynamicSpesific[i]||[];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 d=await new r(t)[a.name]?.();if(d!==null)return d}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 d=await new r(t).free?.();if(d!==null)return d}return null}async hookBeforeRoute(t,i){return!0}async hookErrorPage(t,i,e,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,i){let e=this.createCtx(t);try{if(await this.hookBeforeRoute(e,i)===!1)return;await this.pageRoutes(e,i)===null&&await this.hookErrorInputNotFoundPage(e)}catch(s){await this.hookErrorPage(e,i,s,!1)}}async onCallbackQueryData(t){let i=this.createCtx(t);try{if(await i.callbackQueryAnswer(),await this.hookBeforeRoute(i,"onCallbackQueryData")===!1)return;await this.pageRoutes(i,"callback")}catch(e){await this.hookErrorPage(i,"onCallbackQueryData",e,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,A as Gramstax,b as TemplateEngine,v as TemplateManager};
1
+ var B=Object.defineProperty;var p=(g,t)=>B(g,"name",{value:t,configurable:!0}),k=(g=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(g,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):g)(function(g){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+g+'" is not supported')});import{LoggingPretty as E}from"logging-pretty";var C=class{static{p(this,"BaseGeneral")}static log=new E;static logError(t,e){this.log.error(`[${this.toString().match(/class\s+([^\s{]+)/)?.[1]}:${e}]: ${String(t)}`)}logError(t,e,i){this.constructor.log.error(`[${e||this.constructor.name}:${i}] ${String(t)}`)}};import{Keyv as $}from"keyv";import L from"@keyv/redis";var S=class extends ${constructor(e="memory",i,s,n){let o;e.startsWith("redis")&&(o=new L(e)),e==="memory"&&(o=new Map),n?.forceStore&&(o=n.forceStore);super({store:o,namespace:i,ttl:s});this.url=e}static{p(this,"CacheExternal")}};import{setTimeout as W}from"timers/promises";import{InlineKeyboard as F,Keyboard as w}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(t){this.ct.from.language_code=t}set session(t){this.temp.session=t}get session(){return this.temp.session}ct;cacheSession;cacheKeyboard;templateManager;temp;constructor(t){super(),this.ct=t.ct,this.cacheSession=t.cacheSession,this.cacheKeyboard=t.cacheKeyboard,this.templateManager=t.templateManager,this.temp=t.temp,t?.data&&(this.temp.data=t.data)}async broadcast(t,e,i,s,n,o){let r=e.map(d=>this.templateManager.getMessage(this.data.name,n,d,s));for(let d=0;d<t.length;d++){let c=t[d],l=r[d];await this.ct.api.sendMessage(c,l,{parse_mode:"HTML",reply_markup:i,...o}),d+1==30&&await W(1200)}}async reply(t,e,i,s){let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.reply(n,{parse_mode:"HTML",reply_markup:t,...s})}async replyMedia(t,e,i,s,n){let o=this.templateManager.getMedia(this.data.name,s,this.languageCode,i),a={parse_mode:"HTML",reply_markup:e,...n};if(t=="photo")return await this.ct.replyWithPhoto(o.src,{caption:o.caption,...a});if(t=="video")return await this.ct.replyWithVideo(o.src,{caption:o.caption,...a});if(t=="audio")return await this.ct.replyWithAudio(o.src,{caption:o.caption,...a});if(t=="document")return await this.ct.replyWithDocument(o.src,{caption:o.caption,...a});if(t=="animation")return await this.ct.replyWithAnimation(o.src,{caption:o.caption,...a});if(t=="voice")return await this.ct.replyWithVoice(o.src,a);if(t=="video_note")return await this.ct.replyWithVideoNote(o.src,a);if(t=="sticker")return await this.ct.replyWithSticker(o.src,a);if(t=="location")return await this.ct.replyWithLocation(o.latitude,o.longitude,a);if(t=="contact")return await this.ct.replyWithContact(o.phone,o.first_name,{vcard:o.vcard,...a})}async replyPhoto(t,e,i,s){return this.replyMedia("photo",t,e,i,s)}async replyVideo(t,e,i,s){return this.replyMedia("video",t,e,i,s)}async replyAudio(t,e,i,s){return this.replyMedia("audio",t,e,i,s)}async replyDocument(t,e,i,s){return this.replyMedia("document",t,e,i,s)}async replyAnimation(t,e,i,s){return this.replyMedia("animation",t,e,i,s)}async replyVoice(t,e,i,s){return this.replyMedia("voice",t,e,i,s)}async replyVideoNote(t,e,i,s){return this.replyMedia("video_note",t,e,i,s)}async replySticker(t,e,i,s){return this.replyMedia("sticker",t,e,i,s)}async replyLocation(t,e,i,s){return this.replyMedia("location",t,e,i,s)}async replyContact(t,e,i,s){return this.replyMedia("contact",t,e,i,s)}async replyAction(t){return await this.ct.replyWithChatAction(t)}async edit(t,e,i,s){try{let n=this.templateManager.getMessage(this.data.name,i,this.languageCode,e);return await this.ct.editMessageText(n,{parse_mode:"HTML",reply_markup:t,...s})}catch{await this.reply(t,e,i,s)}}async editMedia(t,e,i,s,n,o){try{let{src:a,caption:r}=this.templateManager.getMedia(this.data.name,s,this.languageCode,i);return t=="voice"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="video_note"?(await this.delete(),await this.replyVoice(e,i,s,n)):t=="sticker"?(await this.delete(),await this.replySticker(e,i,s,n)):t=="location"?(await this.delete(),await this.replyLocation(e,i,s,n)):t=="contact"?(await this.delete(),await this.replyContact(e,i,s,n)):await this.ct.editMessageMedia({media:a,caption:r,type:t,parse_mode:"HTML",...n},{reply_markup:e,...o})}catch{await this.reply(e,i,s,o)}}async editPhoto(t,e,i,s,n){return await this.editMedia("photo",t,e,i,s,n)}async editVideo(t,e,i,s,n){return await this.editMedia("video",t,e,i,s,n)}async editAudio(t,e,i,s,n){return await this.editMedia("audio",t,e,i,s,n)}async editDocument(t,e,i,s,n){return await this.editMedia("document",t,e,i,s,n)}async editAnimation(t,e,i,s,n){return await this.editMedia("animation",t,e,i,s,n)}async editVoice(t,e,i,s){return await this.editMedia("voice",t,e,i,s)}async editVideoNote(t,e,i,s){return await this.editMedia("video_note",t,e,i,s)}async editSticker(t,e,i,s){return await this.editMedia("sticker",t,e,i,s)}async editLocation(t,e,i,s){return await this.editMedia("location",t,e,i,s)}async editContact(t,e,i,s){return await this.editMedia("contact",t,e,i,s)}async delete(){return await this.ct.deleteMessage()}async callbackQueryAnswer(t){try{return await this.ct.answerCallbackQuery(t)}catch{return null}}async sessionSet(t,e,i){try{let s={method:t,params:e,...i},n=await this.cacheSession.set(`${this.userid}`,s);return n&&(this.session=s),n}catch{return null}}async sessionGet(){try{let t=await this.cacheSession.get(`${this.userid}`);return t&&(this.session=t),t||null}catch{return null}}async sessionClear(){try{let t=await this.cacheSession.delete(`${this.userid}`);return t&&(this.session={}),t}catch{return null}}static buildData(t){return{name:"",callbackData:t?function(...e){let i=t(...e);return`${this.name}${i===void 0?"":`:${i}`}`}:function(){return this?.name}}}inlineKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:i`,r=this.cacheKeyboard.get(a);if(!r){let d=new F,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data),l=t(d,c);return this.cacheKeyboard.set(a,l),l}return r}let s=new F,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"inline",e?.data);return t(s,n)}bottomKeyboard(t,e){let i=this.data.name;if(e?.cache===!0){let a=`${i}:${this.languageCode}:b`,r=this.cacheKeyboard.get(a);if(!r){let d=new w,c=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),l=t(d,c);return l.resized(!0),this.cacheKeyboard.set(a,l),l}return r}let s=new w,n=this.templateManager.getKeyboard(i,e?.baseId,this.languageCode,"bottom",e?.data),o=t(s,n);return o.resized(),o}validateSessionCallback(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallback(e)}validateSessionCallbackPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionCallbackPayload(e)}validateSessionText(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionText(e)}validateSessionTextPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextPayload(e)}validateSessionTextCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommand(e)}validateSessionTextCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextCommandPayload(e)}validateSessionTextFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionTextFree(e)}validateSessionPhotoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaption(e)}validateSessionPhotoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionPayload(e)}validateSessionPhotoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommand(e)}validateSessionPhotoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoCaptionCommandPayload(e)}validateSessionPhotoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionPhotoFree(e)}validateSessionVideoCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaption(e)}validateSessionVideoCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionPayload(e)}validateSessionVideoCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommand(e)}validateSessionVideoCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoCaptionCommandPayload(e)}validateSessionVideoFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoFree(e)}validateSessionAudioCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaption(e)}validateSessionAudioCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionPayload(e)}validateSessionAudioCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommand(e)}validateSessionAudioCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioCaptionCommandPayload(e)}validateSessionAudioFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAudioFree(e)}validateSessionDocumentCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaption(e)}validateSessionDocumentCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionPayload(e)}validateSessionDocumentCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommand(e)}validateSessionDocumentCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentCaptionCommandPayload(e)}validateSessionDocumentFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionDocumentFree(e)}validateSessionAnimationCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaption(e)}validateSessionAnimationCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionPayload(e)}validateSessionAnimationCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommand(e)}validateSessionAnimationCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationCaptionCommandPayload(e)}validateSessionAnimationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionAnimationFree(e)}validateSessionVoiceCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaption(e)}validateSessionVoiceCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionPayload(e)}validateSessionVoiceCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommand(e)}validateSessionVoiceCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceCaptionCommandPayload(e)}validateSessionVoiceFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVoiceFree(e)}validateSessionVideoNoteCaption(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaption(e)}validateSessionVideoNoteCaptionPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionPayload(e)}validateSessionVideoNoteCaptionCommand(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommand(e)}validateSessionVideoNoteCaptionCommandPayload(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteCaptionCommandPayload(e)}validateSessionVideoNoteFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionVideoNoteFree(e)}validateSessionStickerFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionStickerFree(e)}validateSessionLocationFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionLocationFree(e)}validateSessionContactFree(t,e){return t===void 0&&(t=this.session.method),t===void 0?!1:t===this.methodSessionContactFree(e)}sessionCallback(t,e){return this.sessionSet(this.methodSessionCallback(e),t)}sessionCallbackPayload(t,e){return this.sessionSet(this.methodSessionCallbackPayload(e),t)}sessionText(t,e){return this.sessionSet(this.methodSessionText(e),t)}sessionTextPayload(t,e){return this.sessionSet(this.methodSessionTextPayload(e),t)}sessionTextCommand(t,e){return this.sessionSet(this.methodSessionTextCommand(e),t)}sessionTextCommandPayload(t,e){return this.sessionSet(this.methodSessionTextCommandPayload(e),t)}sessionTextFree(t,e){return this.sessionSet(this.methodSessionTextFree(e),t)}sessionPhotoCaption(t,e){return this.sessionSet(this.methodSessionPhotoCaption(e),t)}sessionPhotoCaptionPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionPayload(e),t)}sessionPhotoCaptionCommand(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommand(e),t)}sessionPhotoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionPhotoCaptionCommandPayload(e),t)}sessionPhotoFree(t,e){return this.sessionSet(this.methodSessionPhotoFree(e),t)}sessionVideoCaption(t,e){return this.sessionSet(this.methodSessionVideoCaption(e),t)}sessionVideoCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionPayload(e),t)}sessionVideoCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommand(e),t)}sessionVideoCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoCaptionCommandPayload(e),t)}sessionVideoFree(t,e){return this.sessionSet(this.methodSessionVideoFree(e),t)}sessionAudioCaption(t,e){return this.sessionSet(this.methodSessionAudioCaption(e),t)}sessionAudioCaptionPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionPayload(e),t)}sessionAudioCaptionCommand(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommand(e),t)}sessionAudioCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAudioCaptionCommandPayload(e),t)}sessionAudioFree(t,e){return this.sessionSet(this.methodSessionAudioFree(e),t)}sessionDocumentCaption(t,e){return this.sessionSet(this.methodSessionDocumentCaption(e),t)}sessionDocumentCaptionPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionPayload(e),t)}sessionDocumentCaptionCommand(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommand(e),t)}sessionDocumentCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionDocumentCaptionCommandPayload(e),t)}sessionDocumentFree(t,e){return this.sessionSet(this.methodSessionDocumentFree(e),t)}sessionAnimationCaption(t,e){return this.sessionSet(this.methodSessionAnimationCaption(e),t)}sessionAnimationCaptionPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionPayload(e),t)}sessionAnimationCaptionCommand(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommand(e),t)}sessionAnimationCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionAnimationCaptionCommandPayload(e),t)}sessionAnimationFree(t,e){return this.sessionSet(this.methodSessionAnimationFree(e),t)}sessionVoiceCaption(t,e){return this.sessionSet(this.methodSessionVoiceCaption(e),t)}sessionVoiceCaptionPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionPayload(e),t)}sessionVoiceCaptionCommand(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommand(e),t)}sessionVoiceCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVoiceCaptionCommandPayload(e),t)}sessionVoiceFree(t,e){return this.sessionSet(this.methodSessionVoiceFree(e),t)}sessionVideoNoteCaption(t,e){return this.sessionSet(this.methodSessionVideoNoteCaption(e),t)}sessionVideoNoteCaptionPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionPayload(e),t)}sessionVideoNoteCaptionCommand(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommand(e),t)}sessionVideoNoteCaptionCommandPayload(t,e){return this.sessionSet(this.methodSessionVideoNoteCaptionCommandPayload(e),t)}sessionVideoNoteFree(t,e){return this.sessionSet(this.methodSessionVideoNoteFree(e),t)}sessionStickerFree(t,e){return this.sessionSet(this.methodSessionStickerFree(e),t)}sessionLocationFree(t,e){return this.sessionSet(this.methodSessionLocationFree(e),t)}sessionContactFree(t,e){return this.sessionSet(this.methodSessionContactFree(e),t)}sessionToCallback(t,e){return this.sessionCallback({...this.session.params,...t},e)}sessionToCallbackPayload(t,e){return this.sessionCallbackPayload({...this.session.params,...t},e)}sessionToText(t,e){return this.sessionText({...this.session.params,...t},e)}sessionToTextPayload(t,e){return this.sessionTextPayload({...this.session.params,...t},e)}sessionToTextCommand(t,e){return this.sessionTextCommand({...this.session.params,...t},e)}sessionToTextCommandPayload(t,e){return this.sessionTextCommandPayload({...this.session.params,...t},e)}sessionToTextFree(t,e){return this.sessionTextFree({...this.session.params,...t},e)}sessionToPhotoCaption(t,e){return this.sessionPhotoCaption({...this.session.params,...t},e)}sessionToPhotoCaptionPayload(t,e){return this.sessionPhotoCaptionPayload({...this.session.params,...t},e)}sessionToPhotoCaptionCommand(t,e){return this.sessionPhotoCaptionCommand({...this.session.params,...t},e)}sessionToPhotoCaptionCommandPayload(t,e){return this.sessionPhotoCaptionCommandPayload({...this.session.params,...t},e)}sessionToPhotoFree(t,e){return this.sessionPhotoFree({...this.session.params,...t},e)}sessionToVideoCaption(t,e){return this.sessionVideoCaption({...this.session.params,...t},e)}sessionToVideoCaptionPayload(t,e){return this.sessionVideoCaptionPayload({...this.session.params,...t},e)}sessionToVideoCaptionCommand(t,e){return this.sessionVideoCaptionCommand({...this.session.params,...t},e)}sessionToVideoCaptionCommandPayload(t,e){return this.sessionVideoCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoFree(t,e){return this.sessionVideoFree({...this.session.params,...t},e)}sessionToAudioCaption(t,e){return this.sessionAudioCaption({...this.session.params,...t},e)}sessionToAudioCaptionPayload(t,e){return this.sessionAudioCaptionPayload({...this.session.params,...t},e)}sessionToAudioCaptionCommand(t,e){return this.sessionAudioCaptionCommand({...this.session.params,...t},e)}sessionToAudioCaptionCommandPayload(t,e){return this.sessionAudioCaptionCommandPayload({...this.session.params,...t},e)}sessionToAudioFree(t,e){return this.sessionAudioFree({...this.session.params,...t},e)}sessionToDocumentCaption(t,e){return this.sessionDocumentCaption({...this.session.params,...t},e)}sessionToDocumentCaptionPayload(t,e){return this.sessionDocumentCaptionPayload({...this.session.params,...t},e)}sessionToDocumentCaptionCommand(t,e){return this.sessionDocumentCaptionCommand({...this.session.params,...t},e)}sessionToDocumentCaptionCommandPayload(t,e){return this.sessionDocumentCaptionCommandPayload({...this.session.params,...t},e)}sessionToDocumentFree(t,e){return this.sessionDocumentFree({...this.session.params,...t},e)}sessionToAnimationCaption(t,e){return this.sessionAnimationCaption({...this.session.params,...t},e)}sessionToAnimationCaptionPayload(t,e){return this.sessionAnimationCaptionPayload({...this.session.params,...t},e)}sessionToAnimationCaptionCommand(t,e){return this.sessionAnimationCaptionCommand({...this.session.params,...t},e)}sessionToAnimationCaptionCommandPayload(t,e){return this.sessionAnimationCaptionCommandPayload({...this.session.params,...t},e)}sessionToAnimationFree(t,e){return this.sessionAnimationFree({...this.session.params,...t},e)}sessionToVoiceCaption(t,e){return this.sessionVoiceCaption({...this.session.params,...t},e)}sessionToVoiceCaptionPayload(t,e){return this.sessionVoiceCaptionPayload({...this.session.params,...t},e)}sessionToVoiceCaptionCommand(t,e){return this.sessionVoiceCaptionCommand({...this.session.params,...t},e)}sessionToVoiceCaptionCommandPayload(t,e){return this.sessionVoiceCaptionCommandPayload({...this.session.params,...t},e)}sessionToVoiceFree(t,e){return this.sessionVoiceFree({...this.session.params,...t},e)}sessionToVideoNoteCaption(t,e){return this.sessionVideoNoteCaption({...this.session.params,...t},e)}sessionToVideoNoteCaptionPayload(t,e){return this.sessionVideoNoteCaptionPayload({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommand(t,e){return this.sessionVideoNoteCaptionCommand({...this.session.params,...t},e)}sessionToVideoNoteCaptionCommandPayload(t,e){return this.sessionVideoNoteCaptionCommandPayload({...this.session.params,...t},e)}sessionToVideoNoteFree(t,e){return this.sessionVideoNoteFree({...this.session.params,...t},e)}sessionToStickerFree(t,e){return this.sessionStickerFree({...this.session.params,...t},e)}sessionToLocationFree(t,e){return this.sessionLocationFree({...this.session.params,...t},e)}sessionToContactFree(t,e){return this.sessionContactFree({...this.session.params,...t},e)}intent(t,e=!0){t||(t=e?this.data.callbackData():this.data.name);let i=e?":":" ";return t?.indexOf?.(i)!=-1?t?.split?.(i)?.[0]:t}methodSession(t,e){return`${t}-${e||this.data.name}`}methodSessionCallback(t){return this.methodSession("1",t)}methodSessionCallbackPayload(t){return this.methodSession("2",t)}methodSessionText(t){return this.methodSession("3",t)}methodSessionTextPayload(t){return this.methodSession("4",t)}methodSessionTextCommand(t){return this.methodSession("5",t)}methodSessionTextCommandPayload(t){return this.methodSession("6",t)}methodSessionTextFree(t){return this.methodSession("7",t)}methodSessionPhotoCaption(t){return this.methodSession("8",t)}methodSessionPhotoCaptionPayload(t){return this.methodSession("9",t)}methodSessionPhotoCaptionCommand(t){return this.methodSession("10",t)}methodSessionPhotoCaptionCommandPayload(t){return this.methodSession("11",t)}methodSessionPhotoFree(t){return this.methodSession("12",t)}methodSessionVideoCaption(t){return this.methodSession("13",t)}methodSessionVideoCaptionPayload(t){return this.methodSession("14",t)}methodSessionVideoCaptionCommand(t){return this.methodSession("15",t)}methodSessionVideoCaptionCommandPayload(t){return this.methodSession("16",t)}methodSessionVideoFree(t){return this.methodSession("17",t)}methodSessionAudioCaption(t){return this.methodSession("18",t)}methodSessionAudioCaptionPayload(t){return this.methodSession("19",t)}methodSessionAudioCaptionCommand(t){return this.methodSession("20",t)}methodSessionAudioCaptionCommandPayload(t){return this.methodSession("21",t)}methodSessionAudioFree(t){return this.methodSession("22",t)}methodSessionDocumentCaption(t){return this.methodSession("23",t)}methodSessionDocumentCaptionPayload(t){return this.methodSession("24",t)}methodSessionDocumentCaptionCommand(t){return this.methodSession("25",t)}methodSessionDocumentCaptionCommandPayload(t){return this.methodSession("26",t)}methodSessionDocumentFree(t){return this.methodSession("27",t)}methodSessionAnimationCaption(t){return this.methodSession("28",t)}methodSessionAnimationCaptionPayload(t){return this.methodSession("29",t)}methodSessionAnimationCaptionCommand(t){return this.methodSession("30",t)}methodSessionAnimationCaptionCommandPayload(t){return this.methodSession("31",t)}methodSessionAnimationFree(t){return this.methodSession("32",t)}methodSessionVoiceCaption(t){return this.methodSession("33",t)}methodSessionVoiceCaptionPayload(t){return this.methodSession("34",t)}methodSessionVoiceCaptionCommand(t){return this.methodSession("35",t)}methodSessionVoiceCaptionCommandPayload(t){return this.methodSession("36",t)}methodSessionVoiceFree(t){return this.methodSession("37",t)}methodSessionVideoNoteCaption(t){return this.methodSession("38",t)}methodSessionVideoNoteCaptionPayload(t){return this.methodSession("39",t)}methodSessionVideoNoteCaptionCommand(t){return this.methodSession("40",t)}methodSessionVideoNoteCaptionCommandPayload(t){return this.methodSession("41",t)}methodSessionVideoNoteFree(t){return this.methodSession("42",t)}methodSessionStickerFree(t){return this.methodSession("43",t)}methodSessionLocationFree(t){return this.methodSession("44",t)}methodSessionContactFree(t){return this.methodSession("45",t)}};import{serve as Y}from"bun";import{join as _}from"path";import{existsSync as j,readdirSync as Q}from"fs";var f=class{static{p(this,"HelperPage")}static getPath(){return _(process.cwd(),"src","pages")}static _getPage(t,e,i=!0){let n=Object.values(t)[0];if(n===void 0)throw new Error(`File ${e} must have export (not default) class page`);return i===!0&&(n.template=void 0),n}static getPageSync(t,e=!0){t||(t=this.getPath());let i=k(t);return this._getPage(i,t,e)}static async getPage(t,e=!0){t||(t=this.getPath());let i=await import(`${t}?t=${Date.now()}`);return this._getPage(i,t,e)}static getPagesSync(t,e=!0){if(t||(t=this.getPath()),!j(t))throw new Error(`Directory ${t} is not found, please make it manually`);return Q(t).map(s=>{let n=_(t,s);return{path:n,page:this.getPageSync(n,e)}})}};import{join as Z,parse as tt}from"path";import{LoggingPretty as et}from"logging-pretty";var b=class{static{p(this,"TemplateEngine")}static _escape(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static _processVariables(t){return t.replace(/\{\{(\w+)\}\}/g,(e,i)=>`\${(data && data["${i}"]) ?? ""}`)}static _processBaseBlocks(t){let e=/<base\b[^>]*?(?:\sid=(["']?)([^"'\s>]+)\1)?[^>]*?>([\s\S]*?)<\/base>/g,i={};for(let s of t.matchAll(e)){let n=s[2]??"default",a=(s[3]??"").replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[n]=a}return i}static _processScriptBlocks(t){return t.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi,(e,i)=>{let s=i.trim();return s?`\${(() => { if (!data) return ''; try { with(data) { ${s} } } catch(e) { return '' } })()}`:""})}static _processSpaceBlocks(t){return t.replace(/^[ \t]*<space\s*\/>[ \t]*$/gim,"")}static _processDivBlocks(t){return t.replace(/<div>([\s\S]*?)<\/div>/gi,(e,i)=>i.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,""))}static _processMediaBlocks(t){let e=/<media\s+([^>]+)>([\s\S]*?)<\/media>/gi,i={};for(let s of t.matchAll(e)){let n=s[1],o=s[2],a={},r=/(\w+)="([^"]*)"/g;for(let y of n.matchAll(r))a[y[1]]=y[2];if(!a.lang)continue;let d=a.lang,c=a.type,l=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim(),u={type:c};a.src&&(u.src=a.src),l&&c!=="video_note"&&c!=="sticker"&&(u.caption=l),c==="location"&&(a.latitude&&(u.latitude=a.latitude),a.longitude&&(u.longitude=a.longitude),l&&(u.caption=l)),c==="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),l&&(u.caption=l)),i[d]=u}return i}static _processMessageBlocks(t){let e=/<message\s+lang="([^"]+)"\s*>([\s\S]*?)<\/message>/gi,i={};for(let[,s,n]of t.matchAll(e)){let o=n.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]=o}return i}static _processDescriptionBlocks(t){let e=/<description\b[^>]*\blang="([^"]*)"[^>]*\bscope="([^"]*)"[^>]*>([\s\S]*?)<\/description>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=o.replace(/^[\t ]+/gm,"").replace(/^\n+/,"").replace(/\n+$/,"").trim();i[s]||(i[s]={}),i[s][n]=a}return i}static _processKeyboardBlocks(t){let e=/<keyboard\b[^>]*\blang="([^"]*)"[^>]*?(?:\stype="([^"]*)")?[^>]*>([\s\S]*?)<\/keyboard>/gi,i={};for(let[,s,n,o]of t.matchAll(e)){let a=n==="bottom"?"bottom":"inline",r=o.trim();i[s]||(i[s]={}),i[s][a]=r}return i}static _compileToFunction(t,e){let i;e?i=t.map(o=>`\`${o}\``).join(","):i=`\`${t}\``;let s=i;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(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMediaBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))if(r.caption){let d=this._processVariables(this._processScriptBlocks(r.caption)),c=this._compileToFunction(d,!1);i[s][a]=l=>({...r,caption:c(l)})}else i[s][a]=()=>r}return i}static compileMessages(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processMessageBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){let d=this._processVariables(this._processScriptBlocks(r));i[s][a]=this._compileToFunction(d,!1)}}return i}static compileDescription(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processDescriptionBlocks(n);i[s]={};for(let[a,r]of Object.entries(o))for(let[d,c]of Object.entries(r))i[s][d]||(i[s][d]={}),i[s][d][a]=this._compileToFunction(c,!1)}return i}static compileKeyboards(t){let e=this._processBaseBlocks(t),i={};for(let[s,n]of Object.entries(e)){let o=this._processKeyboardBlocks(n);i[s]={};for(let[a,r]of Object.entries(o)){i[s][a]={};for(let[d,c]of Object.entries(r)){let u=c.split(/(?<!\\),\s*/).map(y=>y.replace(/\\,/g,",").trim()).map(y=>this._processVariables(this._processScriptBlocks(y)));i[s][a][d]=this._compileToFunction(u,!0)}}}return i}};import{readFile as U}from"fs/promises";import{watch as z}from"chokidar";import{basename as M,join as V,extname as G}from"path";import{readdirSync as H,readFileSync as J,existsSync as D,statSync as q,writeFileSync as X}from"fs";var v=class{static{p(this,"TemplateManager")}_map=new Map;_engine=b;_watcher=[];_supportedExtensions=new Set([".html",".ts"]);_path;_forceLanguage;_isWatchEnabled;constructor(t){let{path:e,enableWatch:i=!1,forceLanguage:s}=t;this._path=e,this._forceLanguage=s,this._isWatchEnabled=i,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 t=0;t<this._path.length;t++){let e=this._path[t];if(!D(e))throw new Error(`Template base path is not exists: ${e}`);if(!q(e).isDirectory())throw new Error(`Template base path is not a directory: ${e}`)}return!0}catch(t){throw new Error(`Failed to validate Template base path: ${t}`)}}_initializeWatcher(){if(this._isWatchEnabled)throw new Error("Watcher already enabled");for(let t=0;t<this._path.length;t++){let e=this._path[t],i=z(e,{persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}});this._watcher[t]=i,i.on("change",this._handleFileChange.bind(this)),i.on("add",this._handleFileAdd.bind(this)),i.on("unlink",this._handleFileDelete.bind(this)),i.on("error",this._handleWatchError.bind(this))}}async _handleFileChange(t){let e=M(t);this._isValidFile(e)&&await this._loadFile(e,!1)}async _handleFileAdd(t){let e=M(t);this._isValidFile(e)&&await this._loadFile(e,!1)}_handleFileDelete(t){let e=M(t),i=this._getKey(e);this._map.has(i)&&this._map.delete(i)}_handleWatchError(t){}_loadAllFiles(){for(let t=0;t<this._path.length;t++){let e=this._path[t],s=H(e,"utf8").filter(n=>this._isValidFile(n));for(let n of s)this._loadFile(n,!0)}}async _loadFile(t,e=!0){for(let i=0;i<this._path.length;i++){let s=this._path[i],n=V(s,t),o=this._getExtension(t),a=this._getKey(t);if(o==".html"){let r=e?J(n,"utf8"):await U(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 ${t} is not support`)}}_getExtension(t){return G(t).toLowerCase()}_isValidFile(t){return this._supportedExtensions.has(this._getExtension(t))}_getKey(t){return t.replace(/\.[^/.]+$/,"")}_compile(t,e,i){let s=this._map.get(t),n=s||{},o=!1;(i===void 0||i?.media===!1||s?.media===void 0)&&(n.media=b.compileMedia(e),o=!0),(i===void 0||i?.message===!1||s?.message===void 0)&&(n.message=b.compileMessages(e),o=!0),(i===void 0||i?.keyboard===!1||s?.keyboard===void 0)&&(n.keyboard=b.compileKeyboards(e),o=!0),(i===void 0||i?.description===!1||s?.description===void 0)&&(n.description=b.compileDescription(e),o=!0),o&&this._map.set(t,n)}getMedia(t,e="default",i="en",s){let o=this._map.get(t)?.media?.[e]?.[this._forceLanguage||i];if(!o)return{};try{return o(s)}catch{return{}}}getMessage(t,e="default",i="en",s){let o=this._map.get(t)?.message?.[e]?.[this._forceLanguage||i];if(!o)return"";try{return o(s)}catch{return""}}getDescription(t,e="default",i="default",s="default",n){let a=this._map.get(t)?.description?.[e]?.[s]?.[this._forceLanguage||i];if(!a)return"";try{return a(n)}catch{return""}}getDescriptionLanguage(t,e="default",i="default"){let n=this._map.get(t)?.description?.[e]?.[i];return n?Object.keys(n):[]}getDescriptionScopes(t,e="default"){let s=this._map.get(t)?.description?.[e];return s?Object.keys(s):[]}getKeyboard(t,e="default",i="en",s="inline",n){let a=this._map.get(t)?.keyboard?.[e]?.[this._forceLanguage||i]?.[s];if(!a)return[];try{return a(n)}catch{return[]}}async write(t,e){if(this._getExtension(t)!=".html")return null;for(let i=0;i<this._path.length;i++){let s=V(this._path[i],t);if(D(s))return X(s,e,"utf8"),await this._loadFile(t,!1),!0}return null}has(t){return this._map.has(t)}getCacheStats(){return{templateCount:this._map.size,totalSize:JSON.stringify(this._map.entries().toArray(),(t,e)=>typeof e=="function"?e.toString():e).length}}async destroy(){if(this._watcher)for(let t of this._watcher)await t.close();this._map.clear()}};import{Bot as it,webhookCallback as O}from"grammy";var A=class{static{p(this,"Gramstax")}templateManager;cacheKeyboard;cacheSession;pages;log;bot;handlerBotUpdate;constructor(t){if(!t?.token||t?.token?.length==0)throw new Error("Token is not valid or empty");this.log=t.log===!0?new et:t.log?t.log:void 0,this.cacheSession=t.cacheSession||new S("memory","session"),this.cacheKeyboard=t.cacheKeyboard||new Map,this.templateManager=t.templateManager||new v({path:[Z(process.cwd(),"src","pages")]}),this.bot=this.createBot(t.token),this.bot.catch(this.onCatch),this.registerOnCallbackQueryData(),this.registerOnMessageText(),this.registerOnMessagePhoto(),this.registerOnMessageVideo(),this.registerOnMessageAudio(),this.registerOnMessageDocument(),this.registerOnMessageAnimation(),this.registerOnMessageVoice(),this.registerOnMessageVideoNote(),this.registerOnMessageSticker(),this.registerOnMessageLocation(),this.registerOnMessageContact(),this.handlerBotUpdate=this.bot.handleUpdate,this.pages=this.pageLoads(),process.once("SIGINT",()=>this.bot.stop()),process.once("SIGTERM",()=>this.bot.stop()),t.deploy.startsWith("polling")?this.runPolling():t.deploy.startsWith("webhook:")?this.runWebhook(t.deploy.split("webhook:")[1]):t.deploy.startsWith("serverless:")&&this.runServerless(t.deploy.split("serverless:")[1])}onCatch(t){this.log?.error?.(`[Bot.catch]: ${String(t)}`)}onStart(t,e,i){let{username:s}=t;this.log?.success?.(`Telegram bot polling started: ${s} ${e=="webhook"||e=="serverless"?`(${i})`:""}`)}createBot(t){return new it(t)}createCtx(t){return new P({ct:t,cacheSession:this.cacheSession,cacheKeyboard:this.cacheKeyboard,templateManager:this.templateManager,temp:{session:{},data:{}}})}async runPolling(){this.bot.start({onStart:p(async t=>{this.onStart(t,"polling",null)},"onStart")})}async runWebhook(t){let e=O(this.bot,"bun"),i="/telegram-webhook";this.handlerBotUpdate=e,Y({fetch(a){let{pathname:r}=new URL(a.url);if(r===i)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=t.endsWith("/")?t.slice(0,-1)+i:t+i;s.url!=n&&await this.bot.api.setWebhook(n);let o=await this.bot.api.getMe();this.onStart(o,"webhook",n)}async runServerless(t){this.handlerBotUpdate=O(this.bot,t);let e=await this.bot.api.getMe();this.onStart(e,"serverless",t)}pageBuildData(t,e){t?.data===void 0&&(t.data=t.buildData()),t.data.name=tt(e).name}pageSorts(t,e){let i=t.data.name,s=t.prototype,n="Payload",o="Command",a="Caption",r="Free",d=e.dynamic,c=e.dynamicSpesific,l=p(m=>m.charAt(0).toUpperCase()+m.slice(1),"upFirst"),u=p(m=>m.replace(n,"").replace(o,"").replace(a,"").replace(r,""),"getPureFuncName"),y=p((m,h)=>s[`methodSession${l(m)}`](h),"methodSession");e.all[i]=t;for(let m=0;m<e.lenListFuncStaticSession;m++){let h=e.listFuncStaticSession[m],R=e.static[h],N=e.staticIntent[h],x=e.staticSession[h],I={name:i,func:h},T=R||N;if(T!==void 0){let K=h.includes(o)?`/${i}`:i;T[s.intent(K,h.startsWith("callback"))]=I}x!==void 0&&(x[y(h,i)]=I),h.toLowerCase().endsWith("free")&&c[u(h)].push(I)}s.free&&d.push(i)}async pageSyncDescription(t){let e=new Map,i=p((n,o,a,r)=>{e.has(o)||e.set(o,new Map);let d=e.get(o);d.has(a)||d.set(a,[]);let c=d.get(a);c.some(l=>l.command===n)||c.push({command:n,description:r})},"addCommand"),s=t.static.textCommand;for(let[,n]of Object.entries(s)){let o=n.name,a=this.templateManager.getDescriptionScopes(o);for(let r of a){let d=this.templateManager.getDescriptionLanguage(o,"default",r);for(let c of d){let l=this.templateManager.getDescription(o,"default",c,r);l&&i(o,r,c,l)}}}for(let[n,o]of e)for(let[a,r]of o){let d={type:n},c=a==="default"?void 0:a;try{let l=await this.bot.api.getMyCommands({scope:d,language_code:c}),u=JSON.stringify(l.map(m=>({command:m.command,description:m.description})).sort((m,h)=>m.command.localeCompare(h.command))),y=JSON.stringify(r.sort((m,h)=>m.command.localeCompare(h.command)));u!==y&&(await this.bot.api.setMyCommands(r,{scope:d,language_code:c}),this.log?.info?.(`Synced descriptions for scope: ${n},${c?` lang: ${c}`:""} (Total: ${r.length})`))}catch(l){this.log?.error?.(`Failed to sync descriptions for scope: ${n},${c?` lang: ${c}`:""}. ${String(l)}`)}}}pageLoads(){this.log?.info?.("Load pages..");let t={},e=t,i=t,s=[],n=["callback","text","textCommand","photoCaption","photoCaptionCommand","videoCaption","videoCaptionCommand","audioCaption","audioCaptionCommand","documentCaption","documentCaptionCommand","animationCaption","animationCaptionCommand","voiceCaption","voiceCaptionCommand","videoNoteCaption","videoNoteCaptionCommand"],o=["callbackPayload","textPayload","textCommandPayload","photoCaptionPayload","photoCaptionCommandPayload","videoCaptionPayload","videoCaptionCommandPayload","audioCaptionPayload","audioCaptionCommandPayload","documentCaptionPayload","documentCaptionCommandPayload","animationCaptionPayload","animationCaptionCommandPayload","voiceCaptionPayload","voiceCaptionCommandPayload","videoNoteCaptionPayload","videoNoteCaptionCommandPayload"],a=[...n,...o,"textFree","photoFree","videoFree","audioFree","documentFree","animationFree","voiceFree","videoNoteFree","stickerFree","locationFree","contactFree"],r=p((c,l)=>Object.fromEntries(c.map(u=>[u,{...l}])),"makeObject"),d={all:{},dynamic:[],dynamicSpesific:{text:s,photo:s,video:s,audio:s,document:s,animation:s,voice:s,videoNote:s,sticker:s,location:s,contact:s},static:r(n,t),staticIntent:r(o,e),staticSession:r(a,i),listFuncStatic:n,listFuncStaticIntent:o,listFuncStaticSession:a,lenListFuncStatic:n.length,lenListFuncStaticIntent:o.length,lenListFuncStaticSession:a.length};return f.getPagesSync(void 0,!0).forEach(({path:c,page:l})=>{this.pageBuildData(l,c),this.pageSorts(l,d)}),this.log?.info?.(`Finish load pages with total (${Object.keys(d.all).length})`),this.pageSyncDescription(d),d}async pageRoutes(t,e){let i,s;if(i===void 0){let o=t.callbackData,a=t.msgText,r=t.msgCaption,d=this.pages.static;for(let c=0;c<this.pages.lenListFuncStatic;c++){let l=this.pages.listFuncStatic[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i===void 0){let o=await t.sessionGet();if(o){let a=o.method,r=this.pages.staticSession;for(let d=0;d<this.pages.lenListFuncStaticSession;d++){let c=this.pages.listFuncStaticSession[d];if(s=r[c][a],s)break}s!==void 0&&(i=this.pages.all[s.name])}}if(i===void 0){let o=t.callbackDataIntent,a=t.msgTextIntent,r=t.msgCaptionIntent,d=this.pages.staticIntent;for(let c=0;c<this.pages.lenListFuncStaticIntent;c++){let l=this.pages.listFuncStaticIntent[c];if(s=d[l][o||a||r],s)break}s!==void 0&&(i=this.pages.all[s.name])}if(i!==void 0&&s!==void 0)return await new i(t)[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 c=await new r(t)[a.name]?.();if(c!==null)return c}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 c=await new r(t).free?.();if(c!==null)return c}return null}async hookBeforeRoute(t,e){return!0}async hookErrorPage(t,e,i,s){}async hookErrorInputNotFoundPage(t){}async onMessage(t,e){let i=this.createCtx(t);try{if(await this.hookBeforeRoute(i,e)===!1)return;await this.pageRoutes(i,e)===null&&await this.hookErrorInputNotFoundPage(i)}catch(s){await this.hookErrorPage(i,e,s,!1)}}async onCallbackQueryData(t){let e=this.createCtx(t);try{if(await e.callbackQueryAnswer(),await this.hookBeforeRoute(e,"onCallbackQueryData")===!1)return;await this.pageRoutes(e,"callback")}catch(i){await this.hookErrorPage(e,"onCallbackQueryData",i,!0)}}async onMessageText(t){await this.onMessage(t,"onMessageText")}async onMessagePhoto(t){await this.onMessage(t,"onMessagePhoto")}async onMessageVideo(t){await this.onMessage(t,"onMessageVideo")}async onMessageAudio(t){await this.onMessage(t,"onMessageAudio")}async onMessageDocument(t){await this.onMessage(t,"onMessageDocument")}async onMessageAnimation(t){await this.onMessage(t,"onMessageAnimation")}async onMessageVoice(t){await this.onMessage(t,"onMessageVoice")}async onMessageVideoNote(t){await this.onMessage(t,"onMessageVideoNote")}async onMessageSticker(t){await this.onMessage(t,"onMessageSticker")}async onMessageLocation(t){await this.onMessage(t,"onMessageLocation")}async onMessageContact(t){await this.onMessage(t,"onMessageContact")}registerOnCallbackQueryData(){this.bot.on("callback_query:data",this.onCallbackQueryData.bind(this))}registerOnMessageText(){this.bot.on("message:text",this.onMessageText.bind(this))}registerOnMessagePhoto(){this.bot.on("message:photo",this.onMessagePhoto.bind(this))}registerOnMessageVideo(){this.bot.on("message:video",this.onMessageVideo.bind(this))}registerOnMessageAudio(){this.bot.on("message:audio",this.onMessageAudio.bind(this))}registerOnMessageDocument(){this.bot.on("message:document",this.onMessageDocument.bind(this))}registerOnMessageAnimation(){this.bot.on("message:animation",this.onMessageAnimation.bind(this))}registerOnMessageVoice(){this.bot.on("message:voice",this.onMessageVoice.bind(this))}registerOnMessageVideoNote(){this.bot.on("message:video_note",this.onMessageVideoNote.bind(this))}registerOnMessageSticker(){this.bot.on("message:sticker",this.onMessageSticker.bind(this))}registerOnMessageLocation(){this.bot.on("message:location",this.onMessageLocation.bind(this))}registerOnMessageContact(){this.bot.on("message:contact",this.onMessageContact.bind(this))}};export{C as BaseGeneral,S as CacheExternal,P as Ctx,A as Gramstax,b as TemplateEngine,v as TemplateManager};
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "gramstax",
3
- "version": "0.0.22",
4
- "private": false,
5
- "description": "A powerful Telegram bot framework with page-based routing and template system",
6
- "keywords": [
7
- "telegram",
8
- "bot",
9
- "grammy",
10
- "telegram-bot",
11
- "bot-framework",
12
- "gramstax"
13
- ],
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/gramstax/gramstax.git"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/gramstax/gramstax/issues"
20
- },
21
- "homepage": "https://github.com/gramstax/gramstax",
22
- "author": "gramstax",
23
- "license": "MIT",
24
- "type": "module",
25
- "main": "./dist/src/index.js",
26
- "module": "./dist/src/index.mjs",
27
- "types": "./dist/src/index.d.ts",
28
- "exports": {
29
- ".": {
30
- "types": "./dist/src/index.d.ts",
31
- "import": "./dist/src/index.js",
32
- "default": "./dist/src/index.js"
33
- }
34
- },
35
- "files": [
36
- "dist"
37
- ],
38
- "devDependencies": {
39
- "@types/bun": "latest",
40
- "tsup": "^8.5.0"
41
- },
42
- "peerDependencies": {
43
- "typescript": "^5.9.3"
44
- },
45
- "dependencies": {
46
- "@keyv/redis": "^5.1.3",
47
- "chokidar": "^4.0.3",
48
- "grammy": "^1.38.3",
49
- "keyv": "^5.5.3",
50
- "logging-pretty": "^3.0.0"
51
- }
52
- }
1
+ {
2
+ "name": "gramstax",
3
+ "version": "0.0.24",
4
+ "private": false,
5
+ "description": "A powerful Telegram bot framework with page-based routing and template system",
6
+ "keywords": [
7
+ "telegram",
8
+ "bot",
9
+ "grammy",
10
+ "telegram-bot",
11
+ "bot-framework",
12
+ "gramstax"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/gramstax/gramstax.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/gramstax/gramstax/issues"
20
+ },
21
+ "homepage": "https://github.com/gramstax/gramstax",
22
+ "author": "gramstax",
23
+ "license": "MIT",
24
+ "type": "module",
25
+ "main": "./dist/src/index.js",
26
+ "module": "./dist/src/index.mjs",
27
+ "types": "./dist/src/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/src/index.d.ts",
31
+ "import": "./dist/src/index.js",
32
+ "default": "./dist/src/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "devDependencies": {
39
+ "@types/bun": "latest",
40
+ "tsup": "^8.5.1"
41
+ },
42
+ "peerDependencies": {
43
+ "typescript": "^5.9.3"
44
+ },
45
+ "dependencies": {
46
+ "@keyv/redis": "^5.1.4",
47
+ "chokidar": "^4.0.3",
48
+ "grammy": "^1.38.4",
49
+ "keyv": "^5.5.4",
50
+ "logging-pretty": "^3.0.0"
51
+ }
52
+ }