baileys-antiban 1.3.0 → 1.3.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/CHANGELOG.md +9 -0
- package/dist/wrapper.js +137 -60
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.3.1] - 2026-04-16
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Refactor wrapper to use Baileys' `ev.process()` API — single batched event handler reduces listener leaks and cleans up the integration surface
|
|
12
|
+
- Graceful fallback to `ev.on()` for older Baileys versions
|
|
13
|
+
|
|
14
|
+
### Why
|
|
15
|
+
Scattered `ev.on()` registrations are a known leak vector. Consolidating into `process()` shrinks the attack surface for listener-lifecycle bugs and future-proofs for backend-agnostic support.
|
|
16
|
+
|
|
8
17
|
## [1.3.0] - 2026-04-16
|
|
9
18
|
|
|
10
19
|
### Added
|
package/dist/wrapper.js
CHANGED
|
@@ -25,71 +25,148 @@ export function wrapSocket(sock, config, warmUpState, wrapOptions) {
|
|
|
25
25
|
autoRespondToIncoming: false,
|
|
26
26
|
...wrapOptions,
|
|
27
27
|
};
|
|
28
|
-
// Hook into
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const params = update.update.messageStubParameters;
|
|
52
|
-
if (params.includes(463) || params.includes('463')) {
|
|
53
|
-
antiban.timelock.record463Error();
|
|
28
|
+
// Hook into Baileys events for health monitoring
|
|
29
|
+
// Prefer ev.process() (Baileys ≥ late 2022) for batched event handling
|
|
30
|
+
// Fall back to ev.on() for older versions
|
|
31
|
+
if (typeof sock.ev.process === 'function') {
|
|
32
|
+
sock.ev.process(async (events) => {
|
|
33
|
+
// Handle connection updates
|
|
34
|
+
if (events['connection.update']) {
|
|
35
|
+
const update = events['connection.update'];
|
|
36
|
+
if (update.connection === 'close') {
|
|
37
|
+
const reason = update.lastDisconnect?.error?.output?.statusCode || 'unknown';
|
|
38
|
+
antiban.onDisconnect(reason);
|
|
39
|
+
antiban.destroy(); // Clean up all timers
|
|
40
|
+
}
|
|
41
|
+
if (update.connection === 'open') {
|
|
42
|
+
antiban.onReconnect();
|
|
43
|
+
}
|
|
44
|
+
// Reachout timelock detection
|
|
45
|
+
if (update.reachoutTimeLock) {
|
|
46
|
+
antiban.timelock.onTimelockUpdate({
|
|
47
|
+
isActive: update.reachoutTimeLock.isActive,
|
|
48
|
+
timeEnforcementEnds: update.reachoutTimeLock.timeEnforcementEnds,
|
|
49
|
+
enforcementType: update.reachoutTimeLock.enforcementType,
|
|
50
|
+
});
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
antiban.timelock.registerKnownChat(jid);
|
|
66
|
-
// Skip self messages
|
|
67
|
-
const isSelf = msg.key?.fromMe || false;
|
|
68
|
-
if (isSelf)
|
|
69
|
-
continue;
|
|
70
|
-
// Extract message text
|
|
71
|
-
const msgText = msg.message?.conversation ||
|
|
72
|
-
msg.message?.extendedTextMessage?.text ||
|
|
73
|
-
msg.message?.imageMessage?.caption ||
|
|
74
|
-
msg.message?.videoMessage?.caption ||
|
|
75
|
-
'';
|
|
76
|
-
// Handle incoming message (updates reply ratio + contact graph)
|
|
77
|
-
const replySuggestion = antiban.onIncomingMessage(jid, msgText);
|
|
78
|
-
// Auto-respond if enabled and suggested
|
|
79
|
-
if (options.autoRespondToIncoming && replySuggestion.shouldReply && replySuggestion.suggestedText) {
|
|
80
|
-
// Random delay 3-15s
|
|
81
|
-
const replyDelay = Math.floor(Math.random() * 12000) + 3000;
|
|
82
|
-
setTimeout(async () => {
|
|
83
|
-
try {
|
|
84
|
-
await sock.sendMessage(jid, { text: replySuggestion.suggestedText });
|
|
53
|
+
// Catch 463 errors from message updates
|
|
54
|
+
if (events['messages.update']) {
|
|
55
|
+
const updates = events['messages.update'];
|
|
56
|
+
for (const update of updates) {
|
|
57
|
+
if (update?.update?.messageStubParameters) {
|
|
58
|
+
const params = update.update.messageStubParameters;
|
|
59
|
+
if (params.includes(463) || params.includes('463')) {
|
|
60
|
+
antiban.timelock.record463Error();
|
|
61
|
+
}
|
|
85
62
|
}
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Register known chats from incoming messages + handle reply suggestions
|
|
66
|
+
if (events['messages.upsert']) {
|
|
67
|
+
const { messages } = events['messages.upsert'];
|
|
68
|
+
for (const msg of messages || []) {
|
|
69
|
+
const jid = msg.key?.remoteJid;
|
|
70
|
+
if (!jid)
|
|
71
|
+
continue;
|
|
72
|
+
// Register known chat
|
|
73
|
+
antiban.timelock.registerKnownChat(jid);
|
|
74
|
+
// Skip self messages
|
|
75
|
+
const isSelf = msg.key?.fromMe || false;
|
|
76
|
+
if (isSelf)
|
|
77
|
+
continue;
|
|
78
|
+
// Extract message text
|
|
79
|
+
const msgText = msg.message?.conversation ||
|
|
80
|
+
msg.message?.extendedTextMessage?.text ||
|
|
81
|
+
msg.message?.imageMessage?.caption ||
|
|
82
|
+
msg.message?.videoMessage?.caption ||
|
|
83
|
+
'';
|
|
84
|
+
// Handle incoming message (updates reply ratio + contact graph)
|
|
85
|
+
const replySuggestion = antiban.onIncomingMessage(jid, msgText);
|
|
86
|
+
// Auto-respond if enabled and suggested
|
|
87
|
+
if (options.autoRespondToIncoming && replySuggestion.shouldReply && replySuggestion.suggestedText) {
|
|
88
|
+
// Random delay 3-15s
|
|
89
|
+
const replyDelay = Math.floor(Math.random() * 12000) + 3000;
|
|
90
|
+
setTimeout(async () => {
|
|
91
|
+
try {
|
|
92
|
+
await sock.sendMessage(jid, { text: replySuggestion.suggestedText });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// Silently fail — auto-reply is best-effort
|
|
96
|
+
}
|
|
97
|
+
}, replyDelay);
|
|
88
98
|
}
|
|
89
|
-
}
|
|
99
|
+
}
|
|
90
100
|
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Fallback to ev.on() for older Baileys versions
|
|
105
|
+
sock.ev.on('connection.update', (update) => {
|
|
106
|
+
if (update.connection === 'close') {
|
|
107
|
+
const reason = update.lastDisconnect?.error?.output?.statusCode || 'unknown';
|
|
108
|
+
antiban.onDisconnect(reason);
|
|
109
|
+
antiban.destroy(); // Clean up all timers
|
|
110
|
+
}
|
|
111
|
+
if (update.connection === 'open') {
|
|
112
|
+
antiban.onReconnect();
|
|
113
|
+
}
|
|
114
|
+
// Reachout timelock detection
|
|
115
|
+
if (update.reachoutTimeLock) {
|
|
116
|
+
antiban.timelock.onTimelockUpdate({
|
|
117
|
+
isActive: update.reachoutTimeLock.isActive,
|
|
118
|
+
timeEnforcementEnds: update.reachoutTimeLock.timeEnforcementEnds,
|
|
119
|
+
enforcementType: update.reachoutTimeLock.enforcementType,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
// Catch 463 errors from message updates
|
|
124
|
+
sock.ev.on('messages.update', (updates) => {
|
|
125
|
+
for (const update of updates) {
|
|
126
|
+
if (update?.update?.messageStubParameters) {
|
|
127
|
+
const params = update.update.messageStubParameters;
|
|
128
|
+
if (params.includes(463) || params.includes('463')) {
|
|
129
|
+
antiban.timelock.record463Error();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
// Register known chats from incoming messages + handle reply suggestions
|
|
135
|
+
sock.ev.on('messages.upsert', ({ messages }) => {
|
|
136
|
+
for (const msg of messages || []) {
|
|
137
|
+
const jid = msg.key?.remoteJid;
|
|
138
|
+
if (!jid)
|
|
139
|
+
continue;
|
|
140
|
+
// Register known chat
|
|
141
|
+
antiban.timelock.registerKnownChat(jid);
|
|
142
|
+
// Skip self messages
|
|
143
|
+
const isSelf = msg.key?.fromMe || false;
|
|
144
|
+
if (isSelf)
|
|
145
|
+
continue;
|
|
146
|
+
// Extract message text
|
|
147
|
+
const msgText = msg.message?.conversation ||
|
|
148
|
+
msg.message?.extendedTextMessage?.text ||
|
|
149
|
+
msg.message?.imageMessage?.caption ||
|
|
150
|
+
msg.message?.videoMessage?.caption ||
|
|
151
|
+
'';
|
|
152
|
+
// Handle incoming message (updates reply ratio + contact graph)
|
|
153
|
+
const replySuggestion = antiban.onIncomingMessage(jid, msgText);
|
|
154
|
+
// Auto-respond if enabled and suggested
|
|
155
|
+
if (options.autoRespondToIncoming && replySuggestion.shouldReply && replySuggestion.suggestedText) {
|
|
156
|
+
// Random delay 3-15s
|
|
157
|
+
const replyDelay = Math.floor(Math.random() * 12000) + 3000;
|
|
158
|
+
setTimeout(async () => {
|
|
159
|
+
try {
|
|
160
|
+
await sock.sendMessage(jid, { text: replySuggestion.suggestedText });
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
// Silently fail — auto-reply is best-effort
|
|
164
|
+
}
|
|
165
|
+
}, replyDelay);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
93
170
|
// Create proxy that intercepts sendMessage
|
|
94
171
|
const originalSendMessage = sock.sendMessage.bind(sock);
|
|
95
172
|
const wrappedSendMessage = async (jid, content, options) => {
|
package/package.json
CHANGED