baileys-antiban 4.8.0 → 4.10.0
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/dist/antiban.d.ts +21 -0
- package/dist/antiban.js +89 -0
- package/dist/cjs/antiban.js +89 -0
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/reputationVoucher.js +377 -0
- package/dist/cjs/stateExport.js +16 -0
- package/dist/cjs/topologyThrottler.js +343 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/reputationVoucher.d.ts +171 -0
- package/dist/reputationVoucher.js +373 -0
- package/dist/stateExport.d.ts +18 -0
- package/dist/stateExport.js +16 -0
- package/dist/topologyThrottler.d.ts +130 -0
- package/dist/topologyThrottler.js +339 -0
- package/package.json +1 -1
package/dist/antiban.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { ReplyRatioGuard, type ReplyRatioConfig, type ReplyRatioStats } from './
|
|
|
21
21
|
import { ContactGraphWarmer, type ContactGraphConfig, type ContactGraphStats } from './contactGraph.js';
|
|
22
22
|
import { PresenceChoreographer, type PresenceChoreographerConfig, type PresenceChoreographerStats } from './presenceChoreographer.js';
|
|
23
23
|
import { RetryReasonTracker, type RetryTrackerConfig, type RetryStats } from './retryTracker.js';
|
|
24
|
+
import { TopologyThrottler, type TopologyThrottlerConfig } from './topologyThrottler.js';
|
|
24
25
|
import { PostReconnectThrottle, type ReconnectThrottleConfig, type ReconnectThrottleStats } from './reconnectThrottle.js';
|
|
25
26
|
import { LidResolver, type LidResolverConfig, type LidResolverStats } from './lidResolver.js';
|
|
26
27
|
import { JidCanonicalizer, type JidCanonicalizerConfig, type JidCanonicalizerStats } from './jidCanonicalizer.js';
|
|
@@ -31,6 +32,7 @@ import { type DeliveryTrackerStats } from './deliveryTracker.js';
|
|
|
31
32
|
import { type InstanceCoordinatorStats } from './instanceCoordinator.js';
|
|
32
33
|
import { MessageTypeRegistry } from './messageTypeRegistry.js';
|
|
33
34
|
import { type AntibanSnapshot } from './stateExport.js';
|
|
35
|
+
import { ReputationVoucher } from './reputationVoucher.js';
|
|
34
36
|
export interface AntiBanConfigLegacy {
|
|
35
37
|
rateLimiter?: Partial<RateLimiterConfig>;
|
|
36
38
|
warmUp?: Partial<WarmUpConfig>;
|
|
@@ -41,6 +43,7 @@ export interface AntiBanConfigLegacy {
|
|
|
41
43
|
presence?: Partial<PresenceChoreographerConfig>;
|
|
42
44
|
retryTracker?: Partial<RetryTrackerConfig>;
|
|
43
45
|
reconnectThrottle?: Partial<ReconnectThrottleConfig>;
|
|
46
|
+
topologyThrottler?: Partial<TopologyThrottlerConfig>;
|
|
44
47
|
lidResolver?: LidResolverConfig;
|
|
45
48
|
jidCanonicalizer?: JidCanonicalizerConfig;
|
|
46
49
|
sessionStability?: {
|
|
@@ -72,6 +75,16 @@ export interface AntiBanStats {
|
|
|
72
75
|
presence?: PresenceChoreographerStats;
|
|
73
76
|
retryTracker?: RetryStats | null;
|
|
74
77
|
reconnectThrottle?: ReconnectThrottleStats | null;
|
|
78
|
+
topologyThrottler?: {
|
|
79
|
+
newContactsThisHour: number;
|
|
80
|
+
newContactsToday: number;
|
|
81
|
+
replyRatio: number | null;
|
|
82
|
+
blockedRatio: number | null;
|
|
83
|
+
hotspots: Array<{
|
|
84
|
+
sourceGroup: string;
|
|
85
|
+
count: number;
|
|
86
|
+
}>;
|
|
87
|
+
} | null;
|
|
75
88
|
lidResolver?: LidResolverStats | null;
|
|
76
89
|
jidCanonicalizer?: JidCanonicalizerStats | null;
|
|
77
90
|
sessionStability?: SessionHealthStats | null;
|
|
@@ -93,6 +106,7 @@ export declare class AntiBan {
|
|
|
93
106
|
private presenceChoreographer;
|
|
94
107
|
private retryTrackerModule;
|
|
95
108
|
private reconnectThrottleModule;
|
|
109
|
+
private topologyThrottlerModule;
|
|
96
110
|
private lidResolverModule;
|
|
97
111
|
private jidCanonicalizerModule;
|
|
98
112
|
private sessionStabilityMonitor;
|
|
@@ -103,6 +117,8 @@ export declare class AntiBan {
|
|
|
103
117
|
private stateManager;
|
|
104
118
|
private resolvedConfig;
|
|
105
119
|
private logging;
|
|
120
|
+
/** Optional reputation voucher (standalone — caller manages separate voucher sockets) */
|
|
121
|
+
reputationVoucher?: ReputationVoucher;
|
|
106
122
|
private stats;
|
|
107
123
|
constructor(input?: AntiBanInput | AntiBanConfigLegacy, warmUpStateArg?: WarmUpState);
|
|
108
124
|
/**
|
|
@@ -160,6 +176,10 @@ export declare class AntiBan {
|
|
|
160
176
|
get retryTracker(): RetryReasonTracker;
|
|
161
177
|
/** Get the reconnect throttle for direct access */
|
|
162
178
|
get reconnectThrottle(): PostReconnectThrottle;
|
|
179
|
+
/** Get the topology throttler for direct access */
|
|
180
|
+
get topologyThrottler(): TopologyThrottler | null;
|
|
181
|
+
/** Get the topology throttler for direct access (alias) */
|
|
182
|
+
get topology(): TopologyThrottler | null;
|
|
163
183
|
/** Get the LID resolver for direct access */
|
|
164
184
|
get lidResolver(): LidResolver | null;
|
|
165
185
|
/** Get the JID canonicalizer for direct access */
|
|
@@ -186,6 +206,7 @@ export declare class AntiBan {
|
|
|
186
206
|
* Reset everything (use after a ban period)
|
|
187
207
|
*/
|
|
188
208
|
reset(): void;
|
|
209
|
+
private isGroupJid;
|
|
189
210
|
private runAdaptiveCheck;
|
|
190
211
|
private persistStateDebounced;
|
|
191
212
|
private persistStateImmediate;
|
package/dist/antiban.js
CHANGED
|
@@ -21,6 +21,7 @@ import { ReplyRatioGuard } from './replyRatio.js';
|
|
|
21
21
|
import { ContactGraphWarmer } from './contactGraph.js';
|
|
22
22
|
import { PresenceChoreographer } from './presenceChoreographer.js';
|
|
23
23
|
import { RetryReasonTracker } from './retryTracker.js';
|
|
24
|
+
import { TopologyThrottler } from './topologyThrottler.js';
|
|
24
25
|
import { PostReconnectThrottle } from './reconnectThrottle.js';
|
|
25
26
|
import { LidResolver } from './lidResolver.js';
|
|
26
27
|
import { JidCanonicalizer } from './jidCanonicalizer.js';
|
|
@@ -105,6 +106,7 @@ export class AntiBan {
|
|
|
105
106
|
presenceChoreographer;
|
|
106
107
|
retryTrackerModule;
|
|
107
108
|
reconnectThrottleModule;
|
|
109
|
+
topologyThrottlerModule = null;
|
|
108
110
|
lidResolverModule = null;
|
|
109
111
|
jidCanonicalizerModule = null;
|
|
110
112
|
sessionStabilityMonitor = null;
|
|
@@ -115,6 +117,8 @@ export class AntiBan {
|
|
|
115
117
|
stateManager = null;
|
|
116
118
|
resolvedConfig;
|
|
117
119
|
logging;
|
|
120
|
+
/** Optional reputation voucher (standalone — caller manages separate voucher sockets) */
|
|
121
|
+
reputationVoucher;
|
|
118
122
|
stats = {
|
|
119
123
|
messagesAllowed: 0,
|
|
120
124
|
messagesBlocked: 0,
|
|
@@ -246,6 +250,13 @@ export class AntiBan {
|
|
|
246
250
|
...(legacyPassthrough?.reconnectThrottle || {}),
|
|
247
251
|
baselineRatePerMinute: () => this.rateLimiter.getStats().limits.perMinute,
|
|
248
252
|
});
|
|
253
|
+
// Initialize topology throttler if configured
|
|
254
|
+
if (legacyPassthrough?.topologyThrottler) {
|
|
255
|
+
this.topologyThrottlerModule = new TopologyThrottler(legacyPassthrough.topologyThrottler);
|
|
256
|
+
if (this.logging) {
|
|
257
|
+
console.log(`[baileys-antiban] 🌐 Topology throttler enabled — max ${legacyPassthrough.topologyThrottler.maxNewContactsPerHour || 5}/hr, ${legacyPassthrough.topologyThrottler.maxNewContactsPerDay || 20}/day new contacts`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
249
260
|
// Initialize LID resolver and canonicalizer if configured
|
|
250
261
|
// If jidCanonicalizer is enabled but no resolver provided, create standalone resolver
|
|
251
262
|
if (legacyPassthrough?.jidCanonicalizer?.enabled) {
|
|
@@ -381,6 +392,46 @@ export class AntiBan {
|
|
|
381
392
|
health: healthStatus,
|
|
382
393
|
};
|
|
383
394
|
}
|
|
395
|
+
// Topology throttler check — only applies to DMs to new/unknown contacts
|
|
396
|
+
if (this.topologyThrottlerModule && !this.isGroupJid(recipient)) {
|
|
397
|
+
const knownChats = this.rateLimiter.getKnownChats();
|
|
398
|
+
const isNewContact = !knownChats.has(recipient);
|
|
399
|
+
if (isNewContact) {
|
|
400
|
+
// Check if we can send to new contact based on topology limits
|
|
401
|
+
const topologyDecision = this.topologyThrottlerModule.canSendToNewContact();
|
|
402
|
+
if (!topologyDecision.allowed) {
|
|
403
|
+
this.stats.messagesBlocked++;
|
|
404
|
+
if (this.logging) {
|
|
405
|
+
console.log(`[baileys-antiban] 🌐 BLOCKED — topology: ${topologyDecision.reason}`);
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
allowed: false,
|
|
409
|
+
delayMs: topologyDecision.retryAfterMs || 0,
|
|
410
|
+
reason: `Topology: ${topologyDecision.reason}`,
|
|
411
|
+
health: healthStatus,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
// Assess contact risk
|
|
415
|
+
const riskAssessment = this.topologyThrottlerModule.assessContact(recipient, {
|
|
416
|
+
messageType: 'dm',
|
|
417
|
+
hasReplied: false,
|
|
418
|
+
knownGroups: [],
|
|
419
|
+
});
|
|
420
|
+
if (riskAssessment.recommendation === 'abort') {
|
|
421
|
+
this.stats.messagesBlocked++;
|
|
422
|
+
if (this.logging) {
|
|
423
|
+
console.log(`[baileys-antiban] ⛔ BLOCKED — contact risk ${riskAssessment.risk} (score ${riskAssessment.score}): ${riskAssessment.reasons.join(', ')}`);
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
allowed: false,
|
|
427
|
+
delayMs: 0,
|
|
428
|
+
reason: `Contact risk too high: ${riskAssessment.reasons.join(', ')}`,
|
|
429
|
+
health: healthStatus,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
// If delay recommended, we'll add it to the total delay later
|
|
433
|
+
}
|
|
434
|
+
}
|
|
384
435
|
// Reply ratio check
|
|
385
436
|
const replyRatioDecision = this.replyRatioGuard.beforeSend(recipient);
|
|
386
437
|
if (!replyRatioDecision.allowed) {
|
|
@@ -482,6 +533,24 @@ export class AntiBan {
|
|
|
482
533
|
}
|
|
483
534
|
}
|
|
484
535
|
}
|
|
536
|
+
// Topology throttler recommended delay
|
|
537
|
+
if (this.topologyThrottlerModule && !this.isGroupJid(recipient)) {
|
|
538
|
+
const knownChats = this.rateLimiter.getKnownChats();
|
|
539
|
+
const isNewContact = !knownChats.has(recipient);
|
|
540
|
+
if (isNewContact) {
|
|
541
|
+
const riskAssessment = this.topologyThrottlerModule.assessContact(recipient, {
|
|
542
|
+
messageType: 'dm',
|
|
543
|
+
hasReplied: false,
|
|
544
|
+
knownGroups: [],
|
|
545
|
+
});
|
|
546
|
+
if (riskAssessment.recommendation === 'delay' && riskAssessment.suggestedDelayMs) {
|
|
547
|
+
delay += riskAssessment.suggestedDelayMs;
|
|
548
|
+
if (this.logging) {
|
|
549
|
+
console.log(`[baileys-antiban] ⚠️ Topology risk ${riskAssessment.risk} — adding ${Math.floor(riskAssessment.suggestedDelayMs / 60000)}min delay`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
485
554
|
// Roll for distraction pause
|
|
486
555
|
const distractionCheck = this.presenceChoreographer.shouldPauseForDistraction();
|
|
487
556
|
if (distractionCheck.pause) {
|
|
@@ -513,6 +582,7 @@ export class AntiBan {
|
|
|
513
582
|
this.rateLimiter.record(recipient, content);
|
|
514
583
|
this.warmUp.record();
|
|
515
584
|
this.replyRatioGuard.recordSent(recipient);
|
|
585
|
+
this.topologyThrottlerModule?.recordSent(recipient);
|
|
516
586
|
this.stats.messagesAllowed++;
|
|
517
587
|
if (msgId) {
|
|
518
588
|
this.deliveryTracker.onMessageSent(msgId);
|
|
@@ -552,6 +622,7 @@ export class AntiBan {
|
|
|
552
622
|
onIncomingMessage(jid, msgText) {
|
|
553
623
|
this.replyRatioGuard.recordReceived(jid);
|
|
554
624
|
this.contactGraphWarmer.onIncomingMessage(jid);
|
|
625
|
+
this.topologyThrottlerModule?.recordReplied(jid);
|
|
555
626
|
return this.replyRatioGuard.suggestReply(jid, msgText);
|
|
556
627
|
}
|
|
557
628
|
/**
|
|
@@ -595,6 +666,9 @@ export class AntiBan {
|
|
|
595
666
|
if (this.reconnectThrottleModule['config']?.enabled) {
|
|
596
667
|
stats.reconnectThrottle = this.reconnectThrottleModule.getStats();
|
|
597
668
|
}
|
|
669
|
+
if (this.topologyThrottlerModule) {
|
|
670
|
+
stats.topologyThrottler = this.topologyThrottlerModule.getTopologyStats();
|
|
671
|
+
}
|
|
598
672
|
if (this.lidResolverModule) {
|
|
599
673
|
stats.lidResolver = this.lidResolverModule.getStats();
|
|
600
674
|
}
|
|
@@ -640,6 +714,14 @@ export class AntiBan {
|
|
|
640
714
|
get reconnectThrottle() {
|
|
641
715
|
return this.reconnectThrottleModule;
|
|
642
716
|
}
|
|
717
|
+
/** Get the topology throttler for direct access */
|
|
718
|
+
get topologyThrottler() {
|
|
719
|
+
return this.topologyThrottlerModule;
|
|
720
|
+
}
|
|
721
|
+
/** Get the topology throttler for direct access (alias) */
|
|
722
|
+
get topology() {
|
|
723
|
+
return this.topologyThrottlerModule;
|
|
724
|
+
}
|
|
643
725
|
/** Get the LID resolver for direct access */
|
|
644
726
|
get lidResolver() {
|
|
645
727
|
return this.lidResolverModule;
|
|
@@ -701,6 +783,9 @@ export class AntiBan {
|
|
|
701
783
|
console.log('[baileys-antiban] 🔄 Reset — starting fresh warm-up');
|
|
702
784
|
}
|
|
703
785
|
}
|
|
786
|
+
isGroupJid(jid) {
|
|
787
|
+
return jid.endsWith('@g.us') || jid.endsWith('@newsletter');
|
|
788
|
+
}
|
|
704
789
|
runAdaptiveCheck() {
|
|
705
790
|
const delivery = this.deliveryTracker.getStats();
|
|
706
791
|
// Need min sample to be meaningful
|
|
@@ -763,6 +848,8 @@ export class AntiBan {
|
|
|
763
848
|
rateLimiter: this.rateLimiter,
|
|
764
849
|
timelockGuard: this.timelockGuard,
|
|
765
850
|
messageRegistry: this.messageTypeRegistry || undefined,
|
|
851
|
+
topologyThrottler: this.topologyThrottlerModule || undefined,
|
|
852
|
+
reputationVoucher: this.reputationVoucher || undefined,
|
|
766
853
|
instanceId: this.resolvedConfig.instanceId,
|
|
767
854
|
});
|
|
768
855
|
}
|
|
@@ -777,6 +864,8 @@ export class AntiBan {
|
|
|
777
864
|
rateLimiter: this.rateLimiter,
|
|
778
865
|
timelockGuard: this.timelockGuard,
|
|
779
866
|
messageRegistry: this.messageTypeRegistry || undefined,
|
|
867
|
+
topologyThrottler: this.topologyThrottlerModule || undefined,
|
|
868
|
+
reputationVoucher: this.reputationVoucher || undefined,
|
|
780
869
|
});
|
|
781
870
|
}
|
|
782
871
|
/**
|
package/dist/cjs/antiban.js
CHANGED
|
@@ -24,6 +24,7 @@ const replyRatio_js_1 = require("./replyRatio.js");
|
|
|
24
24
|
const contactGraph_js_1 = require("./contactGraph.js");
|
|
25
25
|
const presenceChoreographer_js_1 = require("./presenceChoreographer.js");
|
|
26
26
|
const retryTracker_js_1 = require("./retryTracker.js");
|
|
27
|
+
const topologyThrottler_js_1 = require("./topologyThrottler.js");
|
|
27
28
|
const reconnectThrottle_js_1 = require("./reconnectThrottle.js");
|
|
28
29
|
const lidResolver_js_1 = require("./lidResolver.js");
|
|
29
30
|
const jidCanonicalizer_js_1 = require("./jidCanonicalizer.js");
|
|
@@ -108,6 +109,7 @@ class AntiBan {
|
|
|
108
109
|
presenceChoreographer;
|
|
109
110
|
retryTrackerModule;
|
|
110
111
|
reconnectThrottleModule;
|
|
112
|
+
topologyThrottlerModule = null;
|
|
111
113
|
lidResolverModule = null;
|
|
112
114
|
jidCanonicalizerModule = null;
|
|
113
115
|
sessionStabilityMonitor = null;
|
|
@@ -118,6 +120,8 @@ class AntiBan {
|
|
|
118
120
|
stateManager = null;
|
|
119
121
|
resolvedConfig;
|
|
120
122
|
logging;
|
|
123
|
+
/** Optional reputation voucher (standalone — caller manages separate voucher sockets) */
|
|
124
|
+
reputationVoucher;
|
|
121
125
|
stats = {
|
|
122
126
|
messagesAllowed: 0,
|
|
123
127
|
messagesBlocked: 0,
|
|
@@ -249,6 +253,13 @@ class AntiBan {
|
|
|
249
253
|
...(legacyPassthrough?.reconnectThrottle || {}),
|
|
250
254
|
baselineRatePerMinute: () => this.rateLimiter.getStats().limits.perMinute,
|
|
251
255
|
});
|
|
256
|
+
// Initialize topology throttler if configured
|
|
257
|
+
if (legacyPassthrough?.topologyThrottler) {
|
|
258
|
+
this.topologyThrottlerModule = new topologyThrottler_js_1.TopologyThrottler(legacyPassthrough.topologyThrottler);
|
|
259
|
+
if (this.logging) {
|
|
260
|
+
console.log(`[baileys-antiban] 🌐 Topology throttler enabled — max ${legacyPassthrough.topologyThrottler.maxNewContactsPerHour || 5}/hr, ${legacyPassthrough.topologyThrottler.maxNewContactsPerDay || 20}/day new contacts`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
252
263
|
// Initialize LID resolver and canonicalizer if configured
|
|
253
264
|
// If jidCanonicalizer is enabled but no resolver provided, create standalone resolver
|
|
254
265
|
if (legacyPassthrough?.jidCanonicalizer?.enabled) {
|
|
@@ -384,6 +395,46 @@ class AntiBan {
|
|
|
384
395
|
health: healthStatus,
|
|
385
396
|
};
|
|
386
397
|
}
|
|
398
|
+
// Topology throttler check — only applies to DMs to new/unknown contacts
|
|
399
|
+
if (this.topologyThrottlerModule && !this.isGroupJid(recipient)) {
|
|
400
|
+
const knownChats = this.rateLimiter.getKnownChats();
|
|
401
|
+
const isNewContact = !knownChats.has(recipient);
|
|
402
|
+
if (isNewContact) {
|
|
403
|
+
// Check if we can send to new contact based on topology limits
|
|
404
|
+
const topologyDecision = this.topologyThrottlerModule.canSendToNewContact();
|
|
405
|
+
if (!topologyDecision.allowed) {
|
|
406
|
+
this.stats.messagesBlocked++;
|
|
407
|
+
if (this.logging) {
|
|
408
|
+
console.log(`[baileys-antiban] 🌐 BLOCKED — topology: ${topologyDecision.reason}`);
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
allowed: false,
|
|
412
|
+
delayMs: topologyDecision.retryAfterMs || 0,
|
|
413
|
+
reason: `Topology: ${topologyDecision.reason}`,
|
|
414
|
+
health: healthStatus,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
// Assess contact risk
|
|
418
|
+
const riskAssessment = this.topologyThrottlerModule.assessContact(recipient, {
|
|
419
|
+
messageType: 'dm',
|
|
420
|
+
hasReplied: false,
|
|
421
|
+
knownGroups: [],
|
|
422
|
+
});
|
|
423
|
+
if (riskAssessment.recommendation === 'abort') {
|
|
424
|
+
this.stats.messagesBlocked++;
|
|
425
|
+
if (this.logging) {
|
|
426
|
+
console.log(`[baileys-antiban] ⛔ BLOCKED — contact risk ${riskAssessment.risk} (score ${riskAssessment.score}): ${riskAssessment.reasons.join(', ')}`);
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
allowed: false,
|
|
430
|
+
delayMs: 0,
|
|
431
|
+
reason: `Contact risk too high: ${riskAssessment.reasons.join(', ')}`,
|
|
432
|
+
health: healthStatus,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
// If delay recommended, we'll add it to the total delay later
|
|
436
|
+
}
|
|
437
|
+
}
|
|
387
438
|
// Reply ratio check
|
|
388
439
|
const replyRatioDecision = this.replyRatioGuard.beforeSend(recipient);
|
|
389
440
|
if (!replyRatioDecision.allowed) {
|
|
@@ -485,6 +536,24 @@ class AntiBan {
|
|
|
485
536
|
}
|
|
486
537
|
}
|
|
487
538
|
}
|
|
539
|
+
// Topology throttler recommended delay
|
|
540
|
+
if (this.topologyThrottlerModule && !this.isGroupJid(recipient)) {
|
|
541
|
+
const knownChats = this.rateLimiter.getKnownChats();
|
|
542
|
+
const isNewContact = !knownChats.has(recipient);
|
|
543
|
+
if (isNewContact) {
|
|
544
|
+
const riskAssessment = this.topologyThrottlerModule.assessContact(recipient, {
|
|
545
|
+
messageType: 'dm',
|
|
546
|
+
hasReplied: false,
|
|
547
|
+
knownGroups: [],
|
|
548
|
+
});
|
|
549
|
+
if (riskAssessment.recommendation === 'delay' && riskAssessment.suggestedDelayMs) {
|
|
550
|
+
delay += riskAssessment.suggestedDelayMs;
|
|
551
|
+
if (this.logging) {
|
|
552
|
+
console.log(`[baileys-antiban] ⚠️ Topology risk ${riskAssessment.risk} — adding ${Math.floor(riskAssessment.suggestedDelayMs / 60000)}min delay`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
488
557
|
// Roll for distraction pause
|
|
489
558
|
const distractionCheck = this.presenceChoreographer.shouldPauseForDistraction();
|
|
490
559
|
if (distractionCheck.pause) {
|
|
@@ -516,6 +585,7 @@ class AntiBan {
|
|
|
516
585
|
this.rateLimiter.record(recipient, content);
|
|
517
586
|
this.warmUp.record();
|
|
518
587
|
this.replyRatioGuard.recordSent(recipient);
|
|
588
|
+
this.topologyThrottlerModule?.recordSent(recipient);
|
|
519
589
|
this.stats.messagesAllowed++;
|
|
520
590
|
if (msgId) {
|
|
521
591
|
this.deliveryTracker.onMessageSent(msgId);
|
|
@@ -555,6 +625,7 @@ class AntiBan {
|
|
|
555
625
|
onIncomingMessage(jid, msgText) {
|
|
556
626
|
this.replyRatioGuard.recordReceived(jid);
|
|
557
627
|
this.contactGraphWarmer.onIncomingMessage(jid);
|
|
628
|
+
this.topologyThrottlerModule?.recordReplied(jid);
|
|
558
629
|
return this.replyRatioGuard.suggestReply(jid, msgText);
|
|
559
630
|
}
|
|
560
631
|
/**
|
|
@@ -598,6 +669,9 @@ class AntiBan {
|
|
|
598
669
|
if (this.reconnectThrottleModule['config']?.enabled) {
|
|
599
670
|
stats.reconnectThrottle = this.reconnectThrottleModule.getStats();
|
|
600
671
|
}
|
|
672
|
+
if (this.topologyThrottlerModule) {
|
|
673
|
+
stats.topologyThrottler = this.topologyThrottlerModule.getTopologyStats();
|
|
674
|
+
}
|
|
601
675
|
if (this.lidResolverModule) {
|
|
602
676
|
stats.lidResolver = this.lidResolverModule.getStats();
|
|
603
677
|
}
|
|
@@ -643,6 +717,14 @@ class AntiBan {
|
|
|
643
717
|
get reconnectThrottle() {
|
|
644
718
|
return this.reconnectThrottleModule;
|
|
645
719
|
}
|
|
720
|
+
/** Get the topology throttler for direct access */
|
|
721
|
+
get topologyThrottler() {
|
|
722
|
+
return this.topologyThrottlerModule;
|
|
723
|
+
}
|
|
724
|
+
/** Get the topology throttler for direct access (alias) */
|
|
725
|
+
get topology() {
|
|
726
|
+
return this.topologyThrottlerModule;
|
|
727
|
+
}
|
|
646
728
|
/** Get the LID resolver for direct access */
|
|
647
729
|
get lidResolver() {
|
|
648
730
|
return this.lidResolverModule;
|
|
@@ -704,6 +786,9 @@ class AntiBan {
|
|
|
704
786
|
console.log('[baileys-antiban] 🔄 Reset — starting fresh warm-up');
|
|
705
787
|
}
|
|
706
788
|
}
|
|
789
|
+
isGroupJid(jid) {
|
|
790
|
+
return jid.endsWith('@g.us') || jid.endsWith('@newsletter');
|
|
791
|
+
}
|
|
707
792
|
runAdaptiveCheck() {
|
|
708
793
|
const delivery = this.deliveryTracker.getStats();
|
|
709
794
|
// Need min sample to be meaningful
|
|
@@ -766,6 +851,8 @@ class AntiBan {
|
|
|
766
851
|
rateLimiter: this.rateLimiter,
|
|
767
852
|
timelockGuard: this.timelockGuard,
|
|
768
853
|
messageRegistry: this.messageTypeRegistry || undefined,
|
|
854
|
+
topologyThrottler: this.topologyThrottlerModule || undefined,
|
|
855
|
+
reputationVoucher: this.reputationVoucher || undefined,
|
|
769
856
|
instanceId: this.resolvedConfig.instanceId,
|
|
770
857
|
});
|
|
771
858
|
}
|
|
@@ -780,6 +867,8 @@ class AntiBan {
|
|
|
780
867
|
rateLimiter: this.rateLimiter,
|
|
781
868
|
timelockGuard: this.timelockGuard,
|
|
782
869
|
messageRegistry: this.messageTypeRegistry || undefined,
|
|
870
|
+
topologyThrottler: this.topologyThrottlerModule || undefined,
|
|
871
|
+
reputationVoucher: this.reputationVoucher || undefined,
|
|
783
872
|
});
|
|
784
873
|
}
|
|
785
874
|
/**
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getRetryJitter = exports.getTypingJitter = exports.getMessageSendJitter = exports.applySessionFingerprint = exports.generateSessionFingerprint = exports.proxyRotator = exports.readReceiptVariance = exports.credsSnapshot = exports.applyFingerprint = exports.generateFingerprint = exports.messageRecovery = exports.applyGroupMultiplier = exports.shouldUseGroupProfile = exports.isBroadcast = exports.isNewsletter = exports.isGroup = exports.StateManager = exports.PRESETS = exports.resolveConfig = exports.FileStateAdapter = exports.Scheduler = exports.WebhookAlerts = exports.ContentVariator = exports.MessageQueue = exports.wrapSocketWithFingerprint = exports.wrapSocket = exports.getRetryReasonDescription = exports.isMacError = exports.parseRetryReason = exports.MAC_ERROR_CODES = exports.MessageRetryReason = exports.createLidFirstResolver = exports.LidFirstResolver = exports.DeafSessionDetector = exports.classifyDisconnect = exports.wrapWithSessionStability = exports.SessionHealthMonitor = exports.JidCanonicalizer = exports.LidResolver = exports.PostReconnectThrottle = exports.RetryReasonTracker = exports.getCircadianMultiplier = exports.PresenceChoreographer = exports.ContactGraphWarmer = exports.ReplyRatioGuard = exports.TimelockGuard = exports.HealthMonitor = exports.WarmUp = exports.RateLimiter = exports.AntiBan = void 0;
|
|
13
|
-
exports.createPeriodicExporter = exports.createMetricsHandler = exports.exportPrometheusMetrics = exports.createConsoleLogger = exports.importAntibanState = exports.exportAntibanState = exports.MessageTypeRegistry = exports.createHumanEntropyService = exports.HumanEntropyService = exports.createInMemoryEventStoreBackend = exports.createMySQLEventStoreBackend = exports.createFleetEventStore = exports.createJidCircuitBreaker = exports.JidCircuitBreaker = exports.InstanceCoordinator = exports.DeliveryTracker = exports.BanRecoveryOrchestrator = exports.LegitimacySignalInjector = exports.GROUP_OP_ERRORS = exports.extractPrivacyBlock = exports.classifyGroupOpError = exports.GroupOperationGuard = exports.AbortError = exports.STEALTH_BROWSER_POOL = exports.rampPresenceAfterConnect = exports.getStealthSocketConfig = exports.createStealthFingerprint = exports.getBatteryState = exports.getVoiceNoteMetadata = void 0;
|
|
13
|
+
exports.createPeriodicExporter = exports.createMetricsHandler = exports.exportPrometheusMetrics = exports.createConsoleLogger = exports.ReputationVoucher = exports.TopologyThrottler = exports.importAntibanState = exports.exportAntibanState = exports.MessageTypeRegistry = exports.createHumanEntropyService = exports.HumanEntropyService = exports.createInMemoryEventStoreBackend = exports.createMySQLEventStoreBackend = exports.createFleetEventStore = exports.createJidCircuitBreaker = exports.JidCircuitBreaker = exports.InstanceCoordinator = exports.DeliveryTracker = exports.BanRecoveryOrchestrator = exports.LegitimacySignalInjector = exports.GROUP_OP_ERRORS = exports.extractPrivacyBlock = exports.classifyGroupOpError = exports.GroupOperationGuard = exports.AbortError = exports.STEALTH_BROWSER_POOL = exports.rampPresenceAfterConnect = exports.getStealthSocketConfig = exports.createStealthFingerprint = exports.getBatteryState = exports.getVoiceNoteMetadata = void 0;
|
|
14
14
|
// Core
|
|
15
15
|
var antiban_js_1 = require("./antiban.js");
|
|
16
16
|
Object.defineProperty(exports, "AntiBan", { enumerable: true, get: function () { return antiban_js_1.AntiBan; } });
|
|
@@ -149,6 +149,11 @@ Object.defineProperty(exports, "MessageTypeRegistry", { enumerable: true, get: f
|
|
|
149
149
|
var stateExport_js_1 = require("./stateExport.js");
|
|
150
150
|
Object.defineProperty(exports, "exportAntibanState", { enumerable: true, get: function () { return stateExport_js_1.exportAntibanState; } });
|
|
151
151
|
Object.defineProperty(exports, "importAntibanState", { enumerable: true, get: function () { return stateExport_js_1.importAntibanState; } });
|
|
152
|
+
var topologyThrottler_js_1 = require("./topologyThrottler.js");
|
|
153
|
+
Object.defineProperty(exports, "TopologyThrottler", { enumerable: true, get: function () { return topologyThrottler_js_1.TopologyThrottler; } });
|
|
154
|
+
// v4.9 new modules
|
|
155
|
+
var reputationVoucher_js_1 = require("./reputationVoucher.js");
|
|
156
|
+
Object.defineProperty(exports, "ReputationVoucher", { enumerable: true, get: function () { return reputationVoucher_js_1.ReputationVoucher; } });
|
|
152
157
|
// Observability
|
|
153
158
|
var observability_js_1 = require("./observability.js");
|
|
154
159
|
Object.defineProperty(exports, "createConsoleLogger", { enumerable: true, get: function () { return observability_js_1.createConsoleLogger; } });
|