@realvare/based 2.7.70 → 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.
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;
@@ -593,33 +644,87 @@ await conn.sendMessage(jid, {
593
644
  ```
594
645
 
595
646
  #### Advanced Media
647
+
596
648
  ```typescript
597
649
  // Album (Multiple images)
598
650
  await conn.sendMessage(jid, {
599
651
  album: imageBuffers.map(buffer => ({ image: buffer })),
600
652
  caption: 'ts gettin real'
601
653
  });
654
+ ```
655
+
656
+ #### Stickers
602
657
 
603
- // Sticker
658
+ Sending stickers is supported. You can send a sticker from a URL or a buffer. For creating stickers from images, you can use an external library like `wa-sticker-formatter`.
659
+
660
+ ```typescript
661
+ // Sticker from URL
604
662
  await conn.sendMessage(jid, {
605
663
  sticker: { url: './stickers/sticker.webp' }
606
664
  });
607
665
 
608
- // Location message
609
- await conn.sendMessage(jid, {
610
- location: {
611
- degreesLatitude: 45.4642,
612
- degreesLongitude: 9.1900,
613
- name: "Milano",
614
- address: "Piazza del Duomo, Milano"
615
- }
666
+ // Sticker from buffer using wa-sticker-formatter
667
+ const { Sticker } = require('wa-sticker-formatter'); // Optional external library
668
+ const sticker = new Sticker('path/to/image.jpg', { pack: 'My Pack', author: 'My Bot' });
669
+ const buffer = await sticker.toBuffer();
670
+ await conn.sendMessage(jid, { sticker: buffer });
671
+ ```
672
+
673
+ ##### Sticker Packs
674
+
675
+ Send a complete sticker pack message with multiple stickers. This allows you to send a collection of stickers as a single pack message.
676
+
677
+ ```typescript
678
+ await conn.sendMessage(jid, {
679
+ stickerPack: {
680
+ name: 'My Sticker Pack',
681
+ publisher: 'My Bot',
682
+ description: 'A cool sticker pack',
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!',
687
+ stickers: [
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
+ }
704
+ ]
705
+ }
616
706
  });
617
707
  ```
618
708
 
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.
710
+
711
+ ##### Stickers on Status (2025 Feature)
712
+
713
+ The new interactive stickers on Status (e.g., with lyrics or questions) can be sent by sending a sticker to `status@broadcast`.
714
+
715
+ ```typescript
716
+ await conn.sendMessage('status@broadcast', {
717
+ sticker: { url: './sticker.webp' },
718
+ caption: 'Interactive sticker on Status'
719
+ }, { statusJidList: ['user1@s.whatsapp.net', 'user2@s.whatsapp.net'] });
720
+ ```
721
+
619
722
  #### Interactive Messages
620
- These messages include interactive elements like buttons, lists, and templates.
723
+
724
+ These messages include interactive elements like buttons, lists, polls, carousels, collections, and invoices.
621
725
 
622
726
  ##### Messages with Simple Buttons
727
+
623
728
  Send quick reply buttons.
624
729
 
625
730
  ```typescript
@@ -627,15 +732,15 @@ await conn.sendMessage(jid, {
627
732
  text: 'Choose an option:',
628
733
  footer: 'Footer',
629
734
  buttons: [
630
- { buttonId: 'cmd1', buttonText: { displayText: 'text1' }, type: 1 },
631
- { buttonId: 'cmd2', buttonText: { displayText: 'text2' }, type: 1 },
735
+ { buttonId: 'cmd1', buttonText: { displayText: 'Option 1' }, type: 1 },
736
+ { buttonId: 'cmd2', buttonText: { displayText: 'Option 2' }, type: 1 },
632
737
  ],
633
- headerType: 1,
634
738
  });
635
739
  ```
636
740
 
637
741
  ##### Messages with Buttons and Image
638
- Combine image with buttons.
742
+
743
+ Combine an image with buttons.
639
744
 
640
745
  ```typescript
641
746
  await conn.sendMessage(jid, {
@@ -649,7 +754,8 @@ await conn.sendMessage(jid, {
649
754
  ```
650
755
 
651
756
  ##### List Messages
652
- Send a list of options (only in private).
757
+
758
+ Send a list of options (only in private chats).
653
759
 
654
760
  ```typescript
655
761
  await conn.sendMessage(jid, {
@@ -669,69 +775,726 @@ await conn.sendMessage(jid, {
669
775
  });
670
776
  ```
671
777
 
672
- #### Other Messages
778
+ ##### Collection Messages (Catalog)
779
+
780
+ Send a collection/catalog message to browse products.
781
+
673
782
  ```typescript
674
- // Message with quote
675
- await conn.sendMessage(jid, {
676
- text: 'bang bang',
677
- quoted: quotedMessage // The message to quote/reply/cite
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
+ }
678
792
  });
793
+ ```
679
794
 
680
- // Contact Messages
681
- await conn.sendMessage(jid, {
682
- contacts: {
683
- displayName: 'Sam aka vare',
684
- contacts: [{ vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:Sam aka vare\nTEL;waid=393476686131:+39 347 6686131\nEND:VCARD' }]
685
- }
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
686
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.
687
839
 
688
- // Poll Messages (Survey)
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
+
903
+ ##### Poll Messages
904
+
905
+ Create a poll for users to vote on.
906
+
907
+ ```typescript
689
908
  await conn.sendMessage(jid, {
690
909
  poll: {
691
910
  name: 'Favorite Anime?',
692
911
  values: ['Aot', 'Bleach', 'Death note'],
693
- selectableCount: 1 // how many choices possible
912
+ selectableCount: 1 // or >1 for multi-select
694
913
  }
695
914
  });
915
+ ```
696
916
 
697
- // Ephemeral Messages (Self-Destructing)
698
- await conn.sendMessage(jid, {
699
- text: "This message will self-destruct {hopefully like israel}"
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
+ }
700
1022
  }, {
701
- ephemeralExpiration: 7 * 24 * 60 * 60
1023
+ statusJidList: [jid]
702
1024
  });
1025
+ ```
703
1026
 
704
- // Messages with View Once Response
705
- await conn.sendMessage(
706
- jid,
707
- {
708
- video: { url: './media/hado90.mp4' },
709
- viewOnce: true,
710
- caption: 'tuff'
1027
+ ##### Status Quoted Messages
1028
+
1029
+ Quote a status message (e.g., question-answer reshare).
1030
+
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'
711
1041
  }
712
- )
1042
+ }
1043
+ }, {
1044
+ statusJidList: [jid]
1045
+ });
1046
+ ```
1047
+
1048
+ ##### Status Sticker Interaction Messages
713
1049
 
714
- // Status Messages
1050
+ Interact with stickers on status (e.g., reactions).
1051
+
1052
+ ```typescript
715
1053
  await conn.sendMessage('status@broadcast', {
716
- text: 'god forgive em'
1054
+ statusStickerInteraction: {
1055
+ key: {
1056
+ remoteJid: 'status@broadcast',
1057
+ fromMe: false,
1058
+ id: 'statusMessageId123'
1059
+ },
1060
+ stickerKey: 'stickerKey123',
1061
+ type: 1 // REACTION
1062
+ }
717
1063
  }, {
718
- statusJidList: contacts
1064
+ statusJidList: [jid]
1065
+ });
1066
+ ```
1067
+
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
+ }
719
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.
1113
+
1114
+ #### Other Messages
1115
+
1116
+ ##### Business Call Messages (BCall)
1117
+
1118
+ Send business call messages with media.
1119
+
1120
+ ```typescript
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
+ }
1128
+ });
1129
+ ```
720
1130
 
721
- // Send a status with media (visible only to selected contacts)
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
+ }
1146
+ });
1147
+ ```
1148
+
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
+ }
1160
+ });
1161
+ ```
1162
+
1163
+ ##### Status Mention Messages
1164
+
1165
+ Mention a status in another status.
1166
+
1167
+ ```typescript
722
1168
  await conn.sendMessage('status@broadcast', {
723
- image: { url: './media/menu/menu.jpg' },
724
- caption: 'all i need in this life of sin is-',
725
- }, {
726
- statusJidList: contacts
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
+ }
1181
+ }, {
1182
+ statusJidList: [jid]
727
1183
  });
1184
+ ```
728
1185
 
729
- // Newsletter Messages
730
- await conn.sendMessage('120363418582531215@newsletter', {
731
- text: 'ay yo',
732
- });
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!'
1195
+ }
1196
+ }
1197
+ });
1198
+ ```
1199
+
1200
+ ##### Bot Task Messages
1201
+
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
1233
+ await conn.sendMessage('status@broadcast', {
1234
+ statusAddYours: {
1235
+ message: {
1236
+ conversation: 'Add yours to this trend!'
1237
+ }
1238
+ }
1239
+ }, {
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
+ }
1404
+ });
1405
+ ```
1406
+
1407
+ ##### Newsletter Follower Invite
1408
+
1409
+ Invite followers to a newsletter.
1410
+
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
1461
+ await conn.sendMessage('status@broadcast', {
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]
1477
+ });
1478
+ ```
1479
+
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
+ ```
733
1493
 
734
1494
  // Payment Messages
1495
+
1496
+ ##### Request Payment
1497
+ ```typescript
735
1498
  await conn.sendMessage(jid, {
736
1499
  requestPayment: {
737
1500
  currency: 'EUR',
@@ -740,8 +1503,55 @@ await conn.sendMessage(jid, {
740
1503
  note: 'js gimme my money' // https://paypal.me/samakavare
741
1504
  }
742
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
+ ```
1539
+
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
+ ```
743
1552
 
744
- // Call Messages
1553
+ ##### Scheduled Call Creation
1554
+ ```typescript
745
1555
  await conn.sendMessage(jid, {
746
1556
  call: {
747
1557
  callKey: {
@@ -749,69 +1559,67 @@ await conn.sendMessage(jid, {
749
1559
  id: Date.now().toString(),
750
1560
  remoteJid: jid
751
1561
  },
752
- 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
753
1565
  }
754
1566
  });
1567
+ ```
755
1568
 
756
- // Live Location Messages
1569
+ ##### Scheduled Call Edit
1570
+ ```typescript
757
1571
  await conn.sendMessage(jid, {
758
- liveLocation: {
759
- degreesLatitude: 45.4642,
760
- degreesLongitude: 9.1900,
761
- accuracyInMeters: 50,
762
- speedInMps: 5,
763
- degreesClockwiseFromMagneticNorth: 359,
764
- caption: "kmt im mean kiss my teeth",
765
- sequenceNumber: 21,
766
- timeOffset: 2000,
1572
+ scheduledCallEdit: {
1573
+ key: {
1574
+ remoteJid: jid,
1575
+ fromMe: true,
1576
+ id: 'scheduledCallId123'
1577
+ },
1578
+ editType: 1 // 0 = UNKNOWN, 1 = CANCEL
767
1579
  }
768
1580
  });
1581
+ ```
769
1582
 
770
- // 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)
771
1589
  await conn.sendMessage(jid, {
772
- order: {
773
- id: 'bysamakavare',
774
- thumbnail: buffer, // image buffer
775
- itemCount: 67,
776
- surface: 'CATALOG',
777
- title: 'heh',
778
- text: 'gotta make it happen',
779
- seller: '393514357738@s.whatsapp.net',
780
- amount: 67000,
781
- 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)
782
1598
  }
783
1599
  });
784
1600
 
785
- // Product
1601
+ // Or use simplified syntax
786
1602
  await conn.sendMessage(jid, {
787
- product: {
788
- productImage: { url: './media/menu/menu.jpg' },
789
- productId: 'prod123',
790
- title: 'title',
791
- description: 'Desc',
792
- currency: 'EUR',
793
- priceAmount1000: 67000,
794
- retailerId: 'bysamakavare',
795
- url: 'https://varebot.netlify.app',
1603
+ pin: {
1604
+ remoteJid: jid,
1605
+ fromMe: false,
1606
+ id: 'messageId123'
796
1607
  },
797
- businessOwnerJid: m.sender
1608
+ type: 1, // 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL
1609
+ time: 86400 // Optional: duration in seconds
798
1610
  });
799
1611
 
800
- // Messages with Custom Header
1612
+ // Unpin a message (type 2 = UNPIN_FOR_ALL)
801
1613
  await conn.sendMessage(jid, {
802
- text: 'dilemma',
803
- contextInfo: {
804
- externalAdReply: {
805
- title: `title`,
806
- body: `desc`,
807
- thumbnailUrl: 'https://i.ibb.co/hJW7WwxV/sam.jpg', // image
808
- sourceUrl: '', // not recommended to set
809
- mediaType: 1,
810
- renderLargerThumbnail: false
811
- }
812
- }
1614
+ pin: {
1615
+ key: {
1616
+ remoteJid: jid,
1617
+ fromMe: false,
1618
+ id: 'messageId123'
1619
+ },
1620
+ type: 2 // UNPIN_FOR_ALL
1621
+ }
813
1622
  });
814
- > note: do not use showAdAttribution or keep it false, because with it active the message is not displayed
815
1623
  ```
816
1624
 
817
1625
  ### Response Management
@@ -839,6 +1647,188 @@ conn.ev.on('messages.upsert', async ({ messages }) => {
839
1647
  const selectedOptions = msg.message.pollResponseMessage.selectedOptions;
840
1648
  console.log('Selected options:', selectedOptions);
841
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
+ }
842
1832
  });
843
1833
  ```
844
1834
 
@@ -991,144 +1981,35 @@ await conn.sendMessage(jid, {
991
1981
 
992
1982
  ### Best Practices for LID/JID
993
1983
 
994
- - **decodeJid(jid)**: Main function to normalize JID/LID. Handles:
995
- - Formats with `:\d+@` (uses `jidNormalizedUser`).
996
- - Decodes user/server into `${user}@${server}`.
997
- - Converts `@lid` to `@s.whatsapp.net`.
998
-
999
- **Implementation Example (from main.js):**
1000
- ```typescript
1001
- decodeJid: (jid) => {
1002
- if (!jid) return jid;
1003
- let decoded = jid;
1004
- if (/:\d+@/gi.test(jid)) {
1005
- decoded = jidNormalizedUser(jid);
1006
- }
1007
- if (typeof decoded === 'object' && decoded.user && decoded.server) {
1008
- decoded = `${decoded.user}@${decoded.server}`;
1009
- }
1010
- if (decoded.endsWith('@lid')) {
1011
- decoded = decoded.replace('@lid', '@s.whatsapp.net');
1012
- }
1013
- return decoded;
1014
- },
1015
- ```
1016
- Use `conn.decodeJid(jid)` everywhere to normalize IDs (e.g., sender, participant, quoted).
1017
-
1018
- - **Monkey-Patch for groupParticipantsUpdate**: Fixes group participant updates by finding the real JID from metadata.
1019
-
1020
- **Example (from handler.js):**
1021
- ```typescript
1022
- if (!this.originalGroupParticipantsUpdate) {
1023
- this.originalGroupParticipantsUpdate = this.groupParticipantsUpdate;
1024
- this.groupParticipantsUpdate = async function(chatId, users, action) {
1025
- try {
1026
- let metadata = global.groupCache.get(chatId);
1027
- if (!metadata) {
1028
- metadata = await fetchGroupMetadataWithRetry(this, chatId);
1029
- if (metadata) global.groupCache.set(chatId, metadata);
1030
- }
1031
- if (!metadata) {
1032
- console.error('[ERROR] No group metadata available for safe update');
1033
- return this.originalGroupParticipantsUpdate.call(this, chatId, users, action);
1034
- }
1035
-
1036
- const correctedUsers = users.map(userJid => {
1037
- const decoded = this.decodeJid(userJid);
1038
- const phone = decoded.split('@')[0].split(':')[0];
1039
- const participant = metadata.participants.find(p => {
1040
- const pId = this.decodeJid(p.id || p.jid || '');
1041
- const pPhone = pId.split('@')[0].split(':')[0];
1042
- return pPhone === phone;
1043
- });
1044
- return participant ? participant.id : userJid; // Fallback to original if not found
1045
- });
1046
-
1047
- return this.originalGroupParticipantsUpdate.call(this, chatId, correctedUsers, action);
1048
- } catch (e) {
1049
- console.error('[ERROR] Error in safeGroupParticipantsUpdate:', e);
1050
- throw e;
1051
- }
1052
- };
1053
- }
1054
- ```
1055
-
1056
- - **Cache for Group Metadata**: Use NodeCache to store metadata, normalizing with `decodeJid`.
1057
-
1058
- **Example (from handler.js):**
1059
- ```typescript
1060
- global.groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
1061
-
1062
- // In participantsUpdate or groups.update:
1063
- metadata.participants.forEach(u => {
1064
- const normId = this.decodeJid(u.id);
1065
- const jid = u.jid || normId;
1066
- });
1067
- global.groupCache.set(update.id, metadata);
1068
- ```
1069
-
1070
- - **Normalization in Print/Log**: Remove `:xx` from phone numbers for clean display.
1071
-
1072
- **Example (from print.js):**
1073
- ```typescript
1074
- function formatPhoneNumber(jid, name) {
1075
- if (!jid) return 'Unknown';
1076
- let userPart = jid.split('@')[0];
1077
- let cleanNumber = userPart.split(':')[0]; // Remove the :xx part to get the real number
1078
- try {
1079
- const number = PhoneNumber('+' + cleanNumber).getNumber('international');
1080
- return number + (name ? ` ~${name}` : '');
1081
- } catch {
1082
- return (cleanNumber || '') + (name ? ` ~${name}` : '');
1083
- }
1084
- }
1085
- ```
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.
1086
1987
 
1087
- - **Common Problems and Fixes:**
1088
- - **Missing LID in Groups:** Use `decodeJid` and metadata cache to find real JIDs.
1089
- - **JID Conversion:** Always apply `decodeJid` before `sendMessage` or query.
1090
- - **Multi-Device:** Set `syncFullHistory: true` in config for LID sync.
1091
- - **Errors in Mention/Quoted:** Normalize with `decodeJid` in handler for quoted.sender and mentionedJid.
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.
1092
1992
 
1093
- ### Integrated Example in Main
1993
+ ### Integrated Example
1094
1994
 
1095
1995
  ```typescript
1096
- // In your main file
1097
- import makeWASocket, { getSenderLid, toJid } from '@realvare/based';
1098
- // ... (authentication and sock creation)
1996
+ import makeWASocket, { getSenderLid, toJid, validateJid } from '@realvare/based';
1099
1997
 
1100
1998
  conn.ev.on('messages.upsert', async ({ messages }) => {
1101
1999
  const msg = messages[0];
1102
2000
  if (!msg.message) return;
1103
2001
 
1104
2002
  const info = getSenderLid(msg);
1105
- const senderJid = toJid(info.lid); // Fix LID -> JID
1106
-
1107
- // Example: Reply only if valid JID
1108
- if (senderJid.endsWith('@s.whatsapp.net')) {
1109
- 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 });
1110
2009
  }
1111
2010
  });
1112
2011
  ```
1113
2012
 
1114
- ### Custom Handler Example
1115
-
1116
- ```typescript
1117
- // handler.js
1118
- export async function handleMessage(sock, msg) {
1119
- const info = getSenderLid(msg);
1120
- const jid = toJid(info.lid);
1121
-
1122
- // Log and response
1123
- console.log(`Message from ${jid}`);
1124
- await conn.sendMessage(jid, { text: 'Handler activated!' });
1125
- }
1126
-
1127
- // In main: conn.ev.on('messages.upsert', ({ messages }) => handleMessage(sock, messages[0]));
1128
- ```
1129
-
1130
- **Tip:** Test in groups to verify LID, as Baileys upstream has improved native support in 2025, but the custom fixes here ensure backward compatibility.
1131
-
1132
2013
  ---
1133
2014
 
1134
2015
  ### 🚀 Smart LID/JID Cache
@@ -1221,29 +2102,16 @@ console.log('Cache enabled:', config.performance.enableCache);
1221
2102
 
1222
2103
  ---
1223
2104
 
1224
- ## 🧩 Events: LID and JID always available (new)
2105
+ ## 🧩 Events: LID and JID Management
1225
2106
 
1226
- 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.
1227
2108
 
1228
- ```typescript
1229
- conn.ev.on('messages.upsert', ({ messages, type }) => {
1230
- for (const msg of messages) {
1231
- // Additional fields on msg.key
1232
- // - remoteJidNormalized: Normalized JID (e.g., @s.whatsapp.net)
1233
- // - remoteLid: LID equivalent of remoteJid
1234
- // - participantLid: LID equivalent of participant (if present)
1235
- const jid = msg.key.remoteJidNormalized || msg.key.remoteJid;
1236
- const remoteLid = msg.key.remoteLid;
1237
- 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()`
1238
2113
 
1239
- if (jid?.endsWith('@s.whatsapp.net')) {
1240
- conn.sendMessage(jid, { text: `Hello! LID: ${remoteLid || 'n/a'}` });
1241
- }
1242
- }
1243
- });
1244
- ```
1245
-
1246
- 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.
1247
2115
 
1248
2116
  ---
1249
2117
 
@@ -1271,8 +2139,8 @@ const sock = makeWASocket({
1271
2139
  maxMsgRetryCount: 5,
1272
2140
 
1273
2141
  // 🎛️ Behavior
1274
- markOnlineOnConnect: true,
1275
- 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
1276
2144
  fireInitQueries: true,
1277
2145
  generateHighQualityLinkPreview: true,
1278
2146
  });
@@ -1376,4 +2244,5 @@ See [LICENSE](LICENSE) for details.
1376
2244
 
1377
2245
  <br>
1378
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"/>
2247
+
1379
2248
  </div>