@realvare/based 2.7.62 → 2.7.71

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.
Files changed (57) hide show
  1. package/README.MD +1062 -282
  2. package/WAProto/WAProto.proto +1073 -244
  3. package/WAProto/index.d.ts +16282 -8183
  4. package/WAProto/index.js +76605 -50628
  5. package/engine-requirements.js +10 -10
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +4 -2
  8. package/lib/Defaults/index.js +8 -6
  9. package/lib/Signal/Group/ciphertext-message.d.ts +1 -1
  10. package/lib/Signal/Group/ciphertext-message.js +1 -1
  11. package/lib/Signal/Group/sender-message-key.d.ts +1 -1
  12. package/lib/Signal/Group/sender-message-key.js +1 -1
  13. package/lib/Signal/libsignal.d.ts +1 -1
  14. package/lib/Socket/business.d.ts +1 -1
  15. package/lib/Socket/business.js +1 -1
  16. package/lib/Socket/chats.d.ts +4 -1
  17. package/lib/Socket/chats.js +213 -36
  18. package/lib/Socket/groups.js +87 -15
  19. package/lib/Socket/index.js +9 -0
  20. package/lib/Socket/messages-interactive.js +259 -0
  21. package/lib/Socket/messages-recv.js +1473 -1228
  22. package/lib/Socket/messages-send.js +437 -469
  23. package/lib/Socket/socket.js +143 -26
  24. package/lib/Socket/usync.js +57 -4
  25. package/lib/Store/make-in-memory-store.js +28 -15
  26. package/lib/Types/Auth.d.ts +4 -0
  27. package/lib/Types/Message.d.ts +316 -6
  28. package/lib/Types/Message.js +1 -1
  29. package/lib/Types/Socket.d.ts +2 -0
  30. package/lib/Utils/cache-manager.d.ts +16 -0
  31. package/lib/Utils/cache-manager.js +22 -5
  32. package/lib/Utils/chat-utils.js +17 -13
  33. package/lib/Utils/decode-wa-message.js +1 -11
  34. package/lib/Utils/event-buffer.js +103 -2
  35. package/lib/Utils/generics.js +5 -6
  36. package/lib/Utils/index.d.ts +5 -0
  37. package/lib/Utils/index.js +3 -0
  38. package/lib/Utils/jid-validation.d.ts +2 -0
  39. package/lib/Utils/jid-validation.js +43 -10
  40. package/lib/Utils/link-preview.js +38 -28
  41. package/lib/Utils/messages-media.d.ts +1 -1
  42. package/lib/Utils/messages-media.js +22 -53
  43. package/lib/Utils/messages.js +653 -65
  44. package/lib/Utils/performance-config.d.ts +2 -0
  45. package/lib/Utils/performance-config.js +16 -7
  46. package/lib/Utils/process-message.js +124 -12
  47. package/lib/Utils/rate-limiter.js +15 -20
  48. package/lib/WABinary/generic-utils.js +5 -1
  49. package/lib/WABinary/jid-utils.d.ts +1 -0
  50. package/lib/WABinary/jid-utils.js +265 -5
  51. package/lib/WAUSync/Protocols/USyncContactProtocol.js +75 -5
  52. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -6
  53. package/lib/WAUSync/USyncQuery.js +64 -6
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.js +5 -4
  56. package/package.json +10 -15
  57. package/WAProto/index.ts.ts +0 -53473
package/README.MD CHANGED
@@ -53,12 +53,59 @@
53
53
  - [Text with Formatting](#text-with-formatting)
54
54
  - [Basic Media](#basic-media)
55
55
  - [Advanced Media](#advanced-media)
56
+ - [Stickers](#stickers)
57
+ - [Sticker Packs](#sticker-packs)
58
+ - [Stickers on Status (2025 Feature)](#stickers-on-status-2025-feature)
56
59
  - [Interactive Messages](#interactive-messages)
57
60
  - [Messages with Simple Buttons](#messages-with-simple-buttons)
58
61
  - [Messages with Buttons and Image](#messages-with-buttons-and-image)
59
62
  - [List Messages](#list-messages)
63
+ - [Collection Messages (Catalog)](#collection-messages-catalog)
64
+ - [Invoice Messages](#invoice-messages)
65
+ - [Carousel Messages with Card Types](#carousel-messages-with-card-types)
66
+ - [Interactive Messages with Audio Footer](#interactive-messages-with-audio-footer)
67
+ - [Interactive Messages with Product Header](#interactive-messages-with-product-header)
68
+ - [Interactive Response Messages](#interactive-response-messages)
69
+ - [Poll Messages](#poll-messages)
70
+ - [Poll Result Snapshot](#poll-result-snapshot)
71
+ - [Poll Update](#poll-update)
72
+ - [Comment Messages](#comment-messages)
73
+ - [Question Messages](#question-messages)
74
+ - [Question Response Messages](#question-response-messages)
75
+ - [Status Question Answer Messages](#status-question-answer-messages)
76
+ - [Status Quoted Messages](#status-quoted-messages)
77
+ - [Status Sticker Interaction Messages](#status-sticker-interaction-messages)
78
+ - [AI Rich Response Messages](#ai-rich-response-messages)
79
+ - [New Interactive Features (2025)](#new-interactive-features-2025)
60
80
  - [Other Messages](#other-messages)
61
- - [Response Management](#response-management)
81
+ - [Business Call Messages (BCall)](#business-call-messages-bcall)
82
+ - [Call Log Messages](#call-log-messages)
83
+ - [Event Response Messages](#event-response-messages)
84
+ - [Status Mention Messages](#status-mention-messages)
85
+ - [Group Status Messages](#group-status-messages)
86
+ - [Bot Task Messages](#bot-task-messages)
87
+ - [Limit Sharing Messages](#limit-sharing-messages)
88
+ - [Status Add Yours Messages](#status-add-yours-messages)
89
+ - [Bot Forwarded Messages](#bot-forwarded-messages)
90
+ - [Event Cover Image Messages](#event-cover-image-messages)
91
+ - [Poll Creation Message V4](#poll-creation-message-v4)
92
+ - [Poll Creation Message V5](#poll-creation-message-v5)
93
+ - [Poll Result Snapshot Message V3](#poll-result-snapshot-message-v3)
94
+ - [Encrypted Comment Messages](#encrypted-comment-messages)
95
+ - [Encrypted Event Response Messages](#encrypted-event-response-messages)
96
+ - [Message History Bundle](#message-history-bundle)
97
+ - [Message History Notice](#message-history-notice)
98
+ - [Newsletter Follower Invite](#newsletter-follower-invite)
99
+ - [Placeholder Messages](#placeholder-messages)
100
+ - [Secret Encrypted Messages](#secret-encrypted-messages)
101
+ - [Status Notification Messages](#status-notification-messages)
102
+ - [Sticker Sync RMR Messages](#sticker-sync-rmr-messages)
103
+ - [Send Payment](#send-payment)
104
+ - [Decline Payment Request](#decline-payment-request)
105
+ - [Cancel Payment Request](#cancel-payment-request)
106
+ - [Scheduled Call Creation](#scheduled-call-creation)
107
+ - [Scheduled Call Edit](#scheduled-call-edit)
108
+ - [Pin/Unpin Messages](#pinunpin-messages)
62
109
  - [🎭 Group Features](#-group-features)
63
110
  - [Basic Group Management](#basic-group-management)
64
111
  - [Participant Management](#participant-management)
@@ -73,6 +120,8 @@
73
120
  - [📊 Conditional Logging](#-conditional-logging)
74
121
  - [🔧 Performance Configuration](#-performance-configuration)
75
122
  - [🧩 Events: LID and JID always available (new)](#-events-lid-and-jid-always-available-new)
123
+ - [Gestione dei Messaggi (`messages.upsert`)](#gestione-dei-messaggi-messagesupsert)
124
+ - [Gestione dei Partecipanti di Gruppo (`group-participants.update`)](#gestione-dei-partecipanti-di-gruppo-group-participantsupdate)
76
125
  - [⚙️ Advanced Configuration](#️-advanced-configuration)
77
126
  - [🔧 Complete Options for makeWASocket](#-complete-options-for-makewasocket)
78
127
  - [🛡️ Security and Encryption](#️-security-and-encryption)
@@ -145,7 +194,7 @@ console.log(result.isValid, result.error);
145
194
 
146
195
  // Extract sender information from messages
147
196
  const sender = getSenderLid(message);
148
- console.log(sender.jid, sender.lid, sender.isValid);
197
+ console.log(sender.jid, sender.lid, sender.user, sender.isValid, sender.timestamp, sender.error);
149
198
 
150
199
  // Convert LID to JID format
151
200
  const jid = toJid('1234567890@lid'); // Returns '1234567890@s.whatsapp.net'
@@ -157,6 +206,8 @@ const normalized = normalizeJid('1234567890@lid'); // Returns '1234567890@s.what
157
206
  const isValid = isValidJid('1234567890@s.whatsapp.net');
158
207
  ```
159
208
 
209
+ **Events behavior**: all emitted events (e.g. `messages.upsert`, `messages.update`, `group-participants.update`) will expose standard JIDs (`@s.whatsapp.net`, `@g.us`, etc.) in `msg.key.remoteJid` and `msg.key.participant` whenever possible. When WhatsApp provides LIDs, the original values are preserved in `msg.key.remoteLid` and `msg.key.participantLid`.
210
+
160
211
  ### 📈 Key Benefits
161
212
 
162
213
  **Performance Improvements:**
@@ -214,7 +265,7 @@ const sock = makeWASocket({
214
265
 
215
266
  <p align="center">
216
267
  <img src="https://readme-typing-svg.herokuapp.com?font=Fira+Code&weight=600&size=18&duration=2500&pause=2500&color=8A2BE2&center=true&vCenter=true&width=600&lines=🚀+Powerful+and+Intuitive;🔧+Based+on+Baileys+with+Improvements" alt="Features">
217
- </div>
268
+ </p>
218
269
 
219
270
  <br>
220
271
 
@@ -414,7 +465,7 @@ startBot().catch(console.error);
414
465
  The library now includes an advanced cache system with automatic memory management and configurable TTL:
415
466
 
416
467
  ```typescript
417
- import { CacheManager } from 'based/lib/Utils/cache-manager';
468
+ import { CacheManager } from '@realvare/based';
418
469
 
419
470
  // Example of using the cache
420
471
  const cache = CacheManager;
@@ -621,49 +672,41 @@ await conn.sendMessage(jid, { sticker: buffer });
621
672
 
622
673
  ##### Sticker Packs
623
674
 
624
- While WhatsApp supports installable sticker packs, Baileys (and this fork) does not have a native feature to create or send a pack as a single multi-sticker message (`StickerPackMessage`). This is a requested feature in Baileys (see issues [#1548](https://github.com/WhiskeySockets/Baileys/issues/1548)), but not yet implemented.
625
-
626
- However, the library provides a way to send a sticker pack by sending a metadata message followed by the individual stickers. This simulates a sticker pack in the chat.
627
-
628
- Here is how you can send a sticker pack:
675
+ Send a complete sticker pack message with multiple stickers. This allows you to send a collection of stickers as a single pack message.
629
676
 
630
677
  ```typescript
631
- import { Sticker } from 'wa-sticker-formatter';
632
-
633
- const sticker1 = new Sticker('path/to/image1.png', { pack: 'My Sticker Pack', author: 'Me' });
634
- const sticker2 = new Sticker('path/to/image2.png', { pack: 'My Sticker Pack', author: 'Me' });
635
-
636
- const stickerPack = {
678
+ await conn.sendMessage(jid, {
679
+ stickerPack: {
637
680
  name: 'My Sticker Pack',
638
681
  publisher: 'My Bot',
639
682
  description: 'A cool sticker pack',
640
- cover: 'path/to/cover.png', // or a buffer
683
+ cover: { url: './cover.png' }, // Cover image for the pack
684
+ stickerPackId: 'pack123', // Optional: auto-generated if not provided
685
+ origin: 2, // 0 = FIRST_PARTY, 1 = THIRD_PARTY, 2 = USER_CREATED
686
+ caption: 'Check out my stickers!',
641
687
  stickers: [
642
- {
643
- sticker: await sticker1.toBuffer(),
644
- emojis: ['🎉', '🎊'],
645
- },
646
- {
647
- sticker: await sticker2.toBuffer(),
648
- emojis: ['😄', '😊'],
649
- }
688
+ {
689
+ sticker: { url: './sticker1.webp' },
690
+ emojis: ['🎉', '🎊'],
691
+ isAnimated: false,
692
+ isLottie: false,
693
+ fileName: 'sticker1.webp',
694
+ accessibilityLabel: 'Celebration sticker',
695
+ mimetype: 'image/webp'
696
+ },
697
+ {
698
+ sticker: { url: './sticker2.webp' },
699
+ emojis: ['😄', '😊'],
700
+ isAnimated: true,
701
+ isLottie: false,
702
+ fileName: 'sticker2.webp'
703
+ }
650
704
  ]
651
- };
652
-
653
- await conn.sendMessage(jid, { stickerPack: stickerPack });
705
+ }
706
+ });
654
707
  ```
655
708
 
656
- Alternatively, you can simulate a pack by sending multiple stickers in sequence with a small delay between them:
657
-
658
- ```typescript
659
- // Simulate a pack by sending multiple stickers
660
- const stickers = ['sticker1.webp', 'sticker2.webp'];
661
- for (const url of stickers) {
662
- await conn.sendMessage(jid, { sticker: { url } });
663
- await new Promise(resolve => setTimeout(resolve, 500)); // Small delay
664
- }
665
- ```
666
- To create actual sticker packs that users can install, you should use external tools like the official WhatsApp Sticker Maker app. You can then integrate the individual stickers into your bot.
709
+ **Note**: For creating installable sticker packs that users can add to their WhatsApp, use the official WhatsApp Sticker Maker app. This method sends a pack as a message in the chat.
667
710
 
668
711
  ##### Stickers on Status (2025 Feature)
669
712
 
@@ -678,7 +721,7 @@ await conn.sendMessage('status@broadcast', {
678
721
 
679
722
  #### Interactive Messages
680
723
 
681
- These messages include interactive elements like buttons, lists, and polls.
724
+ These messages include interactive elements like buttons, lists, polls, carousels, collections, and invoices.
682
725
 
683
726
  ##### Messages with Simple Buttons
684
727
 
@@ -692,7 +735,6 @@ await conn.sendMessage(jid, {
692
735
  { buttonId: 'cmd1', buttonText: { displayText: 'Option 1' }, type: 1 },
693
736
  { buttonId: 'cmd2', buttonText: { displayText: 'Option 2' }, type: 1 },
694
737
  ],
695
- headerType: 1,
696
738
  });
697
739
  ```
698
740
 
@@ -733,6 +775,131 @@ await conn.sendMessage(jid, {
733
775
  });
734
776
  ```
735
777
 
778
+ ##### Collection Messages (Catalog)
779
+
780
+ Send a collection/catalog message to browse products.
781
+
782
+ ```typescript
783
+ await conn.sendMessage(jid, {
784
+ text: 'Browse our catalog!',
785
+ footer: 'Shop now',
786
+ title: 'Our Products',
787
+ collection: {
788
+ bizJid: 'business@s.whatsapp.net',
789
+ id: 'catalog123',
790
+ messageVersion: 1
791
+ }
792
+ });
793
+ ```
794
+
795
+ ##### Invoice Messages
796
+
797
+ Send an invoice with attachment (image or PDF).
798
+
799
+ ```typescript
800
+ await conn.sendMessage(jid, {
801
+ invoice: {
802
+ note: 'Invoice for your order',
803
+ token: 'invoice_token_123',
804
+ attachmentType: 1, // 0 = IMAGE, 1 = PDF
805
+ attachment: { url: './invoice.pdf' } // or image
806
+ }
807
+ });
808
+ ```
809
+
810
+ ##### Carousel Messages with Card Types
811
+
812
+ Send a carousel of cards with different card types.
813
+
814
+ ```typescript
815
+ await conn.sendMessage(jid, {
816
+ text: 'Check out these options!',
817
+ footer: 'Swipe to see more',
818
+ cards: [
819
+ {
820
+ title: 'Card 1',
821
+ body: 'Description 1',
822
+ footer: 'Footer 1',
823
+ image: { url: './image1.jpg' },
824
+ buttons: [
825
+ { name: 'quick_reply', buttonParamsJson: '{"display_text":"Button 1"}' }
826
+ ]
827
+ },
828
+ {
829
+ title: 'Card 2',
830
+ body: 'Description 2',
831
+ video: { url: './video.mp4' }
832
+ }
833
+ ],
834
+ carouselCardType: 1 // 1 = HSCROLL_CARDS (horizontal scroll), 2 = ALBUM_IMAGE
835
+ });
836
+ ```
837
+
838
+ **Compatibility note**: `interactiveButtons` and `cards` are sent as `interactiveMessage` and are automatically wrapped by the library in `viewOnceMessageV2` to improve rendering on WhatsApp clients.
839
+
840
+ ##### Interactive Messages with Audio Footer
841
+
842
+ Send interactive messages with audio in the footer.
843
+
844
+ ```typescript
845
+ await conn.sendMessage(jid, {
846
+ text: 'Listen to this message!',
847
+ title: 'Audio Message',
848
+ interactiveButtons: [
849
+ { name: 'action1', buttonParamsJson: '{"display_text":"Action"}' }
850
+ ],
851
+ footer: {
852
+ text: 'Footer text',
853
+ audio: { url: './audio.mp3' } // Audio attachment in footer
854
+ }
855
+ });
856
+ ```
857
+
858
+ ##### Interactive Messages with Product Header
859
+
860
+ Send interactive messages with a product in the header.
861
+
862
+ ```typescript
863
+ await conn.sendMessage(jid, {
864
+ text: 'Check out this product!',
865
+ title: 'Featured Product',
866
+ interactiveButtons: [
867
+ { name: 'buy', buttonParamsJson: '{"display_text":"Buy Now"}' }
868
+ ],
869
+ headerProduct: {
870
+ productImage: { url: './product.jpg' },
871
+ productId: 'prod123',
872
+ title: 'Product Name',
873
+ description: 'Product Description',
874
+ currency: 'EUR',
875
+ priceAmount1000: 10000
876
+ }
877
+ });
878
+ ```
879
+
880
+ ##### Interactive Response Messages
881
+
882
+ Send responses to interactive messages (e.g., Native Flow responses).
883
+
884
+ ```typescript
885
+ await conn.sendMessage(jid, {
886
+ interactiveResponse: {
887
+ body: {
888
+ text: 'Response text',
889
+ format: 0 // 0 = DEFAULT, 1 = EXTENSIONS_1
890
+ },
891
+ nativeFlowResponse: {
892
+ name: 'flow_name',
893
+ paramsJson: '{"key":"value"}',
894
+ version: 1
895
+ },
896
+ contextInfo: {
897
+ mentionedJid: [jid]
898
+ }
899
+ }
900
+ });
901
+ ```
902
+
736
903
  ##### Poll Messages
737
904
 
738
905
  Create a poll for users to vote on.
@@ -747,79 +914,587 @@ await conn.sendMessage(jid, {
747
914
  });
748
915
  ```
749
916
 
750
- #### New Interactive Features (2025)
917
+ ##### Poll Result Snapshot
918
+
919
+ Send a snapshot of poll results.
920
+
921
+ ```typescript
922
+ await conn.sendMessage(jid, {
923
+ pollResultSnapshot: {
924
+ name: 'Favorite Anime?',
925
+ pollVotes: [
926
+ { optionName: 'Aot', optionVoteCount: 10 },
927
+ { optionName: 'Bleach', optionVoteCount: 5 },
928
+ { optionName: 'Death note', optionVoteCount: 3 }
929
+ ],
930
+ pollType: 0, // 0 = POLL, 1 = QUIZ
931
+ contextInfo: {
932
+ mentionedJid: [jid]
933
+ }
934
+ }
935
+ });
936
+ ```
937
+
938
+ ##### Poll Update
939
+
940
+ Send a poll vote update.
941
+
942
+ ```typescript
943
+ await conn.sendMessage(jid, {
944
+ pollUpdate: {
945
+ pollCreationMessageKey: {
946
+ remoteJid: jid,
947
+ fromMe: false,
948
+ id: 'pollMessageId123'
949
+ },
950
+ vote: {
951
+ encPayload: Buffer.from('encrypted_vote_payload'),
952
+ encIv: Buffer.from('encryption_iv')
953
+ },
954
+ senderTimestampMs: Date.now()
955
+ }
956
+ });
957
+ ```
958
+
959
+ ##### Comment Messages
960
+
961
+ Comment on a specific message in a chat.
962
+
963
+ ```typescript
964
+ await conn.sendMessage(jid, {
965
+ comment: {
966
+ message: { text: 'This is a comment!' },
967
+ targetMessageKey: {
968
+ remoteJid: jid,
969
+ fromMe: false,
970
+ id: 'messageId123'
971
+ }
972
+ }
973
+ });
974
+ ```
975
+
976
+ ##### Question Messages
977
+
978
+ Create a question message that users can respond to.
979
+
980
+ ```typescript
981
+ await conn.sendMessage(jid, {
982
+ question: {
983
+ text: 'What is your favorite programming language?',
984
+ contextInfo: {
985
+ mentionedJid: [jid]
986
+ }
987
+ }
988
+ });
989
+ ```
990
+
991
+ ##### Question Response Messages
992
+
993
+ Respond to a question message.
994
+
995
+ ```typescript
996
+ await conn.sendMessage(jid, {
997
+ questionResponse: {
998
+ key: {
999
+ remoteJid: jid,
1000
+ fromMe: false,
1001
+ id: 'questionMessageId123'
1002
+ },
1003
+ text: 'My answer is TypeScript!'
1004
+ }
1005
+ });
1006
+ ```
1007
+
1008
+ ##### Status Question Answer Messages
1009
+
1010
+ Answer a question posted on status.
1011
+
1012
+ ```typescript
1013
+ await conn.sendMessage('status@broadcast', {
1014
+ statusQuestionAnswer: {
1015
+ key: {
1016
+ remoteJid: 'status@broadcast',
1017
+ fromMe: false,
1018
+ id: 'statusQuestionId123'
1019
+ },
1020
+ text: 'My answer to the status question'
1021
+ }
1022
+ }, {
1023
+ statusJidList: [jid]
1024
+ });
1025
+ ```
1026
+
1027
+ ##### Status Quoted Messages
1028
+
1029
+ Quote a status message (e.g., question-answer reshare).
751
1030
 
752
- WhatsApp introduced several new features in 2025. Here's how to handle them with Baileys:
1031
+ ```typescript
1032
+ await conn.sendMessage('status@broadcast', {
1033
+ statusQuoted: {
1034
+ type: 1, // QUESTION_ANSWER
1035
+ text: 'This is my response',
1036
+ thumbnail: buffer, // optional thumbnail
1037
+ originalStatusId: {
1038
+ remoteJid: 'status@broadcast',
1039
+ fromMe: false,
1040
+ id: 'originalStatusId123'
1041
+ }
1042
+ }
1043
+ }, {
1044
+ statusJidList: [jid]
1045
+ });
1046
+ ```
1047
+
1048
+ ##### Status Sticker Interaction Messages
1049
+
1050
+ Interact with stickers on status (e.g., reactions).
1051
+
1052
+ ```typescript
1053
+ await conn.sendMessage('status@broadcast', {
1054
+ statusStickerInteraction: {
1055
+ key: {
1056
+ remoteJid: 'status@broadcast',
1057
+ fromMe: false,
1058
+ id: 'statusMessageId123'
1059
+ },
1060
+ stickerKey: 'stickerKey123',
1061
+ type: 1 // REACTION
1062
+ }
1063
+ }, {
1064
+ statusJidList: [jid]
1065
+ });
1066
+ ```
753
1067
 
754
- - **Missed Call Messages**: Baileys is primarily for messaging and does not handle calls. To approximate this feature, you could potentially listen for call events (if supported) and then send a voice or video note as a follow-up message.
755
- - **Interactive Stickers on Status**: As shown in the sticker section, you can send stickers to `status@broadcast` with an interactive caption.
756
- - **AI-Generated Images**: This is not a native Baileys feature. You need to integrate an external AI image generation API (like Meta AI), generate the image, and then send it as a regular image message.
757
- - **Advanced Interactive Messages**: Features like "native flow" are partially supported in some forks (see issue [#398](https://github.com/WhiskeySockets/Baileys/issues/398)).
1068
+ ##### AI Rich Response Messages
1069
+
1070
+ Send AI-generated rich responses with multiple content types (tables, code, images, maps, etc.).
1071
+
1072
+ ```typescript
1073
+ await conn.sendMessage(jid, {
1074
+ ai: true,
1075
+ richResponse: {
1076
+ messageType: 1, // AI_RICH_RESPONSE_TYPE_STANDARD
1077
+ submessages: [
1078
+ {
1079
+ messageType: 2, // AI_RICH_RESPONSE_TEXT
1080
+ messageText: 'Here is the answer to your question'
1081
+ },
1082
+ {
1083
+ messageType: 4, // AI_RICH_RESPONSE_TABLE
1084
+ tableMetadata: {
1085
+ title: 'Data Table',
1086
+ rows: [
1087
+ { items: ['Header 1', 'Header 2'], isHeading: true },
1088
+ { items: ['Value 1', 'Value 2'], isHeading: false }
1089
+ ]
1090
+ }
1091
+ },
1092
+ {
1093
+ messageType: 5, // AI_RICH_RESPONSE_CODE
1094
+ codeMetadata: {
1095
+ codeLanguage: 'javascript',
1096
+ codeBlocks: [
1097
+ {
1098
+ highlightType: 0, // DEFAULT
1099
+ codeContent: 'console.log("Hello World");'
1100
+ }
1101
+ ]
1102
+ }
1103
+ }
1104
+ ],
1105
+ contextInfo: {
1106
+ mentionedJid: [jid]
1107
+ }
1108
+ }
1109
+ });
1110
+ ```
1111
+
1112
+ Note: AI rich responses may show as "not supported" on some WhatsApp clients/accounts depending on app version and feature availability.
758
1113
 
759
1114
  #### Other Messages
1115
+
1116
+ ##### Business Call Messages (BCall)
1117
+
1118
+ Send business call messages with media.
1119
+
760
1120
  ```typescript
761
- // Message with quote
762
- await conn.sendMessage(jid, {
763
- text: 'bang bang',
764
- quoted: quotedMessage // The message to quote/reply/cite
1121
+ await conn.sendMessage(jid, {
1122
+ bCall: {
1123
+ sessionId: 'call_session_123',
1124
+ mediaType: 2, // 0 = UNKNOWN, 1 = AUDIO, 2 = VIDEO
1125
+ masterKey: Buffer.from('master_key_bytes'),
1126
+ caption: 'Business call'
1127
+ }
765
1128
  });
1129
+ ```
766
1130
 
767
- // Location message
768
- await conn.sendMessage(jid, {
769
- location: {
770
- degreesLatitude: 45.4642,
771
- degreesLongitude: 9.1900,
772
- name: "Milano",
773
- address: "Piazza del Duomo, Milano"
774
- }
1131
+ ##### Call Log Messages
1132
+
1133
+ Send call log information.
1134
+
1135
+ ```typescript
1136
+ await conn.sendMessage(jid, {
1137
+ callLog: {
1138
+ isVideo: true,
1139
+ callOutcome: 0, // 0 = CONNECTED, 1 = MISSED, 2 = FAILED, 3 = REJECTED, etc.
1140
+ durationSecs: 120,
1141
+ callType: 0, // 0 = REGULAR, 1 = SCHEDULED_CALL, 2 = VOICE_CHAT
1142
+ participants: [
1143
+ { jid: 'user@s.whatsapp.net', callOutcome: 0 }
1144
+ ]
1145
+ }
775
1146
  });
1147
+ ```
776
1148
 
777
- // Contact Messages
778
- await conn.sendMessage(jid, {
779
- contacts: {
780
- displayName: 'Sam aka vare',
781
- contacts: [{ vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:Sam aka vare\nTEL;waid=393476686131:+39 347 6686131\nEND:VCARD' }]
782
- }
1149
+ ##### Event Response Messages
1150
+
1151
+ Respond to an event message (e.g., RSVP for an event).
1152
+
1153
+ ```typescript
1154
+ await conn.sendMessage(jid, {
1155
+ eventResponse: {
1156
+ response: 1, // GOING = 1, NOT_GOING = 2, MAYBE = 3
1157
+ timestampMs: Date.now(),
1158
+ extraGuestCount: 0
1159
+ }
783
1160
  });
1161
+ ```
784
1162
 
785
- // Ephemeral Messages (Self-Destructing)
786
- await conn.sendMessage(jid, {
787
- text: "This message will self-destruct {hopefully like israel}"
1163
+ ##### Status Mention Messages
1164
+
1165
+ Mention a status in another status.
1166
+
1167
+ ```typescript
1168
+ await conn.sendMessage('status@broadcast', {
1169
+ statusMention: {
1170
+ quotedStatus: {
1171
+ key: {
1172
+ remoteJid: 'status@broadcast',
1173
+ fromMe: false,
1174
+ id: 'statusId123'
1175
+ },
1176
+ message: {
1177
+ conversation: 'Original status message'
1178
+ }
1179
+ }
1180
+ }
788
1181
  }, {
789
- ephemeralExpiration: 7 * 24 * 60 * 60
1182
+ statusJidList: [jid]
790
1183
  });
1184
+ ```
791
1185
 
792
- // Messages with View Once Response
793
- await conn.sendMessage(
794
- jid,
795
- {
796
- video: { url: './media/hado90.mp4' },
797
- viewOnce: true,
798
- caption: 'tuff'
1186
+ ##### Group Status Messages
1187
+
1188
+ Send a status message specific to a group.
1189
+
1190
+ ```typescript
1191
+ await conn.sendMessage(jid, {
1192
+ groupStatus: {
1193
+ message: {
1194
+ conversation: 'Group status update!'
799
1195
  }
800
- )
1196
+ }
1197
+ });
1198
+ ```
1199
+
1200
+ ##### Bot Task Messages
801
1201
 
802
- // Status Messages
1202
+ Send a message related to a bot task.
1203
+
1204
+ ```typescript
1205
+ await conn.sendMessage(jid, {
1206
+ botTask: {
1207
+ message: {
1208
+ conversation: 'Bot task completed.'
1209
+ }
1210
+ }
1211
+ });
1212
+ ```
1213
+
1214
+ ##### Limit Sharing Messages
1215
+
1216
+ Send a message to limit sharing.
1217
+
1218
+ ```typescript
1219
+ await conn.sendMessage(jid, {
1220
+ limitSharing: {
1221
+ message: {
1222
+ conversation: 'Sharing limited for this message.'
1223
+ }
1224
+ }
1225
+ });
1226
+ ```
1227
+
1228
+ ##### Status Add Yours Messages
1229
+
1230
+ Send a "Add Yours" status message.
1231
+
1232
+ ```typescript
803
1233
  await conn.sendMessage('status@broadcast', {
804
- text: 'god forgive em'
1234
+ statusAddYours: {
1235
+ message: {
1236
+ conversation: 'Add yours to this trend!'
1237
+ }
1238
+ }
805
1239
  }, {
806
- statusJidList: contacts
1240
+ statusJidList: [jid]
1241
+ });
1242
+ ```
1243
+
1244
+ ##### Bot Forwarded Messages
1245
+
1246
+ Send a message that was forwarded by a bot.
1247
+
1248
+ ```typescript
1249
+ await conn.sendMessage(jid, {
1250
+ botForwarded: {
1251
+ message: {
1252
+ conversation: 'This message was forwarded by a bot.'
1253
+ }
1254
+ }
1255
+ });
1256
+ ```
1257
+
1258
+ ##### Event Cover Image Messages
1259
+
1260
+ Send a cover image for an event.
1261
+
1262
+ ```typescript
1263
+ await conn.sendMessage(jid, {
1264
+ eventCoverImage: {
1265
+ message: {
1266
+ imageMessage: {
1267
+ url: 'https://example.com/event_cover.jpg',
1268
+ mimetype: 'image/jpeg'
1269
+ }
1270
+ }
1271
+ }
1272
+ });
1273
+ ```
1274
+
1275
+ ##### Poll Creation Message V4
1276
+
1277
+ Create a poll with additional options (version 4).
1278
+
1279
+ ```typescript
1280
+ await conn.sendMessage(jid, {
1281
+ pollV4: {
1282
+ name: 'Favorite color (V4)?',
1283
+ selectableCount: 1,
1284
+ values: ['Red', 'Green', 'Blue'],
1285
+ pollType: 0 // Default poll type
1286
+ }
1287
+ });
1288
+ ```
1289
+
1290
+ ##### Poll Creation Message V5
1291
+
1292
+ Create a poll with additional options (version 5).
1293
+
1294
+ ```typescript
1295
+ await conn.sendMessage(jid, {
1296
+ pollV5: {
1297
+ name: 'Favorite food (V5)?',
1298
+ selectableCount: 2,
1299
+ values: ['Pizza', 'Pasta', 'Sushi'],
1300
+ pollType: 1 // Quiz poll type
1301
+ }
1302
+ });
1303
+ ```
1304
+
1305
+ ##### Poll Result Snapshot Message V3
1306
+
1307
+ Send a snapshot of poll results (version 3).
1308
+
1309
+ ```typescript
1310
+ await conn.sendMessage(jid, {
1311
+ pollResultSnapshotV3: {
1312
+ pollCreationMessageKey: {
1313
+ remoteJid: jid,
1314
+ fromMe: true,
1315
+ id: 'pollMessageId123'
1316
+ },
1317
+ pollResult: {
1318
+ vote: {
1319
+ selectedOptions: [Buffer.from('Red')]
1320
+ },
1321
+ senderTimestampMs: Date.now()
1322
+ },
1323
+ contextInfo: {
1324
+ mentionedJid: [jid]
1325
+ },
1326
+ pollType: 0 // Default poll type
1327
+ }
1328
+ });
1329
+ ```
1330
+
1331
+ ##### Encrypted Comment Messages
1332
+
1333
+ Send encrypted comments on messages.
1334
+
1335
+ ```typescript
1336
+ await conn.sendMessage(jid, {
1337
+ encComment: {
1338
+ targetMessageKey: {
1339
+ remoteJid: jid,
1340
+ fromMe: false,
1341
+ id: 'messageId123'
1342
+ },
1343
+ encPayload: Buffer.from('encrypted_payload'),
1344
+ encIv: Buffer.from('encryption_iv')
1345
+ }
1346
+ });
1347
+ ```
1348
+
1349
+ ##### Encrypted Event Response Messages
1350
+
1351
+ Send encrypted event responses.
1352
+
1353
+ ```typescript
1354
+ await conn.sendMessage(jid, {
1355
+ encEventResponse: {
1356
+ eventCreationMessageKey: {
1357
+ remoteJid: jid,
1358
+ fromMe: false,
1359
+ id: 'eventMessageId123'
1360
+ },
1361
+ encPayload: Buffer.from('encrypted_payload'),
1362
+ encIv: Buffer.from('encryption_iv')
1363
+ }
1364
+ });
1365
+ ```
1366
+
1367
+ ##### Message History Bundle
1368
+
1369
+ Send a bundle of message history.
1370
+
1371
+ ```typescript
1372
+ await conn.sendMessage(jid, {
1373
+ messageHistoryBundle: {
1374
+ mimetype: 'application/octet-stream',
1375
+ media: { url: './history.bundle' },
1376
+ messageHistoryMetadata: {
1377
+ historyReceivers: ['user1@s.whatsapp.net', 'user2@s.whatsapp.net'],
1378
+ oldestMessageTimestamp: Date.now() - 86400000,
1379
+ messageCount: 100
1380
+ },
1381
+ contextInfo: {
1382
+ mentionedJid: [jid]
1383
+ }
1384
+ }
1385
+ });
1386
+ ```
1387
+
1388
+ ##### Message History Notice
1389
+
1390
+ Send a notice about message history.
1391
+
1392
+ ```typescript
1393
+ await conn.sendMessage(jid, {
1394
+ messageHistoryNotice: {
1395
+ messageHistoryMetadata: {
1396
+ historyReceivers: ['user1@s.whatsapp.net'],
1397
+ oldestMessageTimestamp: Date.now() - 86400000,
1398
+ messageCount: 50
1399
+ },
1400
+ contextInfo: {
1401
+ mentionedJid: [jid]
1402
+ }
1403
+ }
807
1404
  });
1405
+ ```
1406
+
1407
+ ##### Newsletter Follower Invite
1408
+
1409
+ Invite followers to a newsletter.
808
1410
 
809
- // Send a status with media (visible only to selected contacts)
1411
+ ```typescript
1412
+ await conn.sendMessage(jid, {
1413
+ inviteFollower: {
1414
+ newsletterJid: '120363418582531215@newsletter',
1415
+ newsletterName: 'My Newsletter',
1416
+ thumbnail: buffer, // Optional thumbnail
1417
+ caption: 'Join our newsletter!',
1418
+ contextInfo: {
1419
+ mentionedJid: [jid]
1420
+ }
1421
+ }
1422
+ });
1423
+ ```
1424
+
1425
+ ##### Placeholder Messages
1426
+
1427
+ Send placeholder messages (e.g., to mask linked devices).
1428
+
1429
+ ```typescript
1430
+ await conn.sendMessage(jid, {
1431
+ placeholder: {
1432
+ type: 0 // MASK_LINKED_DEVICES = 0
1433
+ }
1434
+ });
1435
+ ```
1436
+
1437
+ ##### Secret Encrypted Messages
1438
+
1439
+ Send secret encrypted messages (for event or message edits).
1440
+
1441
+ ```typescript
1442
+ await conn.sendMessage(jid, {
1443
+ secretEncrypted: {
1444
+ targetMessageKey: {
1445
+ remoteJid: jid,
1446
+ fromMe: false,
1447
+ id: 'targetMessageId123'
1448
+ },
1449
+ encPayload: Buffer.from('encrypted_payload'),
1450
+ encIv: Buffer.from('encryption_iv'),
1451
+ secretEncType: 2 // 0 = UNKNOWN, 1 = EVENT_EDIT, 2 = MESSAGE_EDIT
1452
+ }
1453
+ });
1454
+ ```
1455
+
1456
+ ##### Status Notification Messages
1457
+
1458
+ Send status notification messages (for status interactions).
1459
+
1460
+ ```typescript
810
1461
  await conn.sendMessage('status@broadcast', {
811
- image: { url: './media/menu/menu.jpg' },
812
- caption: 'all i need in this life of sin is-',
813
- }, {
814
- statusJidList: contacts
1462
+ statusNotification: {
1463
+ responseMessageKey: {
1464
+ remoteJid: 'status@broadcast',
1465
+ fromMe: false,
1466
+ id: 'responseId123'
1467
+ },
1468
+ originalMessageKey: {
1469
+ remoteJid: 'status@broadcast',
1470
+ fromMe: false,
1471
+ id: 'originalId123'
1472
+ },
1473
+ type: 1 // 0 = UNKNOWN, 1 = STATUS_ADD_YOURS, 2 = STATUS_RESHARE, 3 = STATUS_QUESTION_ANSWER_RESHARE
1474
+ }
1475
+ }, {
1476
+ statusJidList: [jid]
815
1477
  });
1478
+ ```
816
1479
 
817
- // Newsletter Messages
818
- await conn.sendMessage('120363418582531215@newsletter', {
819
- text: 'ay yo',
820
- });
1480
+ ##### Sticker Sync RMR Messages
1481
+
1482
+ Sync stickers via RMR (Recent Media Request).
1483
+
1484
+ ```typescript
1485
+ await conn.sendMessage(jid, {
1486
+ stickerSyncRMR: {
1487
+ filehash: ['hash1', 'hash2', 'hash3'],
1488
+ rmrSource: 'source_identifier',
1489
+ requestTimestamp: Date.now()
1490
+ }
1491
+ });
1492
+ ```
821
1493
 
822
1494
  // Payment Messages
1495
+
1496
+ ##### Request Payment
1497
+ ```typescript
823
1498
  await conn.sendMessage(jid, {
824
1499
  requestPayment: {
825
1500
  currency: 'EUR',
@@ -828,8 +1503,55 @@ await conn.sendMessage(jid, {
828
1503
  note: 'js gimme my money' // https://paypal.me/samakavare
829
1504
  }
830
1505
  });
1506
+ ```
1507
+
1508
+ ##### Send Payment
1509
+ ```typescript
1510
+ await conn.sendMessage(jid, {
1511
+ sendPayment: {
1512
+ requestMessageKey: {
1513
+ remoteJid: jid,
1514
+ fromMe: false,
1515
+ id: 'paymentRequestId123'
1516
+ },
1517
+ noteMessage: { text: 'Payment sent' },
1518
+ background: {
1519
+ id: 'payment_bg_id',
1520
+ type: 1 // DEFAULT = 1
1521
+ },
1522
+ transactionData: 'transaction_data_string'
1523
+ }
1524
+ });
1525
+ ```
1526
+
1527
+ ##### Decline Payment Request
1528
+ ```typescript
1529
+ await conn.sendMessage(jid, {
1530
+ declinePayment: {
1531
+ key: {
1532
+ remoteJid: jid,
1533
+ fromMe: false,
1534
+ id: 'paymentRequestId123'
1535
+ }
1536
+ }
1537
+ });
1538
+ ```
831
1539
 
832
- // Call Messages
1540
+ ##### Cancel Payment Request
1541
+ ```typescript
1542
+ await conn.sendMessage(jid, {
1543
+ cancelPayment: {
1544
+ key: {
1545
+ remoteJid: jid,
1546
+ fromMe: true,
1547
+ id: 'paymentRequestId123'
1548
+ }
1549
+ }
1550
+ });
1551
+ ```
1552
+
1553
+ ##### Scheduled Call Creation
1554
+ ```typescript
833
1555
  await conn.sendMessage(jid, {
834
1556
  call: {
835
1557
  callKey: {
@@ -837,69 +1559,67 @@ await conn.sendMessage(jid, {
837
1559
  id: Date.now().toString(),
838
1560
  remoteJid: jid
839
1561
  },
840
- type: 'ACCEPT' // 'MISSED', 'OFFER', 'ACCEPT', 'REJECT'..
1562
+ type: 'ACCEPT', // 'MISSED', 'OFFER', 'ACCEPT', 'REJECT'..
1563
+ time: Date.now() + 3600000, // Scheduled time (optional)
1564
+ title: 'Team Meeting' // Optional title
841
1565
  }
842
1566
  });
1567
+ ```
843
1568
 
844
- // Live Location Messages
1569
+ ##### Scheduled Call Edit
1570
+ ```typescript
845
1571
  await conn.sendMessage(jid, {
846
- liveLocation: {
847
- degreesLatitude: 45.4642,
848
- degreesLongitude: 9.1900,
849
- accuracyInMeters: 50,
850
- speedInMps: 5,
851
- degreesClockwiseFromMagneticNorth: 359,
852
- caption: "kmt im mean kiss my teeth",
853
- sequenceNumber: 21,
854
- timeOffset: 2000,
1572
+ scheduledCallEdit: {
1573
+ key: {
1574
+ remoteJid: jid,
1575
+ fromMe: true,
1576
+ id: 'scheduledCallId123'
1577
+ },
1578
+ editType: 1 // 0 = UNKNOWN, 1 = CANCEL
855
1579
  }
856
1580
  });
1581
+ ```
857
1582
 
858
- // Order/Product Messages
1583
+ ##### Pin/Unpin Messages
1584
+
1585
+ Pin or unpin a message in a chat.
1586
+
1587
+ ```typescript
1588
+ // Pin a message (type 1 = PIN_FOR_ALL)
859
1589
  await conn.sendMessage(jid, {
860
- order: {
861
- id: 'bysamakavare',
862
- thumbnail: buffer, // image buffer
863
- itemCount: 67,
864
- surface: 'CATALOG',
865
- title: 'heh',
866
- text: 'gotta make it happen',
867
- seller: '393514357738@s.whatsapp.net',
868
- amount: 67000,
869
- currency: 'EUR'
1590
+ pin: {
1591
+ key: {
1592
+ remoteJid: jid,
1593
+ fromMe: false,
1594
+ id: 'messageId123'
1595
+ },
1596
+ type: 1, // 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL
1597
+ time: 86400 // Duration in seconds (24 hours = 86400, 7 days = 604800, 30 days = 2592000)
870
1598
  }
871
1599
  });
872
1600
 
873
- // Product
1601
+ // Or use simplified syntax
874
1602
  await conn.sendMessage(jid, {
875
- product: {
876
- productImage: { url: './media/menu/menu.jpg' },
877
- productId: 'prod123',
878
- title: 'title',
879
- description: 'Desc',
880
- currency: 'EUR',
881
- priceAmount1000: 67000,
882
- retailerId: 'bysamakavare',
883
- url: 'https://varebot.netlify.app',
1603
+ pin: {
1604
+ remoteJid: jid,
1605
+ fromMe: false,
1606
+ id: 'messageId123'
884
1607
  },
885
- businessOwnerJid: m.sender
1608
+ type: 1, // 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL
1609
+ time: 86400 // Optional: duration in seconds
886
1610
  });
887
1611
 
888
- // Messages with Custom Header
1612
+ // Unpin a message (type 2 = UNPIN_FOR_ALL)
889
1613
  await conn.sendMessage(jid, {
890
- text: 'dilemma',
891
- contextInfo: {
892
- externalAdReply: {
893
- title: `title`,
894
- body: `desc`,
895
- thumbnailUrl: 'https://i.ibb.co/hJW7WwxV/sam.jpg', // image
896
- sourceUrl: '', // not recommended to set
897
- mediaType: 1,
898
- renderLargerThumbnail: false
899
- }
900
- }
1614
+ pin: {
1615
+ key: {
1616
+ remoteJid: jid,
1617
+ fromMe: false,
1618
+ id: 'messageId123'
1619
+ },
1620
+ type: 2 // UNPIN_FOR_ALL
1621
+ }
901
1622
  });
902
- > note: do not use showAdAttribution or keep it false, because with it active the message is not displayed
903
1623
  ```
904
1624
 
905
1625
  ### Response Management
@@ -927,6 +1647,188 @@ conn.ev.on('messages.upsert', async ({ messages }) => {
927
1647
  const selectedOptions = msg.message.pollResponseMessage.selectedOptions;
928
1648
  console.log('Selected options:', selectedOptions);
929
1649
  }
1650
+
1651
+ // Comment response
1652
+ if (msg.message?.commentMessage) {
1653
+ const comment = msg.message.commentMessage;
1654
+ console.log('Comment on message:', comment.targetMessageKey?.id);
1655
+ console.log('Comment content:', comment.message);
1656
+ }
1657
+
1658
+ // Question response
1659
+ if (msg.message?.questionResponseMessage) {
1660
+ const response = msg.message.questionResponseMessage;
1661
+ console.log('Response to question:', response.key?.id);
1662
+ console.log('Answer:', response.text);
1663
+ }
1664
+
1665
+ // Status question answer
1666
+ if (msg.message?.statusQuestionAnswerMessage) {
1667
+ const answer = msg.message.statusQuestionAnswerMessage;
1668
+ console.log('Status question answer:', answer.text);
1669
+ }
1670
+
1671
+ // AI Rich Response
1672
+ if (msg.message?.richResponseMessage) {
1673
+ const richResponse = msg.message.richResponseMessage;
1674
+ console.log('AI Rich Response type:', richResponse.messageType);
1675
+ console.log('Submessages:', richResponse.submessages);
1676
+ }
1677
+
1678
+ // Interactive Response (Native Flow Response)
1679
+ if (msg.message?.interactiveResponseMessage) {
1680
+ const response = msg.message.interactiveResponseMessage;
1681
+ console.log('Interactive response body:', response.body?.text);
1682
+ if (response.nativeFlowResponseMessage) {
1683
+ console.log('Native flow response:', response.nativeFlowResponseMessage.name);
1684
+ console.log('Params:', response.nativeFlowResponseMessage.paramsJson);
1685
+ }
1686
+ }
1687
+
1688
+ // Sticker Pack
1689
+ if (msg.message?.stickerPackMessage) {
1690
+ const pack = msg.message.stickerPackMessage;
1691
+ console.log('Sticker pack:', pack.name);
1692
+ console.log('Publisher:', pack.publisher);
1693
+ console.log('Stickers count:', pack.stickers?.length);
1694
+ console.log('Pack ID:', pack.stickerPackId);
1695
+ console.log('Origin:', pack.stickerPackOrigin);
1696
+ }
1697
+
1698
+ // Collection/Catalog response
1699
+ if (msg.message?.interactiveMessage?.collectionMessage) {
1700
+ const collection = msg.message.interactiveMessage.collectionMessage;
1701
+ console.log('Collection opened:', collection.id);
1702
+ console.log('Business JID:', collection.bizJid);
1703
+ }
1704
+
1705
+ // Invoice response
1706
+ if (msg.message?.invoiceMessage) {
1707
+ const invoice = msg.message.invoiceMessage;
1708
+ console.log('Invoice token:', invoice.token);
1709
+ console.log('Invoice note:', invoice.note);
1710
+ console.log('Attachment type:', invoice.attachmentType === 0 ? 'IMAGE' : 'PDF');
1711
+ }
1712
+
1713
+ // Business Call
1714
+ if (msg.message?.bcallMessage) {
1715
+ const bcall = msg.message.bcallMessage;
1716
+ console.log('Business call session:', bcall.sessionId);
1717
+ console.log('Media type:', bcall.mediaType === 1 ? 'AUDIO' : 'VIDEO');
1718
+ }
1719
+
1720
+ // Call Log
1721
+ if (msg.message?.callLogMesssage) {
1722
+ const callLog = msg.message.callLogMesssage;
1723
+ console.log('Call outcome:', callLog.callOutcome);
1724
+ console.log('Duration:', callLog.durationSecs, 'seconds');
1725
+ console.log('Participants:', callLog.participants);
1726
+ }
1727
+
1728
+ // Encrypted Comment
1729
+ if (msg.message?.encCommentMessage) {
1730
+ const encComment = msg.message.encCommentMessage;
1731
+ console.log('Encrypted comment on message:', encComment.targetMessageKey?.id);
1732
+ }
1733
+
1734
+ // Encrypted Event Response
1735
+ if (msg.message?.encEventResponseMessage) {
1736
+ const encEvent = msg.message.encEventResponseMessage;
1737
+ console.log('Encrypted event response for:', encEvent.eventCreationMessageKey?.id);
1738
+ }
1739
+
1740
+ // Message History Bundle
1741
+ if (msg.message?.messageHistoryBundle) {
1742
+ const bundle = msg.message.messageHistoryBundle;
1743
+ console.log('History bundle receivers:', bundle.messageHistoryMetadata?.historyReceivers);
1744
+ console.log('Message count:', bundle.messageHistoryMetadata?.messageCount);
1745
+ }
1746
+
1747
+ // Message History Notice
1748
+ if (msg.message?.messageHistoryNotice) {
1749
+ const notice = msg.message.messageHistoryNotice;
1750
+ console.log('History notice receivers:', notice.messageHistoryMetadata?.historyReceivers);
1751
+ }
1752
+
1753
+ // Newsletter Follower Invite
1754
+ if (msg.message?.newsletterFollowerInviteMessageV2) {
1755
+ const invite = msg.message.newsletterFollowerInviteMessageV2;
1756
+ console.log('Newsletter invite:', invite.newsletterName);
1757
+ console.log('Newsletter JID:', invite.newsletterJid);
1758
+ }
1759
+
1760
+ // Placeholder
1761
+ if (msg.message?.placeholderMessage) {
1762
+ const placeholder = msg.message.placeholderMessage;
1763
+ console.log('Placeholder type:', placeholder.type);
1764
+ }
1765
+
1766
+ // Secret Encrypted
1767
+ if (msg.message?.secretEncryptedMessage) {
1768
+ const secret = msg.message.secretEncryptedMessage;
1769
+ console.log('Secret encrypted type:', secret.secretEncType);
1770
+ console.log('Target message:', secret.targetMessageKey?.id);
1771
+ }
1772
+
1773
+ // Status Notification
1774
+ if (msg.message?.statusNotificationMessage) {
1775
+ const notification = msg.message.statusNotificationMessage;
1776
+ console.log('Status notification type:', notification.type);
1777
+ console.log('Original message:', notification.originalMessageKey?.id);
1778
+ }
1779
+
1780
+ // Sticker Sync RMR
1781
+ if (msg.message?.stickerSyncRmrMessage) {
1782
+ const sync = msg.message.stickerSyncRmrMessage;
1783
+ console.log('Sticker sync filehashes:', sync.filehash);
1784
+ console.log('RMR source:', sync.rmrSource);
1785
+ }
1786
+
1787
+ // Send Payment
1788
+ if (msg.message?.sendPaymentMessage) {
1789
+ const payment = msg.message.sendPaymentMessage;
1790
+ console.log('Payment sent for request:', payment.requestMessageKey?.id);
1791
+ console.log('Transaction data:', payment.transactionData);
1792
+ }
1793
+
1794
+ // Decline Payment
1795
+ if (msg.message?.declinePaymentRequestMessage) {
1796
+ const decline = msg.message.declinePaymentRequestMessage;
1797
+ console.log('Payment declined for:', decline.key?.id);
1798
+ }
1799
+
1800
+ // Cancel Payment
1801
+ if (msg.message?.cancelPaymentRequestMessage) {
1802
+ const cancel = msg.message.cancelPaymentRequestMessage;
1803
+ console.log('Payment cancelled for:', cancel.key?.id);
1804
+ }
1805
+
1806
+ // Scheduled Call Edit
1807
+ if (msg.message?.scheduledCallEditMessage) {
1808
+ const edit = msg.message.scheduledCallEditMessage;
1809
+ console.log('Scheduled call edited:', edit.key?.id);
1810
+ console.log('Edit type:', edit.editType === 1 ? 'CANCEL' : 'UNKNOWN');
1811
+ }
1812
+
1813
+ // Poll Result Snapshot
1814
+ if (msg.message?.pollResultSnapshotMessage) {
1815
+ const snapshot = msg.message.pollResultSnapshotMessage;
1816
+ console.log('Poll snapshot:', snapshot.name);
1817
+ console.log('Votes:', snapshot.pollVotes);
1818
+ }
1819
+
1820
+ // Poll Update
1821
+ if (msg.message?.pollUpdateMessage) {
1822
+ const update = msg.message.pollUpdateMessage;
1823
+ console.log('Poll update for:', update.pollCreationMessageKey?.id);
1824
+ }
1825
+
1826
+ // Pin/Unpin
1827
+ if (msg.message?.pinInChatMessage) {
1828
+ const pin = msg.message.pinInChatMessage;
1829
+ console.log('Pin action:', pin.type === 1 ? 'PIN_FOR_ALL' : 'UNPIN_FOR_ALL');
1830
+ console.log('Pinned message:', pin.key?.id);
1831
+ }
930
1832
  });
931
1833
  ```
932
1834
 
@@ -1079,144 +1981,35 @@ await conn.sendMessage(jid, {
1079
1981
 
1080
1982
  ### Best Practices for LID/JID
1081
1983
 
1082
- - **decodeJid(jid)**: Main function to normalize JID/LID. Handles:
1083
- - Formats with `:\d+@` (uses `jidNormalizedUser`).
1084
- - Decodes user/server into `${user}@${server}`.
1085
- - Converts `@lid` to `@s.whatsapp.net`.
1086
-
1087
- **Implementation Example (from main.js):**
1088
- ```typescript
1089
- decodeJid: (jid) => {
1090
- if (!jid) return jid;
1091
- let decoded = jid;
1092
- if (/:\d+@/gi.test(jid)) {
1093
- decoded = jidNormalizedUser(jid);
1094
- }
1095
- if (typeof decoded === 'object' && decoded.user && decoded.server) {
1096
- decoded = `${decoded.user}@${decoded.server}`;
1097
- }
1098
- if (decoded.endsWith('@lid')) {
1099
- decoded = decoded.replace('@lid', '@s.whatsapp.net');
1100
- }
1101
- return decoded;
1102
- },
1103
- ```
1104
- Use `conn.decodeJid(jid)` everywhere to normalize IDs (e.g., sender, participant, quoted).
1984
+ - **JID Normalization**: The library automatically handles JID/LID normalization in most cases.
1985
+ - **Use Built-in Functions**: Prefer `toJid()`, `normalizeJid()`, and `validateJid()` from the library.
1986
+ - **Cache Management**: The library includes automatic caching for LID/JID conversions.
1105
1987
 
1106
- - **Monkey-Patch for groupParticipantsUpdate**: Fixes group participant updates by finding the real JID from metadata.
1107
-
1108
- **Example (from handler.js):**
1109
- ```typescript
1110
- if (!this.originalGroupParticipantsUpdate) {
1111
- this.originalGroupParticipantsUpdate = this.groupParticipantsUpdate;
1112
- this.groupParticipantsUpdate = async function(chatId, users, action) {
1113
- try {
1114
- let metadata = global.groupCache.get(chatId);
1115
- if (!metadata) {
1116
- metadata = await fetchGroupMetadataWithRetry(this, chatId);
1117
- if (metadata) global.groupCache.set(chatId, metadata);
1118
- }
1119
- if (!metadata) {
1120
- console.error('[ERROR] No group metadata available for safe update');
1121
- return this.originalGroupParticipantsUpdate.call(this, chatId, users, action);
1122
- }
1123
-
1124
- const correctedUsers = users.map(userJid => {
1125
- const decoded = this.decodeJid(userJid);
1126
- const phone = decoded.split('@')[0].split(':')[0];
1127
- const participant = metadata.participants.find(p => {
1128
- const pId = this.decodeJid(p.id || p.jid || '');
1129
- const pPhone = pId.split('@')[0].split(':')[0];
1130
- return pPhone === phone;
1131
- });
1132
- return participant ? participant.id : userJid; // Fallback to original if not found
1133
- });
1134
-
1135
- return this.originalGroupParticipantsUpdate.call(this, chatId, correctedUsers, action);
1136
- } catch (e) {
1137
- console.error('[ERROR] Error in safeGroupParticipantsUpdate:', e);
1138
- throw e;
1139
- }
1140
- };
1141
- }
1142
- ```
1988
+ **Common Use Cases:**
1989
+ - **Group Participants**: Use `toJid()` to normalize participant IDs before operations.
1990
+ - **Message Sender**: Extract sender info with `getSenderLid()` for reliable identification.
1991
+ - **Validation**: Always validate JIDs with `validateJid()` before critical operations.
1143
1992
 
1144
- - **Cache for Group Metadata**: Use NodeCache to store metadata, normalizing with `decodeJid`.
1145
-
1146
- **Example (from handler.js):**
1147
- ```typescript
1148
- global.groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
1149
-
1150
- // In participantsUpdate or groups.update:
1151
- metadata.participants.forEach(u => {
1152
- const normId = this.decodeJid(u.id);
1153
- const jid = u.jid || normId;
1154
- });
1155
- global.groupCache.set(update.id, metadata);
1156
- ```
1157
-
1158
- - **Normalization in Print/Log**: Remove `:xx` from phone numbers for clean display.
1159
-
1160
- **Example (from print.js):**
1161
- ```typescript
1162
- function formatPhoneNumber(jid, name) {
1163
- if (!jid) return 'Unknown';
1164
- let userPart = jid.split('@')[0];
1165
- let cleanNumber = userPart.split(':')[0]; // Remove the :xx part to get the real number
1166
- try {
1167
- const number = PhoneNumber('+' + cleanNumber).getNumber('international');
1168
- return number + (name ? ` ~${name}` : '');
1169
- } catch {
1170
- return (cleanNumber || '') + (name ? ` ~${name}` : '');
1171
- }
1172
- }
1173
- ```
1174
-
1175
- - **Common Problems and Fixes:**
1176
- - **Missing LID in Groups:** Use `decodeJid` and metadata cache to find real JIDs.
1177
- - **JID Conversion:** Always apply `decodeJid` before `sendMessage` or query.
1178
- - **Multi-Device:** Set `syncFullHistory: true` in config for LID sync.
1179
- - **Errors in Mention/Quoted:** Normalize with `decodeJid` in handler for quoted.sender and mentionedJid.
1180
-
1181
- ### Integrated Example in Main
1993
+ ### Integrated Example
1182
1994
 
1183
1995
  ```typescript
1184
- // In your main file
1185
- import makeWASocket, { getSenderLid, toJid } from '@realvare/based';
1186
- // ... (authentication and sock creation)
1996
+ import makeWASocket, { getSenderLid, toJid, validateJid } from '@realvare/based';
1187
1997
 
1188
1998
  conn.ev.on('messages.upsert', async ({ messages }) => {
1189
1999
  const msg = messages[0];
1190
2000
  if (!msg.message) return;
1191
2001
 
1192
2002
  const info = getSenderLid(msg);
1193
- const senderJid = toJid(info.lid); // Fix LID -> JID
1194
-
1195
- // Example: Reply only if valid JID
1196
- if (senderJid.endsWith('@s.whatsapp.net')) {
1197
- await conn.sendMessage(senderJid, { text: `Hello from ${senderJid}!` }, { quoted: msg });
2003
+ const senderJid = toJid(info.lid);
2004
+
2005
+ // Validate before using
2006
+ const validation = validateJid(senderJid);
2007
+ if (validation.isValid) {
2008
+ await conn.sendMessage(senderJid, { text: 'Message received!' }, { quoted: msg });
1198
2009
  }
1199
2010
  });
1200
2011
  ```
1201
2012
 
1202
- ### Custom Handler Example
1203
-
1204
- ```typescript
1205
- // handler.js
1206
- export async function handleMessage(sock, msg) {
1207
- const info = getSenderLid(msg);
1208
- const jid = toJid(info.lid);
1209
-
1210
- // Log and response
1211
- console.log(`Message from ${jid}`);
1212
- await conn.sendMessage(jid, { text: 'Handler activated!' });
1213
- }
1214
-
1215
- // In main: conn.ev.on('messages.upsert', ({ messages }) => handleMessage(sock, messages[0]));
1216
- ```
1217
-
1218
- **Tip:** Test in groups to verify LID, as Baileys upstream has improved native support in 2025, but the custom fixes here ensure backward compatibility.
1219
-
1220
2013
  ---
1221
2014
 
1222
2015
  ### 🚀 Smart LID/JID Cache
@@ -1309,29 +2102,16 @@ console.log('Cache enabled:', config.performance.enableCache);
1309
2102
 
1310
2103
  ---
1311
2104
 
1312
- ## 🧩 Events: LID and JID always available (new)
2105
+ ## 🧩 Events: LID and JID Management
1313
2106
 
1314
- The emitted events include auxiliary fields on messages to easily access both the sender/participant's JID and LID.
2107
+ The library enriches event payloads to provide both JID and LID, eliminating ambiguity in multi-device and group contexts.
1315
2108
 
1316
- ```typescript
1317
- conn.ev.on('messages.upsert', ({ messages, type }) => {
1318
- for (const msg of messages) {
1319
- // Additional fields on msg.key
1320
- // - remoteJidNormalized: Normalized JID (e.g., @s.whatsapp.net)
1321
- // - remoteLid: LID equivalent of remoteJid
1322
- // - participantLid: LID equivalent of participant (if present)
1323
- const jid = msg.key.remoteJidNormalized || msg.key.remoteJid;
1324
- const remoteLid = msg.key.remoteLid;
1325
- const participantLid = msg.key.participantLid;
2109
+ **Key Features:**
2110
+ - Automatic JID/LID normalization in events
2111
+ - Pre-normalized fields in `msg.key` (`remoteJidNormalized`, `remoteLid`, `participantLid`)
2112
+ - Seamless conversion with `toJid()` and `normalizeJid()`
1326
2113
 
1327
- if (jid?.endsWith('@s.whatsapp.net')) {
1328
- conn.sendMessage(jid, { text: `Hello! LID: ${remoteLid || 'n/a'}` });
1329
- }
1330
- }
1331
- });
1332
- ```
1333
-
1334
- These fields eliminate ambiguity in groups and multi-device contexts where some events report LID, others JID.
2114
+ Refer to the examples in the **Quick Guide** and **API Documentation** sections for practical usage.
1335
2115
 
1336
2116
  ---
1337
2117
 
@@ -1359,8 +2139,8 @@ const sock = makeWASocket({
1359
2139
  maxMsgRetryCount: 5,
1360
2140
 
1361
2141
  // 🎛️ Behavior
1362
- markOnlineOnConnect: true,
1363
- syncFullHistory: false, // Enable for full sync (consumes data)
2142
+ markOnlineOnConnect: false, // Recommended: false to reduce ban risk
2143
+ syncFullHistory: false, // Keep false to prevent slowdowns
1364
2144
  fireInitQueries: true,
1365
2145
  generateHighQualityLinkPreview: true,
1366
2146
  });
@@ -1465,4 +2245,4 @@ See [LICENSE](LICENSE) for details.
1465
2245
  <br>
1466
2246
  <img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=24&height=120&section=footer&text=&fontSize=30&fontColor=ffffff&animation=fadeIn&fontAlignY=35"/>
1467
2247
 
1468
- </div>
2248
+ </div>