zaileys 0.29.8-beta → 0.29.10-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.
@@ -0,0 +1,178 @@
1
+ type Awaitable<T> = T | Promise<T>;
2
+
3
+ export type AuthAdapterHandlerType = Promise<{
4
+ state: AuthenticationState;
5
+ saveCreds: () => Promise<void>;
6
+ clear: () => Promise<void>;
7
+ removeCreds: () => Promise<void>
8
+ }>;
9
+
10
+ type Contact = {
11
+ id: string;
12
+ lid?: string;
13
+ name?: string;
14
+ notify?: string;
15
+ verifiedName?: string;
16
+ imgUrl?: string | null;
17
+ status?: string;
18
+ };
19
+
20
+ type Account = {
21
+ details?: Uint8Array | null;
22
+ accountSignatureKey?: Uint8Array | null;
23
+ accountSignature?: Uint8Array | null;
24
+ deviceSignature?: Uint8Array | null;
25
+ };
26
+
27
+ type SignedKeyPair = {
28
+ keyPair: KeyPair;
29
+ signature: Uint8Array;
30
+ keyId: number;
31
+ timestampS?: number;
32
+ };
33
+
34
+ type ProtocolAddress = {
35
+ name: string;
36
+ deviceId: number;
37
+ };
38
+
39
+ type SignalIdentity = {
40
+ identifier: ProtocolAddress;
41
+ identifierKey: Uint8Array;
42
+ };
43
+
44
+ type LTHashState = {
45
+ version: number;
46
+ hash: Buffer;
47
+ indexValueMap: {
48
+ [indexMacBase64: string]: { valueMac: Uint8Array | Buffer };
49
+ };
50
+ };
51
+
52
+ type SignalCreds = {
53
+ readonly signedIdentityKey: KeyPair;
54
+ readonly signedPreKey: SignedKeyPair;
55
+ readonly registrationId: number;
56
+ };
57
+
58
+ type AccountSettings = {
59
+ unarchiveChats: boolean;
60
+ defaultDisappearingMode?: Pick<any, "ephemeralExpiration" | "ephemeralSettingTimestamp">;
61
+ };
62
+
63
+ type SignalKeyStore = {
64
+ get<T extends keyof SignalDataTypeMap>(
65
+ type: T,
66
+ ids: string[]
67
+ ): Awaitable<{
68
+ [id: string]: SignalDataTypeMap[T];
69
+ }>;
70
+ set(data: SignalDataSet): Awaitable<void>;
71
+ clear?(): Awaitable<void>;
72
+ };
73
+
74
+ interface RegistrationOptions {
75
+ phoneNumber?: string;
76
+ phoneNumberCountryCode: string;
77
+ phoneNumberNationalNumber: string;
78
+ phoneNumberMobileCountryCode: string;
79
+ phoneNumberMobileNetworkCode: string;
80
+ method?: "sms" | "voice" | "captcha";
81
+ captcha?: string;
82
+ }
83
+
84
+ export type SslOptions = {
85
+ pfx?: string;
86
+ key?: string | string[] | Buffer | Buffer[];
87
+ passphrase?: string;
88
+ cert?: string | string[] | Buffer | Buffer[];
89
+ ca?: string | string[] | Buffer | Buffer[];
90
+ crl?: string | string[];
91
+ ciphers?: string;
92
+ rejectUnauthorized?: boolean;
93
+ minVersion?: string;
94
+ maxVersion?: string;
95
+ verifyIdentity?: boolean;
96
+ };
97
+
98
+ export type Fingerprint = {
99
+ rawId: number;
100
+ currentIndex: number;
101
+ deviceIndexes: number[];
102
+ };
103
+
104
+ export type AppDataSync = {
105
+ keyData: Uint8Array;
106
+ fingerprint: Fingerprint;
107
+ timestamp: Long | number;
108
+ };
109
+
110
+ export type SignalDataTypeMap = {
111
+ session: Uint8Array;
112
+ "pre-key": KeyPair;
113
+ "sender-key": Uint8Array;
114
+ "app-state-sync-key": AppDataSync;
115
+ "app-state-sync-version": LTHashState;
116
+ "sender-key-memory": {
117
+ [jid: string]: boolean;
118
+ };
119
+ };
120
+
121
+ export type SignalDataSet = {
122
+ [T in keyof SignalDataTypeMap]?: {
123
+ [id: string]: SignalDataTypeMap[T] | null;
124
+ };
125
+ };
126
+
127
+ export type KeyPair = {
128
+ public: Uint8Array;
129
+ private: Uint8Array;
130
+ };
131
+
132
+ export type sqlData = {
133
+ constructor: {
134
+ name: "RowDataPacket";
135
+ };
136
+ value?: object[];
137
+ };
138
+
139
+ export type valueReplacer = {
140
+ data: number[];
141
+ type: string;
142
+ };
143
+
144
+ export type valueReviver = {
145
+ data: string;
146
+ type: string;
147
+ };
148
+
149
+ export type AuthenticationState = {
150
+ creds: AuthenticationCreds;
151
+ keys: SignalKeyStore;
152
+ };
153
+
154
+ export type AuthenticationCreds = SignalCreds & {
155
+ readonly noiseKey: KeyPair;
156
+ readonly pairingEphemeralKeyPair: KeyPair;
157
+ advSecretKey: string;
158
+ me?: Contact;
159
+ account?: Account;
160
+ signalIdentities?: SignalIdentity[];
161
+ myAppStateKeyId?: string;
162
+ firstUnuploadedPreKeyId: number;
163
+ nextPreKeyId: number;
164
+ lastAccountSyncTimestamp?: number;
165
+ platform?: string;
166
+ processedHistoryMessages: Pick<any, "key" | "messageTimestamp">[];
167
+ accountSyncCounter: number;
168
+ accountSettings: AccountSettings;
169
+ deviceId: string;
170
+ phoneId: string;
171
+ identityId: Buffer;
172
+ registered: boolean;
173
+ backupToken: Buffer;
174
+ registration: RegistrationOptions;
175
+ pairingCode: string | undefined;
176
+ lastPropHash: string | undefined;
177
+ routingInfo: Buffer | undefined;
178
+ };
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+
3
+ export const AdapterDatabaseType = z
4
+ .object({
5
+ type: z.enum(["sqlite", "postgresql", "mysql"]).default("sqlite"),
6
+ connection: z
7
+ .object({
8
+ url: z.string().default("./zaileys.db"),
9
+ })
10
+ .optional()
11
+ .default({}),
12
+ })
13
+ .optional()
14
+ .default({});
15
+
16
+ const ClientClassesBaseType = {
17
+ prefix: z.string().optional(),
18
+ ignoreMe: z.boolean().optional().default(true),
19
+ showLogs: z.boolean().optional().default(true),
20
+ autoMentions: z.boolean().optional().default(true),
21
+ autoOnline: z.boolean().optional().default(true),
22
+ autoRead: z.boolean().optional().default(true),
23
+ autoRejectCall: z.boolean().optional().default(true),
24
+ database: AdapterDatabaseType,
25
+ citation: z
26
+ .record(z.function().returns(z.union([z.number().array(), z.promise(z.number().array())])))
27
+ .optional()
28
+ .transform(async (citation) => {
29
+ const transform: Record<string, any> = {};
30
+ if (citation) {
31
+ for (const key of Object.keys(citation)) {
32
+ const news = `is${key.charAt(0).toUpperCase() + key.slice(1)}`;
33
+ const result = await citation[key]();
34
+ transform[news] = result;
35
+ }
36
+ }
37
+ return transform;
38
+ }),
39
+ };
40
+
41
+ const ClientPairingType = z.object({
42
+ authType: z.literal("pairing"),
43
+ phoneNumber: z.number(),
44
+ ...ClientClassesBaseType,
45
+ });
46
+
47
+ const ClientQRType = z.object({
48
+ authType: z.literal("qr"),
49
+ phoneNumber: z.undefined().optional(),
50
+ ...ClientClassesBaseType,
51
+ });
52
+
53
+ export const ClientClassesType = z.discriminatedUnion("authType", [ClientPairingType, ClientQRType]);
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+
3
+ const EventConnectionType = z.object({
4
+ status: z.enum(["connecting", "open", "close"]),
5
+ });
6
+
7
+ const EventMessagesType = z.object({
8
+ messages: z.object({
9
+ remoteJid: z.string(),
10
+ id: z.string(),
11
+ }),
12
+ });
13
+
14
+ const EventCallType = z.object({
15
+ call: z.object({
16
+ id: z.string(),
17
+ from: z.string(),
18
+ timestamp: z.number(),
19
+ }),
20
+ });
21
+
22
+ const EventEnumType = z.enum(["connection", "messages", "call"]);
23
+ export type EventEnumType = z.infer<typeof EventEnumType>;
24
+
25
+ export type EventCallbackType = {
26
+ connection: (data: z.infer<typeof EventConnectionType>) => void;
27
+ messages: (data: z.infer<typeof EventMessagesType>) => void;
28
+ call: (data: z.infer<typeof EventCallType>) => void;
29
+ };
@@ -0,0 +1,4 @@
1
+ declare module "libsignal" {
2
+ export const libsignal: any;
3
+ export const curve = (...args: any[]): any => {};
4
+ }
@@ -0,0 +1,37 @@
1
+ import Client from "../src";
2
+
3
+ // the configuration below is the default
4
+ const wa = new Client({
5
+ prefix: "/", // for command message, example '/'
6
+ phoneNumber: 6287833764462, // fill bot phone number if auth type is 'pairing'
7
+ authType: "pairing", // auth type 'pairing' or 'qr'
8
+ ignoreMe: true, // ignore messages from bot (bot phone number)
9
+ showLogs: true, // show logs of any chats
10
+ autoMentions: true, // bot will be auto mentioned if text contains sender number with '@' prefix
11
+ autoOnline: true, // bot status will be mark online
12
+ autoRead: true, // auto read message from any chats
13
+ autoRejectCall: true, // auto reject call if someone call you
14
+ database: {
15
+ type: "sqlite", // database type "sqlite" | "postgresql" | "mysql"
16
+ connection: {
17
+ url: "./db/zaileys.db", // database url
18
+ },
19
+ },
20
+ citation: {
21
+ author: async () => {
22
+ // const res = await fetch...
23
+ return await [6285136635787];
24
+ },
25
+ myGroup: () => [6285136635787],
26
+ },
27
+ });
28
+
29
+ wa.on("connection", (ctx) => {
30
+ // console.log("🚀 ~ example.ts:30 ~ wa.on ~ ctx:", ctx);
31
+ });
32
+
33
+ wa.on("messages", (ctx) => {
34
+ console.log("🚀 ~ example.ts:31 ~ wa.on ~ ctx:", ctx);
35
+ });
36
+
37
+ wa.on("call", () => {});
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node",
6
+ "esModuleInterop": true,
7
+ "strict": true,
8
+ "noImplicitAny": true,
9
+ "skipLibCheck": true,
10
+ "declaration": true,
11
+ "declarationDir": "dist",
12
+ "outDir": "dist",
13
+ "rootDir": "src",
14
+ "resolveJsonModule": true,
15
+ "allowSyntheticDefaultImports": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Zeative Media
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.d.mts DELETED
@@ -1,235 +0,0 @@
1
- import { WABusinessProfile, proto } from '@whiskeysockets/baileys';
2
- import { EventEmitter } from 'events';
3
-
4
- declare const MESSAGE_TYPE: {
5
- readonly text: "text";
6
- readonly conversation: "text";
7
- readonly imageMessage: "image";
8
- readonly contactMessage: "contact";
9
- readonly locationMessage: "location";
10
- readonly documentMessage: "document";
11
- readonly audioMessage: "audio";
12
- readonly videoMessage: "video";
13
- readonly protocolMessage: "protocol";
14
- readonly contactsArrayMessage: "contactsArray";
15
- readonly highlyStructuredMessage: "highlyStructured";
16
- readonly sendPaymentMessage: "sendPayment";
17
- readonly liveLocationMessage: "liveLocation";
18
- readonly requestPaymentMessage: "requestPayment";
19
- readonly declinePaymentRequestMessage: "declinePaymentRequest";
20
- readonly cancelPaymentRequestMessage: "cancelPaymentRequest";
21
- readonly templateMessage: "template";
22
- readonly stickerMessage: "sticker";
23
- readonly groupInviteMessage: "groupInvite";
24
- readonly templateButtonReplyMessage: "templateButtonReply";
25
- readonly productMessage: "product";
26
- readonly deviceSentMessage: "deviceSent";
27
- readonly listMessage: "list";
28
- readonly viewOnceMessage: "viewOnce";
29
- readonly orderMessage: "order";
30
- readonly listResponseMessage: "listResponse";
31
- readonly ephemeralMessage: "ephemeral";
32
- readonly invoiceMessage: "invoice";
33
- readonly buttonsMessage: "buttons";
34
- readonly buttonsResponseMessage: "buttonsResponse";
35
- readonly paymentInviteMessage: "paymentInvite";
36
- readonly interactiveMessage: "interactive";
37
- readonly reactionMessage: "reaction";
38
- readonly stickerSyncRmrMessage: "sticker";
39
- readonly interactiveResponseMessage: "interactiveResponse";
40
- readonly pollCreationMessage: "pollCreation";
41
- readonly pollUpdateMessage: "pollUpdate";
42
- readonly keepInChatMessage: "keepInChat";
43
- readonly documentWithCaptionMessage: "document";
44
- readonly requestPhoneNumberMessage: "requestPhoneNumber";
45
- readonly viewOnceMessageV2: "viewOnce";
46
- readonly encReactionMessage: "reaction";
47
- readonly editedMessage: "text";
48
- readonly viewOnceMessageV2Extension: "viewOnce";
49
- readonly pollCreationMessageV2: "pollCreation";
50
- readonly scheduledCallCreationMessage: "scheduledCallCreation";
51
- readonly groupMentionedMessage: "groupMentioned";
52
- readonly pinInChatMessage: "pinInChat";
53
- readonly pollCreationMessageV3: "pollCreation";
54
- readonly scheduledCallEditMessage: "scheduledCallEdit";
55
- readonly ptvMessage: "ptv";
56
- readonly botInvokeMessage: "botInvoke";
57
- readonly callLogMesssage: "callLog";
58
- readonly encCommentMessage: "encComment";
59
- readonly bcallMessage: "bcall";
60
- readonly lottieStickerMessage: "lottieSticker";
61
- readonly eventMessage: "event";
62
- readonly commentMessage: "comment";
63
- readonly newsletterAdminInviteMessage: "text";
64
- readonly extendedTextMessageWithParentKey: "text";
65
- readonly placeholderMessage: "placeholder";
66
- readonly encEventUpdateMessage: "encEventUpdate";
67
- };
68
- declare const VERIFIED_PLATFORM: {
69
- readonly whatsapp: "0@s.whatsapp.net";
70
- readonly meta: "13135550002@s.whatsapp.net";
71
- readonly chatgpt: "18002428478@s.whatsapp.net";
72
- readonly copilot: "18772241042@s.whatsapp.net";
73
- readonly instagram: "447723442971@s.whatsapp.net";
74
- readonly tiktok: "6285574670498@s.whatsapp.net";
75
- };
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
-
83
- type FakeVerifiedEnum = keyof typeof VERIFIED_PLATFORM;
84
- type SendActionType = {
85
- asReply?: boolean;
86
- senderId?: string;
87
- };
88
- type ReplyActionType = {
89
- footer?: string;
90
- fakeVerified?: FakeVerifiedEnum;
91
- senderId?: string;
92
- };
93
-
94
- type Action_FakeVerifiedEnum = FakeVerifiedEnum;
95
- type Action_ReplyActionType = ReplyActionType;
96
- type Action_SendActionType = SendActionType;
97
- declare namespace Action {
98
- export type { Action_FakeVerifiedEnum as FakeVerifiedEnum, Action_ReplyActionType as ReplyActionType, Action_SendActionType as SendActionType };
99
- }
100
-
101
- type MessageTypeEnum = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE];
102
- type DeviceTypeEnum = "unknown" | "android" | "ios" | "desktop" | "web";
103
- type ExtractCitationType<T> = {
104
- [K in keyof T as `is${Capitalize<K & string>}`]: boolean;
105
- };
106
- type MessageBaseContent<T> = {
107
- fromMe: boolean;
108
- chatId: string;
109
- channelId: string;
110
- roomId: string;
111
- roomImage: () => Promise<string | null>;
112
- senderId: string;
113
- senderName: string;
114
- senderDevice: DeviceTypeEnum;
115
- senderBio: () => Promise<string | null>;
116
- senderImage: () => Promise<string | null>;
117
- senderBusiness: () => Promise<WABusinessProfile | null>;
118
- chatType: MessageTypeEnum;
119
- timestamp: number;
120
- text: string;
121
- command: string;
122
- mentions: string[] | null;
123
- isTagMe: boolean;
124
- isGroup: boolean;
125
- isStory: boolean;
126
- isEdited: boolean;
127
- isChannel: boolean;
128
- isBroadcast: boolean;
129
- isEphemeral: boolean;
130
- isForwarded: boolean;
131
- citation: {
132
- [key: string]: unknown;
133
- } | null;
134
- media: {
135
- buffer?: () => Promise<Buffer | null>;
136
- stream?: () => Promise<Buffer | null>;
137
- [key: string]: unknown;
138
- } | null;
139
- reply: MessageBaseContent<T> | null;
140
- key: () => proto.IMessageKey;
141
- message: () => proto.IWebMessageInfo;
142
- };
143
-
144
- type Message_DeviceTypeEnum = DeviceTypeEnum;
145
- type Message_ExtractCitationType<T> = ExtractCitationType<T>;
146
- type Message_MessageBaseContent<T> = MessageBaseContent<T>;
147
- type Message_MessageTypeEnum = MessageTypeEnum;
148
- declare namespace Message {
149
- export type { Message_DeviceTypeEnum as DeviceTypeEnum, Message_ExtractCitationType as ExtractCitationType, Message_MessageBaseContent as MessageBaseContent, Message_MessageTypeEnum as MessageTypeEnum };
150
- }
151
-
152
- type AuthType = "pairing" | "qr";
153
- type CitationConfig = {
154
- [key: string]: (() => string[]) | (() => Promise<string[]>);
155
- };
156
- interface BaseClientConfig {
157
- prefix?: string;
158
- ignoreMe?: boolean;
159
- authPath?: string;
160
- authType: AuthType;
161
- showLogs?: boolean;
162
- autoMentions?: boolean;
163
- autoOnline?: boolean;
164
- autoRead?: boolean;
165
- autoRejectCall?: boolean;
166
- citation?: CitationConfig;
167
- }
168
- interface PairingClientConfig extends BaseClientConfig {
169
- authType: "pairing";
170
- phoneNumber: number;
171
- }
172
- interface QRClientConfig extends BaseClientConfig {
173
- authType: "qr";
174
- }
175
- type ClientConfig = PairingClientConfig | QRClientConfig;
176
- interface BaseContext {
177
- }
178
- interface ConnectionContext extends BaseContext {
179
- status: "connecting" | "open" | "close";
180
- }
181
- interface ErrorContext extends BaseContext {
182
- error: Error;
183
- }
184
- interface ClientEvents<B> {
185
- connection: (ctx: ConnectionContext) => void;
186
- message: (ctx: MessageBaseContent<B>) => void;
187
- error: (ctx: ErrorContext) => void;
188
- }
189
-
190
- type General_AuthType = AuthType;
191
- type General_BaseClientConfig = BaseClientConfig;
192
- type General_BaseContext = BaseContext;
193
- type General_CitationConfig = CitationConfig;
194
- type General_ClientConfig = ClientConfig;
195
- type General_ClientEvents<B> = ClientEvents<B>;
196
- type General_ConnectionContext = ConnectionContext;
197
- type General_ErrorContext = ErrorContext;
198
- type General_PairingClientConfig = PairingClientConfig;
199
- type General_QRClientConfig = QRClientConfig;
200
- declare namespace General {
201
- 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 };
202
- }
203
-
204
- declare class Client extends EventEmitter {
205
- private config;
206
- private authState;
207
- private authProvider;
208
- private socket;
209
- private store;
210
- private groupCache;
211
- private logger;
212
- protected temporaryMessage: MessageBaseContent<any> | null;
213
- protected parseMention: string[];
214
- private spinner;
215
- constructor(config: ClientConfig);
216
- protected initialize(): Promise<void>;
217
- private deleteSession;
218
- on<K extends keyof ClientEvents<typeof this$1.config.citation>>(event: K, listener: ClientEvents<typeof this$1.config.citation>[K]): this;
219
- emit<K extends keyof ClientEvents<typeof this$1.config.citation>>(event: K, ...args: Parameters<ClientEvents<typeof this$1.config.citation>[K]>): boolean;
220
- protected generateMentions(mentions: string[]): string[];
221
- protected generateFakeVerified(key: proto.IMessageKey, platform: FakeVerifiedEnum): {
222
- participant: "0@s.whatsapp.net" | "13135550002@s.whatsapp.net" | "18002428478@s.whatsapp.net" | "18772241042@s.whatsapp.net" | "447723442971@s.whatsapp.net" | "6285574670498@s.whatsapp.net";
223
- remoteJid?: string | null | undefined;
224
- fromMe?: boolean | null | undefined;
225
- id?: string | null | undefined;
226
- };
227
- sendText(text: string, payload?: ReplyActionType): Promise<void>;
228
- sendReply(text: string, payload?: ReplyActionType): Promise<void>;
229
- sendImage(image: string | Buffer, payload?: SendActionType): Promise<void>;
230
- sendVideo(video: string | Buffer, payload?: SendActionType): Promise<void>;
231
- sendAudio(audio: string | Buffer, payload?: SendActionType): Promise<void>;
232
- sendSticker(sticker: string | Buffer, payload?: SendActionType): Promise<void>;
233
- }
234
-
235
- export { Client, Config, General, Message, Action as Types, Client as default };
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- var Se=Object.create;var T=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var fe=(c,m)=>{for(var t in m)T(c,t,{get:m[t],enumerable:!0})},Me=(c,m,t,e)=>{if(m&&typeof m=="object"||typeof m=="function")for(let s of Pe(m))!Be.call(c,s)&&s!==t&&T(c,s,{get:()=>m[s],enumerable:!(e=Ee(m,s))||e.enumerable});return c};var M=(c,m,t)=>(t=c!=null?Se(Re(c)):{},Me(m||!c||!c.__esModule?T(t,"default",{value:c,enumerable:!0}):t,c)),Ae=c=>Me(T({},"__esModule",{value:!0}),c);var Oe={};fe(Oe,{Client:()=>v,Config:()=>b,General:()=>O,Message:()=>q,Types:()=>F,default:()=>Fe});module.exports=Ae(Oe);var b={};fe(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 p=M(require("@whiskeysockets/baileys")),ke=require("awesome-phonenumber"),Ce=M(require("chalk")),B=M(require("consola")),ve=require("events"),Ie=M(require("figlet")),we=M(require("fs")),A=M(require("node-cache")),xe=M(require("ora")),Te=M(require("pino"));var C=require("@whiskeysockets/baileys");var ye=(c,m)=>{let t=new Set(c);for(let e of m)if(t.has(e))return!0;return!1},k=(c,m)=>Array.isArray(c)?c.map(t=>k(t,m)):c&&typeof c=="object"?Object.keys(c).reduce((t,e)=>(m.includes(e)||(t[e]=k(c[e],m)),t),{}):c;var S=class{constructor({socket:m,message:t,config:e,store:s}){this.socket=m,this.message=t,this.config=e,this.store=s}async handle(m){var w,E,V,W,K,L,J,N,D,j,_,z,G,$,U,Y,Q,H,Z,X,ee,te,se,ie,ne,oe,re,ae,ce,ge,me,he,pe,le,de,ue;let t=k(m||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=!!((w=e.message)!=null&&w.extendedTextMessage),o=!!((V=(E=e.message)==null?void 0:E.protocolMessage)!=null&&V.editedMessage),r=!!((W=e.message)!=null&&W.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),n=s?Object.keys(e.message.extendedTextMessage)[0]:o?Object.keys(i)[0]:r?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],h=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[n])==null?void 0:$.contextInfo)==null?void 0:U.stanzaId,d=P[n];(Q=(Y=e.message)==null?void 0:Y.protocolMessage)!=null&&Q.ephemeralExpiration&&(d="ephemeral");let a=s?e.message.extendedTextMessage[n]:o?i[n]:r?e.message.botInvokeMessage.message.extendedTextMessage[n]:e.message[n],l=typeof a=="string"?a:(a==null?void 0:a.caption)||(a==null?void 0:a.text)||(a==null?void 0:a.name)||null,I=(l==null?void 0:l.match(/@\d+/g))||null,g={fromMe:e.key.fromMe,channelId:"",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,x;return(x=(f=u==null?void 0:u[0])==null?void 0:f.status)==null?void 0:x.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)?(H=l.split(" ")[0])==null?void 0:H.slice(1):null,mentions:I,isTagMe:!!(l!=null&&l.match(`@${(X=(Z=this.socket.user)==null?void 0:Z.id)==null?void 0:X.split(":")[0]}`)),isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:o,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:d==="ephemeral"||!!((se=(te=(ee=e.message)==null?void 0:ee.extendedTextMessage)==null?void 0:te.contextInfo)!=null&&se.expiration),isForwarded:!!((oe=(ne=(ie=e.message)==null?void 0:ie.extendedTextMessage)==null?void 0:ne.contextInfo)!=null&&oe.isForwarded),citation:{},media:typeof a!="string"?a:null,reply:null,key:()=>e.key,message:()=>this.message};if(g.channelId=`${(re=g.roomId)==null?void 0:re.split("@")[0]}-${(ae=g.senderId)==null?void 0:ae.split("@")[0]}`,g.media&&(g.media={...g.media,...(g.media.url||((ge=(ce=e.message)==null?void 0:ce.extendedTextMessage)==null?void 0:ge.jpegThumbnail)||((me=e.message)==null?void 0:me.newsletterAdminInviteMessage)||((he=e.message)==null?void 0:he.orderMessage))&&{buffer:async()=>await(0,C.downloadMediaMessage)(this.message,"buffer",{}).catch(()=>null),stream:async()=>await(0,C.downloadMediaMessage)(this.message,"stream",{}).catch(()=>null)}},g.media=k(g.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let u=[(pe=g.roomId)==null?void 0:pe.split("@")[0],(le=g.senderId)==null?void 0:le.split("@")[0]];for(let f of Object.keys(this.config.citation)){let x=`is${f[0].toUpperCase()}${f.slice(1)}`,be=await this.config.citation[f]();g.citation={...g.citation||{},[x]:ye(be,u)}}}if(h){let u=(de=this.store.messages[g.roomId])==null?void 0:de.get(h),f=(ue=this.store.messages[g.senderId])==null?void 0:ue.get(h);if(!u&&!f)return g;g.reply=await this.handle(u||f)}return g}};var v=class extends ve.EventEmitter{constructor(t){var s;super();this.groupCache=new A.default({stdTTL:5*60,useClones:!1});this.logger=(0,Te.default)({level:"silent",enabled:!1});this.spinner=(0,xe.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 o;(o=this==null?void 0:this.store)==null||o.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(o){}Object.keys(this.config).length&&this.initialize()}async initialize(){var s,o,r;await console.clear(),await(0,Ie.default)("Zaileys Libs",function(i,n){console.log(Ce.default.greenBright(n)),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:{creds:this.authState.load.creds,keys:(0,p.makeCacheableSignalKeyStore)(this.authState.load.keys,this.logger)},version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new A.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 n=await this.store.loadMessage(i.remoteJid,i.id);return(n==null?void 0:n.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,ke.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 a,l,I;let{connection:n,lastDisconnect:h,qr:d}=i;if(this.emit("connection",{status:n||"connecting"}),this.config.authType=="qr"&&d&&this.spinner.info("Scan qrcode with your whatsapp: "),n==="close"){let g=(l=(a=h==null?void 0:h.error)==null?void 0:a.output)==null?void 0:l.statusCode,w=g!==p.DisconnectReason.loggedOut;if(this==null||this.spinner.fail((I=h==null?void 0:h.error)==null?void 0:I.message),g==401||g==405||g==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}w&&this.initialize()}else n==="open"&&this.spinner.succeed("Successfully connected to whatsapp")}),(o=this==null?void 0:this.socket)==null||o.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",i=>{var n;for(let h of i){let d=(0,p.jidNormalizedUser)(h.id);this.store&&this.store.contacts&&(this.store.contacts[d]={...((n=this.store.contacts)==null?void 0:n[d])||{},...h||{}})}}),this.socket.ev.on("contacts.upsert",i=>{for(let n of i){let h=(0,p.jidNormalizedUser)(n.id);this.store&&this.store.contacts&&(this.store.contacts[h]={...n||{}})}}),(r=this.socket)==null||r.ev.on("messages.upsert",async i=>{let n=i.messages;for(let h of n){if(this.config.ignoreMe&&h.key.fromMe)continue;let a=await new S({message:h,socket:this.socket,config:this.config,store:this.store}).handle();a&&(this.config.autoRead&&await this.socket.readMessages([a.key()]),this.temporaryMessage=a,this.config.autoMentions&&(this.parseMention=a.mentions),this.emit("message",a))}}),this.socket.ev.on("groups.update",async([i])=>{let n=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,n)}),this.socket.ev.on("group-participants.update",async i=>{let n=await this.socket.groupMetadata(i.id);this.groupCache.set(i.id,n)}),this.socket.ev.on("call",async i=>{for(let n of i)this.config.autoRejectCall&&await this.socket.rejectCall(n.id,n.from)})}async deleteSession(){try{await we.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(o=>{e.forEach(r=>{s.push(o.slice(1)+r)})}),s}generateFakeVerified(t,e){return{...t,participant:R[e]||t.participant}}async sendText(t,e){var s,o,r;try{if(e!=null&&e.footer){let i=(0,p.generateWAMessageFromContent)((e==null?void 0:e.senderId)||((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId),{messageContextInfo:{deviceListMetadata:{},deviceListMetadataVersion:2},interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId});await this.socket.relayMessage(i.key.remoteJid,i.message,{messageId:i.key.id})}else await this.socket.sendMessage((e==null?void 0:e.senderId)||((r=this==null?void 0:this.temporaryMessage)==null?void 0:r.roomId),{text:t,mentions:this.generateMentions(this.parseMention)})}catch(i){throw i}}async sendReply(t,e){var s,o,r,i,n,h,d;try{if(e!=null&&e.footer){let a=(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:{}}},{quoted:{...(o=this.temporaryMessage)==null?void 0:o.message(),key:this.generateFakeVerified((r=this==null?void 0:this.temporaryMessage)==null?void 0:r.message().key,e.fakeVerified)},userJid:(i=this==null?void 0:this.temporaryMessage)==null?void 0:i.roomId});await this.socket.relayMessage(a.key.remoteJid,a.message,{messageId:a.key.id})}else await this.socket.sendMessage((e==null?void 0:e.senderId)||((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId),{text:t,mentions:this.generateMentions(this.parseMention)},{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(a){throw a}}async sendImage(t,e){var s,o;try{let r=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendVideo(t,e){var s,o;try{let r=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendAudio(t,e){var s,o;try{let r=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((e==null?void 0:e.senderId)||((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId),{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendSticker(t,e){var s,o;try{let r=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}};var F={};var O={};var q={};var Fe=v;0&&(module.exports={Client,Config,General,Message,Types});
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- var ye=Object.defineProperty;var ke=(h,p)=>{for(var t in p)ye(h,t,{get:p[t],enumerable:!0})};var S={};ke(S,{MESSAGE_TYPE:()=>T,VERIFIED_PLATFORM:()=>b});var T={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 ve,{Browsers as Ie,DisconnectReason as we,generateWAMessageFromContent as me,jidNormalizedUser as he,makeCacheableSignalKeyStore as xe,makeInMemoryStore as Te,proto as be,useMultiFileAuthState as Se}from"@whiskeysockets/baileys";import{parsePhoneNumber as Ee}from"awesome-phonenumber";import Pe from"chalk";import pe from"consola";import{EventEmitter as Re}from"events";import Be from"figlet";import Ae from"fs";import le from"node-cache";import Fe from"ora";import Oe from"pino";import{downloadMediaMessage as ge,getDevice as Ce}from"@whiskeysockets/baileys";var ce=(h,p)=>{let t=new Set(h);for(let e of p)if(t.has(e))return!0;return!1},y=(h,p)=>Array.isArray(h)?h.map(t=>y(t,p)):h&&typeof h=="object"?Object.keys(h).reduce((t,e)=>(p.includes(e)||(t[e]=y(h[e],p)),t),{}):h;var I=class{constructor({socket:p,message:t,config:e,store:n}){this.socket=p,this.message=t,this.config=e,this.store=n}async handle(p){var C,x,E,P,R,B,A,F,O,q,V,W,K,L,J,N,D,j,_,z,G,$,U,Y,Q,H,Z,X,ee,te,se,ie,ne,oe,re,ae;let t=y(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,n=!!((C=e.message)!=null&&C.extendedTextMessage),o=!!((E=(x=e.message)==null?void 0:x.protocolMessage)!=null&&E.editedMessage),r=!!((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=n?Object.keys(e.message.extendedTextMessage)[0]:o?Object.keys(s)[0]:r?Object.keys(e.message.botInvokeMessage.message.extendedTextMessage)[0]:Object.keys(e.message)[0],g=n?(W=(V=(q=e.message)==null?void 0:q.extendedTextMessage)==null?void 0:V.contextInfo)==null?void 0:W.stanzaId:(J=(L=(K=e.message)==null?void 0:K[i])==null?void 0:L.contextInfo)==null?void 0:J.stanzaId,l=T[i];(D=(N=e.message)==null?void 0:N.protocolMessage)!=null&&D.ephemeralExpiration&&(l="ephemeral");let a=n?e.message.extendedTextMessage[i]:o?s[i]:r?e.message.botInvokeMessage.message.extendedTextMessage[i]:e.message[i],m=typeof a=="string"?a:(a==null?void 0:a.caption)||(a==null?void 0:a.text)||(a==null?void 0:a.name)||null,k=(m==null?void 0:m.match(/@\d+/g))||null,c={fromMe:e.key.fromMe,channelId:"",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:Ce(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:l,timestamp:Number((e.messageTimestamp.low||e.messageTimestamp||0).toString()),text:m,command:m!=null&&m.startsWith(this.config.prefix)?(j=m.split(" ")[0])==null?void 0:j.slice(1):null,mentions:k,isTagMe:!!(m!=null&&m.match(`@${(z=(_=this.socket.user)==null?void 0:_.id)==null?void 0:z.split(":")[0]}`)),isGroup:e.key.remoteJid.endsWith("@g.us"),isStory:e.key.remoteJid.endsWith("@broadcast"),isEdited:o,isChannel:e.key.remoteJid.endsWith("@newsletter"),isBroadcast:!!e.broadcast,isEphemeral:l==="ephemeral"||!!((U=($=(G=e.message)==null?void 0:G.extendedTextMessage)==null?void 0:$.contextInfo)!=null&&U.expiration),isForwarded:!!((H=(Q=(Y=e.message)==null?void 0:Y.extendedTextMessage)==null?void 0:Q.contextInfo)!=null&&H.isForwarded),citation:{},media:typeof a!="string"?a:null,reply:null,key:()=>e.key,message:()=>this.message};if(c.channelId=`${(Z=c.roomId)==null?void 0:Z.split("@")[0]}-${(X=c.senderId)==null?void 0:X.split("@")[0]}`,c.media&&(c.media={...c.media,...(c.media.url||((te=(ee=e.message)==null?void 0:ee.extendedTextMessage)==null?void 0:te.jpegThumbnail)||((se=e.message)==null?void 0:se.newsletterAdminInviteMessage)||((ie=e.message)==null?void 0:ie.orderMessage))&&{buffer:async()=>await ge(this.message,"buffer",{}).catch(()=>null),stream:async()=>await ge(this.message,"stream",{}).catch(()=>null)}},c.media=y(c.media,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"])||null),this.config.citation){let d=[(ne=c.roomId)==null?void 0:ne.split("@")[0],(oe=c.senderId)==null?void 0:oe.split("@")[0]];for(let u of Object.keys(this.config.citation)){let v=`is${u[0].toUpperCase()}${u.slice(1)}`,Me=await this.config.citation[u]();c.citation={...c.citation||{},[v]:ce(Me,d)}}}if(g){let d=(re=this.store.messages[c.roomId])==null?void 0:re.get(g),u=(ae=this.store.messages[c.senderId])==null?void 0:ae.get(g);if(!d&&!u)return c;c.reply=await this.handle(d||u)}return c}};var w=class extends Re{constructor(t){var n;super();this.groupCache=new le({stdTTL:5*60,useClones:!1});this.logger=Oe({level:"silent",enabled:!1});this.spinner=Fe();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=Se(this.config.authPath+"/session"),this.store=Te({logger:this.logger});try{(n=this.store)==null||n.readFromFile(this.config.authPath+"/memory.json"),setInterval(()=>{var o;(o=this==null?void 0:this.store)==null||o.writeToFile(this.config.authPath+"/memory.json")},1e4)}catch(o){}Object.keys(this.config).length&&this.initialize()}async initialize(){var n,o,r;await console.clear(),await Be("Zaileys Libs",function(s,i){console.log(Pe.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=ve({logger:this.logger,printQRInTerminal:this.config.authType=="qr",markOnlineOnConnect:this.config.autoOnline,auth:{creds:this.authState.load.creds,keys:xe(this.authState.load.keys,this.logger)},version:[2,3e3,1017531287],syncFullHistory:!0,msgRetryCounterCache:new le,browser:Ie.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 be.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(!Ee("+"+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)}(n=this==null?void 0:this.socket)==null||n.ev.on("connection.update",async s=>{var a,m,k;let{connection:i,lastDisconnect:g,qr:l}=s;if(this.emit("connection",{status:i||"connecting"}),this.config.authType=="qr"&&l&&this.spinner.info("Scan qrcode with your whatsapp: "),i==="close"){let c=(m=(a=g==null?void 0:g.error)==null?void 0:a.output)==null?void 0:m.statusCode,C=c!==we.loggedOut;if(this==null||this.spinner.fail((k=g==null?void 0:g.error)==null?void 0:k.message),c==401||c==405||c==500){this.spinner.warn(`Bad session, please delete "${this.config.authPath}" folder and try again`),await pe.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")}),(o=this==null?void 0:this.socket)==null||o.ev.on("creds.update",this.authState.save),this.socket.ev.on("contacts.update",s=>{var i;for(let g of s){let l=he(g.id);this.store&&this.store.contacts&&(this.store.contacts[l]={...((i=this.store.contacts)==null?void 0:i[l])||{},...g||{}})}}),this.socket.ev.on("contacts.upsert",s=>{for(let i of s){let g=he(i.id);this.store&&this.store.contacts&&(this.store.contacts[g]={...i||{}})}}),(r=this.socket)==null||r.ev.on("messages.upsert",async s=>{let i=s.messages;for(let g of i){if(this.config.ignoreMe&&g.key.fromMe)continue;let a=await new I({message:g,socket:this.socket,config:this.config,store:this.store}).handle();a&&(this.config.autoRead&&await this.socket.readMessages([a.key()]),this.temporaryMessage=a,this.config.autoMentions&&(this.parseMention=a.mentions),this.emit("message",a))}}),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 Ae.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 pe.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"],n=[];return t==null||t.forEach(o=>{e.forEach(r=>{n.push(o.slice(1)+r)})}),n}generateFakeVerified(t,e){return{...t,participant:b[e]||t.participant}}async sendText(t,e){var n,o,r;try{if(e!=null&&e.footer){let s=me((e==null?void 0:e.senderId)||((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId),{messageContextInfo:{deviceListMetadata:{},deviceListMetadataVersion:2},interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{userJid:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.roomId});await this.socket.relayMessage(s.key.remoteJid,s.message,{messageId:s.key.id})}else await this.socket.sendMessage((e==null?void 0:e.senderId)||((r=this==null?void 0:this.temporaryMessage)==null?void 0:r.roomId),{text:t,mentions:this.generateMentions(this.parseMention)})}catch(s){throw s}}async sendReply(t,e){var n,o,r,s,i,g,l;try{if(e!=null&&e.footer){let a=me((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId,{interactiveMessage:{contextInfo:{mentionedJid:this.generateMentions(this.parseMention)},body:{text:t},footer:{text:e==null?void 0:e.footer},nativeFlowMessage:{}}},{quoted:{...(o=this.temporaryMessage)==null?void 0:o.message(),key:this.generateFakeVerified((r=this==null?void 0:this.temporaryMessage)==null?void 0:r.message().key,e.fakeVerified)},userJid:(s=this==null?void 0:this.temporaryMessage)==null?void 0:s.roomId});await this.socket.relayMessage(a.key.remoteJid,a.message,{messageId:a.key.id})}else await this.socket.sendMessage((e==null?void 0:e.senderId)||((i=this==null?void 0:this.temporaryMessage)==null?void 0:i.roomId),{text:t,mentions:this.generateMentions(this.parseMention)},{quoted:{...(g=this==null?void 0:this.temporaryMessage)==null?void 0:g.message(),key:this.generateFakeVerified((l=this==null?void 0:this.temporaryMessage)==null?void 0:l.message().key,e==null?void 0:e.fakeVerified)}})}catch(a){throw a}}async sendImage(t,e){var n,o;try{let r=typeof t=="string"?{image:{url:t}}:{image:t};this.socket.sendMessage((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendVideo(t,e){var n,o;try{let r=typeof t=="string"?{video:{url:t}}:{video:t};this.socket.sendMessage((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendAudio(t,e){var n,o;try{let r=typeof t=="string"?{audio:{url:t}}:{audio:t};this.socket.sendMessage((e==null?void 0:e.senderId)||((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId),{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}async sendSticker(t,e){var n,o;try{let r=typeof t=="string"?{sticker:{url:t}}:{sticker:t};this.socket.sendMessage((n=this==null?void 0:this.temporaryMessage)==null?void 0:n.roomId,{...r,mentions:this.generateMentions(this.parseMention)},{...(e==null?void 0:e.asReply)&&{quoted:(o=this==null?void 0:this.temporaryMessage)==null?void 0:o.message()}})}catch(r){throw r}}};var de={};var ue={};var fe={};var pt=w;export{w as Client,S as Config,ue as General,fe as Message,de as Types,pt as default};