@realvare/based 2.7.55 → 2.7.57
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 +112 -24
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/chats.js +37 -10
- package/lib/Socket/groups.js +12 -1
- package/lib/Socket/messages-recv.js +41 -12
- package/lib/Socket/messages-send.js +17 -1
- package/lib/Types/Message.d.ts +17 -1
- package/lib/Utils/messages.js +9 -1
- package/package.json +4 -3
package/README.MD
CHANGED
|
@@ -593,33 +593,95 @@ await conn.sendMessage(jid, {
|
|
|
593
593
|
```
|
|
594
594
|
|
|
595
595
|
#### Advanced Media
|
|
596
|
+
|
|
596
597
|
```typescript
|
|
597
598
|
// Album (Multiple images)
|
|
598
599
|
await conn.sendMessage(jid, {
|
|
599
600
|
album: imageBuffers.map(buffer => ({ image: buffer })),
|
|
600
601
|
caption: 'ts gettin real'
|
|
601
602
|
});
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
#### Stickers
|
|
602
606
|
|
|
603
|
-
|
|
607
|
+
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`.
|
|
608
|
+
|
|
609
|
+
```typescript
|
|
610
|
+
// Sticker from URL
|
|
604
611
|
await conn.sendMessage(jid, {
|
|
605
612
|
sticker: { url: './stickers/sticker.webp' }
|
|
606
613
|
});
|
|
607
614
|
|
|
608
|
-
//
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
615
|
+
// Sticker from buffer using wa-sticker-formatter
|
|
616
|
+
const { Sticker } = require('wa-sticker-formatter'); // Optional external library
|
|
617
|
+
const sticker = new Sticker('path/to/image.jpg', { pack: 'My Pack', author: 'My Bot' });
|
|
618
|
+
const buffer = await sticker.toBuffer();
|
|
619
|
+
await conn.sendMessage(jid, { sticker: buffer });
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
##### Sticker Packs
|
|
623
|
+
|
|
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:
|
|
629
|
+
|
|
630
|
+
```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 = {
|
|
637
|
+
name: 'My Sticker Pack',
|
|
638
|
+
publisher: 'My Bot',
|
|
639
|
+
description: 'A cool sticker pack',
|
|
640
|
+
cover: 'path/to/cover.png', // or a buffer
|
|
641
|
+
stickers: [
|
|
642
|
+
{
|
|
643
|
+
sticker: await sticker1.toBuffer(),
|
|
644
|
+
emojis: ['🎉', '🎊'],
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
sticker: await sticker2.toBuffer(),
|
|
648
|
+
emojis: ['😄', '😊'],
|
|
649
|
+
}
|
|
650
|
+
]
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
await conn.sendMessage(jid, { stickerPack: stickerPack });
|
|
654
|
+
```
|
|
655
|
+
|
|
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.
|
|
667
|
+
|
|
668
|
+
##### Stickers on Status (2025 Feature)
|
|
669
|
+
|
|
670
|
+
The new interactive stickers on Status (e.g., with lyrics or questions) can be sent by sending a sticker to `status@broadcast`.
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
await conn.sendMessage('status@broadcast', {
|
|
674
|
+
sticker: { url: './sticker.webp' },
|
|
675
|
+
caption: 'Interactive sticker on Status'
|
|
676
|
+
}, { statusJidList: ['user1@s.whatsapp.net', 'user2@s.whatsapp.net'] });
|
|
617
677
|
```
|
|
618
678
|
|
|
619
679
|
#### Interactive Messages
|
|
620
|
-
|
|
680
|
+
|
|
681
|
+
These messages include interactive elements like buttons, lists, and polls.
|
|
621
682
|
|
|
622
683
|
##### Messages with Simple Buttons
|
|
684
|
+
|
|
623
685
|
Send quick reply buttons.
|
|
624
686
|
|
|
625
687
|
```typescript
|
|
@@ -627,15 +689,16 @@ await conn.sendMessage(jid, {
|
|
|
627
689
|
text: 'Choose an option:',
|
|
628
690
|
footer: 'Footer',
|
|
629
691
|
buttons: [
|
|
630
|
-
{ buttonId: 'cmd1', buttonText: { displayText: '
|
|
631
|
-
{ buttonId: 'cmd2', buttonText: { displayText: '
|
|
692
|
+
{ buttonId: 'cmd1', buttonText: { displayText: 'Option 1' }, type: 1 },
|
|
693
|
+
{ buttonId: 'cmd2', buttonText: { displayText: 'Option 2' }, type: 1 },
|
|
632
694
|
],
|
|
633
695
|
headerType: 1,
|
|
634
696
|
});
|
|
635
697
|
```
|
|
636
698
|
|
|
637
699
|
##### Messages with Buttons and Image
|
|
638
|
-
|
|
700
|
+
|
|
701
|
+
Combine an image with buttons.
|
|
639
702
|
|
|
640
703
|
```typescript
|
|
641
704
|
await conn.sendMessage(jid, {
|
|
@@ -649,7 +712,8 @@ await conn.sendMessage(jid, {
|
|
|
649
712
|
```
|
|
650
713
|
|
|
651
714
|
##### List Messages
|
|
652
|
-
|
|
715
|
+
|
|
716
|
+
Send a list of options (only in private chats).
|
|
653
717
|
|
|
654
718
|
```typescript
|
|
655
719
|
await conn.sendMessage(jid, {
|
|
@@ -669,6 +733,29 @@ await conn.sendMessage(jid, {
|
|
|
669
733
|
});
|
|
670
734
|
```
|
|
671
735
|
|
|
736
|
+
##### Poll Messages
|
|
737
|
+
|
|
738
|
+
Create a poll for users to vote on.
|
|
739
|
+
|
|
740
|
+
```typescript
|
|
741
|
+
await conn.sendMessage(jid, {
|
|
742
|
+
poll: {
|
|
743
|
+
name: 'Favorite Anime?',
|
|
744
|
+
values: ['Aot', 'Bleach', 'Death note'],
|
|
745
|
+
selectableCount: 1 // or >1 for multi-select
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
#### New Interactive Features (2025)
|
|
751
|
+
|
|
752
|
+
WhatsApp introduced several new features in 2025. Here's how to handle them with Baileys:
|
|
753
|
+
|
|
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)).
|
|
758
|
+
|
|
672
759
|
#### Other Messages
|
|
673
760
|
```typescript
|
|
674
761
|
// Message with quote
|
|
@@ -677,6 +764,16 @@ await conn.sendMessage(jid, {
|
|
|
677
764
|
quoted: quotedMessage // The message to quote/reply/cite
|
|
678
765
|
});
|
|
679
766
|
|
|
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
|
+
}
|
|
775
|
+
});
|
|
776
|
+
|
|
680
777
|
// Contact Messages
|
|
681
778
|
await conn.sendMessage(jid, {
|
|
682
779
|
contacts: {
|
|
@@ -685,15 +782,6 @@ await conn.sendMessage(jid, {
|
|
|
685
782
|
}
|
|
686
783
|
});
|
|
687
784
|
|
|
688
|
-
// Poll Messages (Survey)
|
|
689
|
-
await conn.sendMessage(jid, {
|
|
690
|
-
poll: {
|
|
691
|
-
name: 'Favorite Anime?',
|
|
692
|
-
values: ['Aot', 'Bleach', 'Death note'],
|
|
693
|
-
selectableCount: 1 // how many choices possible
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
|
|
697
785
|
// Ephemeral Messages (Self-Destructing)
|
|
698
786
|
await conn.sendMessage(jid, {
|
|
699
787
|
text: "This message will self-destruct {hopefully like israel}"
|
package/lib/Defaults/index.js
CHANGED
package/lib/Socket/chats.js
CHANGED
|
@@ -32,6 +32,12 @@ const makeChatsSocket = (config) => {
|
|
|
32
32
|
if (!config.placeholderResendCache) {
|
|
33
33
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
34
|
}
|
|
35
|
+
const resolveJid = (jid) => {
|
|
36
|
+
if (typeof jid === 'string' && jid.endsWith('@lid')) {
|
|
37
|
+
return (0, WABinary_1.lidToJid)(jid);
|
|
38
|
+
}
|
|
39
|
+
return jid;
|
|
40
|
+
};
|
|
35
41
|
/** helper function to fetch the given app state sync key */
|
|
36
42
|
const getAppStateSyncKey = async (keyId) => {
|
|
37
43
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -136,7 +142,7 @@ const makeChatsSocket = (config) => {
|
|
|
136
142
|
if (section.attrs.type === 'all') {
|
|
137
143
|
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
|
138
144
|
botList.push({
|
|
139
|
-
jid: bot.attrs.jid,
|
|
145
|
+
jid: resolveJid(bot.attrs.jid),
|
|
140
146
|
personaId: bot.attrs['persona_id']
|
|
141
147
|
});
|
|
142
148
|
}
|
|
@@ -149,15 +155,20 @@ const makeChatsSocket = (config) => {
|
|
|
149
155
|
.withContactProtocol()
|
|
150
156
|
.withLIDProtocol();
|
|
151
157
|
for (const jid of jids) {
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
if (jid.includes('@')) {
|
|
159
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(resolveJid(jid)));
|
|
160
|
+
} else {
|
|
161
|
+
const phone = `+${jid}`;
|
|
162
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
163
|
+
}
|
|
154
164
|
}
|
|
155
165
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
156
166
|
if (results) {
|
|
157
|
-
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
167
|
+
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: resolveJid(id), exists: contact, lid }));
|
|
158
168
|
}
|
|
159
169
|
};
|
|
160
170
|
const fetchStatus = async (...jids) => {
|
|
171
|
+
jids = jids.map(resolveJid);
|
|
161
172
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
162
173
|
.withStatusProtocol();
|
|
163
174
|
for (const jid of jids) {
|
|
@@ -169,6 +180,7 @@ const makeChatsSocket = (config) => {
|
|
|
169
180
|
}
|
|
170
181
|
};
|
|
171
182
|
const fetchDisappearingDuration = async (...jids) => {
|
|
183
|
+
jids = jids.map(resolveJid);
|
|
172
184
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
173
185
|
.withDisappearingModeProtocol();
|
|
174
186
|
for (const jid of jids) {
|
|
@@ -181,6 +193,7 @@ const makeChatsSocket = (config) => {
|
|
|
181
193
|
};
|
|
182
194
|
/** update the profile picture for yourself or a group */
|
|
183
195
|
const updateProfilePicture = async (jid, content) => {
|
|
196
|
+
jid = resolveJid(jid);
|
|
184
197
|
let targetJid;
|
|
185
198
|
if (!jid) {
|
|
186
199
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
@@ -208,6 +221,7 @@ const makeChatsSocket = (config) => {
|
|
|
208
221
|
};
|
|
209
222
|
/** remove the profile picture for yourself or a group */
|
|
210
223
|
const removeProfilePicture = async (jid) => {
|
|
224
|
+
jid = resolveJid(jid);
|
|
211
225
|
let targetJid;
|
|
212
226
|
if (!jid) {
|
|
213
227
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
@@ -257,9 +271,10 @@ const makeChatsSocket = (config) => {
|
|
|
257
271
|
});
|
|
258
272
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
259
273
|
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
260
|
-
.map(n => n.attrs.jid);
|
|
274
|
+
.map(n => resolveJid(n.attrs.jid));
|
|
261
275
|
};
|
|
262
276
|
const updateBlockStatus = async (jid, action) => {
|
|
277
|
+
jid = resolveJid(jid);
|
|
263
278
|
await query({
|
|
264
279
|
tag: 'iq',
|
|
265
280
|
attrs: {
|
|
@@ -279,6 +294,7 @@ const makeChatsSocket = (config) => {
|
|
|
279
294
|
});
|
|
280
295
|
};
|
|
281
296
|
const getBusinessProfile = async (jid) => {
|
|
297
|
+
jid = resolveJid(jid);
|
|
282
298
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
283
299
|
const results = await query({
|
|
284
300
|
tag: 'iq',
|
|
@@ -462,6 +478,7 @@ const makeChatsSocket = (config) => {
|
|
|
462
478
|
* type = "image for the high res picture"
|
|
463
479
|
*/
|
|
464
480
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
481
|
+
jid = resolveJid(jid);
|
|
465
482
|
var _a;
|
|
466
483
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
467
484
|
const result = await query({
|
|
@@ -480,6 +497,7 @@ const makeChatsSocket = (config) => {
|
|
|
480
497
|
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
481
498
|
};
|
|
482
499
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
500
|
+
toJid = resolveJid(toJid);
|
|
483
501
|
const me = authState.creds.me;
|
|
484
502
|
if (type === 'available' || type === 'unavailable') {
|
|
485
503
|
if (!me.name) {
|
|
@@ -520,7 +538,7 @@ const makeChatsSocket = (config) => {
|
|
|
520
538
|
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
521
539
|
tag: 'presence',
|
|
522
540
|
attrs: {
|
|
523
|
-
to: toJid,
|
|
541
|
+
to: resolveJid(toJid),
|
|
524
542
|
id: generateMessageTag(),
|
|
525
543
|
type: 'subscribe'
|
|
526
544
|
},
|
|
@@ -537,8 +555,8 @@ const makeChatsSocket = (config) => {
|
|
|
537
555
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
538
556
|
var _a;
|
|
539
557
|
let presence;
|
|
540
|
-
const jid = attrs.from;
|
|
541
|
-
const participant = attrs.participant || attrs.from;
|
|
558
|
+
const jid = resolveJid(attrs.from);
|
|
559
|
+
const participant = resolveJid(attrs.participant || attrs.from);
|
|
542
560
|
if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
|
|
543
561
|
return;
|
|
544
562
|
}
|
|
@@ -660,6 +678,7 @@ const makeChatsSocket = (config) => {
|
|
|
660
678
|
* requires the last messages till the last message received; required for archive & unread
|
|
661
679
|
*/
|
|
662
680
|
const chatModify = (mod, jid) => {
|
|
681
|
+
jid = resolveJid(jid);
|
|
663
682
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
664
683
|
return appPatch(patch);
|
|
665
684
|
};
|
|
@@ -667,6 +686,7 @@ const makeChatsSocket = (config) => {
|
|
|
667
686
|
* Star or Unstar a message
|
|
668
687
|
*/
|
|
669
688
|
const star = (jid, messages, star) => {
|
|
689
|
+
jid = resolveJid(jid);
|
|
670
690
|
return chatModify({
|
|
671
691
|
star: {
|
|
672
692
|
messages,
|
|
@@ -678,6 +698,7 @@ const makeChatsSocket = (config) => {
|
|
|
678
698
|
* Adds label for the chats
|
|
679
699
|
*/
|
|
680
700
|
const addChatLabel = (jid, labelId) => {
|
|
701
|
+
jid = resolveJid(jid);
|
|
681
702
|
return chatModify({
|
|
682
703
|
addChatLabel: {
|
|
683
704
|
labelId
|
|
@@ -688,6 +709,7 @@ const makeChatsSocket = (config) => {
|
|
|
688
709
|
* Removes label for the chat
|
|
689
710
|
*/
|
|
690
711
|
const removeChatLabel = (jid, labelId) => {
|
|
712
|
+
jid = resolveJid(jid);
|
|
691
713
|
return chatModify({
|
|
692
714
|
removeChatLabel: {
|
|
693
715
|
labelId
|
|
@@ -698,6 +720,7 @@ const makeChatsSocket = (config) => {
|
|
|
698
720
|
* Adds label for the message
|
|
699
721
|
*/
|
|
700
722
|
const addMessageLabel = (jid, messageId, labelId) => {
|
|
723
|
+
jid = resolveJid(jid);
|
|
701
724
|
return chatModify({
|
|
702
725
|
addMessageLabel: {
|
|
703
726
|
messageId,
|
|
@@ -709,6 +732,7 @@ const makeChatsSocket = (config) => {
|
|
|
709
732
|
* Removes label for the message
|
|
710
733
|
*/
|
|
711
734
|
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
735
|
+
jid = resolveJid(jid);
|
|
712
736
|
return chatModify({
|
|
713
737
|
removeMessageLabel: {
|
|
714
738
|
messageId,
|
|
@@ -830,7 +854,7 @@ const makeChatsSocket = (config) => {
|
|
|
830
854
|
break;
|
|
831
855
|
}
|
|
832
856
|
});
|
|
833
|
-
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
857
|
+
ev.on('connection.update', ({ connection, receivedPendingNotifications, isOnline }) => {
|
|
834
858
|
var _a;
|
|
835
859
|
if (connection === 'open') {
|
|
836
860
|
if (fireInitQueries) {
|
|
@@ -847,6 +871,9 @@ const makeChatsSocket = (config) => {
|
|
|
847
871
|
ev.buffer();
|
|
848
872
|
needToFlushWithAppStateSync = true;
|
|
849
873
|
}
|
|
874
|
+
if (typeof isOnline !== 'undefined' && isOnline) {
|
|
875
|
+
sendPresenceUpdate('available').catch(error => onUnexpectedError(error, 'presence update on online'));
|
|
876
|
+
}
|
|
850
877
|
});
|
|
851
878
|
return {
|
|
852
879
|
...sock,
|
|
@@ -887,4 +914,4 @@ const makeChatsSocket = (config) => {
|
|
|
887
914
|
star
|
|
888
915
|
};
|
|
889
916
|
};
|
|
890
|
-
exports.makeChatsSocket = makeChatsSocket;
|
|
917
|
+
exports.makeChatsSocket = makeChatsSocket;
|
package/lib/Socket/groups.js
CHANGED
|
@@ -9,6 +9,12 @@ const chats_1 = require("./chats");
|
|
|
9
9
|
const makeGroupsSocket = (config) => {
|
|
10
10
|
const sock = (0, chats_1.makeChatsSocket)(config);
|
|
11
11
|
const { authState, ev, query, upsertMessage } = sock;
|
|
12
|
+
const resolveJid = (jid) => {
|
|
13
|
+
if (typeof jid === 'string' && jid.endsWith('@lid')) {
|
|
14
|
+
return (0, WABinary_1.lidToJid)(jid);
|
|
15
|
+
}
|
|
16
|
+
return jid;
|
|
17
|
+
};
|
|
12
18
|
const groupQuery = async (jid, type, content) => (query({
|
|
13
19
|
tag: 'iq',
|
|
14
20
|
attrs: {
|
|
@@ -70,6 +76,7 @@ const makeGroupsSocket = (config) => {
|
|
|
70
76
|
groupQuery,
|
|
71
77
|
groupMetadata,
|
|
72
78
|
groupCreate: async (subject, participants) => {
|
|
79
|
+
participants = participants.map(resolveJid);
|
|
73
80
|
const key = (0, Utils_1.generateMessageIDV2)();
|
|
74
81
|
const result = await groupQuery('@g.us', 'set', [
|
|
75
82
|
{
|
|
@@ -118,6 +125,7 @@ const makeGroupsSocket = (config) => {
|
|
|
118
125
|
return participants.map(v => v.attrs);
|
|
119
126
|
},
|
|
120
127
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
128
|
+
participants = participants.map(resolveJid);
|
|
121
129
|
const result = await groupQuery(jid, 'set', [{
|
|
122
130
|
tag: 'membership_requests_action',
|
|
123
131
|
attrs: {},
|
|
@@ -140,6 +148,7 @@ const makeGroupsSocket = (config) => {
|
|
|
140
148
|
});
|
|
141
149
|
},
|
|
142
150
|
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
151
|
+
participants = participants.map(resolveJid);
|
|
143
152
|
const result = await groupQuery(jid, 'set', [
|
|
144
153
|
{
|
|
145
154
|
tag: action,
|
|
@@ -195,6 +204,7 @@ const makeGroupsSocket = (config) => {
|
|
|
195
204
|
* @returns true if successful
|
|
196
205
|
*/
|
|
197
206
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
207
|
+
invitedJid = resolveJid(invitedJid);
|
|
198
208
|
const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
|
|
199
209
|
return !!result;
|
|
200
210
|
},
|
|
@@ -206,6 +216,7 @@ const makeGroupsSocket = (config) => {
|
|
|
206
216
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
207
217
|
var _a;
|
|
208
218
|
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
219
|
+
key.remoteJid = resolveJid(key.remoteJid);
|
|
209
220
|
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
|
210
221
|
tag: 'accept',
|
|
211
222
|
attrs: {
|
|
@@ -329,4 +340,4 @@ const extractGroupMetadata = (result) => {
|
|
|
329
340
|
};
|
|
330
341
|
return metadata;
|
|
331
342
|
};
|
|
332
|
-
exports.extractGroupMetadata = extractGroupMetadata;
|
|
343
|
+
exports.extractGroupMetadata = extractGroupMetadata;
|
|
@@ -68,7 +68,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
68
68
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
|
|
69
69
|
await sendNode(stanza);
|
|
70
70
|
};
|
|
71
|
-
|
|
72
71
|
// Add withAck wrapper for guaranteed acknowledgments
|
|
73
72
|
const withAck = (processFn) => async (node) => {
|
|
74
73
|
try {
|
|
@@ -79,6 +78,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
79
78
|
}
|
|
80
79
|
};
|
|
81
80
|
const offerCall = async (toJid, isVideo = false) => {
|
|
81
|
+
toJid = resolveJid(toJid);
|
|
82
82
|
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
|
83
83
|
const offerContent = [];
|
|
84
84
|
offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '16000' }, content: undefined });
|
|
@@ -137,6 +137,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
137
137
|
};
|
|
138
138
|
};
|
|
139
139
|
const rejectCall = async (callId, callFrom) => {
|
|
140
|
+
callFrom = resolveJid(callFrom);
|
|
140
141
|
const stanza = ({
|
|
141
142
|
tag: 'call',
|
|
142
143
|
attrs: {
|
|
@@ -251,6 +252,14 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
};
|
|
255
|
+
const toLidIfNecessary = (jid) => {
|
|
256
|
+
if (typeof jid !== 'string') return jid;
|
|
257
|
+
const [user, server] = jid.split('@');
|
|
258
|
+
if (server === 's.whatsapp.net' && /^[0-9]+$/.test(user) && user.length >= 15) {
|
|
259
|
+
return `${user}@lid`;
|
|
260
|
+
}
|
|
261
|
+
return jid;
|
|
262
|
+
};
|
|
254
263
|
const handleGroupNotification = async (participant, child, groupJid, msg) => {
|
|
255
264
|
var _a, _b, _c, _d;
|
|
256
265
|
const participantJid = (((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant);
|
|
@@ -360,16 +369,28 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
360
369
|
default:
|
|
361
370
|
// console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
362
371
|
}
|
|
363
|
-
|
|
372
|
+
// Apply LID fix before checking needsResolving
|
|
373
|
+
if (msg.messageStubParameters) {
|
|
374
|
+
msg.messageStubParameters = msg.messageStubParameters.map(toLidIfNecessary);
|
|
375
|
+
}
|
|
376
|
+
participant = toLidIfNecessary(participant);
|
|
377
|
+
if (msg.key?.participant) {
|
|
378
|
+
msg.key.participant = toLidIfNecessary(msg.key.participant);
|
|
379
|
+
}
|
|
380
|
+
const needsResolving = (msg.messageStubParameters && msg.messageStubParameters.some(p => typeof p === 'string')) ||
|
|
364
381
|
(participant && (0, WABinary_1.isLid)(participant)) ||
|
|
365
382
|
(msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant));
|
|
366
383
|
if(needsResolving) {
|
|
367
384
|
const metadata = await groupMetadata(groupJid);
|
|
368
385
|
if (msg.messageStubParameters) {
|
|
369
386
|
msg.messageStubParameters = await Promise.all(msg.messageStubParameters.map(async (param) => {
|
|
370
|
-
if (typeof param === 'string'
|
|
371
|
-
|
|
372
|
-
|
|
387
|
+
if (typeof param === 'string') {
|
|
388
|
+
if ((0, WABinary_1.isLid)(param)) {
|
|
389
|
+
const found = metadata.participants.find(p => p.id === param);
|
|
390
|
+
return found?.jid || (0, WABinary_1.lidToJid)(param);
|
|
391
|
+
} else {
|
|
392
|
+
return param;
|
|
393
|
+
}
|
|
373
394
|
}
|
|
374
395
|
return param;
|
|
375
396
|
}));
|
|
@@ -377,10 +398,16 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
377
398
|
if(participant && (0, WABinary_1.isLid)(participant)) {
|
|
378
399
|
const found = metadata.participants.find(p => p.id === participant);
|
|
379
400
|
msg.participant = found?.jid || (0, WABinary_1.lidToJid)(participant);
|
|
401
|
+
} else if (participant) {
|
|
402
|
+
//If it's a JID, treat it as a JID. Do not convert back to LID. *smh brah
|
|
403
|
+
msg.participant = participant;
|
|
380
404
|
}
|
|
381
405
|
if (msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant)) {
|
|
382
406
|
const found = metadata.participants.find(p => p.id === msg.key.participant);
|
|
383
407
|
msg.key.participant = found?.jid || (0, WABinary_1.lidToJid)(msg.key.participant);
|
|
408
|
+
} else if (msg.key?.participant) {
|
|
409
|
+
// If it's a JID, treat it as a JID. Do not convert back to LID. *smh brahpt2
|
|
410
|
+
msg.key.participant = msg.key.participant;
|
|
384
411
|
}
|
|
385
412
|
}
|
|
386
413
|
};
|
|
@@ -421,7 +448,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
421
448
|
action = 'demote';
|
|
422
449
|
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
|
423
450
|
}
|
|
424
|
-
|
|
451
|
+
const author = resolveJid(contentPath.actor.pn);
|
|
452
|
+
const user = resolveJid(contentPath.user.pn);
|
|
453
|
+
ev.emit('newsletter-participants.update', { id, author, user, new_role: contentPath.user_new_role, action });
|
|
425
454
|
}
|
|
426
455
|
if (operation === Types_1.MexOperations.UPDATE) {
|
|
427
456
|
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
|
@@ -809,7 +838,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
809
838
|
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
810
839
|
}
|
|
811
840
|
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
|
|
812
|
-
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
841
|
+
ev.emit('chats.phoneNumberShare', { lid: resolveJid(node.attrs.from), jid: resolveJid(node.attrs.sender_pn) });
|
|
813
842
|
}
|
|
814
843
|
try {
|
|
815
844
|
await Promise.all([
|
|
@@ -971,15 +1000,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
971
1000
|
// current hypothesis is that if pash is sent in the ack
|
|
972
1001
|
// it means -- the message hasn't reached all devices yet
|
|
973
1002
|
// we'll retry sending the message here
|
|
974
|
-
if (attrs.phash) {
|
|
1003
|
+
if (attrs.phash && attrs.class === 'message') {
|
|
975
1004
|
logger.info({ attrs }, 'received phash in ack, resending message...');
|
|
976
1005
|
const cacheKey = `${key.remoteJid}:${key.id}`;
|
|
977
|
-
|
|
1006
|
+
const retryCount = msgRetryCache.get(cacheKey) || 0;
|
|
1007
|
+
if (retryCount >= maxMsgRetryCount) {
|
|
978
1008
|
logger.warn({ attrs }, 'reached max retry count, not sending message again');
|
|
979
1009
|
msgRetryCache.del(cacheKey);
|
|
980
1010
|
return;
|
|
981
1011
|
}
|
|
982
|
-
const retryCount = msgRetryCache.get(cacheKey) || 0;
|
|
983
1012
|
const msg = await getMessage(key);
|
|
984
1013
|
if (msg) {
|
|
985
1014
|
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
|
@@ -1113,8 +1142,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1113
1142
|
} else if (connection === 'open') {
|
|
1114
1143
|
sendActiveReceipts = true;
|
|
1115
1144
|
}
|
|
1116
|
-
if (typeof update.isOnline !== 'undefined') {
|
|
1117
|
-
sendActiveReceipts =
|
|
1145
|
+
if (typeof update.isOnline !== 'undefined' && update.isOnline) {
|
|
1146
|
+
sendActiveReceipts = true;
|
|
1118
1147
|
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
|
|
1119
1148
|
}
|
|
1120
1149
|
});
|
|
@@ -990,6 +990,21 @@ const makeMessagesSocket = (config) => {
|
|
|
990
990
|
}
|
|
991
991
|
};
|
|
992
992
|
|
|
993
|
+
// Helper function to send missed call note
|
|
994
|
+
const sendMissedCallNote = async (jid, media, options = {}) => {
|
|
995
|
+
const prepared = await prepareWAMessageMedia(media, { upload: sock.waUploadToServer });
|
|
996
|
+
return sock.sendMessage(jid, {
|
|
997
|
+
...prepared,
|
|
998
|
+
ptt: !!media.audio,
|
|
999
|
+
contextInfo: {
|
|
1000
|
+
externalAdReply: {
|
|
1001
|
+
title: 'Missed Call Note',
|
|
1002
|
+
body: options.callInfo?.id ? `From call ${options.callInfo.id}` : 'Recent call'
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
};
|
|
1007
|
+
|
|
993
1008
|
return {
|
|
994
1009
|
...sock,
|
|
995
1010
|
getPrivacyTokens,
|
|
@@ -1004,6 +1019,7 @@ const makeMessagesSocket = (config) => {
|
|
|
1004
1019
|
getUSyncDevices,
|
|
1005
1020
|
createParticipantNodes,
|
|
1006
1021
|
sendPeerDataOperationMessage,
|
|
1022
|
+
sendMissedCallNote,
|
|
1007
1023
|
updateMediaMessage: async (message) => {
|
|
1008
1024
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
1009
1025
|
const mediaKey = content.mediaKey;
|
|
@@ -1098,4 +1114,4 @@ const makeMessagesSocket = (config) => {
|
|
|
1098
1114
|
}
|
|
1099
1115
|
};
|
|
1100
1116
|
};
|
|
1101
|
-
exports.makeMessagesSocket = makeMessagesSocket;
|
|
1117
|
+
exports.makeMessagesSocket = makeMessagesSocket;
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -25,6 +25,22 @@ export type WATextMessage = proto.Message.IExtendedTextMessage;
|
|
|
25
25
|
export type WAContextInfo = proto.IContextInfo;
|
|
26
26
|
export type WALocationMessage = proto.Message.ILocationMessage;
|
|
27
27
|
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
28
|
+
export interface StickerPackMessage {
|
|
29
|
+
name: string;
|
|
30
|
+
publisher: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
cover?: WAMediaUpload;
|
|
33
|
+
stickers: Sticker[];
|
|
34
|
+
}
|
|
35
|
+
export interface Sticker {
|
|
36
|
+
sticker: WAMediaUpload;
|
|
37
|
+
emojis?: string[];
|
|
38
|
+
isAnimated?: boolean;
|
|
39
|
+
isLottie?: boolean;
|
|
40
|
+
fileName?: string;
|
|
41
|
+
accessibilityLabel?: string;
|
|
42
|
+
mimetype?: string;
|
|
43
|
+
}
|
|
28
44
|
export declare const WAMessageStubType: typeof proto.WebMessageInfo.StubType;
|
|
29
45
|
export declare const WAMessageStatus: typeof proto.WebMessageInfo.Status;
|
|
30
46
|
export type WAMediaPayloadURL = {
|
|
@@ -300,7 +316,7 @@ export type AnyRegularMessageContent = (({
|
|
|
300
316
|
} & Mentionable & Contextable & Interactiveable & Shopable & Cardsable & WithDimensions) | SharePhoneNumber | RequestPhoneNumber | ({
|
|
301
317
|
album: AlbumMedia[];
|
|
302
318
|
caption?: string;
|
|
303
|
-
} & Mentionable & Contextable & Editable)) & ViewOnce;
|
|
319
|
+
} & Mentionable & Contextable & Editable) | { stickerPack: StickerPackMessage; }) & ViewOnce;
|
|
304
320
|
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
305
321
|
forward: WAMessage;
|
|
306
322
|
force?: boolean;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -535,6 +535,15 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
535
535
|
// Aggiungi altri parametri se disponibili
|
|
536
536
|
...reqPayment
|
|
537
537
|
});
|
|
538
|
+
|
|
539
|
+
// Pix adaptation for Brazilian payments
|
|
540
|
+
if (reqPayment.currencyCodeIso4217 === 'BRL' && reqPayment.pixKey) {
|
|
541
|
+
// Embed Pix key in note for dynamic requests
|
|
542
|
+
if (!m.requestPaymentMessage.noteMessage.extendedTextMessage) {
|
|
543
|
+
m.requestPaymentMessage.noteMessage = { extendedTextMessage: { text: '' } };
|
|
544
|
+
}
|
|
545
|
+
m.requestPaymentMessage.noteMessage.extendedTextMessage.text += `\nPix Key: ${reqPayment.pixKey}`;
|
|
546
|
+
}
|
|
538
547
|
}
|
|
539
548
|
else if ('sharePhoneNumber' in message) {
|
|
540
549
|
m.protocolMessage = {
|
|
@@ -1194,4 +1203,3 @@ const assertMediaContent = (content) => {
|
|
|
1194
1203
|
return mediaContent;
|
|
1195
1204
|
};
|
|
1196
1205
|
exports.assertMediaContent = assertMediaContent;
|
|
1197
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.57",
|
|
4
4
|
"description": "whatsapp api by sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -51,15 +51,16 @@
|
|
|
51
51
|
"chalk": "^4.1.2",
|
|
52
52
|
"cheerio": "^1.1.2",
|
|
53
53
|
"gradient-string": "^2.0.2",
|
|
54
|
-
"jimp": "^
|
|
54
|
+
"jimp": "^0.22.10",
|
|
55
55
|
"libphonenumber-js": "^1.12.31",
|
|
56
56
|
"libsignal": "github:realvare/libsignal",
|
|
57
57
|
"lodash": "^4.17.21",
|
|
58
58
|
"music-metadata": "^11.7.0",
|
|
59
59
|
"pino": "^10.1.0",
|
|
60
60
|
"protobufjs": "^7.5.4",
|
|
61
|
+
"sharp": "^0.33.5",
|
|
61
62
|
"uuid": "^13.0.0",
|
|
62
|
-
"ws": "^8.18.
|
|
63
|
+
"ws": "^8.18.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
|