@heavstaltech/baileys 3.2.4 β 3.2.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/lib/Socket/socket.js +175 -2
- package/lib/index.js +8 -7
- package/package.json +1 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -386,7 +386,7 @@ const makeSocket = (config) => {
|
|
|
386
386
|
|
|
387
387
|
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
388
388
|
/** hey bro, if you delete this text */
|
|
389
|
-
/** you are the most cursed human being who likes to claim other people's property πΉππ»
|
|
389
|
+
/** you are the most cursed human being who likes to claim other people's property πΉππ» */
|
|
390
390
|
const requestPairingCode = async (phoneNumber, pairKey = "HEAV-STAL") => {
|
|
391
391
|
if (pairKey) {
|
|
392
392
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
@@ -489,4 +489,177 @@ const makeSocket = (config) => {
|
|
|
489
489
|
// the server terminated the connection
|
|
490
490
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
491
491
|
// QR gen
|
|
492
|
-
ws.on('CB:iq,type:set,pair-device', async (
|
|
492
|
+
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
493
|
+
const iq = {
|
|
494
|
+
tag: 'iq',
|
|
495
|
+
attrs: {
|
|
496
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
497
|
+
type: 'result',
|
|
498
|
+
id: stanza.attrs.id,
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
await sendNode(iq);
|
|
502
|
+
const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
|
|
503
|
+
const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
|
|
504
|
+
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
505
|
+
const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
|
|
506
|
+
const advB64 = creds.advSecretKey;
|
|
507
|
+
let qrMs = qrTimeout || 60000; // time to let a QR live
|
|
508
|
+
const genPairQR = () => {
|
|
509
|
+
if (!ws.isOpen) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const refNode = refNodes.shift();
|
|
513
|
+
if (!refNode) {
|
|
514
|
+
end(new boom_1.Boom('QR refs attempts ended', { statusCode: Types_1.DisconnectReason.timedOut }));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const ref = refNode.content.toString('utf-8');
|
|
518
|
+
const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
|
|
519
|
+
ev.emit('connection.update', { qr });
|
|
520
|
+
qrTimer = setTimeout(genPairQR, qrMs);
|
|
521
|
+
qrMs = qrTimeout || 20000; // shorter subsequent qrs
|
|
522
|
+
};
|
|
523
|
+
genPairQR();
|
|
524
|
+
});
|
|
525
|
+
// device paired for the first time
|
|
526
|
+
// if device pairs successfully, the server asks to restart the connection
|
|
527
|
+
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
528
|
+
logger.debug('pair success recv');
|
|
529
|
+
try {
|
|
530
|
+
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
531
|
+
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
532
|
+
ev.emit('creds.update', updatedCreds);
|
|
533
|
+
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
534
|
+
await sendNode(reply);
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
logger.info({ trace: error.stack }, 'error in pairing');
|
|
538
|
+
end(error);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
// login complete
|
|
542
|
+
ws.on('CB:success', async (node) => {
|
|
543
|
+
try {
|
|
544
|
+
await uploadPreKeysToServerIfRequired();
|
|
545
|
+
await sendPassiveIq('active');
|
|
546
|
+
logger.info('opened connection to WA');
|
|
547
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
548
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
549
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
550
|
+
}
|
|
551
|
+
catch (err) {
|
|
552
|
+
logger.error({ err }, 'error opening connection');
|
|
553
|
+
end(err);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
ws.on('CB:stream:error', (node) => {
|
|
557
|
+
logger.error({ node }, 'stream errored out');
|
|
558
|
+
const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
|
|
559
|
+
end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
|
|
560
|
+
});
|
|
561
|
+
// stream fail, possible logout
|
|
562
|
+
ws.on('CB:failure', (node) => {
|
|
563
|
+
const reason = +(node.attrs.reason || 500);
|
|
564
|
+
end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
|
|
565
|
+
});
|
|
566
|
+
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
567
|
+
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
568
|
+
});
|
|
569
|
+
ws.on('CB:ib,,offline_preview', (node) => {
|
|
570
|
+
logger.info('offline preview received', JSON.stringify(node));
|
|
571
|
+
sendNode({
|
|
572
|
+
tag: 'ib',
|
|
573
|
+
attrs: {},
|
|
574
|
+
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
ws.on('CB:ib,,edge_routing', (node) => {
|
|
578
|
+
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
579
|
+
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
580
|
+
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
581
|
+
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
582
|
+
ev.emit('creds.update', authState.creds);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
let didStartBuffer = false;
|
|
586
|
+
process.nextTick(() => {
|
|
587
|
+
var _a;
|
|
588
|
+
if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
|
|
589
|
+
// start buffering important events
|
|
590
|
+
// if we're logged in
|
|
591
|
+
ev.buffer();
|
|
592
|
+
didStartBuffer = true;
|
|
593
|
+
}
|
|
594
|
+
ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
|
|
595
|
+
});
|
|
596
|
+
// called when all offline notifs are handled
|
|
597
|
+
ws.on('CB:ib,,offline', (node) => {
|
|
598
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
|
|
599
|
+
const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
|
|
600
|
+
logger.info(`handled ${offlineNotifs} offline messages/notifications`);
|
|
601
|
+
if (didStartBuffer) {
|
|
602
|
+
ev.flush();
|
|
603
|
+
logger.trace('flushed events for initial buffer');
|
|
604
|
+
}
|
|
605
|
+
ev.emit('connection.update', { receivedPendingNotifications: true });
|
|
606
|
+
});
|
|
607
|
+
// update credentials when required
|
|
608
|
+
ev.on('creds.update', update => {
|
|
609
|
+
var _a, _b;
|
|
610
|
+
const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
|
|
611
|
+
// if name has just been received
|
|
612
|
+
if (((_b = creds.me) === null || _b === void 0 ? void 0 : _b.name) !== name) {
|
|
613
|
+
logger.debug({ name }, 'updated pushName');
|
|
614
|
+
sendNode({
|
|
615
|
+
tag: 'presence',
|
|
616
|
+
attrs: { name: name }
|
|
617
|
+
})
|
|
618
|
+
.catch(err => {
|
|
619
|
+
logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
Object.assign(creds, update);
|
|
623
|
+
});
|
|
624
|
+
if (printQRInTerminal) {
|
|
625
|
+
(0, Utils_1.printQRIfNecessaryListener)(ev, logger);
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
type: 'md',
|
|
629
|
+
ws,
|
|
630
|
+
ev,
|
|
631
|
+
authState: {
|
|
632
|
+
creds,
|
|
633
|
+
keys
|
|
634
|
+
},
|
|
635
|
+
signalRepository,
|
|
636
|
+
get user() {
|
|
637
|
+
return authState.creds.me;
|
|
638
|
+
},
|
|
639
|
+
generateMessageTag,
|
|
640
|
+
query,
|
|
641
|
+
waitForMessage,
|
|
642
|
+
waitForSocketOpen,
|
|
643
|
+
sendRawMessage,
|
|
644
|
+
sendNode,
|
|
645
|
+
logout,
|
|
646
|
+
end,
|
|
647
|
+
onUnexpectedError,
|
|
648
|
+
uploadPreKeys,
|
|
649
|
+
uploadPreKeysToServerIfRequired,
|
|
650
|
+
requestPairingCode,
|
|
651
|
+
/** Waits for the connection to WA to reach a state */
|
|
652
|
+
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
653
|
+
sendWAMBuffer,
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
exports.makeSocket = makeSocket;
|
|
657
|
+
/**
|
|
658
|
+
* map the websocket error to the right type
|
|
659
|
+
* so it can be retried by the caller
|
|
660
|
+
* */
|
|
661
|
+
function mapWebSocketError(handler) {
|
|
662
|
+
return (error) => {
|
|
663
|
+
handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
|
|
664
|
+
};
|
|
665
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
|
|
5
|
-
console.log(chalk.magentaBright.bold("\nβ¨ Modified Baileys β¨\n"));
|
|
6
|
-
console.log(chalk.whiteBright("Hi, thank you for using my modified Baileys ^-^"));
|
|
7
|
-
console.log(chalk.cyan("Telegram: ") + chalk.greenBright("@yumevtc"));
|
|
8
|
-
console.log(chalk.gray("------------------------------\n"));
|
|
9
|
-
const latestUpdate = new Date("
|
|
10
|
-
console.log(chalk.yellowBright("π Latest update: ") + chalk.whiteBright(latestUpdate.toLocaleDateString()));
|
|
11
|
-
console.log(chalk.gray("------------------------------\n"));
|
|
5
|
+
// console.log(chalk.magentaBright.bold("\nβ¨ Modified Baileys β¨\n"));
|
|
6
|
+
// console.log(chalk.whiteBright("Hi, thank you for using my modified Baileys ^-^"));
|
|
7
|
+
//console.log(chalk.cyan("Telegram: ") + chalk.greenBright("@yumevtc"));
|
|
8
|
+
// console.log(chalk.gray("------------------------------\n"));
|
|
9
|
+
const latestUpdate = new Date("2026-2-02");
|
|
10
|
+
// console.log(chalk.yellowBright("π Latest update: ") + chalk.whiteBright(latestUpdate.toLocaleDateString()));
|
|
11
|
+
// console.log(chalk.gray("------------------------------\n"));
|
|
12
|
+
console.log(chalk.magentaBright.bold(`MODIFIED BAILEYS BY HEAVSTAL TECHβ’\n\n`));
|
|
12
13
|
|
|
13
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
15
|
if (k2 === undefined) k2 = k;
|