@alannxd/baileys 4.0.4 → 5.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 z4phdev
3
+ Copyright (c) 2024 alannxd
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -477,3 +477,4 @@ Thanks to the following awesome contributors who help improve this project 💖
477
477
  </td>
478
478
  </tr>
479
479
  </table>
480
+
@@ -438,3 +438,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
438
438
  return metadata
439
439
  }
440
440
  exports.extractNewsletterMetadata = extractNewsletterMetadata;
441
+
@@ -384,7 +384,7 @@ const makeSocket = (config) => {
384
384
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
385
385
  };
386
386
 
387
- /** This method was created by snowi, and implemented by KyuuRzy */
387
+ /** This method was created by snowi, and implemented by AlannXD & KyuuRzy */
388
388
  /** hey bro, if you delete this text */
389
389
  /** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
390
390
  const requestPairingCode = async (phoneNumber, pairKey) => {
@@ -13,7 +13,7 @@ const WAProto_1 = require("../../WAProto");
13
13
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
14
  const Types_1 = require("../Types");
15
15
  const WABinary_1 = require("../WABinary");
16
- const baileysVersion = [2, 3000, 1027934701]
16
+ const baileysVersion = [2, 3000, 1029030078]
17
17
  const PLATFORM_MAP = {
18
18
  'aix': 'AIX',
19
19
  'darwin': 'Mac OS',
@@ -81,38 +81,6 @@ const prepareWAMessageMedia = async (message, options) => {
81
81
 
82
82
  const uploadData = {
83
83
  ...message,
84
- ...(message.annotations ? {
85
- annotations: message.annotations
86
- } : {
87
- annotations: [
88
- {
89
- polygonVertices: [
90
- {
91
- x: 60.71664810180664,
92
- y: -36.39784622192383
93
- },
94
- {
95
- x: -16.710189819335938,
96
- y: 49.263675689697266
97
- },
98
- {
99
- x: -56.585853576660156,
100
- y: 37.85963439941406
101
- },
102
- {
103
- x: 20.840980529785156,
104
- y: -47.80188751220703
105
- }
106
- ],
107
- newsletter: {
108
- newsletterJid: "120363342976800779@newsletter",
109
- serverMessageId: 0,
110
- newsletterName: "z4ph",
111
- contentType: "UPDATE",
112
- }
113
- }
114
- ]
115
- }),
116
84
  media: message[mediaType]
117
85
  };
118
86
  delete uploadData[mediaType];
package/lib/index.js CHANGED
@@ -47,3 +47,4 @@ __exportStar(require("./WAM"), exports);
47
47
  __exportStar(require("./WAUSync"), exports);
48
48
 
49
49
  exports.default = Socket_1.default;
50
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alannxd/baileys",
3
- "version": "4.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "WhatsApp API Modification",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -107,3 +107,4 @@
107
107
  "node": ">=20.0.0"
108
108
  }
109
109
  }
110
+
@@ -1,423 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
7
- const boom_1 = require("@hapi/boom");
8
- const axios_1 = __importDefault(require("axios"));
9
- const crypto_1 = require("crypto");
10
- const os_1 = require("os");
11
- const fetch_1 = require("node-fetch")
12
- const WAProto_1 = require("../../WAProto");
13
- const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
- const Types_1 = require("../Types");
15
- const WABinary_1 = require("../WABinary");
16
- const baileysVersion = [2, 3000, 1029030078]
17
- const PLATFORM_MAP = {
18
- 'aix': 'AIX',
19
- 'darwin': 'Mac OS',
20
- 'win32': 'Windows',
21
- 'android': 'Android',
22
- 'freebsd': 'FreeBSD',
23
- 'openbsd': 'OpenBSD',
24
- 'sunos': 'Solaris',
25
- 'linux': undefined,
26
- 'haiku': undefined,
27
- 'cygwin': undefined,
28
- 'netbsd': undefined
29
- };
30
- exports.Browsers = (browser) => {
31
- const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
32
- const osRelease = os_1.release();
33
- return [osName, browser, osRelease];
34
- };
35
-
36
- const getPlatformId = (browser) => {
37
- const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
38
- return platformType ? platformType.toString() : '1'; //chrome
39
- };
40
- exports.getPlatformId = getPlatformId;
41
- exports.BufferJSON = {
42
- replacer: (k, value) => {
43
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
44
- return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
45
- }
46
- return value;
47
- },
48
- reviver: (_, value) => {
49
- if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
50
- const val = value.data || value.value;
51
- return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
52
- }
53
- return value;
54
- }
55
- };
56
- const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
57
- exports.getKeyAuthor = getKeyAuthor;
58
- const writeRandomPadMax16 = (msg) => {
59
- const pad = (0, crypto_1.randomBytes)(1);
60
- pad[0] &= 0xf;
61
- if (!pad[0]) {
62
- pad[0] = 0xf;
63
- }
64
- return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
65
- };
66
- exports.writeRandomPadMax16 = writeRandomPadMax16;
67
- const unpadRandomMax16 = (e) => {
68
- const t = new Uint8Array(e);
69
- if (0 === t.length) {
70
- throw new Error('unpadPkcs7 given empty bytes');
71
- }
72
- var r = t[t.length - 1];
73
- if (r > t.length) {
74
- throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
75
- }
76
- return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
77
- };
78
- exports.unpadRandomMax16 = unpadRandomMax16;
79
- const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
80
- exports.encodeWAMessage = encodeWAMessage;
81
- const generateRegistrationId = () => {
82
- return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
83
- };
84
- exports.generateRegistrationId = generateRegistrationId;
85
- const encodeBigEndian = (e, t = 4) => {
86
- let r = e;
87
- const a = new Uint8Array(t);
88
- for (let i = t - 1; i >= 0; i--) {
89
- a[i] = 255 & r;
90
- r >>>= 8;
91
- }
92
- return a;
93
- };
94
- exports.encodeBigEndian = encodeBigEndian;
95
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
96
- exports.toNumber = toNumber;
97
- /** unix timestamp of a date in seconds */
98
- const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
99
- exports.unixTimestampSeconds = unixTimestampSeconds;
100
- const debouncedTimeout = (intervalMs = 1000, task) => {
101
- let timeout;
102
- return {
103
- start: (newIntervalMs, newTask) => {
104
- task = newTask || task;
105
- intervalMs = newIntervalMs || intervalMs;
106
- timeout && clearTimeout(timeout);
107
- timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
108
- },
109
- cancel: () => {
110
- timeout && clearTimeout(timeout);
111
- timeout = undefined;
112
- },
113
- setTask: (newTask) => task = newTask,
114
- setInterval: (newInterval) => intervalMs = newInterval
115
- };
116
- };
117
- exports.debouncedTimeout = debouncedTimeout;
118
- const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
119
- exports.delay = delay;
120
- const delayCancellable = (ms) => {
121
- const stack = new Error().stack;
122
- let timeout;
123
- let reject;
124
- const delay = new Promise((resolve, _reject) => {
125
- timeout = setTimeout(resolve, ms);
126
- reject = _reject;
127
- });
128
- const cancel = () => {
129
- clearTimeout(timeout);
130
- reject(new boom_1.Boom('Cancelled', {
131
- statusCode: 500,
132
- data: {
133
- stack
134
- }
135
- }));
136
- };
137
- return { delay, cancel };
138
- };
139
- exports.delayCancellable = delayCancellable;
140
- async function promiseTimeout(ms, promise) {
141
- if (!ms) {
142
- return new Promise(promise);
143
- }
144
- const stack = new Error().stack;
145
- // Create a promise that rejects in <ms> milliseconds
146
- const { delay, cancel } = (0, exports.delayCancellable)(ms);
147
- const p = new Promise((resolve, reject) => {
148
- delay
149
- .then(() => reject(new boom_1.Boom('Timed Out', {
150
- statusCode: Types_1.DisconnectReason.timedOut,
151
- data: {
152
- stack
153
- }
154
- })))
155
- .catch(err => reject(err));
156
- promise(resolve, reject);
157
- })
158
- .finally(cancel);
159
- return p;
160
- }
161
- exports.promiseTimeout = promiseTimeout;
162
- const generateMessageIDV2 = (userId) => {
163
- const data = Buffer.alloc(8 + 20 + 16);
164
- data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
165
- if (userId) {
166
- const id = (0, WABinary_1.jidDecode)(userId);
167
- if (id === null || id === void 0 ? void 0 : id.user) {
168
- data.write(id.user, 8);
169
- data.write('@c.us', 8 + id.user.length);
170
- }
171
- }
172
- const random = (0, crypto_1.randomBytes)(16);
173
- random.copy(data, 28);
174
- const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
175
- return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
176
- };
177
- exports.generateMessageIDV2 = generateMessageIDV2;
178
- // generate a random ID to attach to a message
179
- const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
180
- exports.generateMessageID = generateMessageID;
181
- function bindWaitForEvent(ev, event) {
182
- return async (check, timeoutMs) => {
183
- let listener;
184
- let closeListener;
185
- await (promiseTimeout(timeoutMs, (resolve, reject) => {
186
- closeListener = ({ connection, lastDisconnect }) => {
187
- if (connection === 'close') {
188
- reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
189
- || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
190
- }
191
- };
192
- ev.on('connection.update', closeListener);
193
- listener = (update) => {
194
- if (check(update)) {
195
- resolve();
196
- }
197
- };
198
- ev.on(event, listener);
199
- })
200
- .finally(() => {
201
- ev.off(event, listener);
202
- ev.off('connection.update', closeListener);
203
- }));
204
- };
205
- }
206
- exports.bindWaitForEvent = bindWaitForEvent;
207
- const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
208
- exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
209
- const printQRIfNecessaryListener = (ev, logger) => {
210
- ev.on('connection.update', async ({ qr }) => {
211
- if (qr) {
212
- const QR = await import('qrcode-terminal')
213
- .then(m => m.default || m)
214
- .catch(() => {
215
- logger.error('QR code terminal not added as dependency');
216
- });
217
- QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
218
- }
219
- });
220
- };
221
- exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
222
- /**
223
- * utility that fetches latest baileys version from the master branch.
224
- * Use to ensure your WA connection is always on the latest version
225
- */
226
- const fetchLatestWaWebVersion = async (options = {}) => {
227
- try {
228
- const defaultHeaders = {
229
- 'User-Agent':
230
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
231
- 'Accept': '*/*'
232
- }
233
-
234
- const headers = { ...defaultHeaders, ...options.headers }
235
-
236
- const response = await fetch_1('https://web.whatsapp.com/sw.js', {
237
- method: 'GET',
238
- headers
239
- })
240
-
241
- if (!response.ok) {
242
- throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
243
- }
244
-
245
- const data = await response.text()
246
- const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
247
- const match = data.match(regex)
248
-
249
- if (!match || !match[1]) {
250
- return {
251
- version: baileysVersion,
252
- isLatest: false,
253
- error: { message: 'Client revision not found' }
254
- }
255
- }
256
-
257
- const clientRevision = match[1]
258
- return {
259
- version: [2, 3000, +clientRevision],
260
- isLatest: true
261
- }
262
- } catch (error) {
263
- return {
264
- version: baileysVersion,
265
- isLatest: false,
266
- error
267
- }
268
- }
269
- }
270
- exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
271
- /**
272
- * utility that fetches latest baileys version from the master branch.
273
- * Use to ensure your WA connection is always on the latest version
274
- */
275
- const fetchLatestBaileysVersion = async (options = {}) => {
276
- const URL = 'https://raw.githubusercontent.com/kiuur/baileys/master/src/Defaults/baileys-version.json';
277
- try {
278
- const result = await axios_1.default.get(URL, {
279
- ...options,
280
- responseType: 'json'
281
- });
282
- return {
283
- version: result.data.version,
284
- isLatest: true
285
- };
286
- }
287
- catch (error) {
288
- return {
289
- version: baileys_version_json_1.version,
290
- isLatest: false,
291
- error
292
- };
293
- }
294
- };
295
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
296
- /** unique message tag prefix for MD clients */
297
- const generateMdTagPrefix = () => {
298
- const bytes = (0, crypto_1.randomBytes)(4);
299
- return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
300
- };
301
- exports.generateMdTagPrefix = generateMdTagPrefix;
302
- const STATUS_MAP = {
303
- 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
304
- 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
305
- 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
306
- };
307
- /**
308
- * Given a type of receipt, returns what the new status of the message should be
309
- * @param type type from receipt
310
- */
311
- const getStatusFromReceiptType = (type) => {
312
- const status = STATUS_MAP[type];
313
- if (typeof type === 'undefined') {
314
- return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
315
- }
316
- return status;
317
- };
318
- exports.getStatusFromReceiptType = getStatusFromReceiptType;
319
- const CODE_MAP = {
320
- conflict: Types_1.DisconnectReason.connectionReplaced
321
- };
322
- /**
323
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
324
- * @param reason the string reason given, eg. "conflict"
325
- */
326
- const getErrorCodeFromStreamError = (node) => {
327
- const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
328
- let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
329
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
330
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
331
- reason = 'restart required';
332
- }
333
- return {
334
- reason,
335
- statusCode
336
- };
337
- };
338
- exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
339
- const getCallStatusFromNode = ({ tag, attrs }) => {
340
- let status;
341
- switch (tag) {
342
- case 'offer':
343
- case 'offer_notice':
344
- status = 'offer';
345
- break;
346
- case 'terminate':
347
- if (attrs.reason === 'timeout') {
348
- status = 'timeout';
349
- }
350
- else {
351
- status = 'reject';
352
- }
353
- break;
354
- case 'reject':
355
- status = 'reject';
356
- break;
357
- case 'accept':
358
- status = 'accept';
359
- break;
360
- default:
361
- status = 'ringing';
362
- break;
363
- }
364
- return status;
365
- };
366
- exports.getCallStatusFromNode = getCallStatusFromNode;
367
- const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
368
- const getCodeFromWSError = (error) => {
369
- var _a, _b, _c;
370
- let statusCode = 500;
371
- if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
372
- const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
373
- if (!Number.isNaN(code) && code >= 400) {
374
- statusCode = code;
375
- }
376
- }
377
- else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
378
- || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
379
- statusCode = 408;
380
- }
381
- return statusCode;
382
- };
383
- exports.getCodeFromWSError = getCodeFromWSError;
384
- /**
385
- * Is the given platform WA business
386
- * @param platform AuthenticationCreds.platform
387
- */
388
- const isWABusinessPlatform = (platform) => {
389
- return platform === 'smbi' || platform === 'smba';
390
- };
391
- exports.isWABusinessPlatform = isWABusinessPlatform;
392
- function trimUndefined(obj) {
393
- for (const key in obj) {
394
- if (typeof obj[key] === 'undefined') {
395
- delete obj[key];
396
- }
397
- }
398
- return obj;
399
- }
400
- exports.trimUndefined = trimUndefined;
401
- const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
402
- function bytesToCrockford(buffer) {
403
- let value = 0;
404
- let bitCount = 0;
405
- const crockford = [];
406
- for (let i = 0; i < buffer.length; i++) {
407
- value = (value << 8) | (buffer[i] & 0xff);
408
- bitCount += 8;
409
- while (bitCount >= 5) {
410
- crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
411
- bitCount -= 5;
412
- }
413
- }
414
- if (bitCount > 0) {
415
- crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
416
- }
417
- return crockford.join('');
418
- }
419
- exports.bytesToCrockford = bytesToCrockford;
420
- const encodeNewsletterMessage = (message) => {
421
- return WAProto_1.proto.Message.encode(message).finish()
422
- }
423
- exports.encodeNewsletterMessage = encodeNewsletterMessage;