zaileys 0.29.0-beta → 0.29.1-beta

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.
package/dist/index.d.mts CHANGED
@@ -74,6 +74,12 @@ declare const VERIFIED_PLATFORM: {
74
74
  readonly tiktok: "6285574670498@s.whatsapp.net";
75
75
  };
76
76
 
77
+ declare const Config_MESSAGE_TYPE: typeof MESSAGE_TYPE;
78
+ declare const Config_VERIFIED_PLATFORM: typeof VERIFIED_PLATFORM;
79
+ declare namespace Config {
80
+ export { Config_MESSAGE_TYPE as MESSAGE_TYPE, Config_VERIFIED_PLATFORM as VERIFIED_PLATFORM };
81
+ }
82
+
77
83
  type FakeVerifiedEnum = keyof typeof VERIFIED_PLATFORM;
78
84
  type SendActionType = {
79
85
  asReply?: boolean;
@@ -83,8 +89,18 @@ type ReplyActionType = {
83
89
  fakeVerified?: FakeVerifiedEnum;
84
90
  };
85
91
 
92
+ type Action_FakeVerifiedEnum = FakeVerifiedEnum;
93
+ type Action_ReplyActionType = ReplyActionType;
94
+ type Action_SendActionType = SendActionType;
95
+ declare namespace Action {
96
+ export type { Action_FakeVerifiedEnum as FakeVerifiedEnum, Action_ReplyActionType as ReplyActionType, Action_SendActionType as SendActionType };
97
+ }
98
+
86
99
  type MessageTypeEnum = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE];
87
100
  type DeviceTypeEnum = "unknown" | "android" | "ios" | "desktop" | "web";
101
+ type ExtractCitationType<T> = {
102
+ [K in keyof T as `is${Capitalize<K & string>}`]: boolean;
103
+ };
88
104
  type MessageBaseContent<T> = {
89
105
  fromMe: boolean;
90
106
  chatId: string;
@@ -121,6 +137,14 @@ type MessageBaseContent<T> = {
121
137
  message: () => proto.IWebMessageInfo;
122
138
  };
123
139
 
140
+ type Message_DeviceTypeEnum = DeviceTypeEnum;
141
+ type Message_ExtractCitationType<T> = ExtractCitationType<T>;
142
+ type Message_MessageBaseContent<T> = MessageBaseContent<T>;
143
+ type Message_MessageTypeEnum = MessageTypeEnum;
144
+ declare namespace Message {
145
+ export type { Message_DeviceTypeEnum as DeviceTypeEnum, Message_ExtractCitationType as ExtractCitationType, Message_MessageBaseContent as MessageBaseContent, Message_MessageTypeEnum as MessageTypeEnum };
146
+ }
147
+
124
148
  type AuthType = "pairing" | "qr";
125
149
  type CitationConfig = {
126
150
  [key: string]: (() => string[]) | (() => Promise<string[]>);
@@ -159,6 +183,20 @@ interface ClientEvents<B> {
159
183
  error: (ctx: ErrorContext) => void;
160
184
  }
161
185
 
186
+ type General_AuthType = AuthType;
187
+ type General_BaseClientConfig = BaseClientConfig;
188
+ type General_BaseContext = BaseContext;
189
+ type General_CitationConfig = CitationConfig;
190
+ type General_ClientConfig = ClientConfig;
191
+ type General_ClientEvents<B> = ClientEvents<B>;
192
+ type General_ConnectionContext = ConnectionContext;
193
+ type General_ErrorContext = ErrorContext;
194
+ type General_PairingClientConfig = PairingClientConfig;
195
+ type General_QRClientConfig = QRClientConfig;
196
+ declare namespace General {
197
+ export type { General_AuthType as AuthType, General_BaseClientConfig as BaseClientConfig, General_BaseContext as BaseContext, General_CitationConfig as CitationConfig, General_ClientConfig as ClientConfig, General_ClientEvents as ClientEvents, General_ConnectionContext as ConnectionContext, General_ErrorContext as ErrorContext, General_PairingClientConfig as PairingClientConfig, General_QRClientConfig as QRClientConfig };
198
+ }
199
+
162
200
  declare class Client extends EventEmitter {
163
201
  private config;
164
202
  private authState;
@@ -190,4 +228,4 @@ declare class Client extends EventEmitter {
190
228
  sendSticker(sticker: string | Buffer, payload?: SendActionType): Promise<void>;
191
229
  }
192
230
 
193
- export { Client, Client as default };
231
+ export { Client, Config, General, Message, Action as Types, Client as default };
package/dist/index.d.ts CHANGED
@@ -74,6 +74,12 @@ declare const VERIFIED_PLATFORM: {
74
74
  readonly tiktok: "6285574670498@s.whatsapp.net";
75
75
  };
76
76
 
77
+ declare const Config_MESSAGE_TYPE: typeof MESSAGE_TYPE;
78
+ declare const Config_VERIFIED_PLATFORM: typeof VERIFIED_PLATFORM;
79
+ declare namespace Config {
80
+ export { Config_MESSAGE_TYPE as MESSAGE_TYPE, Config_VERIFIED_PLATFORM as VERIFIED_PLATFORM };
81
+ }
82
+
77
83
  type FakeVerifiedEnum = keyof typeof VERIFIED_PLATFORM;
78
84
  type SendActionType = {
79
85
  asReply?: boolean;
@@ -83,8 +89,18 @@ type ReplyActionType = {
83
89
  fakeVerified?: FakeVerifiedEnum;
84
90
  };
85
91
 
92
+ type Action_FakeVerifiedEnum = FakeVerifiedEnum;
93
+ type Action_ReplyActionType = ReplyActionType;
94
+ type Action_SendActionType = SendActionType;
95
+ declare namespace Action {
96
+ export type { Action_FakeVerifiedEnum as FakeVerifiedEnum, Action_ReplyActionType as ReplyActionType, Action_SendActionType as SendActionType };
97
+ }
98
+
86
99
  type MessageTypeEnum = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE];
87
100
  type DeviceTypeEnum = "unknown" | "android" | "ios" | "desktop" | "web";
101
+ type ExtractCitationType<T> = {
102
+ [K in keyof T as `is${Capitalize<K & string>}`]: boolean;
103
+ };
88
104
  type MessageBaseContent<T> = {
89
105
  fromMe: boolean;
90
106
  chatId: string;
@@ -121,6 +137,14 @@ type MessageBaseContent<T> = {
121
137
  message: () => proto.IWebMessageInfo;
122
138
  };
123
139
 
140
+ type Message_DeviceTypeEnum = DeviceTypeEnum;
141
+ type Message_ExtractCitationType<T> = ExtractCitationType<T>;
142
+ type Message_MessageBaseContent<T> = MessageBaseContent<T>;
143
+ type Message_MessageTypeEnum = MessageTypeEnum;
144
+ declare namespace Message {
145
+ export type { Message_DeviceTypeEnum as DeviceTypeEnum, Message_ExtractCitationType as ExtractCitationType, Message_MessageBaseContent as MessageBaseContent, Message_MessageTypeEnum as MessageTypeEnum };
146
+ }
147
+
124
148
  type AuthType = "pairing" | "qr";
125
149
  type CitationConfig = {
126
150
  [key: string]: (() => string[]) | (() => Promise<string[]>);
@@ -159,6 +183,20 @@ interface ClientEvents<B> {
159
183
  error: (ctx: ErrorContext) => void;
160
184
  }
161
185
 
186
+ type General_AuthType = AuthType;
187
+ type General_BaseClientConfig = BaseClientConfig;
188
+ type General_BaseContext = BaseContext;
189
+ type General_CitationConfig = CitationConfig;
190
+ type General_ClientConfig = ClientConfig;
191
+ type General_ClientEvents<B> = ClientEvents<B>;
192
+ type General_ConnectionContext = ConnectionContext;
193
+ type General_ErrorContext = ErrorContext;
194
+ type General_PairingClientConfig = PairingClientConfig;
195
+ type General_QRClientConfig = QRClientConfig;
196
+ declare namespace General {
197
+ export type { General_AuthType as AuthType, General_BaseClientConfig as BaseClientConfig, General_BaseContext as BaseContext, General_CitationConfig as CitationConfig, General_ClientConfig as ClientConfig, General_ClientEvents as ClientEvents, General_ConnectionContext as ConnectionContext, General_ErrorContext as ErrorContext, General_PairingClientConfig as PairingClientConfig, General_QRClientConfig as QRClientConfig };
198
+ }
199
+
162
200
  declare class Client extends EventEmitter {
163
201
  private config;
164
202
  private authState;
@@ -190,4 +228,4 @@ declare class Client extends EventEmitter {
190
228
  sendSticker(sticker: string | Buffer, payload?: SendActionType): Promise<void>;
191
229
  }
192
230
 
193
- export { Client, Client as default };
231
+ export { Client, Config, General, Message, Action as Types, Client as default };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var ye=Object.create;var S=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var Ce=(c,g)=>{for(var t in g)S(c,t,{get:g[t],enumerable:!0})},ae=(c,g,t,e)=>{if(g&&typeof g=="object"||typeof g=="function")for(let s of ve(g))!Ie.call(c,s)&&s!==t&&S(c,s,{get:()=>g[s],enumerable:!(e=ke(g,s))||e.enumerable});return c};var M=(c,g,t)=>(t=c!=null?ye(we(c)):{},ae(g||!c||!c.__esModule?S(t,"default",{value:c,enumerable:!0}):t,c)),Se=c=>ae(S({},"__esModule",{value:!0}),c);var be={};Ce(be,{Client:()=>v,default:()=>Te});module.exports=Se(be);var p=M(require("@whiskeysockets/baileys")),he=require("awesome-phonenumber"),me=M(require("chalk")),R=M(require("consola")),pe=require("events"),de=M(require("figlet")),le=M(require("fs")),P=M(require("node-cache")),ue=M(require("ora")),fe=M(require("pino"));var k=require("@whiskeysockets/baileys");var re={text:"text",conversation:"text",imageMessage:"image",contactMessage:"contact",locationMessage:"location",documentMessage:"document",audioMessage:"audio",videoMessage:"video",protocolMessage:"protocol",contactsArrayMessage:"contactsArray",highlyStructuredMessage:"highlyStructured",sendPaymentMessage:"sendPayment",liveLocationMessage:"liveLocation",requestPaymentMessage:"requestPayment",declinePaymentRequestMessage:"declinePaymentRequest",cancelPaymentRequestMessage:"cancelPaymentRequest",templateMessage:"template",stickerMessage:"sticker",groupInviteMessage:"groupInvite",templateButtonReplyMessage:"templateButtonReply",productMessage:"product",deviceSentMessage:"deviceSent",listMessage:"list",viewOnceMessage:"viewOnce",orderMessage:"order",listResponseMessage:"listResponse",ephemeralMessage:"ephemeral",invoiceMessage:"invoice",buttonsMessage:"buttons",buttonsResponseMessage:"buttonsResponse",paymentInviteMessage:"paymentInvite",interactiveMessage:"interactive",reactionMessage:"reaction",stickerSyncRmrMessage:"sticker",interactiveResponseMessage:"interactiveResponse",pollCreationMessage:"pollCreation",pollUpdateMessage:"pollUpdate",keepInChatMessage:"keepInChat",documentWithCaptionMessage:"document",requestPhoneNumberMessage:"requestPhoneNumber",viewOnceMessageV2:"viewOnce",encReactionMessage:"reaction",editedMessage:"text",viewOnceMessageV2Extension:"viewOnce",pollCreationMessageV2:"pollCreation",scheduledCallCreationMessage:"scheduledCallCreation",groupMentionedMessage:"groupMentioned",pinInChatMessage:"pinInChat",pollCreationMessageV3:"pollCreation",scheduledCallEditMessage:"scheduledCallEdit",ptvMessage:"ptv",botInvokeMessage:"botInvoke",callLogMesssage:"callLog",encCommentMessage:"encComment",bcallMessage:"bcall",lottieStickerMessage:"lottieSticker",eventMessage:"event",commentMessage:"comment",newsletterAdminInviteMessage:"text",extendedTextMessageWithParentKey:"text",placeholderMessage:"placeholder",encEventUpdateMessage:"encEventUpdate"},ce={whatsapp:"0@s.whatsapp.net",meta:"13135550002@s.whatsapp.net",chatgpt:"18002428478@s.whatsapp.net",copilot:"18772241042@s.whatsapp.net",instagram:"447723442971@s.whatsapp.net",tiktok:"6285574670498@s.whatsapp.net"};var ge=(c,g)=>{let t=new Set(c);for(let e of g)if(t.has(e))return!0;return!1},y=(c,g)=>Array.isArray(c)?c.map(t=>y(t,g)):c&&typeof c=="object"?Object.keys(c).reduce((t,e)=>(g.includes(e)||(t[e]=y(c[e],g)),t),{}):c;var b=class{constructor({socket:g,message:t,config:e,store:s}){this.socket=g,this.message=t,this.config=e,this.store=s}async handle(g){var I,x,E,A,B,F,O,q,W,J,K,V,L,N,j,D,z,U,_,$,G,H,Q,Y,Z,X,ee,te,se,ie,oe,ne;let t=y(g||this.message,["senderKeyDistributionMessage","messageContextInfo"]);if(t!=null&&t.messageStubType||!Object.keys(t==null?void 0:t.message).length)return;let e=t.ephemeralMessage||t,s=!!((I=e.message)!=null&&I.extendedTextMessage),n=!!((E=(x=e.message)==null?void 0:x.protocolMessage)!=null&&E.editedMessage),a=!!((A=e.message)!=null&&A.botInvokeMessage),i=((O=(F=(B=e.message)==null?void 0:B.protocolMessage)==null?void 0:F.editedMessage)==null?void 0:O.extendedTextMessage)||((W=(q=e.message)==null?void 0:q.protocolMessage)==null?void 0:W.editedMessage),o=s?Object.keys(e.message.extendedTextMessage)[0]:n?Object.keys(i)[0]:a?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],h=s?(V=(K=(J=e.message)==null?void 0:J.extendedTextMessage)==null?void 0:K.contextInfo)==null?void 0:V.stanzaId:(j=(N=(L=e.message)==null?void 0:L[o])==null?void 0:N.contextInfo)==null?void 0:j.stanzaId,d=re[o];(z=(D=e.message)==null?void 0:D.protocolMessage)!=null&&z.ephemeralExpiration&&(d="ephemeral");let r=s?e.message.extendedTextMessage[o]:n?i[o]:a?e.message.botInvokeMessage.message.extendedTextMessage[o]:e.message[o],l=typeof r=="string"?r:(r==null?void 0:r.caption)||(r==null?void 0:r.text)||(r==null?void 0:r.name)||null,w=(l==null?void 0:l.match(/@\d+/g))||null,m={fromMe:e.key.fromMe,chatId:e.key.id,roomId:e.key.remoteJid,roomImage:async()=>await this.socket.profilePictureUrl(e.key.remoteJid,"image").catch(()=>null),senderId:e.participant||e.key.participant||e.key.remoteJid,senderName:e.pushName||e.verifiedBizName||null,senderDevice:(0,k.getDevice)(e.key.id),senderBio:async()=>await this.socket.fetchStatus(e.key.participant||e.key.remoteJid).then(u=>{var f,C;return(C=(f=u==null?void 0:u[0])==null?void 0:f.status)==null?void 0:C.status}).catch(()=>null),senderImage:async()=>{let u=await this.socket.profilePictureUrl(e.key.participant||e.key.remoteJid,"image").catch(()=>null);return u===void 0?null:u},senderBusiness:async()=>await this.socket.getBusinessProfile(e.key.participant||e.key.remoteJid).catch(()=>null),chatType:d,timestamp:Number((e.messageTimestamp.low||e.messageTimestamp||0).toString()),text:l,command:l!=null&&l.startsWith(this.config.prefix)?(U=l.split(" ")[0])==null?void 0:U.slice(1):null,mentions:w,isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:n,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:d==="ephemeral"||!!((G=($=(_=e.message)==null?void 0:_.extendedTextMessage)==null?void 0:$.contextInfo)!=null&&G.expiration),isForwarded:!!((Y=(Q=(H=e.message)==null?void 0:H.extendedTextMessage)==null?void 0:Q.contextInfo)!=null&&Y.isForwarded),citation:{},media:typeof r!="string"?r:null,reply:null,key:()=>e.key,message:()=>this.message};if(m.media&&(m.media={...m.media,...(m.media.url||((X=(Z=e.message)==null?void 0:Z.extendedTextMessage)==null?void 0:X.jpegThumbnail)||((ee=e.message)==null?void 0:ee.newsletterAdminInviteMessage)||((te=e.message)==null?void 0:te.orderMessage))&&{buffer:async()=>await(0,k.downloadMediaMessage)(this.message,"buffer",{}).catch(()=>null),stream:async()=>await(0,k.downloadMediaMessage)(this.message,"stream",{}).catch(()=>null)}},m.media=y(m.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let u=[(se=m.roomId)==null?void 0:se.split("@")[0],(ie=m.senderId)==null?void 0:ie.split("@")[0]];for(let f of Object.keys(this.config.citation)){let C=`is${f[0].toUpperCase()}${f.slice(1)}`,Me=await this.config.citation[f]();m.citation={...m.citation||{},[C]:ge(Me,u)}}}if(h){let u=(oe=this.store.messages[m.roomId])==null?void 0:oe.get(h),f=(ne=this.store.messages[m.senderId])==null?void 0:ne.get(h);if(!u&&!f)return m;m.reply=await this.handle(u||f)}return m}};var v=class extends pe.EventEmitter{constructor(t){var s;super();this.groupCache=new P.default({stdTTL:5*60,useClones:!1});this.logger=(0,fe.default)({level:"silent",enabled:!1});this.spinner=(0,ue.default)();this.config=t,this.config.showLogs=!!this.config.showLogs,this.config.autoOnline=!!this.config.autoOnline,this.config.authPath=this.config.authPath||".zaileys",this.config.ignoreMe=this.config.ignoreMe==null?!0:this.config.ignoreMe,this.config.showLogs=this.config.showLogs==null?!0:this.config.showLogs,this.authProvider=(0,p.useMultiFileAuthState)(this.config.authPath+"/session"),this.store=(0,p.makeInMemoryStore)({logger:this.logger});try{(s=this.store)==null||s.readFromFile(this.config.authPath+"/memory.json"),setInterval(()=>{var n;(n=this==null?void 0:this.store)==null||n.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(n){}Object.keys(this.config).length&&this.initialize()}async initialize(){var s,n,a;await console.clear(),await(0,de.default)("Zaileys Libs",function(i,o){console.log(me.default.greenBright(o)),console.log()}),this==null||this.spinner.start("Make connection to whatsapp...");let{state:t,saveCreds:e}=await this.authProvider;if(this.authState={load:t,save:e},this.socket=(0,p.default)({logger:this.logger,printQRInTerminal:this.config.authType=="qr",markOnlineOnConnect:this.config.autoOnline,auth:this.authState.load,version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new P.default,browser:p.Browsers.ubuntu(this.config.authType=="qr"?"Zaileys Library":"Firefox"),cachedGroupMetadata:async i=>this.groupCache.get(i),getMessage:async i=>{if(this.store){let o=await this.store.loadMessage(i.remoteJid,i.id);return(o==null?void 0:o.message)||void 0}return p.proto.Message.fromObject({})},shouldSyncHistoryMessage:i=>!!i.syncType}),this.store.bind(this.socket.ev),this.config.authType=="pairing"&&this.config.phoneNumber&&!this.socket.authState.creds.registered){if(!this.config.phoneNumber){this.spinner.warn("Please enter your phone number");return}if(!(0,he.parsePhoneNumber)("+"+this.config.phoneNumber.toString()).valid){this==null||this.spinner.warn("Please enter a valid phone number");return}setTimeout(async()=>{try{if(this.config.authType=="pairing"){let i=await this.socket.requestPairingCode(this.config.phoneNumber.toString());this.spinner.info("This is your OTP code: "+i.replace(/(.{4})/,"$1-"))}}catch(i){}},5e3)}(s=this==null?void 0:this.socket)==null||s.ev.on("connection.update",async i=>{var r,l,w;let{connection:o,lastDisconnect:h,qr:d}=i;if(this.emit("connection",{status:o||"connecting"}),this.config.authType=="qr"&&d&&this.spinner.info("Scan qrcode with your whatsapp: "),o==="close"){let m=(l=(r=h==null?void 0:h.error)==null?void 0:r.output)==null?void 0:l.statusCode,I=m!==p.DisconnectReason.loggedOut;if(this==null||this.spinner.fail((w=h==null?void 0:h.error)==null?void 0:w.message),m==401||m==405||m==500){this.spinner.warn(`Bad session, please delete "${this.config.authPath}" folder and try again`),await R.default.prompt("Do you want to delete the session?",{type:"confirm"})&&await this.deleteSession();return}I&&this.initialize()}else o==="open"&&this.spinner.succeed("Successfully connected to whatsapp")}),(n=this==null?void 0:this.socket)==null||n.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",i=>{var o;for(let h of i){let d=(0,p.jidNormalizedUser)(h.id);this.store&&this.store.contacts&&(this.store.contacts[d]={...((o=this.store.contacts)==null?void 0:o[d])||{},...h||{}})}}),this.socket.ev.on("contacts.upsert",i=>{for(let o of i){let h=(0,p.jidNormalizedUser)(o.id);this.store&&this.store.contacts&&(this.store.contacts[h]={...o||{}})}}),(a=this.socket)==null||a.ev.on("messages.upsert",async i=>{let o=i.messages;for(let h of o){if(this.config.ignoreMe&&h.key.fromMe)continue;let r=await new b({message:h,socket:this.socket,config:this.config,store:this.store}).handle();r&&(this.config.autoRead&&await this.socket.readMessages([r.key()]),this.temporaryMessage=r,this.config.autoMentions&&(this.parseMention=r.mentions),this.emit("message",r))}}),this.socket.ev.on("groups.update",async([i])=>{let o=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,o)}),this.socket.ev.on("group-participants.update",async i=>{let o=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,o)}),this.socket.ev.on("call",async i=>{for(let o of i)this.config.autoRejectCall&&await this.socket.rejectCall(o.id,o.from)})}async deleteSession(){try{await le.default.rmSync(`${this.config.authPath}`,{recursive:!0,force:!0}),await this.spinner.succeed("Session deleted. Please restart manually"),process.exit(0)}catch(t){if(this==null||this.spinner.fail("Failed to delete session"),await R.default.prompt("Do you want to try again?",{type:"confirm"}))return await this.deleteSession();process.exit(0)}}on(t,e){return super.on(t,e)}emit(t,...e){return super.emit(t,...e)}generateMentions(t){let e=["@s.whatsapp.net","@g.us","@newsletter"],s=[];return t==null||t.forEach(n=>{e.forEach(a=>{s.push(n.slice(1)+a)})}),s}generateFakeVerified(t,e){return{...t,participant:ce[e]}}async sendText(t,e){var s,n,a;try{if(e!=null&&e.footer){let i=(0,p.generateWAMessageFromContent)((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId});await this.socket.relayMessage(i.key.remoteJid,i.message,{messageId:i.key.id})}else await this.socket.sendMessage((a=this.temporaryMessage)==null?void 0:a.roomId,{text:t})}catch(i){throw i}}async sendReply(t,e){var s,n,a,i,o,h,d;try{if(e!=null&&e.footer){let r=(0,p.generateWAMessageFromContent)((s=this.temporaryMessage)==null?void 0:s.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{quoted:{...(n=this.temporaryMessage)==null?void 0:n.message(),key:this.generateFakeVerified((a=this==null?void 0:this.temporaryMessage)==null?void 0:a.message().key,e.fakeVerified)},userJid:(i=this==null?void 0:this.temporaryMessage)==null?void 0:i.roomId});await this.socket.relayMessage(r.key.remoteJid,r.message,{messageId:r.key.id})}else await this.socket.sendMessage((o=this.temporaryMessage)==null?void 0:o.roomId,{text:t},{quoted:{...(h=this==null?void 0:this.temporaryMessage)==null?void 0:h.message(),key:this.generateFakeVerified((d=this==null?void 0:this.temporaryMessage)==null?void 0:d.message().key,e==null?void 0:e.fakeVerified)}})}catch(r){throw r}}async sendImage(t,e){var s,n;try{let a=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendVideo(t,e){var s,n;try{let a=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendAudio(t,e){var s,n;try{let a=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((s=this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendSticker(t,e){var s,n;try{let a=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}};var Te=v;0&&(module.exports={Client});
1
+ var xe=Object.create;var I=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var he=(c,g)=>{for(var t in g)I(c,t,{get:g[t],enumerable:!0})},le=(c,g,t,e)=>{if(g&&typeof g=="object"||typeof g=="function")for(let s of Ie(g))!Se.call(c,s)&&s!==t&&I(c,s,{get:()=>g[s],enumerable:!(e=Te(g,s))||e.enumerable});return c};var y=(c,g,t)=>(t=c!=null?xe(be(c)):{},le(g||!c||!c.__esModule?I(t,"default",{value:c,enumerable:!0}):t,c)),Ee=c=>le(I({},"__esModule",{value:!0}),c);var Re={};he(Re,{Client:()=>v,Config:()=>b,General:()=>O,Message:()=>q,Types:()=>F,default:()=>Pe});module.exports=Ee(Re);var b={};he(b,{MESSAGE_TYPE:()=>P,VERIFIED_PLATFORM:()=>R});var P={text:"text",conversation:"text",imageMessage:"image",contactMessage:"contact",locationMessage:"location",documentMessage:"document",audioMessage:"audio",videoMessage:"video",protocolMessage:"protocol",contactsArrayMessage:"contactsArray",highlyStructuredMessage:"highlyStructured",sendPaymentMessage:"sendPayment",liveLocationMessage:"liveLocation",requestPaymentMessage:"requestPayment",declinePaymentRequestMessage:"declinePaymentRequest",cancelPaymentRequestMessage:"cancelPaymentRequest",templateMessage:"template",stickerMessage:"sticker",groupInviteMessage:"groupInvite",templateButtonReplyMessage:"templateButtonReply",productMessage:"product",deviceSentMessage:"deviceSent",listMessage:"list",viewOnceMessage:"viewOnce",orderMessage:"order",listResponseMessage:"listResponse",ephemeralMessage:"ephemeral",invoiceMessage:"invoice",buttonsMessage:"buttons",buttonsResponseMessage:"buttonsResponse",paymentInviteMessage:"paymentInvite",interactiveMessage:"interactive",reactionMessage:"reaction",stickerSyncRmrMessage:"sticker",interactiveResponseMessage:"interactiveResponse",pollCreationMessage:"pollCreation",pollUpdateMessage:"pollUpdate",keepInChatMessage:"keepInChat",documentWithCaptionMessage:"document",requestPhoneNumberMessage:"requestPhoneNumber",viewOnceMessageV2:"viewOnce",encReactionMessage:"reaction",editedMessage:"text",viewOnceMessageV2Extension:"viewOnce",pollCreationMessageV2:"pollCreation",scheduledCallCreationMessage:"scheduledCallCreation",groupMentionedMessage:"groupMentioned",pinInChatMessage:"pinInChat",pollCreationMessageV3:"pollCreation",scheduledCallEditMessage:"scheduledCallEdit",ptvMessage:"ptv",botInvokeMessage:"botInvoke",callLogMesssage:"callLog",encCommentMessage:"encComment",bcallMessage:"bcall",lottieStickerMessage:"lottieSticker",eventMessage:"event",commentMessage:"comment",newsletterAdminInviteMessage:"text",extendedTextMessageWithParentKey:"text",placeholderMessage:"placeholder",encEventUpdateMessage:"encEventUpdate"},R={whatsapp:"0@s.whatsapp.net",meta:"13135550002@s.whatsapp.net",chatgpt:"18002428478@s.whatsapp.net",copilot:"18772241042@s.whatsapp.net",instagram:"447723442971@s.whatsapp.net",tiktok:"6285574670498@s.whatsapp.net"};var h=y(require("@whiskeysockets/baileys")),ue=require("awesome-phonenumber"),fe=y(require("chalk")),B=y(require("consola")),ye=require("events"),Me=y(require("figlet")),ke=y(require("fs")),A=y(require("node-cache")),Ce=y(require("ora")),ve=y(require("pino"));var C=require("@whiskeysockets/baileys");var de=(c,g)=>{let t=new Set(c);for(let e of g)if(t.has(e))return!0;return!1},k=(c,g)=>Array.isArray(c)?c.map(t=>k(t,g)):c&&typeof c=="object"?Object.keys(c).reduce((t,e)=>(g.includes(e)||(t[e]=k(c[e],g)),t),{}):c;var S=class{constructor({socket:g,message:t,config:e,store:s}){this.socket=g,this.message=t,this.config=e,this.store=s}async handle(g){var x,E,W,V,K,L,J,N,D,j,_,z,G,U,$,Y,Q,H,Z,X,ee,te,se,ie,oe,ne,ae,re,ce,ge,me,pe;let t=k(g||this.message,["senderKeyDistributionMessage","messageContextInfo"]);if(t!=null&&t.messageStubType||!Object.keys(t==null?void 0:t.message).length)return;let e=t.ephemeralMessage||t,s=!!((x=e.message)!=null&&x.extendedTextMessage),n=!!((W=(E=e.message)==null?void 0:E.protocolMessage)!=null&&W.editedMessage),a=!!((V=e.message)!=null&&V.botInvokeMessage),i=((J=(L=(K=e.message)==null?void 0:K.protocolMessage)==null?void 0:L.editedMessage)==null?void 0:J.extendedTextMessage)||((D=(N=e.message)==null?void 0:N.protocolMessage)==null?void 0:D.editedMessage),o=s?Object.keys(e.message.extendedTextMessage)[0]:n?Object.keys(i)[0]:a?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],m=s?(z=(_=(j=e.message)==null?void 0:j.extendedTextMessage)==null?void 0:_.contextInfo)==null?void 0:z.stanzaId:($=(U=(G=e.message)==null?void 0:G[o])==null?void 0:U.contextInfo)==null?void 0:$.stanzaId,l=P[o];(Q=(Y=e.message)==null?void 0:Y.protocolMessage)!=null&&Q.ephemeralExpiration&&(l="ephemeral");let r=s?e.message.extendedTextMessage[o]:n?i[o]:a?e.message.botInvokeMessage.message.extendedTextMessage[o]:e.message[o],d=typeof r=="string"?r:(r==null?void 0:r.caption)||(r==null?void 0:r.text)||(r==null?void 0:r.name)||null,w=(d==null?void 0:d.match(/@\d+/g))||null,p={fromMe:e.key.fromMe,chatId:e.key.id,roomId:e.key.remoteJid,roomImage:async()=>await this.socket.profilePictureUrl(e.key.remoteJid,"image").catch(()=>null),senderId:e.participant||e.key.participant||e.key.remoteJid,senderName:e.pushName||e.verifiedBizName||null,senderDevice:(0,C.getDevice)(e.key.id),senderBio:async()=>await this.socket.fetchStatus(e.key.participant||e.key.remoteJid).then(u=>{var f,T;return(T=(f=u==null?void 0:u[0])==null?void 0:f.status)==null?void 0:T.status}).catch(()=>null),senderImage:async()=>{let u=await this.socket.profilePictureUrl(e.key.participant||e.key.remoteJid,"image").catch(()=>null);return u===void 0?null:u},senderBusiness:async()=>await this.socket.getBusinessProfile(e.key.participant||e.key.remoteJid).catch(()=>null),chatType:l,timestamp:Number((e.messageTimestamp.low||e.messageTimestamp||0).toString()),text:d,command:d!=null&&d.startsWith(this.config.prefix)?(H=d.split(" ")[0])==null?void 0:H.slice(1):null,mentions:w,isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:n,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:l==="ephemeral"||!!((ee=(X=(Z=e.message)==null?void 0:Z.extendedTextMessage)==null?void 0:X.contextInfo)!=null&&ee.expiration),isForwarded:!!((ie=(se=(te=e.message)==null?void 0:te.extendedTextMessage)==null?void 0:se.contextInfo)!=null&&ie.isForwarded),citation:{},media:typeof r!="string"?r:null,reply:null,key:()=>e.key,message:()=>this.message};if(p.media&&(p.media={...p.media,...(p.media.url||((ne=(oe=e.message)==null?void 0:oe.extendedTextMessage)==null?void 0:ne.jpegThumbnail)||((ae=e.message)==null?void 0:ae.newsletterAdminInviteMessage)||((re=e.message)==null?void 0:re.orderMessage))&&{buffer:async()=>await(0,C.downloadMediaMessage)(this.message,"buffer",{}).catch(()=>null),stream:async()=>await(0,C.downloadMediaMessage)(this.message,"stream",{}).catch(()=>null)}},p.media=k(p.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let u=[(ce=p.roomId)==null?void 0:ce.split("@")[0],(ge=p.senderId)==null?void 0:ge.split("@")[0]];for(let f of Object.keys(this.config.citation)){let T=`is${f[0].toUpperCase()}${f.slice(1)}`,we=await this.config.citation[f]();p.citation={...p.citation||{},[T]:de(we,u)}}}if(m){let u=(me=this.store.messages[p.roomId])==null?void 0:me.get(m),f=(pe=this.store.messages[p.senderId])==null?void 0:pe.get(m);if(!u&&!f)return p;p.reply=await this.handle(u||f)}return p}};var v=class extends ye.EventEmitter{constructor(t){var s;super();this.groupCache=new A.default({stdTTL:5*60,useClones:!1});this.logger=(0,ve.default)({level:"silent",enabled:!1});this.spinner=(0,Ce.default)();this.config=t,this.config.showLogs=!!this.config.showLogs,this.config.autoOnline=!!this.config.autoOnline,this.config.authPath=this.config.authPath||".zaileys",this.config.ignoreMe=this.config.ignoreMe==null?!0:this.config.ignoreMe,this.config.showLogs=this.config.showLogs==null?!0:this.config.showLogs,this.authProvider=(0,h.useMultiFileAuthState)(this.config.authPath+"/session"),this.store=(0,h.makeInMemoryStore)({logger:this.logger});try{(s=this.store)==null||s.readFromFile(this.config.authPath+"/memory.json"),setInterval(()=>{var n;(n=this==null?void 0:this.store)==null||n.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(n){}Object.keys(this.config).length&&this.initialize()}async initialize(){var s,n,a;await console.clear(),await(0,Me.default)("Zaileys Libs",function(i,o){console.log(fe.default.greenBright(o)),console.log()}),this==null||this.spinner.start("Make connection to whatsapp...");let{state:t,saveCreds:e}=await this.authProvider;if(this.authState={load:t,save:e},this.socket=(0,h.default)({logger:this.logger,printQRInTerminal:this.config.authType=="qr",markOnlineOnConnect:this.config.autoOnline,auth:this.authState.load,version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new A.default,browser:h.Browsers.ubuntu(this.config.authType=="qr"?"Zaileys Library":"Firefox"),cachedGroupMetadata:async i=>this.groupCache.get(i),getMessage:async i=>{if(this.store){let o=await this.store.loadMessage(i.remoteJid,i.id);return(o==null?void 0:o.message)||void 0}return h.proto.Message.fromObject({})},shouldSyncHistoryMessage:i=>!!i.syncType}),this.store.bind(this.socket.ev),this.config.authType=="pairing"&&this.config.phoneNumber&&!this.socket.authState.creds.registered){if(!this.config.phoneNumber){this.spinner.warn("Please enter your phone number");return}if(!(0,ue.parsePhoneNumber)("+"+this.config.phoneNumber.toString()).valid){this==null||this.spinner.warn("Please enter a valid phone number");return}setTimeout(async()=>{try{if(this.config.authType=="pairing"){let i=await this.socket.requestPairingCode(this.config.phoneNumber.toString());this.spinner.info("This is your OTP code: "+i.replace(/(.{4})/,"$1-"))}}catch(i){}},5e3)}(s=this==null?void 0:this.socket)==null||s.ev.on("connection.update",async i=>{var r,d,w;let{connection:o,lastDisconnect:m,qr:l}=i;if(this.emit("connection",{status:o||"connecting"}),this.config.authType=="qr"&&l&&this.spinner.info("Scan qrcode with your whatsapp: "),o==="close"){let p=(d=(r=m==null?void 0:m.error)==null?void 0:r.output)==null?void 0:d.statusCode,x=p!==h.DisconnectReason.loggedOut;if(this==null||this.spinner.fail((w=m==null?void 0:m.error)==null?void 0:w.message),p==401||p==405||p==500){this.spinner.warn(`Bad session, please delete "${this.config.authPath}" folder and try again`),await B.default.prompt("Do you want to delete the session?",{type:"confirm"})&&await this.deleteSession();return}x&&this.initialize()}else o==="open"&&this.spinner.succeed("Successfully connected to whatsapp")}),(n=this==null?void 0:this.socket)==null||n.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",i=>{var o;for(let m of i){let l=(0,h.jidNormalizedUser)(m.id);this.store&&this.store.contacts&&(this.store.contacts[l]={...((o=this.store.contacts)==null?void 0:o[l])||{},...m||{}})}}),this.socket.ev.on("contacts.upsert",i=>{for(let o of i){let m=(0,h.jidNormalizedUser)(o.id);this.store&&this.store.contacts&&(this.store.contacts[m]={...o||{}})}}),(a=this.socket)==null||a.ev.on("messages.upsert",async i=>{let o=i.messages;for(let m of o){if(this.config.ignoreMe&&m.key.fromMe)continue;let r=await new S({message:m,socket:this.socket,config:this.config,store:this.store}).handle();r&&(this.config.autoRead&&await this.socket.readMessages([r.key()]),this.temporaryMessage=r,this.config.autoMentions&&(this.parseMention=r.mentions),this.emit("message",r))}}),this.socket.ev.on("groups.update",async([i])=>{let o=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,o)}),this.socket.ev.on("group-participants.update",async i=>{let o=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,o)}),this.socket.ev.on("call",async i=>{for(let o of i)this.config.autoRejectCall&&await this.socket.rejectCall(o.id,o.from)})}async deleteSession(){try{await ke.default.rmSync(`${this.config.authPath}`,{recursive:!0,force:!0}),await this.spinner.succeed("Session deleted. Please restart manually"),process.exit(0)}catch(t){this==null||this.spinner.fail("Failed to delete session"),await B.default.prompt("Do you want to try again?",{type:"confirm"})||process.exit(0),await this.deleteSession()}}on(t,e){return super.on(t,e)}emit(t,...e){return super.emit(t,...e)}generateMentions(t){let e=["@s.whatsapp.net","@g.us","@newsletter"],s=[];return t==null||t.forEach(n=>{e.forEach(a=>{s.push(n.slice(1)+a)})}),s}generateFakeVerified(t,e){return{...t,participant:R[e]}}async sendText(t,e){var s,n,a;try{if(e!=null&&e.footer){let i=(0,h.generateWAMessageFromContent)((s=this.temporaryMessage)==null?void 0:s.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId});await this.socket.relayMessage(i.key.remoteJid,i.message,{messageId:i.key.id})}else await this.socket.sendMessage((a=this.temporaryMessage)==null?void 0:a.roomId,{text:t})}catch(i){throw i}}async sendReply(t,e){var s,n,a,i,o,m,l;try{if(e!=null&&e.footer){let r=(0,h.generateWAMessageFromContent)((s=this.temporaryMessage)==null?void 0:s.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{quoted:{...(n=this.temporaryMessage)==null?void 0:n.message(),key:this.generateFakeVerified((a=this==null?void 0:this.temporaryMessage)==null?void 0:a.message().key,e.fakeVerified)},userJid:(i=this==null?void 0:this.temporaryMessage)==null?void 0:i.roomId});await this.socket.relayMessage(r.key.remoteJid,r.message,{messageId:r.key.id})}else await this.socket.sendMessage((o=this.temporaryMessage)==null?void 0:o.roomId,{text:t},{quoted:{...(m=this==null?void 0:this.temporaryMessage)==null?void 0:m.message(),key:this.generateFakeVerified((l=this==null?void 0:this.temporaryMessage)==null?void 0:l.message().key,e==null?void 0:e.fakeVerified)}})}catch(r){throw r}}async sendImage(t,e){var s,n;try{let a=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendVideo(t,e){var s,n;try{let a=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendAudio(t,e){var s,n;try{let a=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((s=this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendSticker(t,e){var s,n;try{let a=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}};var F={};var O={};var q={};var Pe=v;0&&(module.exports={Client,Config,General,Message,Types});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import me,{Browsers as pe,DisconnectReason as de,generateWAMessageFromContent as ne,jidNormalizedUser as ae,makeInMemoryStore as le,proto as ue,useMultiFileAuthState as fe}from"@whiskeysockets/baileys";import{parsePhoneNumber as Me}from"awesome-phonenumber";import ye from"chalk";import re from"consola";import{EventEmitter as ke}from"events";import ve from"figlet";import we from"fs";import ce from"node-cache";import Ie from"ora";import Ce from"pino";import{downloadMediaMessage as oe,getDevice as he}from"@whiskeysockets/baileys";var te={text:"text",conversation:"text",imageMessage:"image",contactMessage:"contact",locationMessage:"location",documentMessage:"document",audioMessage:"audio",videoMessage:"video",protocolMessage:"protocol",contactsArrayMessage:"contactsArray",highlyStructuredMessage:"highlyStructured",sendPaymentMessage:"sendPayment",liveLocationMessage:"liveLocation",requestPaymentMessage:"requestPayment",declinePaymentRequestMessage:"declinePaymentRequest",cancelPaymentRequestMessage:"cancelPaymentRequest",templateMessage:"template",stickerMessage:"sticker",groupInviteMessage:"groupInvite",templateButtonReplyMessage:"templateButtonReply",productMessage:"product",deviceSentMessage:"deviceSent",listMessage:"list",viewOnceMessage:"viewOnce",orderMessage:"order",listResponseMessage:"listResponse",ephemeralMessage:"ephemeral",invoiceMessage:"invoice",buttonsMessage:"buttons",buttonsResponseMessage:"buttonsResponse",paymentInviteMessage:"paymentInvite",interactiveMessage:"interactive",reactionMessage:"reaction",stickerSyncRmrMessage:"sticker",interactiveResponseMessage:"interactiveResponse",pollCreationMessage:"pollCreation",pollUpdateMessage:"pollUpdate",keepInChatMessage:"keepInChat",documentWithCaptionMessage:"document",requestPhoneNumberMessage:"requestPhoneNumber",viewOnceMessageV2:"viewOnce",encReactionMessage:"reaction",editedMessage:"text",viewOnceMessageV2Extension:"viewOnce",pollCreationMessageV2:"pollCreation",scheduledCallCreationMessage:"scheduledCallCreation",groupMentionedMessage:"groupMentioned",pinInChatMessage:"pinInChat",pollCreationMessageV3:"pollCreation",scheduledCallEditMessage:"scheduledCallEdit",ptvMessage:"ptv",botInvokeMessage:"botInvoke",callLogMesssage:"callLog",encCommentMessage:"encComment",bcallMessage:"bcall",lottieStickerMessage:"lottieSticker",eventMessage:"event",commentMessage:"comment",newsletterAdminInviteMessage:"text",extendedTextMessageWithParentKey:"text",placeholderMessage:"placeholder",encEventUpdateMessage:"encEventUpdate"},se={whatsapp:"0@s.whatsapp.net",meta:"13135550002@s.whatsapp.net",chatgpt:"18002428478@s.whatsapp.net",copilot:"18772241042@s.whatsapp.net",instagram:"447723442971@s.whatsapp.net",tiktok:"6285574670498@s.whatsapp.net"};var ie=(m,l)=>{let t=new Set(m);for(let e of l)if(t.has(e))return!0;return!1},f=(m,l)=>Array.isArray(m)?m.map(t=>f(t,l)):m&&typeof m=="object"?Object.keys(m).reduce((t,e)=>(l.includes(e)||(t[e]=f(m[e],l)),t),{}):m;var I=class{constructor({socket:l,message:t,config:e,store:o}){this.socket=l,this.message=t,this.config=e,this.store=o}async handle(l){var y,S,T,b,x,R,P,E,A,B,F,O,q,W,J,K,V,L,N,j,D,z,U,_,$,G,H,Q,Y,Z,X,ee;let t=f(l||this.message,["senderKeyDistributionMessage","messageContextInfo"]);if(t!=null&&t.messageStubType||!Object.keys(t==null?void 0:t.message).length)return;let e=t.ephemeralMessage||t,o=!!((y=e.message)!=null&&y.extendedTextMessage),n=!!((T=(S=e.message)==null?void 0:S.protocolMessage)!=null&&T.editedMessage),a=!!((b=e.message)!=null&&b.botInvokeMessage),s=((P=(R=(x=e.message)==null?void 0:x.protocolMessage)==null?void 0:R.editedMessage)==null?void 0:P.extendedTextMessage)||((A=(E=e.message)==null?void 0:E.protocolMessage)==null?void 0:A.editedMessage),i=o?Object.keys(e.message.extendedTextMessage)[0]:n?Object.keys(s)[0]:a?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],c=o?(O=(F=(B=e.message)==null?void 0:B.extendedTextMessage)==null?void 0:F.contextInfo)==null?void 0:O.stanzaId:(J=(W=(q=e.message)==null?void 0:q[i])==null?void 0:W.contextInfo)==null?void 0:J.stanzaId,h=te[i];(V=(K=e.message)==null?void 0:K.protocolMessage)!=null&&V.ephemeralExpiration&&(h="ephemeral");let r=o?e.message.extendedTextMessage[i]:n?s[i]:a?e.message.botInvokeMessage.message.extendedTextMessage[i]:e.message[i],p=typeof r=="string"?r:(r==null?void 0:r.caption)||(r==null?void 0:r.text)||(r==null?void 0:r.name)||null,M=(p==null?void 0:p.match(/@\d+/g))||null,g={fromMe:e.key.fromMe,chatId:e.key.id,roomId:e.key.remoteJid,roomImage:async()=>await this.socket.profilePictureUrl(e.key.remoteJid,"image").catch(()=>null),senderId:e.participant||e.key.participant||e.key.remoteJid,senderName:e.pushName||e.verifiedBizName||null,senderDevice:he(e.key.id),senderBio:async()=>await this.socket.fetchStatus(e.key.participant||e.key.remoteJid).then(d=>{var u,k;return(k=(u=d==null?void 0:d[0])==null?void 0:u.status)==null?void 0:k.status}).catch(()=>null),senderImage:async()=>{let d=await this.socket.profilePictureUrl(e.key.participant||e.key.remoteJid,"image").catch(()=>null);return d===void 0?null:d},senderBusiness:async()=>await this.socket.getBusinessProfile(e.key.participant||e.key.remoteJid).catch(()=>null),chatType:h,timestamp:Number((e.messageTimestamp.low||e.messageTimestamp||0).toString()),text:p,command:p!=null&&p.startsWith(this.config.prefix)?(L=p.split(" ")[0])==null?void 0:L.slice(1):null,mentions:M,isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:n,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:h==="ephemeral"||!!((D=(j=(N=e.message)==null?void 0:N.extendedTextMessage)==null?void 0:j.contextInfo)!=null&&D.expiration),isForwarded:!!((_=(U=(z=e.message)==null?void 0:z.extendedTextMessage)==null?void 0:U.contextInfo)!=null&&_.isForwarded),citation:{},media:typeof r!="string"?r:null,reply:null,key:()=>e.key,message:()=>this.message};if(g.media&&(g.media={...g.media,...(g.media.url||((G=($=e.message)==null?void 0:$.extendedTextMessage)==null?void 0:G.jpegThumbnail)||((H=e.message)==null?void 0:H.newsletterAdminInviteMessage)||((Q=e.message)==null?void 0:Q.orderMessage))&&{buffer:async()=>await oe(this.message,"buffer",{}).catch(()=>null),stream:async()=>await oe(this.message,"stream",{}).catch(()=>null)}},g.media=f(g.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let d=[(Y=g.roomId)==null?void 0:Y.split("@")[0],(Z=g.senderId)==null?void 0:Z.split("@")[0]];for(let u of Object.keys(this.config.citation)){let k=`is${u[0].toUpperCase()}${u.slice(1)}`,ge=await this.config.citation[u]();g.citation={...g.citation||{},[k]:ie(ge,d)}}}if(c){let d=(X=this.store.messages[g.roomId])==null?void 0:X.get(c),u=(ee=this.store.messages[g.senderId])==null?void 0:ee.get(c);if(!d&&!u)return g;g.reply=await this.handle(d||u)}return g}};var C=class extends ke{constructor(t){var o;super();this.groupCache=new ce({stdTTL:5*60,useClones:!1});this.logger=Ce({level:"silent",enabled:!1});this.spinner=Ie();this.config=t,this.config.showLogs=!!this.config.showLogs,this.config.autoOnline=!!this.config.autoOnline,this.config.authPath=this.config.authPath||".zaileys",this.config.ignoreMe=this.config.ignoreMe==null?!0:this.config.ignoreMe,this.config.showLogs=this.config.showLogs==null?!0:this.config.showLogs,this.authProvider=fe(this.config.authPath+"/session"),this.store=le({logger:this.logger});try{(o=this.store)==null||o.readFromFile(this.config.authPath+"/memory.json"),setInterval(()=>{var n;(n=this==null?void 0:this.store)==null||n.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(n){}Object.keys(this.config).length&&this.initialize()}async initialize(){var o,n,a;await console.clear(),await ve("Zaileys Libs",function(s,i){console.log(ye.greenBright(i)),console.log()}),this==null||this.spinner.start("Make connection to whatsapp...");let{state:t,saveCreds:e}=await this.authProvider;if(this.authState={load:t,save:e},this.socket=me({logger:this.logger,printQRInTerminal:this.config.authType=="qr",markOnlineOnConnect:this.config.autoOnline,auth:this.authState.load,version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new ce,browser:pe.ubuntu(this.config.authType=="qr"?"Zaileys Library":"Firefox"),cachedGroupMetadata:async s=>this.groupCache.get(s),getMessage:async s=>{if(this.store){let i=await this.store.loadMessage(s.remoteJid,s.id);return(i==null?void 0:i.message)||void 0}return ue.Message.fromObject({})},shouldSyncHistoryMessage:s=>!!s.syncType}),this.store.bind(this.socket.ev),this.config.authType=="pairing"&&this.config.phoneNumber&&!this.socket.authState.creds.registered){if(!this.config.phoneNumber){this.spinner.warn("Please enter your phone number");return}if(!Me("+"+this.config.phoneNumber.toString()).valid){this==null||this.spinner.warn("Please enter a valid phone number");return}setTimeout(async()=>{try{if(this.config.authType=="pairing"){let s=await this.socket.requestPairingCode(this.config.phoneNumber.toString());this.spinner.info("This is your OTP code: "+s.replace(/(.{4})/,"$1-"))}}catch(s){}},5e3)}(o=this==null?void 0:this.socket)==null||o.ev.on("connection.update",async s=>{var r,p,M;let{connection:i,lastDisconnect:c,qr:h}=s;if(this.emit("connection",{status:i||"connecting"}),this.config.authType=="qr"&&h&&this.spinner.info("Scan qrcode with your whatsapp: "),i==="close"){let g=(p=(r=c==null?void 0:c.error)==null?void 0:r.output)==null?void 0:p.statusCode,y=g!==de.loggedOut;if(this==null||this.spinner.fail((M=c==null?void 0:c.error)==null?void 0:M.message),g==401||g==405||g==500){this.spinner.warn(`Bad session, please delete "${this.config.authPath}" folder and try again`),await re.prompt("Do you want to delete the session?",{type:"confirm"})&&await this.deleteSession();return}y&&this.initialize()}else i==="open"&&this.spinner.succeed("Successfully connected to whatsapp")}),(n=this==null?void 0:this.socket)==null||n.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",s=>{var i;for(let c of s){let h=ae(c.id);this.store&&this.store.contacts&&(this.store.contacts[h]={...((i=this.store.contacts)==null?void 0:i[h])||{},...c||{}})}}),this.socket.ev.on("contacts.upsert",s=>{for(let i of s){let c=ae(i.id);this.store&&this.store.contacts&&(this.store.contacts[c]={...i||{}})}}),(a=this.socket)==null||a.ev.on("messages.upsert",async s=>{let i=s.messages;for(let c of i){if(this.config.ignoreMe&&c.key.fromMe)continue;let r=await new I({message:c,socket:this.socket,config:this.config,store:this.store}).handle();r&&(this.config.autoRead&&await this.socket.readMessages([r.key()]),this.temporaryMessage=r,this.config.autoMentions&&(this.parseMention=r.mentions),this.emit("message",r))}}),this.socket.ev.on("groups.update",async([s])=>{let i=await this.socket.groupMetadata(s.id);this.groupCache.set(s.id,i)}),this.socket.ev.on("group-participants.update",async s=>{let i=await this.socket.groupMetadata(s.id);this.groupCache.set(s.id,i)}),this.socket.ev.on("call",async s=>{for(let i of s)this.config.autoRejectCall&&await this.socket.rejectCall(i.id,i.from)})}async deleteSession(){try{await we.rmSync(`${this.config.authPath}`,{recursive:!0,force:!0}),await this.spinner.succeed("Session deleted. Please restart manually"),process.exit(0)}catch(t){if(this==null||this.spinner.fail("Failed to delete session"),await re.prompt("Do you want to try again?",{type:"confirm"}))return await this.deleteSession();process.exit(0)}}on(t,e){return super.on(t,e)}emit(t,...e){return super.emit(t,...e)}generateMentions(t){let e=["@s.whatsapp.net","@g.us","@newsletter"],o=[];return t==null||t.forEach(n=>{e.forEach(a=>{o.push(n.slice(1)+a)})}),o}generateFakeVerified(t,e){return{...t,participant:se[e]}}async sendText(t,e){var o,n,a;try{if(e!=null&&e.footer){let s=ne((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId});await this.socket.relayMessage(s.key.remoteJid,s.message,{messageId:s.key.id})}else await this.socket.sendMessage((a=this.temporaryMessage)==null?void 0:a.roomId,{text:t})}catch(s){throw s}}async sendReply(t,e){var o,n,a,s,i,c,h;try{if(e!=null&&e.footer){let r=ne((o=this.temporaryMessage)==null?void 0:o.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{quoted:{...(n=this.temporaryMessage)==null?void 0:n.message(),key:this.generateFakeVerified((a=this==null?void 0:this.temporaryMessage)==null?void 0:a.message().key,e.fakeVerified)},userJid:(s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId});await this.socket.relayMessage(r.key.remoteJid,r.message,{messageId:r.key.id})}else await this.socket.sendMessage((i=this.temporaryMessage)==null?void 0:i.roomId,{text:t},{quoted:{...(c=this==null?void 0:this.temporaryMessage)==null?void 0:c.message(),key:this.generateFakeVerified((h=this==null?void 0:this.temporaryMessage)==null?void 0:h.message().key,e==null?void 0:e.fakeVerified)}})}catch(r){throw r}}async sendImage(t,e){var o,n;try{let a=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendVideo(t,e){var o,n;try{let a=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendAudio(t,e){var o,n;try{let a=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((o=this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendSticker(t,e){var o,n;try{let a=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}};var Ze=C;export{C as Client,Ze as default};
1
+ var de=Object.defineProperty;var ue=(m,p)=>{for(var t in p)de(m,t,{get:p[t],enumerable:!0})};var S={};ue(S,{MESSAGE_TYPE:()=>I,VERIFIED_PLATFORM:()=>b});var I={text:"text",conversation:"text",imageMessage:"image",contactMessage:"contact",locationMessage:"location",documentMessage:"document",audioMessage:"audio",videoMessage:"video",protocolMessage:"protocol",contactsArrayMessage:"contactsArray",highlyStructuredMessage:"highlyStructured",sendPaymentMessage:"sendPayment",liveLocationMessage:"liveLocation",requestPaymentMessage:"requestPayment",declinePaymentRequestMessage:"declinePaymentRequest",cancelPaymentRequestMessage:"cancelPaymentRequest",templateMessage:"template",stickerMessage:"sticker",groupInviteMessage:"groupInvite",templateButtonReplyMessage:"templateButtonReply",productMessage:"product",deviceSentMessage:"deviceSent",listMessage:"list",viewOnceMessage:"viewOnce",orderMessage:"order",listResponseMessage:"listResponse",ephemeralMessage:"ephemeral",invoiceMessage:"invoice",buttonsMessage:"buttons",buttonsResponseMessage:"buttonsResponse",paymentInviteMessage:"paymentInvite",interactiveMessage:"interactive",reactionMessage:"reaction",stickerSyncRmrMessage:"sticker",interactiveResponseMessage:"interactiveResponse",pollCreationMessage:"pollCreation",pollUpdateMessage:"pollUpdate",keepInChatMessage:"keepInChat",documentWithCaptionMessage:"document",requestPhoneNumberMessage:"requestPhoneNumber",viewOnceMessageV2:"viewOnce",encReactionMessage:"reaction",editedMessage:"text",viewOnceMessageV2Extension:"viewOnce",pollCreationMessageV2:"pollCreation",scheduledCallCreationMessage:"scheduledCallCreation",groupMentionedMessage:"groupMentioned",pinInChatMessage:"pinInChat",pollCreationMessageV3:"pollCreation",scheduledCallEditMessage:"scheduledCallEdit",ptvMessage:"ptv",botInvokeMessage:"botInvoke",callLogMesssage:"callLog",encCommentMessage:"encComment",bcallMessage:"bcall",lottieStickerMessage:"lottieSticker",eventMessage:"event",commentMessage:"comment",newsletterAdminInviteMessage:"text",extendedTextMessageWithParentKey:"text",placeholderMessage:"placeholder",encEventUpdateMessage:"encEventUpdate"},b={whatsapp:"0@s.whatsapp.net",meta:"13135550002@s.whatsapp.net",chatgpt:"18002428478@s.whatsapp.net",copilot:"18772241042@s.whatsapp.net",instagram:"447723442971@s.whatsapp.net",tiktok:"6285574670498@s.whatsapp.net"};import ye,{Browsers as Me,DisconnectReason as ke,generateWAMessageFromContent as ae,jidNormalizedUser as re,makeInMemoryStore as Ce,proto as ve,useMultiFileAuthState as we}from"@whiskeysockets/baileys";import{parsePhoneNumber as xe}from"awesome-phonenumber";import Te from"chalk";import ce from"consola";import{EventEmitter as Ie}from"events";import be from"figlet";import Se from"fs";import ge from"node-cache";import Ee from"ora";import Pe from"pino";import{downloadMediaMessage as ne,getDevice as fe}from"@whiskeysockets/baileys";var oe=(m,p)=>{let t=new Set(m);for(let e of p)if(t.has(e))return!0;return!1},M=(m,p)=>Array.isArray(m)?m.map(t=>M(t,p)):m&&typeof m=="object"?Object.keys(m).reduce((t,e)=>(p.includes(e)||(t[e]=M(m[e],p)),t),{}):m;var w=class{constructor({socket:p,message:t,config:e,store:o}){this.socket=p,this.message=t,this.config=e,this.store=o}async handle(p){var C,T,E,P,R,B,A,F,O,q,W,V,K,L,J,N,D,j,_,z,G,U,$,Y,Q,H,Z,X,ee,te,se,ie;let t=M(p||this.message,["senderKeyDistributionMessage","messageContextInfo"]);if(t!=null&&t.messageStubType||!Object.keys(t==null?void 0:t.message).length)return;let e=t.ephemeralMessage||t,o=!!((C=e.message)!=null&&C.extendedTextMessage),n=!!((E=(T=e.message)==null?void 0:T.protocolMessage)!=null&&E.editedMessage),a=!!((P=e.message)!=null&&P.botInvokeMessage),s=((A=(B=(R=e.message)==null?void 0:R.protocolMessage)==null?void 0:B.editedMessage)==null?void 0:A.extendedTextMessage)||((O=(F=e.message)==null?void 0:F.protocolMessage)==null?void 0:O.editedMessage),i=o?Object.keys(e.message.extendedTextMessage)[0]:n?Object.keys(s)[0]:a?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],c=o?(V=(W=(q=e.message)==null?void 0:q.extendedTextMessage)==null?void 0:W.contextInfo)==null?void 0:V.stanzaId:(J=(L=(K=e.message)==null?void 0:K[i])==null?void 0:L.contextInfo)==null?void 0:J.stanzaId,h=I[i];(D=(N=e.message)==null?void 0:N.protocolMessage)!=null&&D.ephemeralExpiration&&(h="ephemeral");let r=o?e.message.extendedTextMessage[i]:n?s[i]:a?e.message.botInvokeMessage.message.extendedTextMessage[i]:e.message[i],l=typeof r=="string"?r:(r==null?void 0:r.caption)||(r==null?void 0:r.text)||(r==null?void 0:r.name)||null,k=(l==null?void 0:l.match(/@\d+/g))||null,g={fromMe:e.key.fromMe,chatId:e.key.id,roomId:e.key.remoteJid,roomImage:async()=>await this.socket.profilePictureUrl(e.key.remoteJid,"image").catch(()=>null),senderId:e.participant||e.key.participant||e.key.remoteJid,senderName:e.pushName||e.verifiedBizName||null,senderDevice:fe(e.key.id),senderBio:async()=>await this.socket.fetchStatus(e.key.participant||e.key.remoteJid).then(d=>{var u,v;return(v=(u=d==null?void 0:d[0])==null?void 0:u.status)==null?void 0:v.status}).catch(()=>null),senderImage:async()=>{let d=await this.socket.profilePictureUrl(e.key.participant||e.key.remoteJid,"image").catch(()=>null);return d===void 0?null:d},senderBusiness:async()=>await this.socket.getBusinessProfile(e.key.participant||e.key.remoteJid).catch(()=>null),chatType:h,timestamp:Number((e.messageTimestamp.low||e.messageTimestamp||0).toString()),text:l,command:l!=null&&l.startsWith(this.config.prefix)?(j=l.split(" ")[0])==null?void 0:j.slice(1):null,mentions:k,isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:n,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:h==="ephemeral"||!!((G=(z=(_=e.message)==null?void 0:_.extendedTextMessage)==null?void 0:z.contextInfo)!=null&&G.expiration),isForwarded:!!((Y=($=(U=e.message)==null?void 0:U.extendedTextMessage)==null?void 0:$.contextInfo)!=null&&Y.isForwarded),citation:{},media:typeof r!="string"?r:null,reply:null,key:()=>e.key,message:()=>this.message};if(g.media&&(g.media={...g.media,...(g.media.url||((H=(Q=e.message)==null?void 0:Q.extendedTextMessage)==null?void 0:H.jpegThumbnail)||((Z=e.message)==null?void 0:Z.newsletterAdminInviteMessage)||((X=e.message)==null?void 0:X.orderMessage))&&{buffer:async()=>await ne(this.message,"buffer",{}).catch(()=>null),stream:async()=>await ne(this.message,"stream",{}).catch(()=>null)}},g.media=M(g.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let d=[(ee=g.roomId)==null?void 0:ee.split("@")[0],(te=g.senderId)==null?void 0:te.split("@")[0]];for(let u of Object.keys(this.config.citation)){let v=`is${u[0].toUpperCase()}${u.slice(1)}`,le=await this.config.citation[u]();g.citation={...g.citation||{},[v]:oe(le,d)}}}if(c){let d=(se=this.store.messages[g.roomId])==null?void 0:se.get(c),u=(ie=this.store.messages[g.senderId])==null?void 0:ie.get(c);if(!d&&!u)return g;g.reply=await this.handle(d||u)}return g}};var x=class extends Ie{constructor(t){var o;super();this.groupCache=new ge({stdTTL:5*60,useClones:!1});this.logger=Pe({level:"silent",enabled:!1});this.spinner=Ee();this.config=t,this.config.showLogs=!!this.config.showLogs,this.config.autoOnline=!!this.config.autoOnline,this.config.authPath=this.config.authPath||".zaileys",this.config.ignoreMe=this.config.ignoreMe==null?!0:this.config.ignoreMe,this.config.showLogs=this.config.showLogs==null?!0:this.config.showLogs,this.authProvider=we(this.config.authPath+"/session"),this.store=Ce({logger:this.logger});try{(o=this.store)==null||o.readFromFile(this.config.authPath+"/memory.json"),setInterval(()=>{var n;(n=this==null?void 0:this.store)==null||n.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(n){}Object.keys(this.config).length&&this.initialize()}async initialize(){var o,n,a;await console.clear(),await be("Zaileys Libs",function(s,i){console.log(Te.greenBright(i)),console.log()}),this==null||this.spinner.start("Make connection to whatsapp...");let{state:t,saveCreds:e}=await this.authProvider;if(this.authState={load:t,save:e},this.socket=ye({logger:this.logger,printQRInTerminal:this.config.authType=="qr",markOnlineOnConnect:this.config.autoOnline,auth:this.authState.load,version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new ge,browser:Me.ubuntu(this.config.authType=="qr"?"Zaileys Library":"Firefox"),cachedGroupMetadata:async s=>this.groupCache.get(s),getMessage:async s=>{if(this.store){let i=await this.store.loadMessage(s.remoteJid,s.id);return(i==null?void 0:i.message)||void 0}return ve.Message.fromObject({})},shouldSyncHistoryMessage:s=>!!s.syncType}),this.store.bind(this.socket.ev),this.config.authType=="pairing"&&this.config.phoneNumber&&!this.socket.authState.creds.registered){if(!this.config.phoneNumber){this.spinner.warn("Please enter your phone number");return}if(!xe("+"+this.config.phoneNumber.toString()).valid){this==null||this.spinner.warn("Please enter a valid phone number");return}setTimeout(async()=>{try{if(this.config.authType=="pairing"){let s=await this.socket.requestPairingCode(this.config.phoneNumber.toString());this.spinner.info("This is your OTP code: "+s.replace(/(.{4})/,"$1-"))}}catch(s){}},5e3)}(o=this==null?void 0:this.socket)==null||o.ev.on("connection.update",async s=>{var r,l,k;let{connection:i,lastDisconnect:c,qr:h}=s;if(this.emit("connection",{status:i||"connecting"}),this.config.authType=="qr"&&h&&this.spinner.info("Scan qrcode with your whatsapp: "),i==="close"){let g=(l=(r=c==null?void 0:c.error)==null?void 0:r.output)==null?void 0:l.statusCode,C=g!==ke.loggedOut;if(this==null||this.spinner.fail((k=c==null?void 0:c.error)==null?void 0:k.message),g==401||g==405||g==500){this.spinner.warn(`Bad session, please delete "${this.config.authPath}" folder and try again`),await ce.prompt("Do you want to delete the session?",{type:"confirm"})&&await this.deleteSession();return}C&&this.initialize()}else i==="open"&&this.spinner.succeed("Successfully connected to whatsapp")}),(n=this==null?void 0:this.socket)==null||n.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",s=>{var i;for(let c of s){let h=re(c.id);this.store&&this.store.contacts&&(this.store.contacts[h]={...((i=this.store.contacts)==null?void 0:i[h])||{},...c||{}})}}),this.socket.ev.on("contacts.upsert",s=>{for(let i of s){let c=re(i.id);this.store&&this.store.contacts&&(this.store.contacts[c]={...i||{}})}}),(a=this.socket)==null||a.ev.on("messages.upsert",async s=>{let i=s.messages;for(let c of i){if(this.config.ignoreMe&&c.key.fromMe)continue;let r=await new w({message:c,socket:this.socket,config:this.config,store:this.store}).handle();r&&(this.config.autoRead&&await this.socket.readMessages([r.key()]),this.temporaryMessage=r,this.config.autoMentions&&(this.parseMention=r.mentions),this.emit("message",r))}}),this.socket.ev.on("groups.update",async([s])=>{let i=await this.socket.groupMetadata(s.id);this.groupCache.set(s.id,i)}),this.socket.ev.on("group-participants.update",async s=>{let i=await this.socket.groupMetadata(s.id);this.groupCache.set(s.id,i)}),this.socket.ev.on("call",async s=>{for(let i of s)this.config.autoRejectCall&&await this.socket.rejectCall(i.id,i.from)})}async deleteSession(){try{await Se.rmSync(`${this.config.authPath}`,{recursive:!0,force:!0}),await this.spinner.succeed("Session deleted. Please restart manually"),process.exit(0)}catch(t){this==null||this.spinner.fail("Failed to delete session"),await ce.prompt("Do you want to try again?",{type:"confirm"})||process.exit(0),await this.deleteSession()}}on(t,e){return super.on(t,e)}emit(t,...e){return super.emit(t,...e)}generateMentions(t){let e=["@s.whatsapp.net","@g.us","@newsletter"],o=[];return t==null||t.forEach(n=>{e.forEach(a=>{o.push(n.slice(1)+a)})}),o}generateFakeVerified(t,e){return{...t,participant:b[e]}}async sendText(t,e){var o,n,a;try{if(e!=null&&e.footer){let s=ae((o=this.temporaryMessage)==null?void 0:o.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId});await this.socket.relayMessage(s.key.remoteJid,s.message,{messageId:s.key.id})}else await this.socket.sendMessage((a=this.temporaryMessage)==null?void 0:a.roomId,{text:t})}catch(s){throw s}}async sendReply(t,e){var o,n,a,s,i,c,h;try{if(e!=null&&e.footer){let r=ae((o=this.temporaryMessage)==null?void 0:o.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{quoted:{...(n=this.temporaryMessage)==null?void 0:n.message(),key:this.generateFakeVerified((a=this==null?void 0:this.temporaryMessage)==null?void 0:a.message().key,e.fakeVerified)},userJid:(s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId});await this.socket.relayMessage(r.key.remoteJid,r.message,{messageId:r.key.id})}else await this.socket.sendMessage((i=this.temporaryMessage)==null?void 0:i.roomId,{text:t},{quoted:{...(c=this==null?void 0:this.temporaryMessage)==null?void 0:c.message(),key:this.generateFakeVerified((h=this==null?void 0:this.temporaryMessage)==null?void 0:h.message().key,e==null?void 0:e.fakeVerified)}})}catch(r){throw r}}async sendImage(t,e){var o,n;try{let a=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendVideo(t,e){var o,n;try{let a=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendAudio(t,e){var o,n;try{let a=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((o=this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}async sendSticker(t,e){var o,n;try{let a=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId,{...a},{...(e==null?void 0:e.asReply)&&{quoted:(n=this==null?void 0:this.temporaryMessage)==null?void 0:n.message()}})}catch(a){throw a}}};var me={};var pe={};var he={};var rt=x;export{x as Client,S as Config,pe as General,he as Message,me as Types,rt as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zaileys",
3
- "version": "0.29.00-beta",
3
+ "version": "0.29.01-beta",
4
4
  "description": "Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API",
5
5
  "keywords": [
6
6
  "zaileys",
@@ -1,38 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Describe the bug**
11
- A clear and concise description of what the bug is.
12
-
13
- **To Reproduce**
14
- Steps to reproduce the behavior:
15
- 1. Go to '...'
16
- 2. Click on '....'
17
- 3. Scroll down to '....'
18
- 4. See error
19
-
20
- **Expected behavior**
21
- A clear and concise description of what you expected to happen.
22
-
23
- **Screenshots**
24
- If applicable, add screenshots to help explain your problem.
25
-
26
- **Desktop (please complete the following information):**
27
- - OS: [e.g. iOS]
28
- - Browser [e.g. chrome, safari]
29
- - Version [e.g. 22]
30
-
31
- **Smartphone (please complete the following information):**
32
- - Device: [e.g. iPhone6]
33
- - OS: [e.g. iOS8.1]
34
- - Browser [e.g. stock browser, safari]
35
- - Version [e.g. 22]
36
-
37
- **Additional context**
38
- Add any other context about the problem here.
@@ -1,10 +0,0 @@
1
- ---
2
- name: Custom issue template
3
- about: Describe this issue template's purpose here.
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
-
@@ -1,20 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe.**
11
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
-
13
- **Describe the solution you'd like**
14
- A clear and concise description of what you want to happen.
15
-
16
- **Describe alternatives you've considered**
17
- A clear and concise description of any alternative solutions or features you've considered.
18
-
19
- **Additional context**
20
- Add any other context or screenshots about the feature request here.
package/tsup.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- format: ["cjs", "esm"],
5
- entry: ["./src/index.ts"],
6
- dts: true,
7
- shims: true,
8
- skipNodeModulesBundle: true,
9
- clean: true,
10
- minify: true,
11
- });