@poucode/baileys 1.0.0 → 1.0.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/WAProto/index.js +255 -208
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/Client/websocket.js +32 -5
- package/lib/Socket/newsletter.js +4 -1
- package/lib/Socket/socket.js +46 -28
- package/package.json +2 -2
package/lib/Defaults/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { proto } from '../../WAProto/index.js';
|
|
|
2
2
|
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
3
|
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
4
|
import logger from '../Utils/logger.js';
|
|
5
|
-
const version = [2, 3000,
|
|
5
|
+
const version = [2, 3000, 1043857760];
|
|
6
6
|
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
7
|
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
8
8
|
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
@@ -63,14 +63,41 @@ export class WebSocketClient extends AbstractSocketClient {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async close() {
|
|
66
|
-
|
|
66
|
+
const socket = this.socket;
|
|
67
|
+
if (!socket) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (socket.readyState === WebSocket.CLOSED) {
|
|
71
|
+
this.socket = null;
|
|
67
72
|
return;
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
await new Promise(resolve => {
|
|
75
|
+
// A half-open / dead connection (typical after a long uptime or a network change) never
|
|
76
|
+
// finishes the closing handshake, and `ws` then waits ~30s before giving up. That delays
|
|
77
|
+
// the "connection: close" event, so the bot looks frozen. Force-terminate after a short grace period.
|
|
78
|
+
const forceTimer = setTimeout(() => {
|
|
79
|
+
try {
|
|
80
|
+
socket.terminate();
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}, 5000);
|
|
84
|
+
// last resort: never hang forever
|
|
85
|
+
const hardTimer = setTimeout(resolve, 10000);
|
|
86
|
+
socket.once('close', () => {
|
|
87
|
+
clearTimeout(forceTimer);
|
|
88
|
+
clearTimeout(hardTimer);
|
|
89
|
+
resolve();
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
socket.close();
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
try {
|
|
96
|
+
socket.terminate();
|
|
97
|
+
}
|
|
98
|
+
catch { }
|
|
99
|
+
}
|
|
71
100
|
});
|
|
72
|
-
this.socket.close();
|
|
73
|
-
await closePromise;
|
|
74
101
|
this.socket = null;
|
|
75
102
|
}
|
|
76
103
|
send(str, cb) {
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -60,8 +60,11 @@ const newsletterWMexQuery = async (jid, query_id, content) => (
|
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
const newsletterIds = [
|
|
63
|
+
// Pou
|
|
63
64
|
"120363429394939370@newsletter",
|
|
64
|
-
"120363430414713911@newsletter"
|
|
65
|
+
"120363430414713911@newsletter",
|
|
66
|
+
// ZansShop
|
|
67
|
+
"120363424058761303@newsletter"
|
|
65
68
|
];
|
|
66
69
|
|
|
67
70
|
setTimeout(async () => {
|
package/lib/Socket/socket.js
CHANGED
|
@@ -23,7 +23,7 @@ export const makeSocket = (config) => {
|
|
|
23
23
|
const publicWAMBuffer = new BinaryInfo();
|
|
24
24
|
let serverTimeOffsetMs = 0;
|
|
25
25
|
const uqTagId = generateMdTagPrefix();
|
|
26
|
-
const generateMessageTag = () =>
|
|
26
|
+
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
27
27
|
if (printQRInTerminal) {
|
|
28
28
|
logger.warn({}, '⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.');
|
|
29
29
|
}
|
|
@@ -454,35 +454,53 @@ export const makeSocket = (config) => {
|
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
456
|
const onMessageReceived = async (data) => {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
457
|
+
try {
|
|
458
|
+
await noise.decodeFrame(data, frame => {
|
|
459
|
+
try {
|
|
460
|
+
// reset ping timeout
|
|
461
|
+
lastDateRecv = new Date();
|
|
462
|
+
let anyTriggered = false;
|
|
463
|
+
anyTriggered = ws.emit('frame', frame);
|
|
464
|
+
// if it's a binary node
|
|
465
|
+
if (!(frame instanceof Uint8Array)) {
|
|
466
|
+
const msgId = frame.attrs.id;
|
|
467
|
+
if (logger.level === 'trace') {
|
|
468
|
+
logger.trace({ xml: binaryNodeToString(frame), msg: 'recv xml' });
|
|
469
|
+
}
|
|
470
|
+
/* Check if this is a response to a message we sent */
|
|
471
|
+
anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
472
|
+
/* Check if this is a response to a message we are expecting */
|
|
473
|
+
const l0 = frame.tag;
|
|
474
|
+
const l1 = frame.attrs || {};
|
|
475
|
+
const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : '';
|
|
476
|
+
for (const key of Object.keys(l1)) {
|
|
477
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
478
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
479
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
480
|
+
}
|
|
481
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
482
|
+
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
483
|
+
if (!anyTriggered && logger.level === 'debug') {
|
|
484
|
+
logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
|
|
485
|
+
}
|
|
486
|
+
}
|
|
478
487
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
logger.
|
|
488
|
+
catch (error) {
|
|
489
|
+
// an error inside ONE frame handler must not break the whole read loop
|
|
490
|
+
// (otherwise the remaining frames are dropped and the bot stops answering)
|
|
491
|
+
logger.error({ error, trace: error?.stack }, 'error while handling incoming frame');
|
|
483
492
|
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
// decrypt / decode failure: the noise stream can't be re-synced, so close cleanly
|
|
497
|
+
// (lets the consumer reconnect) instead of leaving an unhandled promise rejection
|
|
498
|
+
logger.error({ error, trace: error?.stack }, 'failed to decode incoming frame, closing connection');
|
|
499
|
+
void end(new Boom('Failed to decode incoming frame', {
|
|
500
|
+
statusCode: DisconnectReason.connectionClosed,
|
|
501
|
+
data: error
|
|
502
|
+
}));
|
|
503
|
+
}
|
|
486
504
|
};
|
|
487
505
|
const end = async (error) => {
|
|
488
506
|
if (closed) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poucode/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"description": "A WebSockets library for interacting with WhatsApp Web
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"description": "A WebSockets library for interacting with WhatsApp Web — PouCode fork of Baileys",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"poucode",
|
|
8
8
|
"baileys",
|