innovators-bot2 2.0.4 → 2.0.6

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/README.md CHANGED
@@ -66,6 +66,11 @@ const client = new WhatsAppClient({
66
66
  authmethod: authMethod
67
67
  });
68
68
 
69
+ // Handle pairing code event
70
+ client.on('pairing-code', (code) => {
71
+ console.log('Pairing Code:', code)
72
+ })
73
+
69
74
  // Handle ready event
70
75
  client.on('connected', () => {
71
76
  console.log('Client is ready!')
@@ -80,22 +85,45 @@ client.connect()
80
85
  ### 1. Basic Messaging
81
86
 
82
87
  ```javascript
88
+ // Determine the correct reply target (group JID for groups, sender JID for DMs)
89
+ const isGroupMsg = msg.isGroup;
90
+ const msgFrom = isGroupMsg ? msg.from : msg.sender;
91
+
83
92
  // Send a text message
84
- await client.sendMessage('1234567890@s.whatsapp.net', 'Hello world!')
93
+ await client.sendMessage(msgFrom, 'Hello world!')
85
94
 
86
95
  // Send a reply
87
- await client.reply('1234567890@s.whatsapp.net', 'This is a reply', {
88
- quoted: originalMessage
96
+ await msg.reply('This is a reply message')
97
+
98
+ // Mention a specific user
99
+ // Use msg.sender (the person's JID), NOT msg.from (which is the group JID in groups)
100
+ const number = msg.sender.split('@')[0]
101
+ await client.sendMessage(msgFrom, {
102
+ type: 'text',
103
+ text: `Hey @${number}! How are you?`,
104
+ mentions: [number]
89
105
  })
90
106
 
91
- // Send with mentions
92
- await client.sendMessage('1234567890@s.whatsapp.net', {
107
+ // Mention all members in a group (only works in groups)
108
+ await client.sendMessage(msgFrom, {
93
109
  type: 'text',
94
- text: 'Hey @user!',
95
- mentions: ['user@s.whatsapp.net']
110
+ text: 'Hey @all! How are you?',
111
+ mentions: ['@all']
112
+ })
113
+
114
+ // You can also use the explicit mentionAll flag
115
+ await client.sendMessage(msgFrom, {
116
+ type: 'text',
117
+ text: 'Attention everyone!',
118
+ mentionAll: true
96
119
  })
97
120
  ```
98
121
 
122
+ > **Note on `msg.from` vs `msg.sender`:**
123
+ > - `msg.from` — The chat JID. For groups this is the group ID (e.g. `120363...@g.us`), for DMs it's the person's JID.
124
+ > - `msg.sender` — The actual person who sent the message (always a user JID like `923001234567@s.whatsapp.net`).
125
+ > - When mentioning a user, always use `msg.sender` (not `msg.from`) to get the correct user JID.
126
+
99
127
  ### Call Methods
100
128
 
101
129
  ```javascript
@@ -308,6 +336,12 @@ await client.updateGroupsAddPrivacy('contacts')
308
336
  // Update default disappearing mode for new chats
309
337
  // Options: 0 (off), 86400 (24h), 604800 (7d), 7776000 (90d)
310
338
  await client.updateDefaultDisappearingMode(604800)
339
+
340
+ // Update profile status
341
+ await client.updateProfileStatus('Hello World!')
342
+
343
+ // Update profile name
344
+ await client.updateProfileName('My name')
311
345
  ```
312
346
 
313
347
  ### 7. Interactive Messages
@@ -403,10 +437,135 @@ await client.SendList('1234567890@s.whatsapp.net', {
403
437
  });
404
438
  ```
405
439
 
406
- ### 8. Message History
440
+ #### Cards Messages
441
+ ```javascript
442
+ // Send interactive cards
443
+ await client.sendcards('1234567890@s.whatsapp.net', {
444
+ text: 'Body Message',
445
+ title: 'Title Message',
446
+ subtile: 'Subtitle Message',
447
+ footer: 'Footer Message',
448
+ cards: [
449
+ {
450
+ image: { url: 'https://example.com/image1.jpg' }, // or buffer
451
+ title: 'Title Card 1',
452
+ body: 'Body Card 1',
453
+ footer: 'Footer Card 1',
454
+ buttons: [
455
+ {
456
+ name: 'quick_reply',
457
+ buttonParamsJson: JSON.stringify({
458
+ display_text: 'Button 1',
459
+ id: 'id1'
460
+ })
461
+ },
462
+ {
463
+ name: 'cta_url',
464
+ buttonParamsJson: JSON.stringify({
465
+ display_text: 'Open Link',
466
+ url: 'https://www.example.com'
467
+ })
468
+ }
469
+ ]
470
+ },
471
+ {
472
+ video: { url: 'https://example.com/video1.mp4' }, // or buffer
473
+ title: 'Title Card 2',
474
+ body: 'Body Card 2',
475
+ footer: 'Footer Card 2',
476
+ buttons: [
477
+ {
478
+ name: 'quick_reply',
479
+ buttonParamsJson: JSON.stringify({
480
+ display_text: 'Button 2',
481
+ id: 'id2'
482
+ })
483
+ }
484
+ ]
485
+ }
486
+ ]
487
+ });
488
+ ```
489
+
490
+ #### Interactive Messages (V2)
491
+
492
+ Modern interactive message generation with simplified API.
407
493
 
494
+ **Quick Reply Buttons (V2)**
408
495
  ```javascript
409
- ### 8. Message Store (History)
496
+ await client.sendQuickReplyV2(jid, 'Please select an option below:', [
497
+ { id: 'btn-1', displayText: '✅ Accept' },
498
+ { id: 'btn-2', displayText: '❌ Reject' }
499
+ ], { footer: 'Powered by Innovators Soft' });
500
+ ```
501
+
502
+ **URL Button (V2)**
503
+ ```javascript
504
+ await client.sendUrlButtonV2(jid, 'Visit our website for more info', [
505
+ { displayText: '🌐 Open Website', url: 'https://example.com' }
506
+ ], { title: 'Product Info', footer: 'Click to open' });
507
+ ```
508
+
509
+ **Copy Code Button (V2)**
510
+ ```javascript
511
+ await client.sendCopyCodeV2(jid, 'Your OTP Code is:', '123456', '📋 Copy Code');
512
+ ```
513
+
514
+ **Combined Buttons (Mix URL, Reply, Copy, Call) (V2)**
515
+ ```javascript
516
+ await client.sendCombinedButtonsV2(jid, 'Choose an action:', [
517
+ { type: 'reply', displayText: '🛒 Order Now', id: 'order' },
518
+ { type: 'url', displayText: '🌐 Website', url: 'https://example.com' },
519
+ { type: 'call', displayText: '📞 Phone', phoneNumber: '+923224559543' },
520
+ { type: 'copy', displayText: '📋 Copy Promo', copyCode: 'PROMO2024' }
521
+ ], { title: 'Main Menu', footer: 'Innovators Soft' });
522
+ ```
523
+
524
+ **List Message (V2)**
525
+ ```javascript
526
+ await client.sendListV2(jid, {
527
+ title: '📋 Product Menu',
528
+ buttonText: 'View Menu',
529
+ description: 'Please select a product',
530
+ footer: 'Powered by Innovators Soft',
531
+ sections: [
532
+ {
533
+ title: 'Food',
534
+ rows: [
535
+ { rowId: 'nasi-goreng', title: 'Fried Rice', description: '$2.50' },
536
+ { rowId: 'mie-goreng', title: 'Fried Noodles', description: '$2.00' }
537
+ ]
538
+ }
539
+ ]
540
+ });
541
+ ```
542
+
543
+ ### 8. Typing & Presence Control
544
+
545
+ Use `createPresenceController` for manual or standalone typing/recording presence control — without needing the auto-reply system.
546
+
547
+ ```javascript
548
+ const typing = client.createPresenceController();
549
+
550
+ // Show "typing..." for 2 s, then send the message — all in one call
551
+ const sent = await typing.simulateTyping(jid, 2000, async () => {
552
+ await client.sendMessage(jid, 'Here is your answer! ✅');
553
+ });
554
+
555
+ // Manual start (auto-pauses after 5 s by default)
556
+ await typing.startTyping(jid, { duration: 5000 });
557
+
558
+ // Manual stop
559
+ await typing.stopTyping(jid);
560
+
561
+ // Voice note recording indicator
562
+ await typing.startRecording(jid, { duration: 3000 });
563
+
564
+ // Stop all active indicators (e.g. on socket close)
565
+ await typing.stopAll();
566
+ ```
567
+
568
+ ### 9. Message History (Store)
410
569
 
411
570
  The library includes a robust message store to keep track of chat history, even across reloads.
412
571
 
@@ -472,8 +631,64 @@ client.on('store-loaded', (info) => {
472
631
  console.log(`Loaded ${info.messageCount} messages from file`);
473
632
  });
474
633
  ```
634
+
635
+ ### 10. Status / Story Posting
636
+
637
+ Post text, image, video, and voice note statuses easily using the `sendStatus` method.
638
+
639
+ | Feature | Description |
640
+ |---------|-------------|
641
+ | **Multi-Device Support** | Automatically handles `statusJidList` for correct visibility |
642
+ | **All Media Types** | Supports Text, Image, Video, GIF, and Voice Note statuses |
643
+ | **Rich Customization** | Supports backgrounds, fonts, and colors for text status |
644
+
645
+ #### Sending Text Status
646
+ ```javascript
647
+ await client.sendStatus({
648
+ text: 'Hello from Innovators Soft! 🌍',
649
+ backgroundColor: '#34B7F1', // Hex color
650
+ font: 2, // Norican font (0-9)
651
+ textColor: '#FFFFFF'
652
+ }, ['1234567890@s.whatsapp.net']);
653
+ ```
654
+
655
+ #### Sending Media Status
656
+ ```javascript
657
+ // Image Status
658
+ await client.sendStatus({
659
+ imagePath: './photo.jpg',
660
+ caption: 'Beautiful day! ☀️'
661
+ }, ['1234567890@s.whatsapp.net']);
662
+
663
+ // Video/GIF Status
664
+ await client.sendStatus({
665
+ videoPath: './video.mp4',
666
+ caption: 'Check this out! 🎬',
667
+ isGif: true
668
+ }, ['1234567890@s.whatsapp.net']);
669
+
670
+ // Voice Note Status
671
+ await client.sendStatus({
672
+ audioPath: './voice.ogg'
673
+ }, ['1234567890@s.whatsapp.net']);
475
674
  ```
476
675
 
676
+ #### Status Visibility
677
+ > [!IMPORTANT]
678
+ > The second parameter of `sendStatus` is an array of JIDs (contacts) who should be able to see this status. On Multi-Device WhatsApp, statuses are NOT visible to anyone unless you explicitly include them in this list.
679
+
680
+ #### Helper Utilities
681
+ You can also access the underlying `StatusHelper` directly:
682
+ ```javascript
683
+ const { StatusHelper, STATUS_BACKGROUNDS, STATUS_FONTS } = require('@innovatorssoft/baileys');
684
+
685
+ // Generate raw status content
686
+ const status = StatusHelper.text('Direct usage', STATUS_BACKGROUNDS.solid.purple);
687
+ await StatusHelper.send(client.sock, status, ['1234567890@s.whatsapp.net']);
688
+ ```
689
+
690
+ ---
691
+
477
692
  ## More Examples and Information
478
693
 
479
694
  For a complete working example with message handling, group management, and error handling, check out our [`example.js`](https://github.com/innovatorssoft/innovators-bot2/blob/main/example.js) file. This example includes:
@@ -496,7 +711,8 @@ The library includes example bot commands that you can use:
496
711
  - `!help` - Show all available commands
497
712
 
498
713
  ### Messaging
499
- - `!mention` - Mention you in a message
714
+ - `!mention` - Mention the sender in a message
715
+ - `!mentionall` - Mention all group members (groups only)
500
716
  - `!reply` - Reply to your message
501
717
  - `!react` - React to your message with ❤️
502
718
  - `!read` - Mark messages as read
@@ -546,10 +762,18 @@ The library includes example bot commands that you can use:
546
762
  - `!readreceiptprivacy <value>` - Update read receipts privacy (all/none)
547
763
  - `!groupaddprivacy <value>` - Update who can add you to groups (all/contacts/contact_blacklist)
548
764
  - `!disappearing <seconds>` - Update default disappearing mode (0/86400/604800/7776000)
765
+ - `!updatestatus <text>` - Update profile status
766
+ - `!updatename <text>` - Update profile name
549
767
 
550
768
  ### Interactive Messages
551
769
  - `!buttons` - Show interactive buttons
552
770
  - `!list` - Display a scrollable list
771
+ - `!quickreplyv2` - Quick reply buttons V2
772
+ - `!urlbuttonv2` - URL button V2
773
+ - `!copycodev2` - Copy code button V2
774
+ - `!combinedv2` - Mixed buttons V2
775
+ - `!listv2` - Interactive list V2
776
+ - `!cards` - Show interactive cards message
553
777
  - `!logout` - Logout from current session
554
778
 
555
779
  ### 💾 Message Store
@@ -611,12 +835,22 @@ client.on('contacts-update', (updates) => {
611
835
  ```javascript
612
836
  // When a new message is received
613
837
  client.on('message', async msg => {
614
- console.log('Message from:', msg.from)
615
- console.log('Message content:', msg.body)
838
+ console.log('Message from:', msg.from) // Chat JID (group or DM)
839
+ console.log('Sender:', msg.sender) // Person who sent it
840
+ console.log('Sender Name:', msg.raw.pushName) // Display name
841
+ console.log('Message:', msg.body)
842
+ console.log('Is Group:', msg.isGroup)
843
+
844
+ // Determine reply target: group JID for groups, sender JID for DMs
845
+ const isGroupMsg = msg.isGroup;
846
+ const msgFrom = isGroupMsg ? msg.from : msg.sender;
616
847
 
617
848
  // Mark message as read
618
849
  await client.readMessage(msg.raw.key)
619
850
 
851
+ // Reply back
852
+ await msg.reply('Got your message!')
853
+
620
854
  // Handle different message types
621
855
  if (msg.hasMedia) {
622
856
  console.log('Message contains media')