baileys-antiban 3.6.1 → 3.7.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/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ 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
+ ## [3.7.0] - 2026-04-27
9
+
10
+ ### Added
11
+ - `LidResolver.learnFromGroupMetadata(participants)` — ingest LID↔PN mappings from Baileys group metadata. Supports v6 (`id: '@s.whatsapp.net', lid: '@lid'`) and v7 (`id: '@lid', phoneNumber: '@s.whatsapp.net'`) participant formats.
12
+ - `JidCanonicalizer.learnFromGroupMetadata(participants)` — passthrough to `LidResolver.learnFromGroupMetadata()`.
13
+
14
+ ### Fixed
15
+ - Confirmed compatibility with Baileys v7.0.0-rc.9 LID migration. `resolveCanonical()` correctly falls back to original JID when LID→PN mapping is unknown (no throw).
16
+
17
+ ### Notes
18
+ - Default `enabled: false` unchanged — opt-in as always.
19
+ - Group metadata learning is the recommended way to pre-populate LID mappings for auction groups where `getCachedGroupMetadata()` is called anyway.
20
+
8
21
  ## [3.6.1] - 2026-04-26
9
22
 
10
23
  ### Changed
@@ -80,6 +80,21 @@ export declare class JidCanonicalizer {
80
80
  messages: Array<any>;
81
81
  type?: string;
82
82
  }): void;
83
+ /**
84
+ * Learn LID↔PN mappings from group metadata participants.
85
+ * Call after fetchGroupMetadata() to pre-populate the resolver map.
86
+ * No-op if canonicalization is disabled.
87
+ *
88
+ * @param participants - Group metadata participants array from Baileys
89
+ * @returns Number of new mappings learned (0 if disabled)
90
+ */
91
+ learnFromGroupMetadata(participants: Array<{
92
+ id: string;
93
+ lid?: string;
94
+ phoneNumber?: string;
95
+ phone?: string;
96
+ number?: string;
97
+ }>): number;
83
98
  /**
84
99
  * Called by wrapper on messages.update event. Learns from sent-message refs.
85
100
  */
@@ -149,6 +149,20 @@ export class JidCanonicalizer {
149
149
  this.learnFromMessage(msg);
150
150
  }
151
151
  }
152
+ /**
153
+ * Learn LID↔PN mappings from group metadata participants.
154
+ * Call after fetchGroupMetadata() to pre-populate the resolver map.
155
+ * No-op if canonicalization is disabled.
156
+ *
157
+ * @param participants - Group metadata participants array from Baileys
158
+ * @returns Number of new mappings learned (0 if disabled)
159
+ */
160
+ learnFromGroupMetadata(participants) {
161
+ if (!this.config.enabled || !this.config.learnFromEvents) {
162
+ return 0;
163
+ }
164
+ return this.lidResolver.learnFromGroupMetadata(participants);
165
+ }
152
166
  /**
153
167
  * Called by wrapper on messages.update event. Learns from sent-message refs.
154
168
  */
@@ -71,6 +71,22 @@ export declare class LidResolver {
71
71
  * Full mapping for inspection
72
72
  */
73
73
  getMapping(jid: string): LidMapping | null;
74
+ /**
75
+ * Learn LID↔PN mappings from group metadata participants.
76
+ * Call this after fetchGroupMetadata() to pre-populate the map.
77
+ * Supports both {id: '@lid', phoneNumber: '@s.whatsapp.net'} and
78
+ * {id: '@s.whatsapp.net', lid: '@lid'} participant formats (v7 + v6 shapes).
79
+ *
80
+ * @param participants - Group metadata participants array from Baileys
81
+ * @returns Number of new mappings learned
82
+ */
83
+ learnFromGroupMetadata(participants: Array<{
84
+ id: string;
85
+ lid?: string;
86
+ phoneNumber?: string;
87
+ phone?: string;
88
+ number?: string;
89
+ }>): number;
74
90
  /**
75
91
  * Seed from persistence (called automatically in constructor if persistence provided)
76
92
  */
@@ -178,6 +178,38 @@ export class LidResolver {
178
178
  }
179
179
  return null;
180
180
  }
181
+ /**
182
+ * Learn LID↔PN mappings from group metadata participants.
183
+ * Call this after fetchGroupMetadata() to pre-populate the map.
184
+ * Supports both {id: '@lid', phoneNumber: '@s.whatsapp.net'} and
185
+ * {id: '@s.whatsapp.net', lid: '@lid'} participant formats (v7 + v6 shapes).
186
+ *
187
+ * @param participants - Group metadata participants array from Baileys
188
+ * @returns Number of new mappings learned
189
+ */
190
+ learnFromGroupMetadata(participants) {
191
+ let learned = 0;
192
+ for (const p of participants) {
193
+ const domain = p.id.split('@')[1] || '';
194
+ if (domain === 'lid' && (p.phoneNumber || p.phone || p.number)) {
195
+ const pn = p.phoneNumber || (p.phone ? `${p.phone}@s.whatsapp.net` : null) || (p.number ? `${p.number}@s.whatsapp.net` : null);
196
+ if (pn) {
197
+ const prevSize = this.lidToPn.size;
198
+ this.learn({ lid: p.id, pn });
199
+ if (this.lidToPn.size > prevSize)
200
+ learned++;
201
+ }
202
+ }
203
+ else if (domain === 's.whatsapp.net' && p.lid) {
204
+ const lid = p.lid.endsWith('@lid') ? p.lid : `${p.lid}@lid`;
205
+ const prevSize = this.lidToPn.size;
206
+ this.learn({ lid, pn: p.id });
207
+ if (this.lidToPn.size > prevSize)
208
+ learned++;
209
+ }
210
+ }
211
+ return learned;
212
+ }
181
213
  /**
182
214
  * Seed from persistence (called automatically in constructor if persistence provided)
183
215
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baileys-antiban",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "Anti-ban middleware for Baileys WhatsApp bots. Rate limiting, warmup, health monitor, LID resolver, disconnect classifier. Free Whapi.Cloud alternative.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",