innovators-bot2 1.1.6 → 1.1.7

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.
@@ -0,0 +1,333 @@
1
+ # Baileys v7.x.x LID Store Implementation Guide
2
+
3
+ ## Overview
4
+
5
+ This guide explains how to properly implement and use the LID (Local Identifier) store functionality in Baileys v7.x.x, based on the official [migration guide](https://baileys.wiki/docs/migration/to-v7.0.0/).
6
+
7
+ ## What are LIDs?
8
+
9
+ **LID (Local Identifier)** is WhatsApp's privacy feature that replaces phone numbers in large groups. Key points:
10
+
11
+ - **Unique per user** (not per group)
12
+ - Ensures user anonymity in large groups
13
+ - Allows messaging users via either LID or PN (Phone Number)
14
+ - Part of WhatsApp's transition to username system (@username)
15
+
16
+ ### JID Format Changes
17
+
18
+ - **PN (Phone Number)**: `1234567890@s.whatsapp.net` (traditional format)
19
+ - **LID**: `123456@lid` (new format)
20
+
21
+ ## Store Implementation
22
+
23
+ ### 1. Accessing the Store
24
+
25
+ The store is initialized automatically when you create a socket and is accessible via:
26
+
27
+ ```javascript
28
+ const store = sock.signalRepository.lidMapping;
29
+ ```
30
+
31
+ ### 2. Available Methods
32
+
33
+ ```javascript
34
+ // Get LID from Phone Number
35
+ const lid = await store.getLIDForPN('1234567890@s.whatsapp.net');
36
+
37
+ // Get Phone Number from LID
38
+ const pn = await store.getPNForLID('123456@lid');
39
+
40
+ // Get multiple LIDs from multiple PNs
41
+ const lids = await store.getLIDsForPNs([
42
+ '1234567890@s.whatsapp.net',
43
+ '0987654321@s.whatsapp.net'
44
+ ]);
45
+
46
+ // Store a single mapping (usually automatic)
47
+ await store.storeLIDPNMapping('1234567890@s.whatsapp.net', '123456@lid');
48
+
49
+ // Store multiple mappings (usually automatic)
50
+ await store.storeLIDPNMappings({
51
+ '1234567890@s.whatsapp.net': '123456@lid',
52
+ '0987654321@s.whatsapp.net': '654321@lid'
53
+ });
54
+ ```
55
+
56
+ ## Implementation in Code
57
+
58
+ ### 1. Socket Initialization
59
+
60
+ ```javascript
61
+ const { makeWASocket, useMultiFileAuthState } = require('@itsukichan/baileys');
62
+
63
+ const { state, saveCreds } = await useMultiFileAuthState('auth_session');
64
+
65
+ const sock = makeWASocket({
66
+ auth: state,
67
+ // ... other options
68
+ });
69
+
70
+ // Initialize store
71
+ const store = sock.signalRepository.lidMapping;
72
+ ```
73
+
74
+ ### 2. Listen for LID Mapping Updates
75
+
76
+ ```javascript
77
+ sock.ev.on('lid-mapping.update', async (update) => {
78
+ console.log('New LID/PN mappings received:', update);
79
+ // Mappings are automatically stored in the store
80
+ // You can emit custom events or perform additional processing
81
+ });
82
+ ```
83
+
84
+ ### 3. Handle Messages with LID Support
85
+
86
+ ```javascript
87
+ sock.ev.on('messages.upsert', async ({ messages }) => {
88
+ const message = messages[0];
89
+
90
+ // Get the chat JID (prefer PN over LID)
91
+ let jid = message.key.remoteJid;
92
+
93
+ // Use alternate JID if available (PN when primary is LID)
94
+ if (message.key.remoteJidAlt?.endsWith('@s.whatsapp.net')) {
95
+ jid = message.key.remoteJidAlt;
96
+ }
97
+
98
+ // For group messages, get participant info
99
+ const participant = message.key.participant; // Could be LID or PN
100
+ const participantAlt = message.key.participantAlt; // Alternate format
101
+
102
+ console.log('Message from:', jid);
103
+ console.log('Participant:', participant);
104
+ console.log('Participant Alt:', participantAlt);
105
+ });
106
+ ```
107
+
108
+ ## Message Key Structure Changes
109
+
110
+ ### New Fields in MessageKey:
111
+
112
+ ```typescript
113
+ interface MessageKey {
114
+ remoteJid: string; // Primary JID (could be LID or PN)
115
+ remoteJidAlt?: string; // Alternate JID for DMs
116
+ participant?: string; // Sender in groups (could be LID or PN)
117
+ participantAlt?: string; // Alternate JID for group senders
118
+ fromMe: boolean;
119
+ id: string;
120
+ }
121
+ ```
122
+
123
+ ## Best Practices
124
+
125
+ ### 1. Prefer PN over LID for Compatibility
126
+
127
+ ```javascript
128
+ // Always try to use PN (Phone Number) when available
129
+ const getPreferredJid = (messageKey) => {
130
+ if (messageKey.remoteJidAlt?.endsWith('@s.whatsapp.net')) {
131
+ return messageKey.remoteJidAlt; // Use PN
132
+ }
133
+ return messageKey.remoteJid; // Fallback to primary JID
134
+ };
135
+ ```
136
+
137
+ ### 2. Convert LID to PN When Needed
138
+
139
+ ```javascript
140
+ const convertToPN = async (jid, store) => {
141
+ if (jid.endsWith('@lid')) {
142
+ const pn = await store.getPNForLID(jid);
143
+ return pn || jid; // Return PN if found, otherwise return LID
144
+ }
145
+ return jid;
146
+ };
147
+ ```
148
+
149
+ ### 3. Handle Both Formats
150
+
151
+ ```javascript
152
+ const sendMessageSafely = async (sock, store, recipientJid, content) => {
153
+ // Try to get PN if recipient is using LID
154
+ const jid = await convertToPN(recipientJid, store);
155
+ await sock.sendMessage(jid, content);
156
+ };
157
+ ```
158
+
159
+ ## Authentication State Requirements
160
+
161
+ ⚠️ **Important**: Your authentication state must support these keys:
162
+ - `lid-mapping`
163
+ - `device-list`
164
+ - `tctoken`
165
+
166
+ Check `SignalDataTypeMap` in Baileys for the full type structure.
167
+
168
+ ## Events
169
+
170
+ ### 1. lid-mapping.update
171
+
172
+ Emitted when new LID/PN mappings are discovered:
173
+
174
+ ```javascript
175
+ sock.ev.on('lid-mapping.update', (update) => {
176
+ // update structure: { [pn: string]: lid: string }
177
+ Object.entries(update).forEach(([pn, lid]) => {
178
+ console.log(`Mapping: ${pn} -> ${lid}`);
179
+ });
180
+ });
181
+ ```
182
+
183
+ ## Helper Functions
184
+
185
+ ### Check if JID is a PN
186
+
187
+ ```javascript
188
+ const isPnUser = (jid) => {
189
+ return jid?.endsWith('@s.whatsapp.net');
190
+ };
191
+ ```
192
+
193
+ ### Check if JID is a LID
194
+
195
+ ```javascript
196
+ const isLidUser = (jid) => {
197
+ return jid?.endsWith('@lid');
198
+ };
199
+ ```
200
+
201
+ ## Example Usage in WhatsAppClient
202
+
203
+ ```javascript
204
+ class WhatsAppClient extends EventEmitter {
205
+ constructor() {
206
+ super();
207
+ this.sock = null;
208
+ this.store = null;
209
+ }
210
+
211
+ async connect() {
212
+ const { state, saveCreds } = await useMultiFileAuthState('session');
213
+
214
+ this.sock = makeWASocket({ auth: state });
215
+
216
+ // Initialize store
217
+ this.store = this.sock.signalRepository.lidMapping;
218
+
219
+ // Listen for LID updates
220
+ this.sock.ev.on('lid-mapping.update', (update) => {
221
+ this.emit('lid-mapping-update', update);
222
+ });
223
+
224
+ this.sock.ev.on('creds.update', saveCreds);
225
+ }
226
+
227
+ async getLIDForPN(phoneNumber) {
228
+ return await this.store.getLIDForPN(phoneNumber);
229
+ }
230
+
231
+ async getPNForLID(lid) {
232
+ return await this.store.getPNForLID(lid);
233
+ }
234
+ }
235
+ ```
236
+
237
+ ## Common Use Cases
238
+
239
+ ### 1. Getting User's LID
240
+
241
+ ```javascript
242
+ const userPN = '1234567890@s.whatsapp.net';
243
+ const userLID = await client.getLIDForPN(userPN);
244
+ console.log(`LID for ${userPN}: ${userLID}`);
245
+ ```
246
+
247
+ ### 2. Resolving LID to Phone Number
248
+
249
+ ```javascript
250
+ const lid = '123456@lid';
251
+ const phoneNumber = await client.getPNForLID(lid);
252
+ console.log(`Phone number for ${lid}: ${phoneNumber}`);
253
+ ```
254
+
255
+ ### 3. Handling Group Messages
256
+
257
+ ```javascript
258
+ sock.ev.on('messages.upsert', async ({ messages }) => {
259
+ const msg = messages[0];
260
+
261
+ if (msg.key.remoteJid.endsWith('@g.us')) {
262
+ // Group message
263
+ const senderJid = msg.key.participant;
264
+ const senderPN = msg.key.participantAlt || senderJid;
265
+
266
+ // Get LID if sender is using PN
267
+ if (senderPN.endsWith('@s.whatsapp.net')) {
268
+ const lid = await store.getLIDForPN(senderPN);
269
+ console.log(`Sender LID: ${lid}`);
270
+ }
271
+ }
272
+ });
273
+ ```
274
+
275
+ ## Migration Notes
276
+
277
+ ### From Baileys v6.x to v7.x:
278
+
279
+ 1. **Remove `store` parameter** from `makeWASocket()` configuration
280
+ 2. **Access store via** `sock.signalRepository.lidMapping`
281
+ 3. **Update message handling** to check `remoteJidAlt` and `participantAlt`
282
+ 4. **Add event listener** for `lid-mapping.update`
283
+ 5. **Replace `isJidUser()`** with `isPnUser()`
284
+
285
+ ## Troubleshooting
286
+
287
+ ### Store is undefined
288
+
289
+ **Problem**: `this.store` is `undefined`
290
+
291
+ **Solution**: Ensure socket is properly initialized before accessing store:
292
+ ```javascript
293
+ if (!this.sock || !this.sock.signalRepository) {
294
+ throw new Error('Socket not initialized');
295
+ }
296
+ this.store = this.sock.signalRepository.lidMapping;
297
+ ```
298
+
299
+ ### No LID found for PN
300
+
301
+ **Problem**: `getLIDForPN()` returns `undefined`
302
+
303
+ **Possible causes**:
304
+ - User hasn't migrated to LID system yet
305
+ - No LID/PN mapping received from WhatsApp server
306
+ - Using old session that doesn't support LIDs
307
+
308
+ **Solution**: Always handle `undefined` returns gracefully.
309
+
310
+ ### Auth state errors
311
+
312
+ **Problem**: Connection fails with auth state errors
313
+
314
+ **Solution**: Update your auth state implementation to support:
315
+ - `lid-mapping`
316
+ - `device-list`
317
+ - `tctoken`
318
+
319
+ ## References
320
+
321
+ - [Baileys Migration Guide](https://baileys.wiki/docs/migration/to-v7.0.0/)
322
+ - [Baileys GitHub](https://github.com/WhiskeySockets/Baileys)
323
+ - [WhatsApp LID System Announcement](https://whiskey.so/migrate-latest)
324
+
325
+ ## Summary
326
+
327
+ The LID store in Baileys v7.x.x provides:
328
+ - ✅ Automatic LID/PN mapping storage
329
+ - ✅ Easy conversion between LIDs and phone numbers
330
+ - ✅ Privacy-preserving messaging in large groups
331
+ - ✅ Future-proof for WhatsApp's username system
332
+
333
+ Always prefer using phone numbers (PNs) when available for better compatibility, but ensure your code handles both LIDs and PNs gracefully.
package/README.md CHANGED
@@ -5,13 +5,15 @@ A powerful WhatsApp client library that provides seamless integration between Ba
5
5
  ## Features
6
6
 
7
7
  - 🚀 Easy to use, familiar WhatsApp-web.js style API
8
- - 📱 Multi-device support
8
+ - 📱 Multi-device support (Baileys v7.x.x)
9
9
  - 💬 Send and receive messages
10
10
  - 📸 Media handling (images, videos, documents)
11
11
  - 👥 Group management
12
12
  - 💾 Message history and chat management
13
13
  - 🔄 Auto-reconnect functionality
14
14
  - 📝 Read receipts
15
+ - 🔐 LID (Local Identifier) support for enhanced privacy
16
+ - 🗂️ Signal repository store for LID/PN mapping
15
17
 
16
18
  ## Installation
17
19
 
@@ -233,6 +235,10 @@ The library includes example bot commands that you can use:
233
235
  - `!list` - Display a scrollable list
234
236
  - `!logout` - Logout from current session
235
237
 
238
+ ### LID/PN Management (v7.x.x)
239
+ - `!lid` - Get your LID (Local Identifier)
240
+ - `!pn <lid>` - Get phone number from a LID
241
+
236
242
  ## Event Handling
237
243
 
238
244
  ### Connection Events
@@ -276,6 +282,15 @@ client.on('message', async msg => {
276
282
  })
277
283
  ```
278
284
 
285
+ ### LID Mapping Events
286
+ ```javascript
287
+ // Listen for LID/PN mapping updates
288
+ client.on('lid-mapping-update', (update) => {
289
+ console.log('New LID/PN mappings received:', update)
290
+ // Handle new mappings as needed
291
+ })
292
+ ```
293
+
279
294
  ### Error Handling
280
295
 
281
296
  ```javascript
@@ -301,6 +316,277 @@ try {
301
316
  }
302
317
  ```
303
318
 
319
+ ## Baileys v7.x.x LID Store Implementation
320
+
321
+ ### Overview
322
+
323
+ This library fully supports Baileys v7.x.x LID (Local Identifier) system for enhanced privacy and WhatsApp's transition to username-based identification.
324
+
325
+ | Feature | Description |
326
+ |---------|-------------|
327
+ | **LID Support** | Full support for Local Identifiers alongside Phone Numbers |
328
+ | **Store Access** | Automatic initialization via `client.sock.signalRepository.lidMapping` |
329
+ | **Helper Methods** | `getLIDForPN()`, `getPNForLID()`, `getLIDsForPNs()` |
330
+ | **Event Handling** | `lid-mapping-update` event for real-time mapping updates |
331
+ | **Message Handling** | Automatic preference for PN over LID with fallback support |
332
+ | **Compatibility** | Backward compatible with v6.x code patterns |
333
+
334
+ ### What are LIDs?
335
+
336
+ **LID (Local Identifier)** is WhatsApp's privacy feature that replaces phone numbers in large groups. Key points:
337
+
338
+ - **Unique per user** (not per group)
339
+ - Ensures user anonymity in large groups
340
+ - Allows messaging users via either LID or PN (Phone Number)
341
+ - Part of WhatsApp's transition to username system (@username)
342
+
343
+ #### JID Format Changes
344
+
345
+ - **PN (Phone Number)**: `1234567890@s.whatsapp.net` (traditional format)
346
+ - **LID**: `123456@lid` (new format)
347
+
348
+ ### Accessing the Store
349
+
350
+ The store is automatically initialized when you create a WhatsAppClient and is accessible via the internal socket:
351
+
352
+ ```javascript
353
+ const client = new WhatsAppClient({ sessionName: ".Sessions" });
354
+ await client.connect();
355
+
356
+ // Store is available internally as client.store
357
+ // Access via: client.sock.signalRepository.lidMapping
358
+ ```
359
+
360
+ ### Available Methods
361
+
362
+ The WhatsAppClient provides convenient methods to work with LID/PN mappings:
363
+
364
+ #### Quick Reference
365
+
366
+ ```javascript
367
+ // Get LID from Phone Number
368
+ const lid = await client.getLIDForPN('1234567890@s.whatsapp.net');
369
+
370
+ // Get Phone Number from LID
371
+ const pn = await client.getPNForLID('123456@lid');
372
+
373
+ // Get multiple LIDs
374
+ const lids = await client.getLIDsForPNs(['phone1@s.whatsapp.net', 'phone2@s.whatsapp.net']);
375
+ ```
376
+
377
+ #### Detailed Examples
378
+
379
+ ```javascript
380
+ // Get LID from Phone Number
381
+ const lid = await client.getLIDForPN('1234567890@s.whatsapp.net');
382
+ console.log('LID:', lid);
383
+
384
+ // Get Phone Number from LID
385
+ const pn = await client.getPNForLID('123456@lid');
386
+ console.log('Phone Number:', pn);
387
+
388
+ // Get multiple LIDs from multiple PNs
389
+ const lids = await client.getLIDsForPNs([
390
+ '1234567890@s.whatsapp.net',
391
+ '0987654321@s.whatsapp.net'
392
+ ]);
393
+ console.log('LIDs:', lids);
394
+ ```
395
+
396
+ ### Message Handling with LID Support
397
+
398
+ The library automatically handles both LID and PN formats in messages:
399
+
400
+ ```javascript
401
+ client.on('message', async msg => {
402
+ // msg.from will prefer PN over LID when available
403
+ console.log('Message from:', msg.from);
404
+
405
+ // Access raw message key for both formats
406
+ const remoteJid = msg.raw.key.remoteJid; // Primary JID
407
+ const remoteJidAlt = msg.raw.key.remoteJidAlt; // Alternate JID
408
+
409
+ // For group messages
410
+ const participant = msg.raw.key.participant; // Could be LID or PN
411
+ const participantAlt = msg.raw.key.participantAlt; // Alternate format
412
+
413
+ // Convert LID to PN if needed
414
+ if (remoteJid.endsWith('@lid')) {
415
+ const phoneNumber = await client.getPNForLID(remoteJid);
416
+ console.log('Phone number:', phoneNumber);
417
+ }
418
+ });
419
+ ```
420
+
421
+ ### Best Practices
422
+
423
+ #### 1. Prefer PN over LID for Compatibility
424
+
425
+ ```javascript
426
+ const getPreferredJid = (messageKey) => {
427
+ if (messageKey.remoteJidAlt?.endsWith('@s.whatsapp.net')) {
428
+ return messageKey.remoteJidAlt; // Use PN
429
+ }
430
+ return messageKey.remoteJid; // Fallback to primary JID
431
+ };
432
+ ```
433
+
434
+ #### 2. Convert LID to PN When Needed
435
+
436
+ ```javascript
437
+ const convertToPN = async (jid) => {
438
+ if (jid.endsWith('@lid')) {
439
+ const pn = await client.getPNForLID(jid);
440
+ return pn || jid; // Return PN if found, otherwise return LID
441
+ }
442
+ return jid;
443
+ };
444
+ ```
445
+
446
+ #### 3. Handle Both Formats Gracefully
447
+
448
+ ```javascript
449
+ // Always handle undefined returns
450
+ const lid = await client.getLIDForPN(phoneNumber);
451
+ if (lid) {
452
+ console.log('LID found:', lid);
453
+ } else {
454
+ console.log('No LID mapping available, using PN');
455
+ }
456
+ ```
457
+
458
+ ### Common Use Cases
459
+
460
+ #### Getting User's LID
461
+
462
+ ```javascript
463
+ client.on('message', async msg => {
464
+ if (msg.body === '!myid') {
465
+ const lid = await client.getLIDForPN(msg.from);
466
+ if (lid) {
467
+ await msg.reply(`Your LID: ${lid}\nYour PN: ${msg.from}`);
468
+ } else {
469
+ await msg.reply('No LID found. You may be using a PN-only session.');
470
+ }
471
+ }
472
+ });
473
+ ```
474
+
475
+ #### Resolving LID to Phone Number
476
+
477
+ ```javascript
478
+ client.on('message', async msg => {
479
+ if (msg.body.startsWith('!lookup ')) {
480
+ const lid = msg.body.split(' ')[1];
481
+ const phoneNumber = await client.getPNForLID(lid);
482
+
483
+ if (phoneNumber) {
484
+ await msg.reply(`Phone number: ${phoneNumber}`);
485
+ } else {
486
+ await msg.reply('No phone number found for that LID.');
487
+ }
488
+ }
489
+ });
490
+ ```
491
+
492
+ #### Handling Group Messages with LIDs
493
+
494
+ ```javascript
495
+ client.on('message', async msg => {
496
+ if (msg.isGroup) {
497
+ const participant = msg.raw.key.participant;
498
+ const participantAlt = msg.raw.key.participantAlt;
499
+
500
+ // Use alternate (PN) if available, otherwise use primary
501
+ const senderJid = participantAlt || participant;
502
+
503
+ console.log('Group message from:', senderJid);
504
+
505
+ // Get LID if sender is using PN
506
+ if (senderJid.endsWith('@s.whatsapp.net')) {
507
+ const lid = await client.getLIDForPN(senderJid);
508
+ console.log('Sender LID:', lid);
509
+ }
510
+ }
511
+ });
512
+ ```
513
+
514
+ ### Helper Functions
515
+
516
+ ```javascript
517
+ // Check if JID is a Phone Number
518
+ const isPnUser = (jid) => {
519
+ return jid?.endsWith('@s.whatsapp.net');
520
+ };
521
+
522
+ // Check if JID is a LID
523
+ const isLidUser = (jid) => {
524
+ return jid?.endsWith('@lid');
525
+ };
526
+
527
+ // Get preferred JID format
528
+ const getPreferredFormat = async (jid, client) => {
529
+ if (isLidUser(jid)) {
530
+ const pn = await client.getPNForLID(jid);
531
+ return pn || jid;
532
+ }
533
+ return jid;
534
+ };
535
+ ```
536
+
537
+ ### Authentication State Requirements
538
+
539
+ ⚠️ **Important**: Your authentication state must support these keys:
540
+ - `lid-mapping` - Stores LID/PN mappings
541
+ - `device-list` - Manages linked devices
542
+ - `tctoken` - Token for communications
543
+
544
+ The library handles this automatically with `useMultiFileAuthState`.
545
+
546
+ ### Migration from v6.x to v7.x
547
+
548
+ If you're upgrading from Baileys v6.x:
549
+
550
+ 1. **Store access changed**: Access via `sock.signalRepository.lidMapping` instead of separate store parameter
551
+ 2. **New message key fields**: Check for `remoteJidAlt` and `participantAlt`
552
+ 3. **Event listener**: Add handler for `lid-mapping-update` event
553
+ 4. **Function naming**: `isJidUser()` replaced with `isPnUser()`
554
+ 5. **Automatic handling**: The WhatsAppClient already implements these changes
555
+
556
+ ### Troubleshooting
557
+
558
+ #### Store is undefined
559
+
560
+ **Problem**: Cannot access LID store methods
561
+
562
+ **Solution**: Ensure client is connected before accessing store:
563
+ ```javascript
564
+ await client.connect();
565
+ // Wait for 'connected' event
566
+ client.on('connected', async () => {
567
+ // Now store methods are available
568
+ const lid = await client.getLIDForPN(phoneNumber);
569
+ });
570
+ ```
571
+
572
+ #### No LID found for PN
573
+
574
+ **Problem**: `getLIDForPN()` returns `undefined`
575
+
576
+ **Possible causes**:
577
+ - User hasn't migrated to LID system yet
578
+ - No LID/PN mapping received from WhatsApp server
579
+ - Using old session that doesn't support LIDs
580
+
581
+ **Solution**: Always handle `undefined` returns gracefully
582
+
583
+ ### Additional Resources
584
+
585
+ For more detailed information about the LID system implementation, see:
586
+ - [LID_STORE_GUIDE.md](./LID_STORE_GUIDE.md) - Complete implementation guide
587
+ - [Baileys Migration Guide](https://baileys.wiki/docs/migration/to-v7.0.0/) - Official migration documentation
588
+ - [example.js](./example.js) - Working examples with LID handling
589
+
304
590
  ## Contributing
305
591
 
306
592
  Contributions are welcome! Please feel free to submit a Pull Request.
package/example.js CHANGED
@@ -32,6 +32,11 @@ client.on('connected', (user) => {
32
32
  console.log('Client is ready!', user)
33
33
  })
34
34
 
35
+ // Handle LID mapping updates
36
+ client.on('lid-mapping-update', (update) => {
37
+ console.log('New LID/PN mappings received:', update)
38
+ })
39
+
35
40
  client.on('disconnected', (error) => {
36
41
  console.log('Client disconnected:')
37
42
  })
@@ -46,14 +51,16 @@ client.on('status', async status => {
46
51
  console.log ('Sender:', status.raw.pushName);
47
52
  console.log ('Message:', status.body);
48
53
  console.log ('Has Media:', status.hasMedia);
49
- console.log('ID', status.key)
50
54
 
51
- await client.readMessage(status.key)
52
- await status.reply('Thanks for the status! ❤️');
53
- await status.like('❤️');
54
- console.log('Status Seen! and Replied With Emoji')
55
+ // Mark status as read using the complete message key
56
+
57
+ //await client.readMessage(status.key);
55
58
 
59
+ //Reply With Emoji
60
+ //await status.reply('Liked Your Status! ❤️');
56
61
 
62
+ await status.like('❤️');
63
+ console.log('Status Seen! and Replied With Emoji')
57
64
  });
58
65
 
59
66
  // Listen for incoming messages
@@ -323,6 +330,10 @@ client.on('message', async msg => {
323
330
  `• !buttons - Button template\n` +
324
331
  `• !list - Scrollable list\n\n` +
325
332
 
333
+ `*🔐 LID/PN Management*\n` +
334
+ `• !lid - Get your LID\n` +
335
+ `• !pn <lid> - Get PN from LID\n\n` +
336
+
326
337
  `*⚙️ Admin Commands*\n` +
327
338
  `• !read - Mark as read\n` +
328
339
  `• !typing - Show typing\n` +
@@ -392,6 +403,40 @@ client.on('message', async msg => {
392
403
  case 'logout_no':
393
404
  await client.sendMessage(msg.from, 'Logout cancelled.');
394
405
  break;
406
+ case '!lid':
407
+ // Get LID for the user's phone number
408
+ try {
409
+ const lid = await client.getLIDForPN(msg.from);
410
+ if (lid) {
411
+ await client.sendMessage(msg.from, `Your LID: ${lid}\nYour PN: ${msg.from}`);
412
+ } else {
413
+ await client.sendMessage(msg.from, `No LID found for ${msg.from}. You might be using a PN-only session.`);
414
+ }
415
+ } catch (error) {
416
+ console.error('Error getting LID:', error);
417
+ await client.sendMessage(msg.from, 'Failed to get LID.');
418
+ }
419
+ break;
420
+
421
+ case '!pn':
422
+ // Get PN from LID
423
+ try {
424
+ const lidToCheck = args.trim();
425
+ if (!lidToCheck) {
426
+ await client.sendMessage(msg.from, 'Please provide a LID. Example: !pn 123456@lid');
427
+ break;
428
+ }
429
+ const pn = await client.getPNForLID(lidToCheck);
430
+ if (pn) {
431
+ await client.sendMessage(msg.from, `Phone Number for ${lidToCheck}: ${pn}`);
432
+ } else {
433
+ await client.sendMessage(msg.from, `No phone number found for LID: ${lidToCheck}`);
434
+ }
435
+ } catch (error) {
436
+ console.error('Error getting PN from LID:', error);
437
+ await client.sendMessage(msg.from, 'Failed to get phone number.');
438
+ }
439
+ break;
395
440
  case '!ad':
396
441
  await client.sendAdReply(
397
442
  msg.from ,
package/index.js CHANGED
@@ -4,6 +4,7 @@ const { makeWASocket,
4
4
  DisconnectReason,
5
5
  fetchLatestBaileysVersion } =
6
6
  require('@itsukichan/baileys');
7
+
7
8
  const { Boom } = require('@hapi/boom');
8
9
  const { EventEmitter } = require('events');
9
10
  const P = require('pino');
@@ -35,8 +36,7 @@ console.log(figlet.textSync('INNOVATORS'))
35
36
  console.log(figlet.textSync('SOFT'))
36
37
  console.log(figlet.textSync('PRO'))
37
38
  console.log(figlet.textSync('PAKISTANI'))
38
-
39
-
39
+
40
40
  class Group {
41
41
  constructor(client, groupData) {
42
42
  this.client = client
@@ -49,7 +49,30 @@ class Group {
49
49
  }
50
50
  }
51
51
 
52
-
52
+ /**
53
+ * WhatsApp Client class for Baileys v7.x.x
54
+ *
55
+ * ## LID (Local Identifier) System
56
+ * Baileys v7.x.x introduces WhatsApp's LID system for user privacy in large groups.
57
+ * LIDs are unique identifiers that replace phone numbers in certain contexts.
58
+ *
59
+ * ### Store Implementation:
60
+ * The store is accessible via `sock.signalRepository.lidMapping` and provides:
61
+ * - `getLIDForPN(phoneNumber)` - Get LID from phone number
62
+ * - `getPNForLID(lid)` - Get phone number from LID
63
+ * - `getLIDsForPNs(phoneNumbers)` - Get multiple LIDs
64
+ * - `storeLIDPNMapping(pn, lid)` - Store a single mapping
65
+ * - `storeLIDPNMappings(mappings)` - Store multiple mappings
66
+ *
67
+ * ### Message Key Changes:
68
+ * - `remoteJidAlt` - Alternate JID for DMs (PN if primary is LID, or vice versa)
69
+ * - `participantAlt` - Alternate JID for group participants
70
+ *
71
+ * ### Events:
72
+ * - `lid-mapping.update` - Emitted when new LID/PN mappings are received
73
+ *
74
+ * @extends EventEmitter
75
+ */
53
76
  class WhatsAppClient extends EventEmitter {
54
77
  constructor(config = {}) {
55
78
  super()
@@ -82,9 +105,13 @@ class WhatsAppClient extends EventEmitter {
82
105
  syncFullHistory: true,
83
106
  generateHighQualityLinkPreview: true,
84
107
  linkPreviewImageThumbnailWidth: 192,
85
- emitOwnEvents: true
108
+ emitOwnEvents: true,
86
109
  });
87
110
 
111
+ // Initialize store for LID/PN mapping
112
+ this.store = this.sock.signalRepository.lidMapping;
113
+
114
+
88
115
  this.sock.ev.on('connection.update', async (update) => {
89
116
  const { connection, lastDisconnect, qr, isNewLogin, isOnline } = update;
90
117
 
@@ -159,11 +186,16 @@ class WhatsAppClient extends EventEmitter {
159
186
 
160
187
  let jid = message.key.remoteJid;
161
188
 
189
+ // Prefer PN (Phone Number) JID over LID for better compatibility
190
+ // remoteJidAlt contains the alternate JID (PN if primary is LID, or vice versa)
162
191
  if (typeof message.key.remoteJidAlt === 'string' &&
163
192
  message.key.remoteJidAlt.endsWith('@s.whatsapp.net')
164
193
  ) {
165
194
  jid = message.key.remoteJidAlt;
166
195
  }
196
+ // For group messages, check participantAlt for sender's PN
197
+ const participant = message.key.participant || null;
198
+ const participantAlt = message.key.participantAlt || null;
167
199
 
168
200
  const timestamp = new Date((message.messageTimestamp || Date.now()) * 1000);
169
201
 
@@ -204,16 +236,23 @@ class WhatsAppClient extends EventEmitter {
204
236
  timestamp,
205
237
  key: message.key,
206
238
  raw: message,
207
-
208
239
  // Reply to status
209
240
  reply: async (text) => {
210
241
  if (!from) throw new Error('Missing participant JID');
211
242
  return this.sock.sendMessage(from, { text }, { quoted: message });
212
- },
213
-
243
+ },
214
244
  // 👍 Like (react) to status
215
245
  like: async (emoji = '❤️') => {
216
246
  if (!from) throw new Error('Missing participant JID');
247
+
248
+ // Read the message first
249
+ try {
250
+ await this.sock.readMessages([message.key]);
251
+ } catch (readError) {
252
+ console.error('Error reading status message:', readError);
253
+ }
254
+
255
+ // Then send the reaction
217
256
  return this.sock.sendMessage(from, {
218
257
  react: {
219
258
  text: emoji,
@@ -252,6 +291,30 @@ class WhatsAppClient extends EventEmitter {
252
291
  // Handle incoming calls
253
292
  this.sock.ev.on('call', async (call) => {
254
293
  try {
294
+ // Extract phone number from LID if available
295
+ for (const callData of call) {
296
+ if (callData.chatId || callData.from) {
297
+ const jid = callData.chatId || callData.from;
298
+
299
+ // If it's a LID, try to get the phone number
300
+ if (jid.endsWith('@lid')) {
301
+ const phoneNumber = await this.store.getPNForLID(jid);
302
+
303
+ if (phoneNumber) {
304
+ // Extract numeric part before colon (e.g., '923014434335' from '923014434335:0@s.whatsapp.net')
305
+ callData.phoneNumber = phoneNumber.split(':')[0].split('@')[0];
306
+ } else {
307
+ // Fallback: extract from the numeric part before @lid
308
+ callData.phoneNumber = jid.split('@')[0];
309
+ }
310
+ } else {
311
+ // For PN format, extract the number before colon and @
312
+ callData.phoneNumber = jid.split(':')[0].split('@')[0];
313
+ }
314
+ }
315
+ }
316
+
317
+ console.log('Call received:', call);
255
318
  await this.emit('call', call);
256
319
  } catch (error) {
257
320
  console.error('Error in call handler:', error);
@@ -259,6 +322,20 @@ class WhatsAppClient extends EventEmitter {
259
322
  }
260
323
  });
261
324
 
325
+ // Handle LID/PN mapping updates
326
+ this.sock.ev.on('lid-mapping.update', async (update) => {
327
+ try {
328
+ // Store the mapping for future use
329
+ if (update && Object.keys(update).length > 0) {
330
+ // The update object contains PN -> LID mappings
331
+ // They are automatically stored in sock.signalRepository.lidMapping
332
+ this.emit('lid-mapping-update', update);
333
+ }
334
+ } catch (error) {
335
+ console.error('Error processing LID mapping update:', error);
336
+ }
337
+ });
338
+
262
339
  // Handle credential updates
263
340
  this.sock.ev.on('creds.update', saveCreds);
264
341
 
@@ -646,17 +723,25 @@ class WhatsAppClient extends EventEmitter {
646
723
  }
647
724
  /**
648
725
  * Mark a message as read
649
- * @param {string} messageId - The ID of the message to mark as read
726
+ * @param {object|string} messageKey - The message key object or message ID
650
727
  * @returns {Promise<void>}
651
728
  * @throws {Error} If client is not connected or an error occurs
652
729
  */
653
- async readMessage(messageId) {
730
+ async readMessage(messageKey) {
654
731
  if (!this.isConnected) {
655
732
  throw new Error('Client is not connected');
656
733
  }
657
734
 
658
735
  try {
659
- await this.sock.readMessages([messageId]);
736
+ // If messageKey is a string (legacy), convert to key object format
737
+ // Otherwise use it directly as a key object
738
+ if (typeof messageKey === 'string') {
739
+ // Legacy support: just ID string
740
+ await this.sock.readMessages([{ id: messageKey }]);
741
+ } else {
742
+ // Proper key object with remoteJid, id, fromMe, etc.
743
+ await this.sock.readMessages([messageKey]);
744
+ }
660
745
  } catch (error) {
661
746
  console.error('Error marking message as read:', error);
662
747
  throw error;
@@ -811,6 +896,57 @@ class WhatsAppClient extends EventEmitter {
811
896
  throw error;
812
897
  }
813
898
  }
899
+ /**
900
+ * Get LID (Local Identifier) for a phone number
901
+ * @param {string} phoneNumber - Phone number in format: '1234567890@s.whatsapp.net'
902
+ * @returns {Promise<string|undefined>} The LID for the phone number, or undefined if not found
903
+ */
904
+ async getLIDForPN(phoneNumber) {
905
+ if (!this.sock || !this.store) {
906
+ throw new Error('Client is not connected');
907
+ }
908
+ try {
909
+ return await this.store.getLIDForPN(phoneNumber);
910
+ } catch (error) {
911
+ console.error('Error getting LID for PN:', error);
912
+ return undefined;
913
+ }
914
+ }
915
+
916
+ /**
917
+ * Get Phone Number for a LID (Local Identifier)
918
+ * @param {string} lid - LID in format: '123456@lid'
919
+ * @returns {Promise<string|undefined>} The phone number for the LID, or undefined if not found
920
+ */
921
+ async getPNForLID(lid) {
922
+ if (!this.sock || !this.store) {
923
+ throw new Error('Client is not connected');
924
+ }
925
+ try {
926
+ return await this.store.getPNForLID(lid);
927
+ } catch (error) {
928
+ console.error('Error getting PN for LID:', error);
929
+ return undefined;
930
+ }
931
+ }
932
+
933
+ /**
934
+ * Get multiple LIDs for multiple phone numbers
935
+ * @param {Array<string>} phoneNumbers - Array of phone numbers
936
+ * @returns {Promise<Array<string>>} Array of LIDs
937
+ */
938
+ async getLIDsForPNs(phoneNumbers) {
939
+ if (!this.sock || !this.store) {
940
+ throw new Error('Client is not connected');
941
+ }
942
+ try {
943
+ return await this.store.getLIDsForPNs(phoneNumbers);
944
+ } catch (error) {
945
+ console.error('Error getting LIDs for PNs:', error);
946
+ return [];
947
+ }
948
+ }
949
+
814
950
  /**
815
951
  * Log out from WhatsApp
816
952
  * @returns {Promise<boolean>} True if logout was successful
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "innovators-bot2",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {