@denzy-official/baileys 1.2.0 → 1.2.1
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 +2 -2
- package/lib/Socket/Client/web-socket-client.js +1 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/socket.js +89 -81
- package/lib/Utils/generics.js +10 -28
- package/lib/Utils/messages.js +2 -2
- package/package.json +11 -12
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Denzy ZeroDay
|
|
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
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/lib/Socket/dugong.js
CHANGED
package/lib/Socket/socket.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Telegram: t.me/pantatBegetar
|
|
2
|
+
|
|
1
3
|
"use strict";
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
5
|
exports.makeSocket = void 0;
|
|
@@ -10,39 +12,30 @@ const Defaults_1 = require("../Defaults");
|
|
|
10
12
|
const Types_1 = require("../Types");
|
|
11
13
|
const Utils_1 = require("../Utils");
|
|
12
14
|
const WABinary_1 = require("../WABinary");
|
|
13
|
-
const Client_1 = require("./Client");
|
|
14
|
-
/**
|
|
15
|
-
* Connects to WA servers and performs:
|
|
16
|
-
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
17
|
-
* - listen to messages and emit events
|
|
18
|
-
* - query phone connection
|
|
19
|
-
*/
|
|
15
|
+
const Client_1 = require("./Client");
|
|
20
16
|
const makeSocket = (config) => {
|
|
21
17
|
var _a, _b;
|
|
22
18
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
20
|
+
if (config.mobile || url.protocol === 'tcp:') {
|
|
21
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', {
|
|
22
|
+
statusCode: Types_1.DisconnectReason.loggedOut
|
|
23
|
+
});
|
|
27
24
|
}
|
|
28
|
-
if (
|
|
25
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
29
26
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
30
27
|
}
|
|
31
|
-
const ws =
|
|
28
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
32
29
|
ws.connect();
|
|
33
|
-
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
34
|
-
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
30
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
35
31
|
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
36
|
-
/** WA noise protocol wrapper */
|
|
37
32
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
38
33
|
keyPair: ephemeralKeyPair,
|
|
39
|
-
NOISE_HEADER:
|
|
40
|
-
mobile: config.mobile,
|
|
34
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
41
35
|
logger,
|
|
42
36
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
37
|
});
|
|
44
38
|
const { creds } = authState;
|
|
45
|
-
// add transaction capability
|
|
46
39
|
const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
47
40
|
const signalRepository = makeSignalRepository({ creds, keys });
|
|
48
41
|
let lastDateRecv;
|
|
@@ -53,7 +46,6 @@ const makeSocket = (config) => {
|
|
|
53
46
|
const uqTagId = (0, Utils_1.generateMdTagPrefix)();
|
|
54
47
|
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
55
48
|
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
56
|
-
/** send a raw buffer */
|
|
57
49
|
const sendRawMessage = async (data) => {
|
|
58
50
|
if (!ws.isOpen) {
|
|
59
51
|
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
@@ -68,20 +60,34 @@ const makeSocket = (config) => {
|
|
|
68
60
|
reject(error);
|
|
69
61
|
}
|
|
70
62
|
});
|
|
71
|
-
};
|
|
72
|
-
/** send a binary node */
|
|
63
|
+
};
|
|
73
64
|
const sendNode = (frame) => {
|
|
74
65
|
if (logger.level === 'trace') {
|
|
75
66
|
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
|
|
76
67
|
}
|
|
77
68
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
78
69
|
return sendRawMessage(buff);
|
|
79
|
-
};
|
|
80
|
-
/** log & process any unexpected errors */
|
|
70
|
+
};
|
|
81
71
|
const onUnexpectedError = (err, msg) => {
|
|
82
72
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
73
|
+
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
74
|
+
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
75
|
+
try {
|
|
76
|
+
uploadPreKeysToServerIfRequired(true)
|
|
77
|
+
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
78
|
+
}
|
|
79
|
+
catch (_e) {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (message.includes('429') || message.includes('rate limit')) {
|
|
84
|
+
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
85
|
+
logger.info({ wait }, 'backing off due to rate limit');
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
}, wait);
|
|
88
|
+
}
|
|
83
89
|
};
|
|
84
|
-
|
|
90
|
+
|
|
85
91
|
const awaitNextMessage = async (sendMsg) => {
|
|
86
92
|
if (!ws.isOpen) {
|
|
87
93
|
throw new boom_1.Boom('Connection Closed', {
|
|
@@ -106,47 +112,45 @@ const makeSocket = (config) => {
|
|
|
106
112
|
sendRawMessage(sendMsg).catch(onClose);
|
|
107
113
|
}
|
|
108
114
|
return result;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
* Wait for a message with a certain tag to be received
|
|
112
|
-
* @param msgId the message tag to await
|
|
113
|
-
* @param timeoutMs timeout after which the promise will reject
|
|
114
|
-
*/
|
|
115
|
+
};
|
|
116
|
+
|
|
115
117
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
116
118
|
let onRecv;
|
|
117
119
|
let onErr;
|
|
118
120
|
try {
|
|
119
|
-
|
|
121
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
120
122
|
onRecv = resolve;
|
|
121
123
|
onErr = err => {
|
|
122
124
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
123
125
|
};
|
|
124
126
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
125
|
-
ws.on('close', onErr);
|
|
127
|
+
ws.on('close', onErr);
|
|
126
128
|
ws.off('error', onErr);
|
|
127
129
|
});
|
|
130
|
+
return result;
|
|
128
131
|
}
|
|
129
132
|
finally {
|
|
130
133
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
131
|
-
ws.off('close', onErr);
|
|
134
|
+
ws.off('close', onErr);
|
|
132
135
|
ws.off('error', onErr);
|
|
133
136
|
}
|
|
134
137
|
};
|
|
135
|
-
|
|
138
|
+
|
|
136
139
|
const query = async (node, timeoutMs) => {
|
|
137
140
|
if (!node.attrs.id) {
|
|
138
141
|
node.attrs.id = generateMessageTag();
|
|
139
142
|
}
|
|
140
143
|
const msgId = node.attrs.id;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
const [result] = await Promise.all([
|
|
145
|
+
waitForMessage(msgId, timeoutMs),
|
|
146
|
+
sendNode(node)
|
|
147
|
+
]);
|
|
144
148
|
if ('tag' in result) {
|
|
145
149
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
146
150
|
}
|
|
147
151
|
return result;
|
|
148
152
|
};
|
|
149
|
-
|
|
153
|
+
|
|
150
154
|
const validateConnection = async () => {
|
|
151
155
|
let helloMsg = {
|
|
152
156
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
@@ -157,12 +161,9 @@ const makeSocket = (config) => {
|
|
|
157
161
|
const result = await awaitNextMessage(init);
|
|
158
162
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
159
163
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
160
|
-
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
164
|
+
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
161
165
|
let node;
|
|
162
|
-
if (
|
|
163
|
-
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
-
}
|
|
165
|
-
else if (!creds.me) {
|
|
166
|
+
if (!creds.me) {
|
|
166
167
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
167
168
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
168
169
|
}
|
|
@@ -232,11 +233,11 @@ const makeSocket = (config) => {
|
|
|
232
233
|
const l0 = frame.tag;
|
|
233
234
|
const l1 = frame.attrs || {};
|
|
234
235
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
235
|
-
Object.keys(l1)
|
|
236
|
+
for (const key of Object.keys(l1)) {
|
|
236
237
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
237
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
238
239
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
239
|
-
}
|
|
240
|
+
}
|
|
240
241
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
241
242
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
242
243
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -300,15 +301,12 @@ const makeSocket = (config) => {
|
|
|
300
301
|
lastDateRecv = new Date();
|
|
301
302
|
}
|
|
302
303
|
const diff = Date.now() - lastDateRecv.getTime();
|
|
303
|
-
|
|
304
|
-
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
305
|
-
it could be that the network is down
|
|
306
|
-
*/
|
|
304
|
+
|
|
307
305
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
308
306
|
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
309
307
|
}
|
|
310
308
|
else if (ws.isOpen) {
|
|
311
|
-
|
|
309
|
+
|
|
312
310
|
query({
|
|
313
311
|
tag: 'iq',
|
|
314
312
|
attrs: {
|
|
@@ -327,7 +325,7 @@ const makeSocket = (config) => {
|
|
|
327
325
|
logger.warn('keep alive called when WS not open');
|
|
328
326
|
}
|
|
329
327
|
}, keepAliveIntervalMs));
|
|
330
|
-
|
|
328
|
+
|
|
331
329
|
const sendPassiveIq = (tag) => (query({
|
|
332
330
|
tag: 'iq',
|
|
333
331
|
attrs: {
|
|
@@ -339,7 +337,7 @@ const makeSocket = (config) => {
|
|
|
339
337
|
{ tag, attrs: {} }
|
|
340
338
|
]
|
|
341
339
|
}));
|
|
342
|
-
|
|
340
|
+
|
|
343
341
|
const logout = async (msg) => {
|
|
344
342
|
var _a;
|
|
345
343
|
const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
|
|
@@ -365,11 +363,8 @@ const makeSocket = (config) => {
|
|
|
365
363
|
}
|
|
366
364
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
367
365
|
};
|
|
368
|
-
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
369
366
|
|
|
370
|
-
|
|
371
|
-
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
372
|
-
const requestPairingCode = async (phoneNumber, pairKey = "DENZYMOD") => {
|
|
367
|
+
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
373
368
|
if (pairKey) {
|
|
374
369
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
375
370
|
} else {
|
|
@@ -431,12 +426,11 @@ const makeSocket = (config) => {
|
|
|
431
426
|
});
|
|
432
427
|
|
|
433
428
|
return authState.creds.pairingCode;
|
|
434
|
-
}
|
|
435
|
-
|
|
429
|
+
}
|
|
436
430
|
async function generatePairingKey() {
|
|
437
431
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
438
432
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
439
|
-
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
433
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
440
434
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
441
435
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
442
436
|
}
|
|
@@ -469,9 +463,9 @@ const makeSocket = (config) => {
|
|
|
469
463
|
});
|
|
470
464
|
ws.on('error', mapWebSocketError(end));
|
|
471
465
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
472
|
-
|
|
466
|
+
|
|
473
467
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
474
|
-
|
|
468
|
+
|
|
475
469
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
476
470
|
const iq = {
|
|
477
471
|
tag: 'iq',
|
|
@@ -505,8 +499,7 @@ const makeSocket = (config) => {
|
|
|
505
499
|
};
|
|
506
500
|
genPairQR();
|
|
507
501
|
});
|
|
508
|
-
|
|
509
|
-
// if device pairs successfully, the server asks to restart the connection
|
|
502
|
+
|
|
510
503
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
511
504
|
logger.debug('pair success recv');
|
|
512
505
|
try {
|
|
@@ -521,14 +514,21 @@ const makeSocket = (config) => {
|
|
|
521
514
|
end(error);
|
|
522
515
|
}
|
|
523
516
|
});
|
|
524
|
-
|
|
517
|
+
|
|
525
518
|
ws.on('CB:success', async (node) => {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
519
|
+
try {
|
|
520
|
+
await uploadPreKeysToServerIfRequired();
|
|
521
|
+
await sendPassiveIq('active');
|
|
522
|
+
logger.info('opened connection to WA');
|
|
523
|
+
clearTimeout(qrTimer);
|
|
524
|
+
|
|
525
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
526
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
527
|
+
}
|
|
528
|
+
catch (err) {
|
|
529
|
+
logger.error({ err }, 'error opening connection');
|
|
530
|
+
end(err);
|
|
531
|
+
}
|
|
532
532
|
});
|
|
533
533
|
ws.on('CB:stream:error', (node) => {
|
|
534
534
|
logger.error({ node }, 'stream errored out');
|
|
@@ -543,25 +543,33 @@ const makeSocket = (config) => {
|
|
|
543
543
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
544
544
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
545
545
|
});
|
|
546
|
+
ws.on('CB:ib,,offline_preview', (node) => {
|
|
547
|
+
logger.info('offline preview received', JSON.stringify(node));
|
|
548
|
+
sendNode({
|
|
549
|
+
tag: 'ib',
|
|
550
|
+
attrs: {},
|
|
551
|
+
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
552
|
+
});
|
|
553
|
+
});
|
|
546
554
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
547
555
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
548
556
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
549
557
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
550
558
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
559
|
+
ev.emit('creds.update', authState.creds);
|
|
551
560
|
}
|
|
552
561
|
});
|
|
553
562
|
let didStartBuffer = false;
|
|
554
563
|
process.nextTick(() => {
|
|
555
564
|
var _a;
|
|
556
565
|
if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
|
|
557
|
-
|
|
558
|
-
// if we're logged in
|
|
566
|
+
|
|
559
567
|
ev.buffer();
|
|
560
568
|
didStartBuffer = true;
|
|
561
569
|
}
|
|
562
570
|
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
563
571
|
});
|
|
564
|
-
|
|
572
|
+
|
|
565
573
|
ws.on('CB:ib,,offline', (node) => {
|
|
566
574
|
const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
|
|
567
575
|
const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
|
|
@@ -572,7 +580,7 @@ const makeSocket = (config) => {
|
|
|
572
580
|
}
|
|
573
581
|
ev.emit('connection.update', { receivedPendingNotifications: true });
|
|
574
582
|
});
|
|
575
|
-
|
|
583
|
+
|
|
576
584
|
ev.on('creds.update', update => {
|
|
577
585
|
var _a, _b;
|
|
578
586
|
const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
|
|
@@ -596,7 +604,10 @@ const makeSocket = (config) => {
|
|
|
596
604
|
type: 'md',
|
|
597
605
|
ws,
|
|
598
606
|
ev,
|
|
599
|
-
authState: {
|
|
607
|
+
authState: {
|
|
608
|
+
creds,
|
|
609
|
+
keys
|
|
610
|
+
},
|
|
600
611
|
signalRepository,
|
|
601
612
|
get user() {
|
|
602
613
|
return authState.creds.me;
|
|
@@ -613,16 +624,13 @@ const makeSocket = (config) => {
|
|
|
613
624
|
uploadPreKeys,
|
|
614
625
|
uploadPreKeysToServerIfRequired,
|
|
615
626
|
requestPairingCode,
|
|
616
|
-
|
|
627
|
+
|
|
617
628
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
618
629
|
sendWAMBuffer,
|
|
619
630
|
};
|
|
620
631
|
};
|
|
621
632
|
exports.makeSocket = makeSocket;
|
|
622
|
-
|
|
623
|
-
* map the websocket error to the right type
|
|
624
|
-
* so it can be retried by the caller
|
|
625
|
-
* */
|
|
633
|
+
|
|
626
634
|
function mapWebSocketError(handler) {
|
|
627
635
|
return (error) => {
|
|
628
636
|
handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
|
package/lib/Utils/generics.js
CHANGED
|
@@ -174,7 +174,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
174
174
|
};
|
|
175
175
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
176
176
|
// generate a random ID to attach to a message
|
|
177
|
-
const generateMessageID = () => '
|
|
177
|
+
const generateMessageID = () => 'DENZY-ZERODAY-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
178
178
|
exports.generateMessageID = generateMessageID;
|
|
179
179
|
function bindWaitForEvent(ev, event) {
|
|
180
180
|
return async (check, timeoutMs) => {
|
|
@@ -216,11 +216,7 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
216
216
|
}
|
|
217
217
|
});
|
|
218
218
|
};
|
|
219
|
-
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
220
|
-
/**
|
|
221
|
-
* utility that fetches latest baileys version from the master branch.
|
|
222
|
-
* Use to ensure your WA connection is always on the latest version
|
|
223
|
-
*/
|
|
219
|
+
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
224
220
|
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
225
221
|
try {
|
|
226
222
|
const defaultHeaders = {
|
|
@@ -241,7 +237,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
241
237
|
}
|
|
242
238
|
|
|
243
239
|
const data = await response.text()
|
|
244
|
-
const regex = /"client_revision":\s*(\d+)/
|
|
240
|
+
const regex = /"client_revision":\s*(\d+)/
|
|
245
241
|
const match = data.match(regex)
|
|
246
242
|
|
|
247
243
|
if (!match || !match[1]) {
|
|
@@ -266,12 +262,9 @@ const fetchLatestWaWebVersion = async (options = {}) => {
|
|
|
266
262
|
}
|
|
267
263
|
}
|
|
268
264
|
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
269
|
-
|
|
270
|
-
* utility that fetches latest baileys version from the master branch.
|
|
271
|
-
* Use to ensure your WA connection is always on the latest version
|
|
272
|
-
*/
|
|
265
|
+
|
|
273
266
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
274
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
267
|
+
const URL = 'https://raw.githubusercontent.com/Denzy-ZeroDay/baileys/master/src/Defaults/baileys-version.json';
|
|
275
268
|
try {
|
|
276
269
|
const result = await axios_1.default.get(URL, {
|
|
277
270
|
...options,
|
|
@@ -291,7 +284,7 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
291
284
|
}
|
|
292
285
|
};
|
|
293
286
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
294
|
-
|
|
287
|
+
|
|
295
288
|
const generateMdTagPrefix = () => {
|
|
296
289
|
const bytes = (0, crypto_1.randomBytes)(4);
|
|
297
290
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
@@ -301,11 +294,7 @@ const STATUS_MAP = {
|
|
|
301
294
|
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
302
295
|
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
303
296
|
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Given a type of receipt, returns what the new status of the message should be
|
|
307
|
-
* @param type type from receipt
|
|
308
|
-
*/
|
|
297
|
+
};
|
|
309
298
|
const getStatusFromReceiptType = (type) => {
|
|
310
299
|
const status = STATUS_MAP[type];
|
|
311
300
|
if (typeof type === 'undefined') {
|
|
@@ -316,11 +305,7 @@ const getStatusFromReceiptType = (type) => {
|
|
|
316
305
|
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
317
306
|
const CODE_MAP = {
|
|
318
307
|
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
319
|
-
};
|
|
320
|
-
/**
|
|
321
|
-
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
322
|
-
* @param reason the string reason given, eg. "conflict"
|
|
323
|
-
*/
|
|
308
|
+
};
|
|
324
309
|
const getErrorCodeFromStreamError = (node) => {
|
|
325
310
|
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
326
311
|
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
@@ -378,11 +363,8 @@ const getCodeFromWSError = (error) => {
|
|
|
378
363
|
}
|
|
379
364
|
return statusCode;
|
|
380
365
|
};
|
|
381
|
-
exports.getCodeFromWSError = getCodeFromWSError;
|
|
382
|
-
|
|
383
|
-
* Is the given platform WA business
|
|
384
|
-
* @param platform AuthenticationCreds.platform
|
|
385
|
-
*/
|
|
366
|
+
exports.getCodeFromWSError = getCodeFromWSError;
|
|
367
|
+
|
|
386
368
|
const isWABusinessPlatform = (platform) => {
|
|
387
369
|
return platform === 'smbi' || platform === 'smba';
|
|
388
370
|
};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -105,9 +105,9 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
105
105
|
}
|
|
106
106
|
],
|
|
107
107
|
newsletter: {
|
|
108
|
-
newsletterJid: "
|
|
108
|
+
newsletterJid: "120363402308105961@newsletter",
|
|
109
109
|
serverMessageId: 0,
|
|
110
|
-
newsletterName: "
|
|
110
|
+
newsletterName: "Denzy ZeroDay",
|
|
111
111
|
contentType: "UPDATE",
|
|
112
112
|
}
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denzy-official/baileys",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Baileys Custom Denzy-ZeroDay",
|
|
5
5
|
"keywords": [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
],
|
|
6
|
+
"whatsapp",
|
|
7
|
+
"awa-subaru",
|
|
8
|
+
"baileys",
|
|
9
|
+
"whatsapp-web",
|
|
10
|
+
"whatsapp-chat",
|
|
11
|
+
"whatsapp-group",
|
|
12
|
+
"whatsapp-api",
|
|
13
|
+
"botwa",
|
|
14
|
+
"Denzy ZeroDay"
|
|
15
|
+
],
|
|
17
16
|
"homepage": "https://www.npmjs.com/package/@denzy-official/baileys",
|
|
18
17
|
"repository": {
|
|
19
18
|
"url": "https://www.npmjs.com/package/@denzy-official/baileys"
|