zaileys 1.1.35 → 1.1.37
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/LICENSE +21 -21
- package/README.md +718 -718
- package/package.json +88 -88
- package/CHANGELOG.md +0 -92
- package/dist/index.d.mts +0 -1230
- package/dist/index.d.ts +0 -1230
- package/dist/index.js +0 -1986
- package/dist/index.mjs +0 -1960
package/dist/index.js
DELETED
|
@@ -1,1986 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var makeWASocket = require('baileys');
|
|
4
|
-
var EventEmitter = require('events');
|
|
5
|
-
var nanospinner = require('nanospinner');
|
|
6
|
-
var NodeCache2 = require('node-cache');
|
|
7
|
-
var pino = require('pino');
|
|
8
|
-
var fs = require('fs');
|
|
9
|
-
var lowdb = require('lowdb');
|
|
10
|
-
var FileSync = require('lowdb/adapters/FileSync');
|
|
11
|
-
var path = require('path');
|
|
12
|
-
var chalk = require('chalk');
|
|
13
|
-
var _2 = require('lodash');
|
|
14
|
-
var z2 = require('zod/v4');
|
|
15
|
-
var figlet = require('figlet');
|
|
16
|
-
var QRCode = require('qrcode');
|
|
17
|
-
var zod = require('zod');
|
|
18
|
-
|
|
19
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
-
|
|
21
|
-
var makeWASocket__default = /*#__PURE__*/_interopDefault(makeWASocket);
|
|
22
|
-
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
23
|
-
var NodeCache2__default = /*#__PURE__*/_interopDefault(NodeCache2);
|
|
24
|
-
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
25
|
-
var lowdb__default = /*#__PURE__*/_interopDefault(lowdb);
|
|
26
|
-
var FileSync__default = /*#__PURE__*/_interopDefault(FileSync);
|
|
27
|
-
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
28
|
-
var _2__default = /*#__PURE__*/_interopDefault(_2);
|
|
29
|
-
var z2__default = /*#__PURE__*/_interopDefault(z2);
|
|
30
|
-
var figlet__default = /*#__PURE__*/_interopDefault(figlet);
|
|
31
|
-
var QRCode__default = /*#__PURE__*/_interopDefault(QRCode);
|
|
32
|
-
|
|
33
|
-
// src/classes/Client.ts
|
|
34
|
-
var sendError = (text) => new Error(chalk__default.default.red(text));
|
|
35
|
-
var toJson = (object) => {
|
|
36
|
-
try {
|
|
37
|
-
return JSON.parse(object);
|
|
38
|
-
} catch {
|
|
39
|
-
return _2__default.default.attempt(() => JSON.parse(JSON.stringify(object) || "{}"));
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var toString = (object) => {
|
|
43
|
-
try {
|
|
44
|
-
return JSON.stringify(object);
|
|
45
|
-
} catch {
|
|
46
|
-
const result = _2__default.default.attempt(() => JSON.stringify(toJson(object) || "{}"));
|
|
47
|
-
return _2__default.default.isError(result) ? "{}" : result;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var shuffleString = (str) => {
|
|
51
|
-
return _2__default.default.shuffle([...str]).join("");
|
|
52
|
-
};
|
|
53
|
-
var tryAgain = async (fn) => {
|
|
54
|
-
const RETRY_DELAY = 200;
|
|
55
|
-
const MAX_RETRIES = 10;
|
|
56
|
-
for (let x = 0; x < MAX_RETRIES; x++) {
|
|
57
|
-
try {
|
|
58
|
-
return await fn();
|
|
59
|
-
} catch (_e) {
|
|
60
|
-
await new Promise((r) => setTimeout(r, RETRY_DELAY));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
throw sendError("Max retries reached");
|
|
64
|
-
};
|
|
65
|
-
var findWord = (text = "", word = "") => {
|
|
66
|
-
if (!text) return null;
|
|
67
|
-
return _2__default.default.includes(text.toLowerCase(), word.toLowerCase());
|
|
68
|
-
};
|
|
69
|
-
var normalizeText = (text = "") => {
|
|
70
|
-
if (!text) return null;
|
|
71
|
-
return _2__default.default.replace(text, /\u202E([\s\S]*?)\u202C/g, (_e, segmen) => {
|
|
72
|
-
const arr = _2__default.default.toArray(segmen);
|
|
73
|
-
const reversed = _2__default.default.reverse(_2__default.default.clone(arr));
|
|
74
|
-
return _2__default.default.join(reversed, "");
|
|
75
|
-
}).replace(/[\u202A-\u202E\u202C]/g, "");
|
|
76
|
-
};
|
|
77
|
-
var extractJids = (text = "") => {
|
|
78
|
-
if (!text) return [];
|
|
79
|
-
const ids = /* @__PURE__ */ new Set();
|
|
80
|
-
for (const match of text.matchAll(/@(\d+)/g)) {
|
|
81
|
-
ids.add(match[1]);
|
|
82
|
-
}
|
|
83
|
-
return _2__default.default.flatMap([...ids], (id) => [`${id}@s.whatsapp.net`, `${id}@g.us`]);
|
|
84
|
-
};
|
|
85
|
-
var extractUrls = (text = "") => {
|
|
86
|
-
if (!text) return [];
|
|
87
|
-
const regex = /https?:\/\/(?:[-\w.])+(?:\.[a-zA-Z]{2,})+(?:\/[^\s<>"']*)?/g;
|
|
88
|
-
return _2__default.default.castArray(text.match(regex) || []);
|
|
89
|
-
};
|
|
90
|
-
var getMentions = (text = "") => {
|
|
91
|
-
if (!text) return [];
|
|
92
|
-
const ids = /* @__PURE__ */ new Set();
|
|
93
|
-
for (const match of text.matchAll(/@(\d+)/g)) {
|
|
94
|
-
ids.add(match[1]);
|
|
95
|
-
}
|
|
96
|
-
return _2__default.default.toArray(ids);
|
|
97
|
-
};
|
|
98
|
-
var CHUNK_SIZE = 1e3;
|
|
99
|
-
var JsonDB = class {
|
|
100
|
-
session = "zaileys-sessions";
|
|
101
|
-
db;
|
|
102
|
-
storeDir;
|
|
103
|
-
async initialize(session) {
|
|
104
|
-
this.session = session;
|
|
105
|
-
const authPath = `sessions/${this.session}/auth.json`;
|
|
106
|
-
this.storeDir = `sessions/${this.session}/stores`;
|
|
107
|
-
const dirAuth = path.dirname(authPath);
|
|
108
|
-
if (!fs.existsSync(dirAuth)) fs.mkdirSync(dirAuth, { recursive: true });
|
|
109
|
-
if (!fs.existsSync(this.storeDir)) fs.mkdirSync(this.storeDir, { recursive: true });
|
|
110
|
-
const adapter = new FileSync__default.default(authPath);
|
|
111
|
-
this.db = lowdb__default.default(adapter);
|
|
112
|
-
this.db.defaults([]).write();
|
|
113
|
-
}
|
|
114
|
-
tryRecoverRaw(raw) {
|
|
115
|
-
const s = raw.trim();
|
|
116
|
-
try {
|
|
117
|
-
return JSON.parse(s);
|
|
118
|
-
} catch (_error) {
|
|
119
|
-
try {
|
|
120
|
-
const a = s.indexOf("[");
|
|
121
|
-
const b = s.lastIndexOf("]");
|
|
122
|
-
if (a !== -1 && b !== -1 && b > a) {
|
|
123
|
-
const sub = s.slice(a, b + 1);
|
|
124
|
-
return JSON.parse(sub);
|
|
125
|
-
}
|
|
126
|
-
} catch (_error2) {
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
const wrapped = `[${s.replace(/}\s*{/g, "},{")}]`;
|
|
130
|
-
return JSON.parse(wrapped);
|
|
131
|
-
} catch (_error2) {
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const lines = _2__default.default.filter(_2__default.default.map(s.split(/\\r?\\n/), (l) => l.trim()), Boolean);
|
|
135
|
-
const parsedResults = _2__default.default.map(lines, (l) => {
|
|
136
|
-
try {
|
|
137
|
-
return JSON.parse(l);
|
|
138
|
-
} catch (_error2) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
const parsed = _2__default.default.filter(parsedResults, (item) => item !== null);
|
|
143
|
-
if (parsed.length) return parsed;
|
|
144
|
-
} catch (_error2) {
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
async chunks(key) {
|
|
150
|
-
const files = _2__default.default.filter(fs.readdirSync(this.storeDir), (f) => _2__default.default.startsWith(f, `${key}-`) && _2__default.default.endsWith(f, ".json")).sort();
|
|
151
|
-
const result = [];
|
|
152
|
-
for (const file of files) {
|
|
153
|
-
const full = `${this.storeDir}/${file}`;
|
|
154
|
-
const adapter = new FileSync__default.default(full);
|
|
155
|
-
const db = lowdb__default.default(adapter);
|
|
156
|
-
try {
|
|
157
|
-
db.defaults([]).write();
|
|
158
|
-
result.push(...toJson(db.value()));
|
|
159
|
-
} catch {
|
|
160
|
-
let raw = "";
|
|
161
|
-
try {
|
|
162
|
-
raw = fs.readFileSync(full, "utf8");
|
|
163
|
-
} catch (_error) {
|
|
164
|
-
raw = "";
|
|
165
|
-
}
|
|
166
|
-
const recovered = raw ? this.tryRecoverRaw(raw) : null;
|
|
167
|
-
if (recovered) {
|
|
168
|
-
db.setState(Array.isArray(recovered) ? recovered : [recovered]).write();
|
|
169
|
-
result.push(...toJson(db.value()));
|
|
170
|
-
} else {
|
|
171
|
-
const corrupt = `${full}.corrupt.${Date.now()}`;
|
|
172
|
-
try {
|
|
173
|
-
fs.renameSync(full, corrupt);
|
|
174
|
-
} catch (_renameErr) {
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
fs.writeFileSync(full, "[]", "utf8");
|
|
178
|
-
} catch (_writeFileErr) {
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
async writeChunks(key, items) {
|
|
186
|
-
_2__default.default.forEach(
|
|
187
|
-
_2__default.default.filter(fs.readdirSync(this.storeDir), (f) => _2__default.default.startsWith(f, `${key}-`) && _2__default.default.endsWith(f, ".json")),
|
|
188
|
-
(f) => fs.unlinkSync(`${this.storeDir}/${f}`)
|
|
189
|
-
);
|
|
190
|
-
let index = 0;
|
|
191
|
-
for (let i = 0; i < items.length; i += CHUNK_SIZE) {
|
|
192
|
-
const chunk = items.slice(i, i + CHUNK_SIZE);
|
|
193
|
-
const file = `${this.storeDir}/${key}-${index}.json`;
|
|
194
|
-
const adapter = new FileSync__default.default(file);
|
|
195
|
-
const db = lowdb__default.default(adapter);
|
|
196
|
-
db.setState(chunk).write();
|
|
197
|
-
try {
|
|
198
|
-
db.write();
|
|
199
|
-
} catch (err) {
|
|
200
|
-
if (err?.code === "ENOENT") {
|
|
201
|
-
try {
|
|
202
|
-
fs.renameSync(`${file}.tmp`, file);
|
|
203
|
-
} catch (_renameErr) {
|
|
204
|
-
try {
|
|
205
|
-
db.write();
|
|
206
|
-
} catch (_writeErr) {
|
|
207
|
-
try {
|
|
208
|
-
fs.writeFileSync(file, JSON.stringify(chunk), "utf8");
|
|
209
|
-
} catch (_writeFileErr) {
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
} else {
|
|
214
|
-
throw err;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
index++;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
store(key) {
|
|
221
|
-
return {
|
|
222
|
-
read: async (id) => {
|
|
223
|
-
const list = await this.chunks(key);
|
|
224
|
-
const row = _2__default.default.find(list, (i) => i.id === id);
|
|
225
|
-
return row ? JSON.parse(row.value) : null;
|
|
226
|
-
},
|
|
227
|
-
write: async (obj) => {
|
|
228
|
-
const list = await this.chunks(key);
|
|
229
|
-
const id = obj.key && typeof obj.key === "object" && "id" in obj.key ? obj.key.id : obj.id;
|
|
230
|
-
const serialized = JSON.stringify(obj);
|
|
231
|
-
const idx = list.findIndex((i) => i.id === id);
|
|
232
|
-
if (idx !== -1) list[idx].value = serialized;
|
|
233
|
-
else list.push({ id, value: serialized });
|
|
234
|
-
await this.writeChunks(key, list);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
async upsert(id, value) {
|
|
239
|
-
const replacer = JSON.stringify(value, makeWASocket.BufferJSON.replacer);
|
|
240
|
-
const dbValue = this.db.value();
|
|
241
|
-
const data = Array.isArray(dbValue) ? dbValue : [];
|
|
242
|
-
const idx = _2__default.default.findIndex(data, (i) => i.id === id);
|
|
243
|
-
if (idx !== -1) {
|
|
244
|
-
data[idx].value = replacer;
|
|
245
|
-
} else {
|
|
246
|
-
data.push({ id, value: replacer });
|
|
247
|
-
}
|
|
248
|
-
this.db.setState(data).write();
|
|
249
|
-
}
|
|
250
|
-
async read(id) {
|
|
251
|
-
const dbValue = this.db.value();
|
|
252
|
-
const data = Array.isArray(dbValue) ? dbValue : [];
|
|
253
|
-
const row = _2__default.default.find(data, (i) => i.id === id);
|
|
254
|
-
if (!row || !row.value) return null;
|
|
255
|
-
const creds = typeof row.value === "object" ? toString(row.value) : row.value;
|
|
256
|
-
return JSON.parse(creds, makeWASocket.BufferJSON.reviver);
|
|
257
|
-
}
|
|
258
|
-
async remove(id) {
|
|
259
|
-
const dbValue = this.db.value();
|
|
260
|
-
const data = Array.isArray(dbValue) ? dbValue : [];
|
|
261
|
-
const filtered = _2__default.default.filter(data, (i) => i.id !== id);
|
|
262
|
-
this.db.setState(filtered).write();
|
|
263
|
-
}
|
|
264
|
-
async clear() {
|
|
265
|
-
const dbValue = this.db.value();
|
|
266
|
-
const data = Array.isArray(dbValue) ? dbValue : [];
|
|
267
|
-
const filtered = _2__default.default.filter(data, (i) => i.id === "creds");
|
|
268
|
-
this.db.setState(filtered).write();
|
|
269
|
-
}
|
|
270
|
-
async delete() {
|
|
271
|
-
this.db.setState([]);
|
|
272
|
-
await this.db.write();
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// src/utils/decrypt.ts
|
|
277
|
-
var allocate = (str) => {
|
|
278
|
-
let n = 0;
|
|
279
|
-
let p = str.length;
|
|
280
|
-
if (!p) return new Uint8Array(1);
|
|
281
|
-
while (--p % 4 > 1 && str.charAt(p) === "=") ++n;
|
|
282
|
-
return new Uint8Array(Math.ceil(str.length * 3) / 4 - n).fill(0);
|
|
283
|
-
};
|
|
284
|
-
var parseTimestamp = (timestamp) => {
|
|
285
|
-
if (typeof timestamp === "string") return parseInt(timestamp, 10);
|
|
286
|
-
if (typeof timestamp === "number") return timestamp;
|
|
287
|
-
return timestamp;
|
|
288
|
-
};
|
|
289
|
-
var fromObject = (args) => {
|
|
290
|
-
const fingerprint = args.fingerprint || {};
|
|
291
|
-
const f = {
|
|
292
|
-
...fingerprint,
|
|
293
|
-
deviceIndexes: Array.isArray(fingerprint.deviceIndexes) ? fingerprint.deviceIndexes : []
|
|
294
|
-
};
|
|
295
|
-
const message = {
|
|
296
|
-
keyData: Array.isArray(args.keyData) ? args.keyData : new Uint8Array(),
|
|
297
|
-
fingerprint: {
|
|
298
|
-
rawId: fingerprint.rawId || 0,
|
|
299
|
-
currentIndex: fingerprint.rawId || 0,
|
|
300
|
-
deviceIndexes: f.deviceIndexes
|
|
301
|
-
},
|
|
302
|
-
timestamp: parseTimestamp(args.timestamp)
|
|
303
|
-
};
|
|
304
|
-
if (typeof args.keyData === "string") {
|
|
305
|
-
message.keyData = allocate(args.keyData);
|
|
306
|
-
}
|
|
307
|
-
return message;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// src/modules/store.ts
|
|
311
|
-
var StoreHandler = async (db) => {
|
|
312
|
-
return {
|
|
313
|
-
bind: (client) => {
|
|
314
|
-
client?.socket?.ev.on("messaging-history.set", async (update) => {
|
|
315
|
-
const { chats, contacts, messages } = update;
|
|
316
|
-
for (const chat of chats) {
|
|
317
|
-
await db.store("chats").write(chat);
|
|
318
|
-
}
|
|
319
|
-
for (const contact of contacts) {
|
|
320
|
-
await db.store("contacts").write(contact);
|
|
321
|
-
}
|
|
322
|
-
for (const message of messages) {
|
|
323
|
-
if (!message.message) return;
|
|
324
|
-
if (message.message?.protocolMessage) return;
|
|
325
|
-
await db.store("messages").write(message);
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
client?.socket?.ev.on("messages.upsert", async ({ messages }) => {
|
|
329
|
-
for (const message of messages) {
|
|
330
|
-
await db.store("messages").write(message);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
client?.socket?.ev.on("chats.upsert", async (chats) => {
|
|
334
|
-
for (const chat of chats) {
|
|
335
|
-
await db.store("chats").write(chat);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
client?.socket?.ev.on("contacts.upsert", async (contacts) => {
|
|
339
|
-
for (const contact of contacts) {
|
|
340
|
-
await db.store("contacts").write(contact);
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
client?.socket?.ev.on("groups.update", async ([event]) => {
|
|
344
|
-
if (event.id) {
|
|
345
|
-
const metadata = await client?.socket?.groupMetadata(event.id);
|
|
346
|
-
client.cache.set(event.id, metadata);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
client?.socket?.ev.on("group-participants.update", async (event) => {
|
|
350
|
-
const metadata = await client?.socket?.groupMetadata(event.id);
|
|
351
|
-
client.cache.set(event.id, metadata);
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// src/modules/auth.ts
|
|
358
|
-
var AuthHandler = async (db) => {
|
|
359
|
-
const creds = await tryAgain(() => db.read("creds")) || makeWASocket.initAuthCreds();
|
|
360
|
-
const store = await StoreHandler(db);
|
|
361
|
-
return {
|
|
362
|
-
db,
|
|
363
|
-
store,
|
|
364
|
-
state: {
|
|
365
|
-
creds,
|
|
366
|
-
keys: {
|
|
367
|
-
get: async (type, ids) => {
|
|
368
|
-
const data = {};
|
|
369
|
-
for (const id of ids) {
|
|
370
|
-
let value = await tryAgain(() => db.read(`${type}-${id}`));
|
|
371
|
-
if (type === "app-state-sync-key" && value) {
|
|
372
|
-
value = fromObject(value);
|
|
373
|
-
}
|
|
374
|
-
if (value !== null && value !== void 0) {
|
|
375
|
-
data[id] = value;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return data;
|
|
379
|
-
},
|
|
380
|
-
set: async (data) => {
|
|
381
|
-
for (const category in data) {
|
|
382
|
-
for (const id in data[category]) {
|
|
383
|
-
const value = data[category][id];
|
|
384
|
-
const name = `${category}-${id}`;
|
|
385
|
-
if (value) {
|
|
386
|
-
await tryAgain(() => db.upsert(name, value));
|
|
387
|
-
} else {
|
|
388
|
-
await tryAgain(() => db.remove(name));
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
clear: async () => {
|
|
396
|
-
await tryAgain(() => db.clear());
|
|
397
|
-
},
|
|
398
|
-
saveCreds: async () => {
|
|
399
|
-
await tryAgain(() => db.upsert("creds", creds));
|
|
400
|
-
},
|
|
401
|
-
removeCreds: async () => {
|
|
402
|
-
await tryAgain(() => db.delete());
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
var PluginsHandler = (necessary, props) => {
|
|
407
|
-
const plugins = _2__default.default.find(props.plugins, (x) => x?.necessary == necessary);
|
|
408
|
-
return plugins;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
// src/modules/database.ts
|
|
412
|
-
var CredsHandler = async (props) => {
|
|
413
|
-
const db = PluginsHandler("database", props) || new JsonDB();
|
|
414
|
-
await db.initialize(props.session || "default");
|
|
415
|
-
return await AuthHandler(db);
|
|
416
|
-
};
|
|
417
|
-
var defaultBoolean = (state) => z2.z.boolean().default(state).optional();
|
|
418
|
-
var AdsReplyType = z2.z.custom();
|
|
419
|
-
|
|
420
|
-
// src/types/classes/Client.ts
|
|
421
|
-
var PluginsType = z2__default.default.array(
|
|
422
|
-
z2__default.default.object({
|
|
423
|
-
necessary: z2__default.default.string()
|
|
424
|
-
}).passthrough()
|
|
425
|
-
).optional();
|
|
426
|
-
var LimiterType = z2__default.default.object({
|
|
427
|
-
durationMs: z2__default.default.number(),
|
|
428
|
-
maxMessages: z2__default.default.number()
|
|
429
|
-
}).optional();
|
|
430
|
-
var CitationType = z2__default.default.partialRecord(z2__default.default.string(), z2__default.default.number().array()).optional();
|
|
431
|
-
var FakeReplyType = z2__default.default.object({
|
|
432
|
-
provider: z2__default.default.enum(["whatsapp", "meta", "chatgpt", "copilot", "instagram", "tiktok"])
|
|
433
|
-
}).optional();
|
|
434
|
-
var ClientBaseType = z2__default.default.object({
|
|
435
|
-
session: z2__default.default.string().default("zaileys-sessions").optional(),
|
|
436
|
-
prefix: z2__default.default.string().optional(),
|
|
437
|
-
ignoreMe: defaultBoolean(true),
|
|
438
|
-
showLogs: defaultBoolean(true),
|
|
439
|
-
autoMentions: defaultBoolean(true),
|
|
440
|
-
autoOnline: defaultBoolean(true),
|
|
441
|
-
autoRead: defaultBoolean(true),
|
|
442
|
-
autoPresence: defaultBoolean(true),
|
|
443
|
-
autoRejectCall: defaultBoolean(true),
|
|
444
|
-
plugins: PluginsType,
|
|
445
|
-
limiter: LimiterType,
|
|
446
|
-
citation: CitationType,
|
|
447
|
-
fakeReply: FakeReplyType
|
|
448
|
-
});
|
|
449
|
-
var ClientAuthPairingType = z2__default.default.object({
|
|
450
|
-
authType: z2__default.default.literal("pairing"),
|
|
451
|
-
phoneNumber: z2__default.default.number()
|
|
452
|
-
});
|
|
453
|
-
var ClientAuthQRType = z2__default.default.object({
|
|
454
|
-
authType: z2__default.default.literal("qr")
|
|
455
|
-
});
|
|
456
|
-
var ClientOptionsType = z2__default.default.discriminatedUnion("authType", [ClientAuthPairingType.extend(ClientBaseType.shape), ClientAuthQRType.extend(ClientBaseType.shape)]);
|
|
457
|
-
var EventEnumType = z2__default.default.enum(["connection", "messages", "calls", "webhooks"]);
|
|
458
|
-
var displayBanner = async (text = "ZAILEYS") => {
|
|
459
|
-
figlet__default.default(text, async (err, data) => {
|
|
460
|
-
if (err) return;
|
|
461
|
-
console.log(chalk__default.default.gray.italic(data));
|
|
462
|
-
});
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
// src/extractor/calls.ts
|
|
466
|
-
var CallsExtractor = async (client, caller) => {
|
|
467
|
-
const payload = {};
|
|
468
|
-
payload.callId = caller.id;
|
|
469
|
-
payload.roomId = caller.chatId;
|
|
470
|
-
payload.callerId = caller.from;
|
|
471
|
-
payload.date = caller.date;
|
|
472
|
-
payload.offline = caller.offline;
|
|
473
|
-
payload.status = caller.status;
|
|
474
|
-
payload.isVideo = !!caller.isVideo;
|
|
475
|
-
payload.isGroup = !!caller.isGroup;
|
|
476
|
-
return payload;
|
|
477
|
-
};
|
|
478
|
-
var MessagesMediaType = {
|
|
479
|
-
text: "text",
|
|
480
|
-
conversation: "text",
|
|
481
|
-
imageMessage: "image",
|
|
482
|
-
contactMessage: "contact",
|
|
483
|
-
locationMessage: "location",
|
|
484
|
-
documentMessage: "document",
|
|
485
|
-
audioMessage: "audio",
|
|
486
|
-
videoMessage: "video",
|
|
487
|
-
protocolMessage: "protocol",
|
|
488
|
-
contactsArrayMessage: "contacts",
|
|
489
|
-
highlyStructuredMessage: "highlyStructured",
|
|
490
|
-
sendPaymentMessage: "sendPayment",
|
|
491
|
-
liveLocationMessage: "location",
|
|
492
|
-
requestPaymentMessage: "requestPayment",
|
|
493
|
-
declinePaymentRequestMessage: "declinePaymentRequest",
|
|
494
|
-
cancelPaymentRequestMessage: "cancelPaymentRequest",
|
|
495
|
-
templateMessage: "template",
|
|
496
|
-
stickerMessage: "sticker",
|
|
497
|
-
groupInviteMessage: "groupInvite",
|
|
498
|
-
templateButtonReplyMessage: "buttons",
|
|
499
|
-
productMessage: "product",
|
|
500
|
-
deviceSentMessage: "deviceSent",
|
|
501
|
-
listMessage: "list",
|
|
502
|
-
viewOnceMessage: "viewOnce",
|
|
503
|
-
orderMessage: "order",
|
|
504
|
-
listResponseMessage: "list",
|
|
505
|
-
ephemeralMessage: "ephemeral",
|
|
506
|
-
invoiceMessage: "invoice",
|
|
507
|
-
buttonsMessage: "buttons",
|
|
508
|
-
buttonsResponseMessage: "buttons",
|
|
509
|
-
paymentInviteMessage: "paymentInvite",
|
|
510
|
-
interactiveMessage: "interactive",
|
|
511
|
-
reactionMessage: "reaction",
|
|
512
|
-
stickerSyncRmrMessage: "sticker",
|
|
513
|
-
interactiveResponseMessage: "interactiveResponse",
|
|
514
|
-
pollCreationMessage: "pollCreation",
|
|
515
|
-
pollUpdateMessage: "pollUpdate",
|
|
516
|
-
keepInChatMessage: "keepInChat",
|
|
517
|
-
documentWithCaptionMessage: "document",
|
|
518
|
-
requestPhoneNumberMessage: "requestPhoneNumber",
|
|
519
|
-
viewOnceMessageV2: "viewOnce",
|
|
520
|
-
encReactionMessage: "reaction",
|
|
521
|
-
editedMessage: "text",
|
|
522
|
-
viewOnceMessageV2Extension: "viewOnce",
|
|
523
|
-
pollCreationMessageV2: "pollCreation",
|
|
524
|
-
scheduledCallCreationMessage: "scheduledCallCreation",
|
|
525
|
-
groupMentionedMessage: "groupMentioned",
|
|
526
|
-
pinInChatMessage: "pinInChat",
|
|
527
|
-
pollCreationMessageV3: "pollCreation",
|
|
528
|
-
scheduledCallEditMessage: "scheduledCallEdit",
|
|
529
|
-
ptvMessage: "ptv",
|
|
530
|
-
botInvokeMessage: "botInvoke",
|
|
531
|
-
callLogMesssage: "callLog",
|
|
532
|
-
encCommentMessage: "encComment",
|
|
533
|
-
bcallMessage: "bcall",
|
|
534
|
-
lottieStickerMessage: "lottieSticker",
|
|
535
|
-
eventMessage: "event",
|
|
536
|
-
commentMessage: "comment",
|
|
537
|
-
newsletterAdminInviteMessage: "text",
|
|
538
|
-
extendedTextMessageWithParentKey: "text",
|
|
539
|
-
extendedTextMessage: "text",
|
|
540
|
-
placeholderMessage: "placeholder",
|
|
541
|
-
encEventUpdateMessage: "encEventUpdate"
|
|
542
|
-
};
|
|
543
|
-
var MessagesVerifiedPlatformType = {
|
|
544
|
-
whatsapp: "0@s.whatsapp.net",
|
|
545
|
-
meta: "13135550002@s.whatsapp.net",
|
|
546
|
-
chatgpt: "18002428478@s.whatsapp.net",
|
|
547
|
-
copilot: "18772241042@s.whatsapp.net",
|
|
548
|
-
instagram: "447723442971@s.whatsapp.net",
|
|
549
|
-
tiktok: "6285574670498@s.whatsapp.net"
|
|
550
|
-
};
|
|
551
|
-
var MessagesEnumType = zod.z.enum([
|
|
552
|
-
"text",
|
|
553
|
-
"image",
|
|
554
|
-
"contact",
|
|
555
|
-
"location",
|
|
556
|
-
"document",
|
|
557
|
-
"audio",
|
|
558
|
-
"video",
|
|
559
|
-
"protocol",
|
|
560
|
-
"contacts",
|
|
561
|
-
"highlyStructured",
|
|
562
|
-
"sendPayment",
|
|
563
|
-
"requestPayment",
|
|
564
|
-
"declinePaymentRequest",
|
|
565
|
-
"cancelPaymentRequest",
|
|
566
|
-
"template",
|
|
567
|
-
"sticker",
|
|
568
|
-
"groupInvite",
|
|
569
|
-
"product",
|
|
570
|
-
"deviceSent",
|
|
571
|
-
"list",
|
|
572
|
-
"viewOnce",
|
|
573
|
-
"order",
|
|
574
|
-
"ephemeral",
|
|
575
|
-
"invoice",
|
|
576
|
-
"buttons",
|
|
577
|
-
"paymentInvite",
|
|
578
|
-
"interactive",
|
|
579
|
-
"reaction",
|
|
580
|
-
"sticker",
|
|
581
|
-
"interactiveResponse",
|
|
582
|
-
"pollCreation",
|
|
583
|
-
"pollUpdate",
|
|
584
|
-
"keepInChat",
|
|
585
|
-
"document",
|
|
586
|
-
"requestPhoneNumber",
|
|
587
|
-
"viewOnce",
|
|
588
|
-
"reaction",
|
|
589
|
-
"text",
|
|
590
|
-
"viewOnce",
|
|
591
|
-
"pollCreation",
|
|
592
|
-
"scheduledCallCreation",
|
|
593
|
-
"groupMentioned",
|
|
594
|
-
"pinInChat",
|
|
595
|
-
"pollCreation",
|
|
596
|
-
"scheduledCallEdit",
|
|
597
|
-
"ptv",
|
|
598
|
-
"botInvoke",
|
|
599
|
-
"callLog",
|
|
600
|
-
"encComment",
|
|
601
|
-
"bcall",
|
|
602
|
-
"lottieSticker",
|
|
603
|
-
"event",
|
|
604
|
-
"comment",
|
|
605
|
-
"placeholder",
|
|
606
|
-
"encEventUpdate"
|
|
607
|
-
]);
|
|
608
|
-
var MessagesDeviceEnumType = zod.z.enum([
|
|
609
|
-
"unknown",
|
|
610
|
-
"android",
|
|
611
|
-
"ios",
|
|
612
|
-
"desktop",
|
|
613
|
-
"web"
|
|
614
|
-
]);
|
|
615
|
-
var ExtractorMessagesType = zod.z.object({
|
|
616
|
-
chatId: zod.z.string(),
|
|
617
|
-
channelId: zod.z.string(),
|
|
618
|
-
uniqueId: zod.z.string(),
|
|
619
|
-
receiverId: zod.z.string(),
|
|
620
|
-
receiverName: zod.z.string(),
|
|
621
|
-
roomId: zod.z.string(),
|
|
622
|
-
roomName: zod.z.string(),
|
|
623
|
-
senderLid: zod.z.string(),
|
|
624
|
-
senderId: zod.z.string(),
|
|
625
|
-
senderName: zod.z.string(),
|
|
626
|
-
senderDevice: MessagesDeviceEnumType,
|
|
627
|
-
chatType: MessagesEnumType,
|
|
628
|
-
timestamp: zod.z.number(),
|
|
629
|
-
text: zod.z.string().nullable(),
|
|
630
|
-
mentions: zod.z.string().array(),
|
|
631
|
-
links: zod.z.string().array(),
|
|
632
|
-
isPrefix: zod.z.boolean(),
|
|
633
|
-
isSpam: zod.z.boolean(),
|
|
634
|
-
isFromMe: zod.z.boolean(),
|
|
635
|
-
isTagMe: zod.z.boolean(),
|
|
636
|
-
isGroup: zod.z.boolean(),
|
|
637
|
-
isStory: zod.z.boolean(),
|
|
638
|
-
isViewOnce: zod.z.boolean(),
|
|
639
|
-
isEdited: zod.z.boolean(),
|
|
640
|
-
isDeleted: zod.z.boolean(),
|
|
641
|
-
isPinned: zod.z.boolean(),
|
|
642
|
-
isUnPinned: zod.z.boolean(),
|
|
643
|
-
isChannel: zod.z.boolean(),
|
|
644
|
-
isBroadcast: zod.z.boolean(),
|
|
645
|
-
isEphemeral: zod.z.boolean(),
|
|
646
|
-
isForwarded: zod.z.boolean(),
|
|
647
|
-
citation: zod.z.record(zod.z.string(), zod.z.boolean()).nullable(),
|
|
648
|
-
media: zod.z.object({
|
|
649
|
-
buffer: zod.z.function(),
|
|
650
|
-
stream: zod.z.function()
|
|
651
|
-
}).loose().nullable(),
|
|
652
|
-
message: zod.z.function({
|
|
653
|
-
input: [],
|
|
654
|
-
output: zod.z.record(zod.z.string(), zod.z.any())
|
|
655
|
-
}),
|
|
656
|
-
get replied() {
|
|
657
|
-
return ExtractorMessagesType.nullable();
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
var limiterCache = new NodeCache2__default.default({ stdTTL: 60 * 60 });
|
|
661
|
-
var LimiterHandler = async (key, max, ms) => {
|
|
662
|
-
try {
|
|
663
|
-
if (max <= 0) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
const state = limiterCache.get(key);
|
|
667
|
-
const now = Date.now();
|
|
668
|
-
if (!state || now - state.firstRequestTime > ms) {
|
|
669
|
-
const newState2 = {
|
|
670
|
-
count: 1,
|
|
671
|
-
firstRequestTime: now
|
|
672
|
-
};
|
|
673
|
-
limiterCache.set(key, newState2, Math.ceil(ms / 1e3) + 10);
|
|
674
|
-
return false;
|
|
675
|
-
}
|
|
676
|
-
const newState = {
|
|
677
|
-
count: state.count + 1,
|
|
678
|
-
firstRequestTime: state.firstRequestTime
|
|
679
|
-
};
|
|
680
|
-
limiterCache.set(key, newState, Math.ceil((ms - (now - state.firstRequestTime)) / 1e3) + 10);
|
|
681
|
-
if (newState.count > max) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
return false;
|
|
685
|
-
} catch (err) {
|
|
686
|
-
console.error("Error detecting spam:", err);
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
// src/extractor/messages.ts
|
|
692
|
-
var MessagesExtractor = async (client, message) => {
|
|
693
|
-
let MAX_REPLIES = 0;
|
|
694
|
-
const CLONE = message;
|
|
695
|
-
const extract = async (obj, isReplied, isExtract) => {
|
|
696
|
-
let msg = toJson(obj);
|
|
697
|
-
if (!msg.message || !msg?.key?.id) {
|
|
698
|
-
return null;
|
|
699
|
-
}
|
|
700
|
-
if (msg?.messageStubType || !!msg?.messageStubParameters || msg?.message?.botInvokeMessage || msg.message?.protocolMessage?.peerDataOperationRequestResponseMessage) {
|
|
701
|
-
return null;
|
|
702
|
-
}
|
|
703
|
-
if (msg?.key?.fromMe && !msg?.participant && msg?.key?.remoteJid != "status@broadcast" && client.props?.ignoreMe && !MAX_REPLIES && true) {
|
|
704
|
-
return null;
|
|
705
|
-
}
|
|
706
|
-
const pinId = msg?.message?.pinInChatMessage?.key?.id;
|
|
707
|
-
const isPinned = msg?.message?.pinInChatMessage?.type == 1;
|
|
708
|
-
const isUnPinned = msg?.message?.pinInChatMessage?.type == 2;
|
|
709
|
-
if (pinId && client.db) {
|
|
710
|
-
const read = await client.db.store("messages").read(pinId);
|
|
711
|
-
msg = read;
|
|
712
|
-
}
|
|
713
|
-
const protocolId = !msg?.message?.protocolMessage?.editedMessage && msg?.message?.protocolMessage?.key?.id;
|
|
714
|
-
const isDeleted = !!protocolId;
|
|
715
|
-
if (protocolId && client.db) {
|
|
716
|
-
const read = await client.db.store("messages").read(protocolId);
|
|
717
|
-
msg = read;
|
|
718
|
-
}
|
|
719
|
-
const edited = msg?.message?.protocolMessage?.editedMessage || msg?.message?.editedMessage;
|
|
720
|
-
if (edited) {
|
|
721
|
-
const id = edited?.message?.protocolMessage?.key?.id;
|
|
722
|
-
if (id && client.db) {
|
|
723
|
-
const read3 = await client.db.store("messages").read(id);
|
|
724
|
-
const editType = makeWASocket.getContentType(edited?.message?.protocolMessage?.editedMessage);
|
|
725
|
-
const readType = makeWASocket.getContentType(read3?.message);
|
|
726
|
-
let editing = void 0;
|
|
727
|
-
if (editType && edited?.message?.protocolMessage?.editedMessage) {
|
|
728
|
-
editing = edited.message.protocolMessage.editedMessage[editType];
|
|
729
|
-
if (readType && read3?.message) {
|
|
730
|
-
read3.message[readType] = _2__default.default.merge(read3.message[readType], editing);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
msg = read3 || msg;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
const contentType = makeWASocket.getContentType(msg?.message?.protocolMessage?.editedMessage || msg?.message);
|
|
737
|
-
if (!contentType) return null;
|
|
738
|
-
const payload = {};
|
|
739
|
-
payload.chatId = msg?.message?.protocolMessage?.key?.id || msg?.key?.id || "";
|
|
740
|
-
payload.channelId = "";
|
|
741
|
-
payload.uniqueId = "";
|
|
742
|
-
payload.receiverId = makeWASocket.jidNormalizedUser(client.socket?.user?.id || "");
|
|
743
|
-
payload.receiverName = client.socket?.user?.name || client.socket?.user?.verifiedName || "";
|
|
744
|
-
payload.roomId = makeWASocket.jidNormalizedUser(message?.key?.remoteJid || "");
|
|
745
|
-
if (client.db) {
|
|
746
|
-
const roomName = await client.db.store("chats").read(payload.roomId);
|
|
747
|
-
payload.roomName = toJson(roomName)?.name || "";
|
|
748
|
-
}
|
|
749
|
-
payload.senderLid = msg?.message?.protocolMessage?.key?.senderLid || msg?.key?.senderLid || msg?.key?.participantLid || "";
|
|
750
|
-
payload.senderId = makeWASocket.jidNormalizedUser(msg?.participant || msg?.key?.participant || msg?.key?.remoteJid);
|
|
751
|
-
if (client.db) {
|
|
752
|
-
const senderName = await client.db.store("chats").read(payload.senderId);
|
|
753
|
-
payload.senderLid = payload.senderLid || toJson(senderName)?.lidJid || "";
|
|
754
|
-
payload.senderName = msg?.pushName || msg?.verifiedBizName || toJson(senderName)?.name || payload.receiverName;
|
|
755
|
-
}
|
|
756
|
-
payload.senderDevice = makeWASocket.getDevice(payload.chatId);
|
|
757
|
-
if (payload.senderId == payload.receiverId) {
|
|
758
|
-
payload.senderName = payload.receiverName;
|
|
759
|
-
}
|
|
760
|
-
payload.roomName = payload.roomName || payload.senderName || _2__default.default.split(payload.roomId || "", "@")[0];
|
|
761
|
-
payload.chatType = MessagesMediaType[contentType];
|
|
762
|
-
payload.timestamp = Number(msg?.messageTimestamp || 0);
|
|
763
|
-
payload.text = null;
|
|
764
|
-
payload.mentions = [];
|
|
765
|
-
payload.links = [];
|
|
766
|
-
payload.isPrefix = false;
|
|
767
|
-
payload.isSpam = false;
|
|
768
|
-
payload.isFromMe = message?.key?.fromMe || false;
|
|
769
|
-
payload.isTagMe = false;
|
|
770
|
-
payload.isGroup = _2__default.default.includes(payload.roomId, "@g.us");
|
|
771
|
-
payload.isStory = _2__default.default.includes(payload.roomId, "@broadcast");
|
|
772
|
-
payload.isViewOnce = false;
|
|
773
|
-
payload.isEdited = false;
|
|
774
|
-
payload.isDeleted = isDeleted;
|
|
775
|
-
payload.isPinned = isPinned;
|
|
776
|
-
payload.isUnPinned = isUnPinned;
|
|
777
|
-
payload.isChannel = _2__default.default.includes(payload.roomId, "@newsletter");
|
|
778
|
-
payload.isBroadcast = !!message?.broadcast;
|
|
779
|
-
payload.isEphemeral = false;
|
|
780
|
-
payload.isForwarded = false;
|
|
781
|
-
if (!isReplied && true) {
|
|
782
|
-
const limiter = await LimiterHandler(payload.roomId, client.props.limiter?.maxMessages || 3, client.props.limiter?.durationMs || 5e3);
|
|
783
|
-
payload.isSpam = limiter;
|
|
784
|
-
}
|
|
785
|
-
if (payload.isFromMe) {
|
|
786
|
-
payload.senderId = payload.receiverId;
|
|
787
|
-
payload.senderName = payload.receiverName;
|
|
788
|
-
}
|
|
789
|
-
payload.citation = null;
|
|
790
|
-
payload.media = null;
|
|
791
|
-
payload.replied = null;
|
|
792
|
-
payload.channelId = _2__default.default.join([_2__default.default.split(payload.roomId, "@")[0], _2__default.default.split(payload.senderId, "@")[0]], "-");
|
|
793
|
-
payload.uniqueId = _2__default.default.join([payload.channelId, payload.chatId], "-");
|
|
794
|
-
const citation = client.props?.citation || {};
|
|
795
|
-
if (Object.keys(citation).length) {
|
|
796
|
-
payload.citation = {};
|
|
797
|
-
for (const key of Object.keys(citation)) {
|
|
798
|
-
const slug = "is" + _2__default.default.upperFirst(_2__default.default.camelCase(key));
|
|
799
|
-
const citationEntry = citation[key];
|
|
800
|
-
if (citationEntry && Array.isArray(citationEntry)) {
|
|
801
|
-
const senderId = payload.senderId.split("@")[0];
|
|
802
|
-
const roomId = payload.roomId.split("@")[0];
|
|
803
|
-
const citationRecord = citation;
|
|
804
|
-
payload.citation[slug] = (senderId ? (citationRecord[key] || []).includes(Number(senderId)) : false) || (roomId ? (citationRecord[key] || []).includes(Number(roomId)) : false);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
const media = msg?.message?.editedMessage?.[contentType] || msg?.message?.protocolMessage?.editedMessage?.[contentType] || msg?.message?.[contentType]?.message?.documentMessage || msg?.message?.[contentType];
|
|
809
|
-
if (payload.chatType != "text") {
|
|
810
|
-
payload.media = {
|
|
811
|
-
..._2__default.default.omit(media, [
|
|
812
|
-
"url",
|
|
813
|
-
"contextInfo",
|
|
814
|
-
"fileSha256",
|
|
815
|
-
"fileEncSha256",
|
|
816
|
-
"mediaKey",
|
|
817
|
-
"directPath",
|
|
818
|
-
"waveform",
|
|
819
|
-
"thumbnail",
|
|
820
|
-
"jpegThumbnail",
|
|
821
|
-
"thumbnailEncSha256",
|
|
822
|
-
"thumbnailSha256",
|
|
823
|
-
"thumbnailDirectPath",
|
|
824
|
-
"firstFrameSidecar",
|
|
825
|
-
"streamingSidecar",
|
|
826
|
-
"scansSidecar",
|
|
827
|
-
"callKey",
|
|
828
|
-
"message",
|
|
829
|
-
"key",
|
|
830
|
-
"midQualityFileSha256"
|
|
831
|
-
]),
|
|
832
|
-
buffer: () => makeWASocket.downloadMediaMessage(message, "buffer", {}),
|
|
833
|
-
stream: () => makeWASocket.downloadMediaMessage(message, "stream", {})
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
const repliedId = toJson(msg?.message?.[contentType])?.contextInfo?.stanzaId;
|
|
837
|
-
if (repliedId && MAX_REPLIES < 1 && client.db) {
|
|
838
|
-
MAX_REPLIES++;
|
|
839
|
-
const replied = await client.db.store("messages").read(repliedId);
|
|
840
|
-
if (!replied) {
|
|
841
|
-
payload.replied = await extract(msg, true);
|
|
842
|
-
} else {
|
|
843
|
-
payload.replied = await extract(replied, true);
|
|
844
|
-
}
|
|
845
|
-
MAX_REPLIES = 0;
|
|
846
|
-
}
|
|
847
|
-
const text = typeof media == "string" ? media : media?.text || media?.caption || media?.name || media?.displayName || media?.conversation || media?.contentText || media?.selectedDisplayText || "";
|
|
848
|
-
payload.text = normalizeText(text) || "";
|
|
849
|
-
payload.mentions = getMentions(payload.text || "");
|
|
850
|
-
payload.links = extractUrls(payload.text || "");
|
|
851
|
-
const messaging = toJson(msg?.message?.[contentType]);
|
|
852
|
-
payload.isPrefix = !!(client.props?.prefix && _2__default.default.startsWith(payload.text, client.props?.prefix));
|
|
853
|
-
payload.isTagMe = _2__default.default.includes(payload.mentions, _2__default.default.split(payload.receiverId, "@")[0] || "");
|
|
854
|
-
payload.isEdited = !!edited;
|
|
855
|
-
payload.isEphemeral = !!findWord(toString(messaging?.contextInfo), "ephemeralSettingTimestamp");
|
|
856
|
-
payload.isForwarded = !!findWord(toString(messaging?.contextInfo), "forwardingScore");
|
|
857
|
-
payload.isViewOnce = !!messaging?.viewOnce;
|
|
858
|
-
if (payload.isPrefix) {
|
|
859
|
-
payload.text = _2__default.default.replace(payload.text, new RegExp(`^${client.props?.prefix}`), "");
|
|
860
|
-
}
|
|
861
|
-
payload.message = () => CLONE;
|
|
862
|
-
return payload;
|
|
863
|
-
};
|
|
864
|
-
return extract(message);
|
|
865
|
-
};
|
|
866
|
-
var Listener = class {
|
|
867
|
-
client;
|
|
868
|
-
async bind(client, db) {
|
|
869
|
-
this.client = client;
|
|
870
|
-
this.client.db = db;
|
|
871
|
-
this.client.socket?.ev.on("connection.update", async (update) => {
|
|
872
|
-
await this.connection(update);
|
|
873
|
-
});
|
|
874
|
-
this.client.socket?.ev.on("messages.upsert", async ({ messages }) => {
|
|
875
|
-
for (const message of messages) {
|
|
876
|
-
await this.messages(message);
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
this.client.socket?.ev.on("call", async (callers) => {
|
|
880
|
-
for (const caller of callers) {
|
|
881
|
-
await this.calls(caller);
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
this.client.socket?.ev.on("creds.update", () => {
|
|
885
|
-
});
|
|
886
|
-
if (this.client.socket?.ws) {
|
|
887
|
-
const originalEmit = this.client.socket.ws.emit.bind(this.client.socket.ws);
|
|
888
|
-
this.client.socket.ws.emit = (event, ...args) => {
|
|
889
|
-
if (event === "error" && args[0]) {
|
|
890
|
-
const errorMessage = args[0].message || args[0]?.toString();
|
|
891
|
-
if (_2__default.default.includes(errorMessage, "Closing open session in favor of incoming prekey bundle") || _2__default.default.includes(errorMessage, "Closing stale open session for new outgoing prekey bundle") || _2__default.default.includes(errorMessage, "Closing session: SessionEntry")) {
|
|
892
|
-
this.handleSessionClosing();
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
return originalEmit(event, ...args);
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
async handleSessionClosing() {
|
|
900
|
-
this.client.spinner.start("Processing session changes...");
|
|
901
|
-
await makeWASocket.delay(3e3);
|
|
902
|
-
this.client.spinner.success("Session processing completed");
|
|
903
|
-
}
|
|
904
|
-
async connection(update) {
|
|
905
|
-
const { connection, lastDisconnect, qr } = update;
|
|
906
|
-
this.client.emit("connection", { status: "connecting" });
|
|
907
|
-
if (this.client.props.authType === "qr" && qr) {
|
|
908
|
-
this.client.spinner.info(`Please scan the QR
|
|
909
|
-
|
|
910
|
-
${await QRCode__default.default.toString(qr, { type: "terminal", small: true })}`);
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
if (connection === "close") {
|
|
914
|
-
const code = toJson(lastDisconnect?.error)?.output?.statusCode;
|
|
915
|
-
const errorMessage = lastDisconnect?.error?.message || "";
|
|
916
|
-
const isReconnect = typeof code === "number" && code !== makeWASocket.DisconnectReason.loggedOut;
|
|
917
|
-
if (_2__default.default.includes(errorMessage, "Closing open session in favor of incoming prekey bundle") || _2__default.default.includes(errorMessage, "Closing stale open session for new outgoing prekey bundle") || _2__default.default.includes(errorMessage, "Closing session: SessionEntry")) {
|
|
918
|
-
this.client.spinner.start("Processing session changes...");
|
|
919
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
920
|
-
this.client.spinner.success("Session processing completed");
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
this.client.spinner.error(`[Connection Closed] [${code}] ${errorMessage}`);
|
|
924
|
-
if (code === 401 || code === 405 || code === 500) {
|
|
925
|
-
this.client.spinner.error("Invalid session, please delete manually");
|
|
926
|
-
this.client.spinner.error(`Session "${this.client.props.session}" has not valid, please delete it`);
|
|
927
|
-
return;
|
|
928
|
-
}
|
|
929
|
-
if (isReconnect) {
|
|
930
|
-
this.client.spinner.warn("Connection lost. Attempting auto-reload...");
|
|
931
|
-
const clientRecord = this.client;
|
|
932
|
-
if (typeof clientRecord.autoReload === "function") {
|
|
933
|
-
await clientRecord.autoReload();
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
} else if (connection === "open") {
|
|
937
|
-
if (this.client.socket?.user) {
|
|
938
|
-
const id = makeWASocket.jidNormalizedUser(this.client.socket.user.id).split("@")[0];
|
|
939
|
-
const name = this.client.socket.user.name || this.client.socket.user.verifiedName;
|
|
940
|
-
const clientRecord = this.client;
|
|
941
|
-
if (typeof clientRecord.resetRetryCount === "function") {
|
|
942
|
-
clientRecord.resetRetryCount();
|
|
943
|
-
}
|
|
944
|
-
this.client.spinner.success(`Connected as ${chalk__default.default.green(name || id)}`);
|
|
945
|
-
this.client.emit("connection", { status: "open" });
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
async messages(message) {
|
|
950
|
-
if (this.client.props?.autoRead && this.client.socket) {
|
|
951
|
-
if (message?.key) {
|
|
952
|
-
await this.client.socket.readMessages([message.key]);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
const extract = await MessagesExtractor(this.client, message);
|
|
956
|
-
if (extract) {
|
|
957
|
-
this.client.emit("messages", extract);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
async calls(caller) {
|
|
961
|
-
if (this.client.props?.autoRejectCall && this.client.socket) {
|
|
962
|
-
await this.client.socket.rejectCall(caller.id, caller.from);
|
|
963
|
-
}
|
|
964
|
-
const extract = await CallsExtractor(this.client, caller);
|
|
965
|
-
this.client.emit("calls", extract);
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
var RelayTextType = z2.z.string().or(z2.z.object({
|
|
969
|
-
text: z2.z.string(),
|
|
970
|
-
roomId: z2.z.string().optional(),
|
|
971
|
-
options: z2.z.custom().optional(),
|
|
972
|
-
externalAdReply: AdsReplyType.optional()
|
|
973
|
-
}));
|
|
974
|
-
var RelayReplyType = z2.z.string().or(
|
|
975
|
-
z2.z.object({
|
|
976
|
-
text: z2.z.string(),
|
|
977
|
-
roomId: z2.z.string().optional(),
|
|
978
|
-
options: z2.z.custom().optional(),
|
|
979
|
-
externalAdReply: AdsReplyType.optional()
|
|
980
|
-
})
|
|
981
|
-
);
|
|
982
|
-
var RelayForwardType = z2.z.string().or(
|
|
983
|
-
z2.z.object({
|
|
984
|
-
text: z2.z.string(),
|
|
985
|
-
isForwardMany: defaultBoolean(false),
|
|
986
|
-
roomId: z2.z.string().optional(),
|
|
987
|
-
options: z2.z.custom().optional(),
|
|
988
|
-
externalAdReply: AdsReplyType.optional()
|
|
989
|
-
})
|
|
990
|
-
);
|
|
991
|
-
var RelayImageEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
992
|
-
var RelayImageType = z2.z.object({
|
|
993
|
-
image: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)),
|
|
994
|
-
text: z2.z.string().optional(),
|
|
995
|
-
viewOnce: defaultBoolean(false),
|
|
996
|
-
roomId: z2.z.string().optional(),
|
|
997
|
-
externalAdReply: AdsReplyType.optional()
|
|
998
|
-
});
|
|
999
|
-
var RelayVideoEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1000
|
-
var RelayVideoType = z2.z.object({
|
|
1001
|
-
video: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)),
|
|
1002
|
-
text: z2.z.string().optional(),
|
|
1003
|
-
viewOnce: defaultBoolean(false),
|
|
1004
|
-
roomId: z2.z.string().optional()
|
|
1005
|
-
});
|
|
1006
|
-
var RelayAudioEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1007
|
-
var RelayAudioType = z2.z.object({
|
|
1008
|
-
audio: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)),
|
|
1009
|
-
viewOnce: defaultBoolean(false),
|
|
1010
|
-
roomId: z2.z.string().optional(),
|
|
1011
|
-
externalAdReply: AdsReplyType.optional()
|
|
1012
|
-
});
|
|
1013
|
-
var RelayStickerEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1014
|
-
var RelayStickerType = z2.z.object({
|
|
1015
|
-
sticker: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)),
|
|
1016
|
-
roomId: z2.z.string().optional()
|
|
1017
|
-
});
|
|
1018
|
-
var RelayEditType = z2.z.object({
|
|
1019
|
-
text: z2.z.string(),
|
|
1020
|
-
message: z2.z.function({
|
|
1021
|
-
input: [],
|
|
1022
|
-
output: z2.z.any()
|
|
1023
|
-
}).optional()
|
|
1024
|
-
});
|
|
1025
|
-
var RelayDeleteType = z2.z.object({
|
|
1026
|
-
message: z2.z.function({
|
|
1027
|
-
input: [],
|
|
1028
|
-
output: z2.z.any()
|
|
1029
|
-
}).optional()
|
|
1030
|
-
});
|
|
1031
|
-
var ExtractorCallsType = z2.z.object({
|
|
1032
|
-
callId: z2.z.string(),
|
|
1033
|
-
roomId: z2.z.string(),
|
|
1034
|
-
callerId: z2.z.string(),
|
|
1035
|
-
date: z2.z.date(),
|
|
1036
|
-
offline: z2.z.boolean(),
|
|
1037
|
-
status: z2.z.enum(["accept", "offer", "reject", "ringing", "terminate", "timeout"]),
|
|
1038
|
-
isVideo: z2.z.boolean(),
|
|
1039
|
-
isGroup: z2.z.boolean()
|
|
1040
|
-
});
|
|
1041
|
-
|
|
1042
|
-
// src/types/relay/reject.ts
|
|
1043
|
-
var RelayRejectType = ExtractorCallsType.pick({
|
|
1044
|
-
callId: true,
|
|
1045
|
-
callerId: true
|
|
1046
|
-
});
|
|
1047
|
-
var RelayPresenceType = z2.z.enum(["typing", "recording", "online", "offline", "paused"]);
|
|
1048
|
-
var RelayReactionType = z2.z.emoji().or(
|
|
1049
|
-
z2.z.object({
|
|
1050
|
-
emoticon: z2.z.emoji(),
|
|
1051
|
-
message: z2.z.function({
|
|
1052
|
-
input: [],
|
|
1053
|
-
output: z2.z.any()
|
|
1054
|
-
}).optional()
|
|
1055
|
-
})
|
|
1056
|
-
);
|
|
1057
|
-
var RelayLocationEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1058
|
-
var RelayLocationType = z2.z.object({
|
|
1059
|
-
latitude: z2.z.number(),
|
|
1060
|
-
longitude: z2.z.number(),
|
|
1061
|
-
title: z2.z.string().optional(),
|
|
1062
|
-
footer: z2.z.string().optional(),
|
|
1063
|
-
roomId: z2.z.string().optional(),
|
|
1064
|
-
externalAdReply: AdsReplyType.optional()
|
|
1065
|
-
});
|
|
1066
|
-
var RelayContactEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1067
|
-
var RelayContactType = z2.z.object({
|
|
1068
|
-
title: z2.z.string().optional(),
|
|
1069
|
-
contacts: z2.z.object({
|
|
1070
|
-
fullname: z2.z.string(),
|
|
1071
|
-
nickname: z2.z.string().optional(),
|
|
1072
|
-
organization: z2.z.string().optional(),
|
|
1073
|
-
phoneNumber: z2.z.number(),
|
|
1074
|
-
website: z2.z.url().optional()
|
|
1075
|
-
}).array(),
|
|
1076
|
-
roomId: z2.z.string().optional()
|
|
1077
|
-
});
|
|
1078
|
-
var RelayPollEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1079
|
-
var RelayPollCreateType = z2.z.object({
|
|
1080
|
-
action: z2.z.literal("create"),
|
|
1081
|
-
name: z2.z.string(),
|
|
1082
|
-
answers: z2.z.string().array(),
|
|
1083
|
-
isMultiple: defaultBoolean(false),
|
|
1084
|
-
roomId: z2.z.string().optional()
|
|
1085
|
-
});
|
|
1086
|
-
z2.z.object({
|
|
1087
|
-
action: z2.z.literal("result"),
|
|
1088
|
-
name: z2.z.string(),
|
|
1089
|
-
votes: z2.z.tuple([z2.z.string(), z2.z.number()]).array(),
|
|
1090
|
-
roomId: z2.z.string().optional()
|
|
1091
|
-
});
|
|
1092
|
-
var RelayPollType = z2.z.discriminatedUnion("action", [RelayPollCreateType]);
|
|
1093
|
-
var RelayDocumentEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1094
|
-
var RelayDocumentType = z2.z.object({
|
|
1095
|
-
document: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)),
|
|
1096
|
-
mimetype: z2.z.string(),
|
|
1097
|
-
text: z2.z.string().optional(),
|
|
1098
|
-
fileName: z2.z.string().optional(),
|
|
1099
|
-
roomId: z2.z.string().optional(),
|
|
1100
|
-
externalAdReply: AdsReplyType.optional()
|
|
1101
|
-
});
|
|
1102
|
-
var RelayButtonEnumType = z2.z.enum(["text", "reply", "forward"]);
|
|
1103
|
-
var RelayButtonSimpleType = z2.z.object({
|
|
1104
|
-
type: z2.z.literal("simple"),
|
|
1105
|
-
text: z2.z.string(),
|
|
1106
|
-
footer: z2.z.string().optional(),
|
|
1107
|
-
buttons: z2.z.object({
|
|
1108
|
-
id: z2.z.string(),
|
|
1109
|
-
text: z2.z.string()
|
|
1110
|
-
}).array(),
|
|
1111
|
-
roomId: z2.z.string().optional()
|
|
1112
|
-
});
|
|
1113
|
-
var RelayButtonInteractiveReplyType = z2.z.object({
|
|
1114
|
-
type: z2.z.literal("quick_reply"),
|
|
1115
|
-
id: z2.z.string(),
|
|
1116
|
-
text: z2.z.string()
|
|
1117
|
-
});
|
|
1118
|
-
var RelayButtonInteractiveUrlType = z2.z.object({
|
|
1119
|
-
type: z2.z.literal("cta_url"),
|
|
1120
|
-
id: z2.z.string(),
|
|
1121
|
-
url: z2.z.url(),
|
|
1122
|
-
text: z2.z.string()
|
|
1123
|
-
});
|
|
1124
|
-
var RelayButtonInteractiveCopyType = z2.z.object({
|
|
1125
|
-
type: z2.z.literal("cta_copy"),
|
|
1126
|
-
id: z2.z.string(),
|
|
1127
|
-
copy: z2.z.string(),
|
|
1128
|
-
text: z2.z.string()
|
|
1129
|
-
});
|
|
1130
|
-
var RelayButtonInteractiveCallType = z2.z.object({
|
|
1131
|
-
type: z2.z.literal("cta_call"),
|
|
1132
|
-
id: z2.z.string(),
|
|
1133
|
-
phoneNumber: z2.z.string(),
|
|
1134
|
-
text: z2.z.string()
|
|
1135
|
-
});
|
|
1136
|
-
var RelayButtonInteractiveType = z2.z.object({
|
|
1137
|
-
type: z2.z.literal("interactive"),
|
|
1138
|
-
text: z2.z.string(),
|
|
1139
|
-
footer: z2.z.string().optional(),
|
|
1140
|
-
buttons: z2.z.discriminatedUnion("type", [RelayButtonInteractiveReplyType, RelayButtonInteractiveUrlType, RelayButtonInteractiveCopyType, RelayButtonInteractiveCallType]).array(),
|
|
1141
|
-
roomId: z2.z.string().optional()
|
|
1142
|
-
});
|
|
1143
|
-
z2.z.object({
|
|
1144
|
-
type: z2.z.literal("list"),
|
|
1145
|
-
text: z2.z.string(),
|
|
1146
|
-
footer: z2.z.string(),
|
|
1147
|
-
roomId: z2.z.string().optional()
|
|
1148
|
-
});
|
|
1149
|
-
var RelayButtonType = z2.z.discriminatedUnion("type", [RelayButtonSimpleType, RelayButtonInteractiveType]);
|
|
1150
|
-
var RelayGroupCreateType = z2.z.object({
|
|
1151
|
-
title: z2.z.string(),
|
|
1152
|
-
members: z2.z.string().array()
|
|
1153
|
-
});
|
|
1154
|
-
var RelayGroupActionType = z2.z.object({
|
|
1155
|
-
roomId: z2.z.string(),
|
|
1156
|
-
action: z2.z.enum(["add", "kick", "promote", "demote"]),
|
|
1157
|
-
members: z2.z.string().array()
|
|
1158
|
-
});
|
|
1159
|
-
var RelayGroupUpdateType = z2.z.object({
|
|
1160
|
-
roomId: z2.z.string(),
|
|
1161
|
-
text: z2.z.string(),
|
|
1162
|
-
action: z2.z.enum(["subject", "description"])
|
|
1163
|
-
});
|
|
1164
|
-
var RelayGroupSettingsType = z2.z.object({
|
|
1165
|
-
roomId: z2.z.string(),
|
|
1166
|
-
action: z2.z.enum(["open", "close", "lock", "unlock"])
|
|
1167
|
-
});
|
|
1168
|
-
var RelayGroupLeaveType = z2.z.object({
|
|
1169
|
-
roomId: z2.z.string()
|
|
1170
|
-
});
|
|
1171
|
-
var RelayGroupLinksType = z2.z.object({
|
|
1172
|
-
roomId: z2.z.string(),
|
|
1173
|
-
action: z2.z.enum(["get", "revoke"])
|
|
1174
|
-
});
|
|
1175
|
-
var RelayGroupInviteType = z2.z.object({
|
|
1176
|
-
url: z2.z.url().regex(/^https:\/\/chat\.whatsapp\.com\/[A-Za-z0-9_-]{5,}$/),
|
|
1177
|
-
action: z2.z.enum(["join", "info"])
|
|
1178
|
-
});
|
|
1179
|
-
var RelayGroupRequestsListType = z2.z.object({
|
|
1180
|
-
roomId: z2.z.string()
|
|
1181
|
-
});
|
|
1182
|
-
var RelayGroupRequestsApproveType = z2.z.object({
|
|
1183
|
-
roomId: z2.z.string(),
|
|
1184
|
-
members: z2.z.string().array()
|
|
1185
|
-
});
|
|
1186
|
-
var RelayGroupRequestsRejectType = z2.z.object({
|
|
1187
|
-
roomId: z2.z.string(),
|
|
1188
|
-
members: z2.z.string().array()
|
|
1189
|
-
});
|
|
1190
|
-
var RelayGroupMetadataType = z2.z.object({
|
|
1191
|
-
roomId: z2.z.string()
|
|
1192
|
-
});
|
|
1193
|
-
var RelayPrivacyUpdateControlType = z2.z.object({
|
|
1194
|
-
action: z2.z.literal("control"),
|
|
1195
|
-
type: z2.z.enum(["block", "unblock"]),
|
|
1196
|
-
senderId: z2.z.string()
|
|
1197
|
-
});
|
|
1198
|
-
var RelayPrivacyUpdateLastSeenType = z2.z.object({
|
|
1199
|
-
action: z2.z.literal("lastSeen"),
|
|
1200
|
-
type: z2.z.enum(["all", "contacts", "contact_blacklist", "none"])
|
|
1201
|
-
});
|
|
1202
|
-
var RelayPrivacyUpdateOnlineType = z2.z.object({
|
|
1203
|
-
action: z2.z.literal("online"),
|
|
1204
|
-
type: z2.z.enum(["all", "match_last_seen"])
|
|
1205
|
-
});
|
|
1206
|
-
var RelayPrivacyUpdateAvatarType = z2.z.object({
|
|
1207
|
-
action: z2.z.literal("avatar"),
|
|
1208
|
-
type: z2.z.enum(["all", "contacts", "contact_blacklist", "none"])
|
|
1209
|
-
});
|
|
1210
|
-
var RelayPrivacyUpdateStoryType = z2.z.object({
|
|
1211
|
-
action: z2.z.literal("story"),
|
|
1212
|
-
type: z2.z.enum(["all", "contacts", "contact_blacklist", "none"])
|
|
1213
|
-
});
|
|
1214
|
-
var RelayPrivacyUpdateReadType = z2.z.object({
|
|
1215
|
-
action: z2.z.literal("read"),
|
|
1216
|
-
type: z2.z.enum(["all", "none"])
|
|
1217
|
-
});
|
|
1218
|
-
var RelayPrivacyGroupsAddType = z2.z.object({
|
|
1219
|
-
action: z2.z.literal("groupsAdd"),
|
|
1220
|
-
type: z2.z.enum(["all", "contacts", "contact_blacklist"])
|
|
1221
|
-
});
|
|
1222
|
-
var RelayPrivacyEphemeralType = z2.z.object({
|
|
1223
|
-
action: z2.z.literal("ephemeral"),
|
|
1224
|
-
type: z2.z.enum(["remove", "24h", "7d", "90d"])
|
|
1225
|
-
});
|
|
1226
|
-
var RelayPrivacyUpdateType = z2.z.discriminatedUnion("action", [
|
|
1227
|
-
RelayPrivacyUpdateControlType,
|
|
1228
|
-
RelayPrivacyUpdateLastSeenType,
|
|
1229
|
-
RelayPrivacyUpdateOnlineType,
|
|
1230
|
-
RelayPrivacyUpdateAvatarType,
|
|
1231
|
-
RelayPrivacyUpdateStoryType,
|
|
1232
|
-
RelayPrivacyUpdateReadType,
|
|
1233
|
-
RelayPrivacyGroupsAddType,
|
|
1234
|
-
RelayPrivacyEphemeralType
|
|
1235
|
-
]);
|
|
1236
|
-
var RelayProfileBioType = z2.z.object({
|
|
1237
|
-
senderId: z2.z.string()
|
|
1238
|
-
});
|
|
1239
|
-
var RelayProfileUpdateType = z2.z.object({
|
|
1240
|
-
type: z2.z.enum(["name", "bio", "avatar"]),
|
|
1241
|
-
text: z2.z.string().optional(),
|
|
1242
|
-
roomId: z2.z.string().optional(),
|
|
1243
|
-
avatar: z2.z.url().or(z2.z.base64()).or(z2.z.instanceof(Buffer)).or(z2.z.literal("remove"))
|
|
1244
|
-
});
|
|
1245
|
-
var RelayProfileCheckType = z2.z.object({
|
|
1246
|
-
senderId: z2.z.string()
|
|
1247
|
-
});
|
|
1248
|
-
|
|
1249
|
-
// src/classes/Relay.ts
|
|
1250
|
-
var Relay = class {
|
|
1251
|
-
client;
|
|
1252
|
-
message;
|
|
1253
|
-
db;
|
|
1254
|
-
ctx;
|
|
1255
|
-
bind(client, db) {
|
|
1256
|
-
this.client = client;
|
|
1257
|
-
this.db = db;
|
|
1258
|
-
this.ctx = client;
|
|
1259
|
-
this.ctx.db = db;
|
|
1260
|
-
this.client.on("messages", (ctx) => {
|
|
1261
|
-
this.message = ctx;
|
|
1262
|
-
});
|
|
1263
|
-
}
|
|
1264
|
-
async initial(props) {
|
|
1265
|
-
await makeWASocket.delay(0);
|
|
1266
|
-
if (!props?.disabledPresence) {
|
|
1267
|
-
if (this.client.props?.autoPresence && props?.isAudio) {
|
|
1268
|
-
this.client.socket?.sendPresenceUpdate("recording", this.message?.roomId);
|
|
1269
|
-
} else {
|
|
1270
|
-
this.client.socket?.sendPresenceUpdate("composing", this.message?.roomId);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
// GENERAL RELAY
|
|
1275
|
-
async text(props) {
|
|
1276
|
-
await this.initial();
|
|
1277
|
-
const params = RelayTextType.parse(props);
|
|
1278
|
-
let extend = { contextInfo: {} };
|
|
1279
|
-
if (this.client.props.autoMentions) {
|
|
1280
|
-
extend.contextInfo.mentionedJid = extractJids(this.message.text);
|
|
1281
|
-
}
|
|
1282
|
-
if (typeof params == "string") {
|
|
1283
|
-
if (this.client.socket) {
|
|
1284
|
-
const res = await this.client.socket.sendMessage(this.message?.roomId, {
|
|
1285
|
-
text: params,
|
|
1286
|
-
...extend
|
|
1287
|
-
});
|
|
1288
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
if (typeof params == "object") {
|
|
1292
|
-
const obj = { ...extend, ...params.options };
|
|
1293
|
-
if (params.externalAdReply) {
|
|
1294
|
-
obj.contextInfo = { externalAdReply: params.externalAdReply };
|
|
1295
|
-
}
|
|
1296
|
-
if (this.client.socket) {
|
|
1297
|
-
if (params.text != "$$media$$") {
|
|
1298
|
-
obj.text = params?.text;
|
|
1299
|
-
}
|
|
1300
|
-
const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
|
|
1301
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
async reply(props) {
|
|
1306
|
-
await this.initial();
|
|
1307
|
-
const params = RelayReplyType.parse(props);
|
|
1308
|
-
const quoted = this.message?.message();
|
|
1309
|
-
let extend = { contextInfo: {} };
|
|
1310
|
-
if (this.client.props.autoMentions) {
|
|
1311
|
-
extend.contextInfo.mentionedJid = extractJids(this.message.text);
|
|
1312
|
-
}
|
|
1313
|
-
if (this.client.props?.fakeReply?.provider) {
|
|
1314
|
-
const provider = this.client.props.fakeReply.provider;
|
|
1315
|
-
if (quoted && quoted.key) {
|
|
1316
|
-
quoted.key.remoteJid = MessagesVerifiedPlatformType[provider];
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
const options = quoted ? { quoted } : void 0;
|
|
1320
|
-
if (typeof params == "string") {
|
|
1321
|
-
if (this.client.socket) {
|
|
1322
|
-
const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend }, options);
|
|
1323
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
if (typeof params == "object") {
|
|
1327
|
-
const obj = { ...extend, ...params.options };
|
|
1328
|
-
if (params.externalAdReply) {
|
|
1329
|
-
obj.contextInfo = { externalAdReply: params.externalAdReply };
|
|
1330
|
-
}
|
|
1331
|
-
if (this.client.socket) {
|
|
1332
|
-
if (params.text != "$$media$$") {
|
|
1333
|
-
obj.text = params?.text;
|
|
1334
|
-
}
|
|
1335
|
-
const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj, options);
|
|
1336
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
async forward(props) {
|
|
1341
|
-
await this.initial();
|
|
1342
|
-
const params = RelayForwardType.parse(props);
|
|
1343
|
-
const quoted = this.message?.message();
|
|
1344
|
-
let extend = { contextInfo: { isForwarded: true } };
|
|
1345
|
-
if (this.client.props.autoMentions) {
|
|
1346
|
-
extend.contextInfo.mentionedJid = extractJids(this.message.text);
|
|
1347
|
-
}
|
|
1348
|
-
if (this.client.props?.fakeReply?.provider) {
|
|
1349
|
-
const provider = this.client.props.fakeReply.provider;
|
|
1350
|
-
if (quoted && quoted.key) {
|
|
1351
|
-
quoted.key.remoteJid = MessagesVerifiedPlatformType[provider];
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
if (typeof params == "string") {
|
|
1355
|
-
if (this.client.socket) {
|
|
1356
|
-
const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend });
|
|
1357
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
if (typeof params == "object") {
|
|
1361
|
-
const obj = { ...extend, ...params.options };
|
|
1362
|
-
if (params.externalAdReply) {
|
|
1363
|
-
obj.contextInfo.externalAdReply = params.externalAdReply;
|
|
1364
|
-
}
|
|
1365
|
-
if (params.isForwardMany) {
|
|
1366
|
-
extend.contextInfo.forwardingScore = 999999;
|
|
1367
|
-
}
|
|
1368
|
-
if (this.client.socket) {
|
|
1369
|
-
if (params.text != "$$media$$") {
|
|
1370
|
-
obj.text = params?.text;
|
|
1371
|
-
}
|
|
1372
|
-
const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
|
|
1373
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
async edit(props) {
|
|
1378
|
-
await this.initial({ disabledPresence: true });
|
|
1379
|
-
const params = RelayEditType.parse(props);
|
|
1380
|
-
const message = params.message();
|
|
1381
|
-
const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { text: params.text, edit: message?.key });
|
|
1382
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1383
|
-
}
|
|
1384
|
-
async delete(props) {
|
|
1385
|
-
await this.initial({ disabledPresence: true });
|
|
1386
|
-
const params = RelayDeleteType.parse(props);
|
|
1387
|
-
const message = params.message();
|
|
1388
|
-
const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { delete: message?.key });
|
|
1389
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1390
|
-
}
|
|
1391
|
-
async reject(props) {
|
|
1392
|
-
const params = RelayRejectType.parse(props);
|
|
1393
|
-
return await this.client.socket.rejectCall(params.callId, params.callerId);
|
|
1394
|
-
}
|
|
1395
|
-
async presence(props) {
|
|
1396
|
-
await this.initial({ disabledPresence: true });
|
|
1397
|
-
const params = RelayPresenceType.parse(props);
|
|
1398
|
-
const opts = {
|
|
1399
|
-
typing: "composing",
|
|
1400
|
-
recording: "recording",
|
|
1401
|
-
online: "available",
|
|
1402
|
-
offline: "unavailable",
|
|
1403
|
-
paused: "paused"
|
|
1404
|
-
};
|
|
1405
|
-
return await this.client.socket.sendPresenceUpdate(opts[params], this.message.roomId);
|
|
1406
|
-
}
|
|
1407
|
-
async reaction(props) {
|
|
1408
|
-
await this.initial({ disabledPresence: true });
|
|
1409
|
-
const params = RelayReactionType.parse(props);
|
|
1410
|
-
const message = typeof params == "string" ? this.message.message() : params.message();
|
|
1411
|
-
const text = typeof params == "string" ? params : params.emoticon;
|
|
1412
|
-
const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { react: { text, key: message?.key } });
|
|
1413
|
-
return await MessagesExtractor(this.ctx, res);
|
|
1414
|
-
}
|
|
1415
|
-
// MEDIA RELAY
|
|
1416
|
-
async document(type, props) {
|
|
1417
|
-
await this.initial();
|
|
1418
|
-
const enumType = RelayDocumentEnumType.parse(type);
|
|
1419
|
-
const params = RelayDocumentType.parse(props);
|
|
1420
|
-
const options = {
|
|
1421
|
-
document: typeof params.document === "string" ? { url: params.document } : params.document,
|
|
1422
|
-
caption: params.text,
|
|
1423
|
-
mimetype: params.mimetype,
|
|
1424
|
-
fileName: params.fileName,
|
|
1425
|
-
contextInfo: { externalAdReply: params.externalAdReply }
|
|
1426
|
-
};
|
|
1427
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1428
|
-
}
|
|
1429
|
-
async image(type, props) {
|
|
1430
|
-
await this.initial();
|
|
1431
|
-
const enumType = RelayImageEnumType.parse(type);
|
|
1432
|
-
const params = RelayImageType.parse(props);
|
|
1433
|
-
const options = {
|
|
1434
|
-
image: typeof params.image === "string" ? { url: params.image } : params.image,
|
|
1435
|
-
caption: params.text,
|
|
1436
|
-
viewOnce: params.viewOnce,
|
|
1437
|
-
contextInfo: { externalAdReply: params.externalAdReply, isQuestion: true }
|
|
1438
|
-
};
|
|
1439
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1440
|
-
}
|
|
1441
|
-
async sticker(type, props) {
|
|
1442
|
-
await this.initial();
|
|
1443
|
-
const enumType = RelayStickerEnumType.parse(type);
|
|
1444
|
-
const params = RelayStickerType.parse(props);
|
|
1445
|
-
const options = { sticker: typeof params.sticker === "string" ? { url: params.sticker } : params.sticker };
|
|
1446
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1447
|
-
}
|
|
1448
|
-
async video(type, props) {
|
|
1449
|
-
await this.initial();
|
|
1450
|
-
const enumType = RelayVideoEnumType.parse(type);
|
|
1451
|
-
const params = RelayVideoType.parse(props);
|
|
1452
|
-
const options = {
|
|
1453
|
-
video: typeof params.video === "string" ? { url: params.video } : params.video,
|
|
1454
|
-
caption: params.text,
|
|
1455
|
-
viewOnce: params.viewOnce
|
|
1456
|
-
};
|
|
1457
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1458
|
-
}
|
|
1459
|
-
async audio(type, props) {
|
|
1460
|
-
const enumType = RelayAudioEnumType.parse(type);
|
|
1461
|
-
const params = RelayAudioType.parse(props);
|
|
1462
|
-
const options = {
|
|
1463
|
-
audio: typeof params.audio === "string" ? { url: params.audio } : params.audio,
|
|
1464
|
-
viewOnce: params.viewOnce,
|
|
1465
|
-
contextInfo: { externalAdReply: params.externalAdReply }
|
|
1466
|
-
};
|
|
1467
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1468
|
-
}
|
|
1469
|
-
async voice(type, props) {
|
|
1470
|
-
const enumType = RelayAudioEnumType.parse(type);
|
|
1471
|
-
const params = RelayAudioType.parse(props);
|
|
1472
|
-
const options = {
|
|
1473
|
-
audio: typeof params.audio === "string" ? { url: params.audio } : params.audio,
|
|
1474
|
-
ptt: true,
|
|
1475
|
-
viewOnce: params.viewOnce,
|
|
1476
|
-
mimetype: "audio/ogg; codecs=opus",
|
|
1477
|
-
contextInfo: { externalAdReply: params.externalAdReply }
|
|
1478
|
-
};
|
|
1479
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1480
|
-
}
|
|
1481
|
-
async note(type, props) {
|
|
1482
|
-
await this.initial();
|
|
1483
|
-
const enumType = RelayVideoEnumType.parse(type);
|
|
1484
|
-
const params = RelayVideoType.parse(props);
|
|
1485
|
-
const options = { video: typeof params.video === "string" ? { url: params.video } : params.video, caption: params.text, ptv: true };
|
|
1486
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1487
|
-
}
|
|
1488
|
-
async gif(type, props) {
|
|
1489
|
-
await this.initial();
|
|
1490
|
-
const enumType = RelayVideoEnumType.parse(type);
|
|
1491
|
-
const params = RelayVideoType.parse(props);
|
|
1492
|
-
const options = { video: typeof params.video === "string" ? { url: params.video } : params.video, gifPlayback: true };
|
|
1493
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1494
|
-
}
|
|
1495
|
-
async location(type, props) {
|
|
1496
|
-
await this.initial();
|
|
1497
|
-
const enumType = RelayLocationEnumType.parse(type);
|
|
1498
|
-
const params = RelayLocationType.parse(props);
|
|
1499
|
-
const options = {
|
|
1500
|
-
location: {
|
|
1501
|
-
degreesLatitude: params.latitude,
|
|
1502
|
-
degreesLongitude: params.longitude,
|
|
1503
|
-
url: params.title,
|
|
1504
|
-
address: params.footer,
|
|
1505
|
-
name: params.title
|
|
1506
|
-
},
|
|
1507
|
-
contextInfo: { externalAdReply: params.externalAdReply }
|
|
1508
|
-
};
|
|
1509
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1510
|
-
}
|
|
1511
|
-
async contacts(type, props) {
|
|
1512
|
-
await this.initial();
|
|
1513
|
-
const enumType = RelayContactEnumType.parse(type);
|
|
1514
|
-
const params = RelayContactType.parse(props);
|
|
1515
|
-
const contacts = params.contacts.map((x) => {
|
|
1516
|
-
const vcard = [
|
|
1517
|
-
"BEGIN:VCARD",
|
|
1518
|
-
"VERSION:3.0",
|
|
1519
|
-
`FN:${x.fullname}`,
|
|
1520
|
-
`ORG:${x.organization || ""}`,
|
|
1521
|
-
`TEL;type=CELL;type=VOICE;waid=${x.phoneNumber}:${x.phoneNumber}`,
|
|
1522
|
-
"END:VCARD"
|
|
1523
|
-
].join("\n");
|
|
1524
|
-
return { displayName: x.fullname, vcard };
|
|
1525
|
-
});
|
|
1526
|
-
const options = {
|
|
1527
|
-
contacts: {
|
|
1528
|
-
displayName: params?.title,
|
|
1529
|
-
contacts
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1533
|
-
}
|
|
1534
|
-
async poll(type, props) {
|
|
1535
|
-
await this.initial();
|
|
1536
|
-
const enumType = RelayPollEnumType.parse(type);
|
|
1537
|
-
const params = RelayPollType.parse(props);
|
|
1538
|
-
const options = {};
|
|
1539
|
-
if (params.action == "create") {
|
|
1540
|
-
options.poll = {
|
|
1541
|
-
name: params.name,
|
|
1542
|
-
values: params.answers,
|
|
1543
|
-
selectableCount: !!params.isMultiple ? 1 : 0,
|
|
1544
|
-
toAnnouncementGroup: true
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1548
|
-
}
|
|
1549
|
-
async button(type, props) {
|
|
1550
|
-
await this.initial();
|
|
1551
|
-
const enumType = RelayButtonEnumType.parse(type);
|
|
1552
|
-
const params = RelayButtonType.parse(props);
|
|
1553
|
-
const options = {
|
|
1554
|
-
text: params.text,
|
|
1555
|
-
footer: params.footer
|
|
1556
|
-
};
|
|
1557
|
-
if (params.type == "simple") {
|
|
1558
|
-
options.buttons = params.buttons.map((x) => ({ buttonId: x.id, buttonText: { displayText: x.text } }));
|
|
1559
|
-
}
|
|
1560
|
-
if (params.type == "interactive") {
|
|
1561
|
-
options.interactiveButtons = params.buttons.map((x) => {
|
|
1562
|
-
let schema = { name: x.type };
|
|
1563
|
-
if (x.type == "quick_reply") {
|
|
1564
|
-
schema.buttonParamsJson = toString({
|
|
1565
|
-
id: x.id,
|
|
1566
|
-
display_text: x.text
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1569
|
-
if (x.type == "cta_url") {
|
|
1570
|
-
schema.buttonParamsJson = toString({
|
|
1571
|
-
id: x.id,
|
|
1572
|
-
display_text: x.text,
|
|
1573
|
-
url: x.url,
|
|
1574
|
-
merchant_url: x.url
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
if (x.type == "cta_copy") {
|
|
1578
|
-
schema.buttonParamsJson = toString({
|
|
1579
|
-
id: x.id,
|
|
1580
|
-
display_text: x.text,
|
|
1581
|
-
copy_code: x.copy
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
if (x.type == "cta_call") {
|
|
1585
|
-
schema.buttonParamsJson = toString({
|
|
1586
|
-
id: x.id,
|
|
1587
|
-
display_text: x.text,
|
|
1588
|
-
phone_number: x.phoneNumber
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
return schema;
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
|
|
1595
|
-
}
|
|
1596
|
-
// GROUP RELAY
|
|
1597
|
-
group() {
|
|
1598
|
-
const client = this.ctx;
|
|
1599
|
-
const create = async (props) => {
|
|
1600
|
-
const params = RelayGroupCreateType.parse(props);
|
|
1601
|
-
try {
|
|
1602
|
-
return await client.socket.groupCreate(params.title, params.members);
|
|
1603
|
-
} catch (error) {
|
|
1604
|
-
client.spinner.error("Failed create group. Make sure members has valid number.\n\n" + error);
|
|
1605
|
-
return null;
|
|
1606
|
-
}
|
|
1607
|
-
};
|
|
1608
|
-
const action = async (props) => {
|
|
1609
|
-
const params = RelayGroupActionType.parse(props);
|
|
1610
|
-
const opts = {
|
|
1611
|
-
add: "add",
|
|
1612
|
-
kick: "remove",
|
|
1613
|
-
promote: "promote",
|
|
1614
|
-
demote: "demote"
|
|
1615
|
-
};
|
|
1616
|
-
try {
|
|
1617
|
-
return await client.socket.groupParticipantsUpdate(params.roomId, params.members, opts[params.action]);
|
|
1618
|
-
} catch (error) {
|
|
1619
|
-
client.spinner.error("Failed update user. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1620
|
-
return null;
|
|
1621
|
-
}
|
|
1622
|
-
};
|
|
1623
|
-
const update = async (props) => {
|
|
1624
|
-
const params = RelayGroupUpdateType.parse(props);
|
|
1625
|
-
const opts = {
|
|
1626
|
-
subject: "groupUpdateSubject",
|
|
1627
|
-
description: "groupUpdateDescription"
|
|
1628
|
-
};
|
|
1629
|
-
try {
|
|
1630
|
-
return await client.socket[opts[props.action]](params.roomId, props.text);
|
|
1631
|
-
} catch (error) {
|
|
1632
|
-
client.spinner.error("Failed update group. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1633
|
-
return null;
|
|
1634
|
-
}
|
|
1635
|
-
};
|
|
1636
|
-
const settings = async (props) => {
|
|
1637
|
-
const params = RelayGroupSettingsType.parse(props);
|
|
1638
|
-
const opts = {
|
|
1639
|
-
open: "not_announcement",
|
|
1640
|
-
close: "announcement",
|
|
1641
|
-
lock: "locked",
|
|
1642
|
-
unlock: "unlocked"
|
|
1643
|
-
};
|
|
1644
|
-
try {
|
|
1645
|
-
return await client.socket.groupSettingUpdate(params.roomId, opts[params.action]);
|
|
1646
|
-
} catch (error) {
|
|
1647
|
-
client.spinner.error("Failed settings group. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1648
|
-
return null;
|
|
1649
|
-
}
|
|
1650
|
-
};
|
|
1651
|
-
const leave = async (props) => {
|
|
1652
|
-
const params = RelayGroupLeaveType.parse(props);
|
|
1653
|
-
try {
|
|
1654
|
-
return await client.socket.groupLeave(params.roomId);
|
|
1655
|
-
} catch (error) {
|
|
1656
|
-
client.spinner.error("Failed leave group. Make sure this number is in the group.\n\n" + error);
|
|
1657
|
-
return null;
|
|
1658
|
-
}
|
|
1659
|
-
};
|
|
1660
|
-
const links = async (props) => {
|
|
1661
|
-
const params = RelayGroupLinksType.parse(props);
|
|
1662
|
-
const opts = {
|
|
1663
|
-
get: "groupInviteCode",
|
|
1664
|
-
revoke: "groupRevokeInvite"
|
|
1665
|
-
};
|
|
1666
|
-
try {
|
|
1667
|
-
const code = await client.socket[opts[params.action]](params.roomId);
|
|
1668
|
-
return `https://chat.whatsapp.com/` + code;
|
|
1669
|
-
} catch (error) {
|
|
1670
|
-
client.spinner.error("Failed get group link. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1671
|
-
return null;
|
|
1672
|
-
}
|
|
1673
|
-
};
|
|
1674
|
-
const invite = async (props) => {
|
|
1675
|
-
const params = RelayGroupInviteType.parse(props);
|
|
1676
|
-
const opts = {
|
|
1677
|
-
join: "groupAcceptInvite",
|
|
1678
|
-
info: "groupGetInviteInfo"
|
|
1679
|
-
};
|
|
1680
|
-
try {
|
|
1681
|
-
const code = params.url.split("https://chat.whatsapp.com/");
|
|
1682
|
-
return await client.socket[opts[params.action]](code[1]);
|
|
1683
|
-
} catch (error) {
|
|
1684
|
-
client.spinner.error("Failed get group link. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1685
|
-
return null;
|
|
1686
|
-
}
|
|
1687
|
-
};
|
|
1688
|
-
const metadata = async (props) => {
|
|
1689
|
-
const params = RelayGroupMetadataType.parse(props);
|
|
1690
|
-
try {
|
|
1691
|
-
const meta = await client.socket.groupMetadata(params.roomId);
|
|
1692
|
-
return meta;
|
|
1693
|
-
} catch (error) {
|
|
1694
|
-
client.spinner.error("Failed get group metadata. Make sure this number is in the group and as admin.\n\n" + error);
|
|
1695
|
-
return null;
|
|
1696
|
-
}
|
|
1697
|
-
};
|
|
1698
|
-
const requests = {
|
|
1699
|
-
list: async (props) => {
|
|
1700
|
-
const params = RelayGroupRequestsListType.parse(props);
|
|
1701
|
-
return await client.socket.groupRequestParticipantsList(params.roomId);
|
|
1702
|
-
},
|
|
1703
|
-
approve: async (props) => {
|
|
1704
|
-
const params = RelayGroupRequestsApproveType.parse(props);
|
|
1705
|
-
return await client.socket.groupRequestParticipantsUpdate(params.roomId, params.members, "approve");
|
|
1706
|
-
},
|
|
1707
|
-
reject: async (props) => {
|
|
1708
|
-
const params = RelayGroupRequestsRejectType.parse(props);
|
|
1709
|
-
return await client.socket.groupRequestParticipantsUpdate(params.roomId, params.members, "reject");
|
|
1710
|
-
}
|
|
1711
|
-
};
|
|
1712
|
-
return {
|
|
1713
|
-
create,
|
|
1714
|
-
action,
|
|
1715
|
-
update,
|
|
1716
|
-
settings,
|
|
1717
|
-
leave,
|
|
1718
|
-
links,
|
|
1719
|
-
invite,
|
|
1720
|
-
metadata,
|
|
1721
|
-
requests
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
// PRIVACY RELAY
|
|
1725
|
-
privacy() {
|
|
1726
|
-
const client = this.ctx;
|
|
1727
|
-
const update = async (props) => {
|
|
1728
|
-
const params = RelayPrivacyUpdateType.parse(props);
|
|
1729
|
-
try {
|
|
1730
|
-
if (params.action == "control") {
|
|
1731
|
-
return await client.socket.updateBlockStatus(params.senderId, params.type);
|
|
1732
|
-
}
|
|
1733
|
-
if (params.action == "lastSeen") {
|
|
1734
|
-
return await client.socket.updateLastSeenPrivacy(params.type);
|
|
1735
|
-
}
|
|
1736
|
-
if (params.action == "online") {
|
|
1737
|
-
return await client.socket.updateOnlinePrivacy(params.type);
|
|
1738
|
-
}
|
|
1739
|
-
if (params.action == "avatar") {
|
|
1740
|
-
return await client.socket.updateProfilePicturePrivacy(params.type);
|
|
1741
|
-
}
|
|
1742
|
-
if (params.action == "story") {
|
|
1743
|
-
return await client.socket.updateStatusPrivacy(params.type);
|
|
1744
|
-
}
|
|
1745
|
-
if (params.action == "read") {
|
|
1746
|
-
return await client.socket.updateReadReceiptsPrivacy(params.type);
|
|
1747
|
-
}
|
|
1748
|
-
if (params.action == "groupsAdd") {
|
|
1749
|
-
return await client.socket.updateGroupsAddPrivacy(params.type);
|
|
1750
|
-
}
|
|
1751
|
-
if (params.action == "ephemeral") {
|
|
1752
|
-
const opts = { remove: 0, "24h": 86400, "7d": 604800, "90d": 7776e3 };
|
|
1753
|
-
return await client.socket.updateDefaultDisappearingMode(opts[params.type]);
|
|
1754
|
-
}
|
|
1755
|
-
} catch (error) {
|
|
1756
|
-
client.spinner.error("Failed update privacy, please try again.\n\n" + error);
|
|
1757
|
-
return null;
|
|
1758
|
-
}
|
|
1759
|
-
};
|
|
1760
|
-
const fetch = {
|
|
1761
|
-
settings: async () => {
|
|
1762
|
-
return await client.socket.fetchPrivacySettings(true);
|
|
1763
|
-
},
|
|
1764
|
-
blocklists: async () => {
|
|
1765
|
-
return await client.socket.fetchBlocklist();
|
|
1766
|
-
}
|
|
1767
|
-
};
|
|
1768
|
-
return {
|
|
1769
|
-
update,
|
|
1770
|
-
fetch
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
// PROFILE RELAY
|
|
1774
|
-
profile() {
|
|
1775
|
-
const client = this.ctx;
|
|
1776
|
-
const bio = async (props) => {
|
|
1777
|
-
const params = RelayProfileBioType.parse(props);
|
|
1778
|
-
try {
|
|
1779
|
-
return await client.socket.fetchStatus(params.senderId);
|
|
1780
|
-
} catch (error) {
|
|
1781
|
-
client.spinner.error("Failed fetch profile bio. Make sure senderId is valid.\n\n" + error);
|
|
1782
|
-
return null;
|
|
1783
|
-
}
|
|
1784
|
-
};
|
|
1785
|
-
const avatar = async (props) => {
|
|
1786
|
-
const params = RelayProfileBioType.parse(props);
|
|
1787
|
-
try {
|
|
1788
|
-
return await client.socket.profilePictureUrl(params.senderId);
|
|
1789
|
-
} catch (error) {
|
|
1790
|
-
client.spinner.error("Failed fetch profile avatar. Make sure senderId is valid.\n\n" + error);
|
|
1791
|
-
return null;
|
|
1792
|
-
}
|
|
1793
|
-
};
|
|
1794
|
-
const business = async (props) => {
|
|
1795
|
-
const params = RelayProfileBioType.parse(props);
|
|
1796
|
-
try {
|
|
1797
|
-
return await client.socket.getBusinessProfile(params.senderId);
|
|
1798
|
-
} catch (error) {
|
|
1799
|
-
client.spinner.error("Failed fetch profile business. Make sure senderId is valid.\n\n" + error);
|
|
1800
|
-
return null;
|
|
1801
|
-
}
|
|
1802
|
-
};
|
|
1803
|
-
const update = async (props) => {
|
|
1804
|
-
const params = RelayProfileUpdateType.parse(props);
|
|
1805
|
-
try {
|
|
1806
|
-
if (params.type == "name") {
|
|
1807
|
-
return await client.socket.updateProfileName(params.text);
|
|
1808
|
-
}
|
|
1809
|
-
if (params.type == "bio") {
|
|
1810
|
-
return await client.socket.updateProfileStatus(params.text);
|
|
1811
|
-
}
|
|
1812
|
-
if (params.type == "avatar") {
|
|
1813
|
-
if (params.avatar == "remove") {
|
|
1814
|
-
return await client.socket.removeProfilePicture(params.roomId);
|
|
1815
|
-
}
|
|
1816
|
-
const avatar2 = typeof params.avatar == "string" ? { url: params.avatar } : params.avatar;
|
|
1817
|
-
return await client.socket.updateProfilePicture(params.roomId, avatar2);
|
|
1818
|
-
}
|
|
1819
|
-
} catch (error) {
|
|
1820
|
-
client.spinner.error("Failed update profile. Make sure senderId is valid.\n\n" + error);
|
|
1821
|
-
return null;
|
|
1822
|
-
}
|
|
1823
|
-
};
|
|
1824
|
-
const check = async (props) => {
|
|
1825
|
-
const params = RelayProfileCheckType.parse(props);
|
|
1826
|
-
try {
|
|
1827
|
-
const [wa] = await client.socket.onWhatsApp(params.senderId);
|
|
1828
|
-
if (!wa) return { isOnWhatsApp: false };
|
|
1829
|
-
const pic = await avatar({ senderId: wa.jid });
|
|
1830
|
-
const status = await bio({ senderId: wa.jid });
|
|
1831
|
-
const obj = {
|
|
1832
|
-
isOnWhatsApp: true,
|
|
1833
|
-
avatar: pic,
|
|
1834
|
-
bio: status,
|
|
1835
|
-
...wa
|
|
1836
|
-
};
|
|
1837
|
-
return obj;
|
|
1838
|
-
} catch (error) {
|
|
1839
|
-
client.spinner.error("Failed check profile. Make sure senderId is valid.\n\n" + error);
|
|
1840
|
-
return null;
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
return {
|
|
1844
|
-
bio,
|
|
1845
|
-
avatar,
|
|
1846
|
-
business,
|
|
1847
|
-
update,
|
|
1848
|
-
check
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
};
|
|
1852
|
-
var Client = class {
|
|
1853
|
-
props;
|
|
1854
|
-
db;
|
|
1855
|
-
logger = pino__default.default({ level: "silent", enabled: false });
|
|
1856
|
-
events = new EventEmitter__default.default();
|
|
1857
|
-
relay;
|
|
1858
|
-
retryCount = 0;
|
|
1859
|
-
maxRetries = 10;
|
|
1860
|
-
connectionTimeout;
|
|
1861
|
-
spinner = nanospinner.createSpinner("", { color: "green" });
|
|
1862
|
-
socket;
|
|
1863
|
-
cache = new NodeCache2__default.default({ stdTTL: 5 * 60, useClones: false });
|
|
1864
|
-
constructor(props) {
|
|
1865
|
-
this.props = ClientOptionsType.parse(props);
|
|
1866
|
-
this.initialize();
|
|
1867
|
-
return new Proxy(this, {
|
|
1868
|
-
get(target, prop) {
|
|
1869
|
-
if (typeof prop === "string" && (prop in target || _2__default.default.includes(["on", "emit"], prop))) return target[prop];
|
|
1870
|
-
if (typeof prop === "string") return target.relay[prop];
|
|
1871
|
-
return void 0;
|
|
1872
|
-
}
|
|
1873
|
-
});
|
|
1874
|
-
}
|
|
1875
|
-
async initialize() {
|
|
1876
|
-
console.clear();
|
|
1877
|
-
await displayBanner();
|
|
1878
|
-
await makeWASocket.delay(1e3);
|
|
1879
|
-
await this.spinner.start("Initializing database...");
|
|
1880
|
-
const { db, state, store, saveCreds } = await CredsHandler(this.props);
|
|
1881
|
-
await this.spinner.start("Fetching newest version...");
|
|
1882
|
-
const { version } = await makeWASocket.fetchLatestBaileysVersion();
|
|
1883
|
-
this.socket = makeWASocket__default.default({
|
|
1884
|
-
version,
|
|
1885
|
-
logger: this.logger,
|
|
1886
|
-
markOnlineOnConnect: this.props.autoOnline,
|
|
1887
|
-
syncFullHistory: true,
|
|
1888
|
-
printQRInTerminal: false,
|
|
1889
|
-
defaultQueryTimeoutMs: void 0,
|
|
1890
|
-
msgRetryCounterCache: new NodeCache2__default.default(),
|
|
1891
|
-
mediaCache: new NodeCache2__default.default({ stdTTL: 60 }),
|
|
1892
|
-
userDevicesCache: new NodeCache2__default.default(),
|
|
1893
|
-
cachedGroupMetadata: async (jid) => this.cache.get(jid),
|
|
1894
|
-
auth: {
|
|
1895
|
-
creds: state.creds,
|
|
1896
|
-
keys: makeWASocket.makeCacheableSignalKeyStore(state.keys, this.logger)
|
|
1897
|
-
},
|
|
1898
|
-
getMessage: async (key) => {
|
|
1899
|
-
if (!key?.id) return void 0;
|
|
1900
|
-
const message = await db.store("messages").read(key.id);
|
|
1901
|
-
return message;
|
|
1902
|
-
}
|
|
1903
|
-
});
|
|
1904
|
-
await this.socket?.ev.on("creds.update", saveCreds);
|
|
1905
|
-
if (this.props.authType === "pairing" && this.props.phoneNumber && !this.socket?.authState.creds.registered) {
|
|
1906
|
-
this.spinner.start("Generating pairing code...");
|
|
1907
|
-
setTimeout(async () => {
|
|
1908
|
-
try {
|
|
1909
|
-
if (this.props?.authType === "pairing") {
|
|
1910
|
-
const code = await this.socket?.requestPairingCode(this.props.phoneNumber.toString(), shuffleString("Z4D3V0FC"));
|
|
1911
|
-
this.spinner.info(`Pairing code: ${code}`);
|
|
1912
|
-
}
|
|
1913
|
-
} catch {
|
|
1914
|
-
this.spinner.error(`Session "${this.props.session}" has not valid, please delete it`);
|
|
1915
|
-
process.exit(0);
|
|
1916
|
-
}
|
|
1917
|
-
}, 5e3);
|
|
1918
|
-
}
|
|
1919
|
-
const listener = new Listener();
|
|
1920
|
-
this.relay = new Relay();
|
|
1921
|
-
this.spinner.success("Initialize Successfully");
|
|
1922
|
-
await store.bind(this);
|
|
1923
|
-
await listener.bind(this, db);
|
|
1924
|
-
await this.relay.bind(this, db);
|
|
1925
|
-
this.spinner.start("Connecting to WhatsApp...");
|
|
1926
|
-
this.startConnectionTimeout();
|
|
1927
|
-
}
|
|
1928
|
-
startConnectionTimeout() {
|
|
1929
|
-
if (this.connectionTimeout) {
|
|
1930
|
-
clearTimeout(this.connectionTimeout);
|
|
1931
|
-
}
|
|
1932
|
-
this.connectionTimeout = setTimeout(() => {
|
|
1933
|
-
this.handleConnectionTimeout();
|
|
1934
|
-
}, 6e4);
|
|
1935
|
-
}
|
|
1936
|
-
handleConnectionTimeout() {
|
|
1937
|
-
if (this.retryCount < this.maxRetries) {
|
|
1938
|
-
this.retryCount++;
|
|
1939
|
-
this.spinner.warn(`Connection timeout. Retrying... (${this.retryCount}/${this.maxRetries})`);
|
|
1940
|
-
this.autoReload();
|
|
1941
|
-
} else {
|
|
1942
|
-
this.spinner.error(`Max retries reached (${this.maxRetries}). Connection failed.`);
|
|
1943
|
-
process.exit(1);
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
async autoReload() {
|
|
1947
|
-
try {
|
|
1948
|
-
if (this.connectionTimeout) {
|
|
1949
|
-
clearTimeout(this.connectionTimeout);
|
|
1950
|
-
}
|
|
1951
|
-
if (this.socket) {
|
|
1952
|
-
this.socket.end?.(void 0);
|
|
1953
|
-
this.socket = void 0;
|
|
1954
|
-
}
|
|
1955
|
-
await makeWASocket.delay(2e3);
|
|
1956
|
-
await this.initialize();
|
|
1957
|
-
} catch (error) {
|
|
1958
|
-
this.spinner.error(`Auto-reload failed: ${error.message}`);
|
|
1959
|
-
this.handleConnectionTimeout();
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
resetRetryCount() {
|
|
1963
|
-
this.retryCount = 0;
|
|
1964
|
-
if (this.connectionTimeout) {
|
|
1965
|
-
clearTimeout(this.connectionTimeout);
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
on(event, handler) {
|
|
1969
|
-
this.events.on(event, handler);
|
|
1970
|
-
}
|
|
1971
|
-
emit(event, ...args) {
|
|
1972
|
-
this.events.emit(event, ...args);
|
|
1973
|
-
}
|
|
1974
|
-
};
|
|
1975
|
-
|
|
1976
|
-
exports.CitationType = CitationType;
|
|
1977
|
-
exports.Client = Client;
|
|
1978
|
-
exports.ClientAuthPairingType = ClientAuthPairingType;
|
|
1979
|
-
exports.ClientAuthQRType = ClientAuthQRType;
|
|
1980
|
-
exports.ClientBaseType = ClientBaseType;
|
|
1981
|
-
exports.ClientOptionsType = ClientOptionsType;
|
|
1982
|
-
exports.EventEnumType = EventEnumType;
|
|
1983
|
-
exports.FakeReplyType = FakeReplyType;
|
|
1984
|
-
exports.JsonDB = JsonDB;
|
|
1985
|
-
exports.LimiterType = LimiterType;
|
|
1986
|
-
exports.PluginsType = PluginsType;
|