@d0v3riz/baileys 6.5.0 → 6.6.0
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 +20 -92
- package/lib/Defaults/index.d.ts +2 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +7 -0
- package/lib/Socket/chats.d.ts +4 -0
- package/lib/Socket/chats.js +13 -1
- package/lib/Socket/groups.d.ts +4 -0
- package/lib/Socket/groups.js +4 -0
- package/lib/Socket/index.d.ts +7 -0
- package/lib/Socket/messages-recv.d.ts +7 -0
- package/lib/Socket/messages-recv.js +20 -4
- package/lib/Socket/messages-send.d.ts +5 -0
- package/lib/Socket/messages-send.js +7 -4
- package/lib/Socket/registration.d.ts +7 -0
- package/lib/Socket/socket.js +3 -2
- package/lib/Store/make-in-memory-store.js +11 -11
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Events.d.ts +5 -0
- package/lib/Types/GroupMetadata.d.ts +6 -0
- package/lib/Types/Message.d.ts +7 -1
- package/lib/Types/index.d.ts +3 -1
- package/lib/Types/index.js +2 -0
- package/lib/Utils/chat-utils.js +14 -0
- package/lib/Utils/decode-wa-message.d.ts +2 -2
- package/lib/Utils/decode-wa-message.js +18 -4
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +10 -5
- package/lib/Utils/process-message.js +16 -1
- package/lib/Utils/validate-connection.js +5 -1
- package/lib/WABinary/decode.js +1 -1
- package/lib/WABinary/encode.js +3 -3
- package/lib/WABinary/jid-utils.d.ts +4 -2
- package/lib/WABinary/jid-utils.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -376,65 +376,6 @@ const sentMsg = await sock.sendMessage(
|
|
|
376
376
|
}
|
|
377
377
|
)
|
|
378
378
|
|
|
379
|
-
// send a buttons message!
|
|
380
|
-
const buttons = [
|
|
381
|
-
{buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},
|
|
382
|
-
{buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},
|
|
383
|
-
{buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}
|
|
384
|
-
]
|
|
385
|
-
|
|
386
|
-
const buttonMessage = {
|
|
387
|
-
text: "Hi it's button message",
|
|
388
|
-
footer: 'Hello World',
|
|
389
|
-
buttons: buttons,
|
|
390
|
-
headerType: 1
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const sendMsg = await sock.sendMessage(id, buttonMessage)
|
|
394
|
-
|
|
395
|
-
//send a template message!
|
|
396
|
-
const templateButtons = [
|
|
397
|
-
{index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}},
|
|
398
|
-
{index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}},
|
|
399
|
-
{index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}},
|
|
400
|
-
]
|
|
401
|
-
|
|
402
|
-
const templateMessage = {
|
|
403
|
-
text: "Hi it's a template message",
|
|
404
|
-
footer: 'Hello World',
|
|
405
|
-
templateButtons: templateButtons
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const sendMsg = await sock.sendMessage(id, templateMessage)
|
|
409
|
-
|
|
410
|
-
// send a list message!
|
|
411
|
-
const sections = [
|
|
412
|
-
{
|
|
413
|
-
title: "Section 1",
|
|
414
|
-
rows: [
|
|
415
|
-
{title: "Option 1", rowId: "option1"},
|
|
416
|
-
{title: "Option 2", rowId: "option2", description: "This is a description"}
|
|
417
|
-
]
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
title: "Section 2",
|
|
421
|
-
rows: [
|
|
422
|
-
{title: "Option 3", rowId: "option3"},
|
|
423
|
-
{title: "Option 4", rowId: "option4", description: "This is a description V2"}
|
|
424
|
-
]
|
|
425
|
-
},
|
|
426
|
-
]
|
|
427
|
-
|
|
428
|
-
const listMessage = {
|
|
429
|
-
text: "This is a list",
|
|
430
|
-
footer: "nice footer, link: https://google.com",
|
|
431
|
-
title: "Amazing boldfaced list title",
|
|
432
|
-
buttonText: "Required, text on the button to view the list",
|
|
433
|
-
sections
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
const sendMsg = await sock.sendMessage(id, listMessage)
|
|
437
|
-
|
|
438
379
|
const reactionMessage = {
|
|
439
380
|
react: {
|
|
440
381
|
text: "💖", // use an empty string to remove the reaction
|
|
@@ -489,39 +430,6 @@ await sock.sendMessage(
|
|
|
489
430
|
{ audio: { url: "./Media/audio.mp3" }, mimetype: 'audio/mp4' }
|
|
490
431
|
{ url: "Media/audio.mp3" }, // can send mp3, mp4, & ogg
|
|
491
432
|
)
|
|
492
|
-
|
|
493
|
-
// send a buttons message with image header!
|
|
494
|
-
const buttons = [
|
|
495
|
-
{buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},
|
|
496
|
-
{buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},
|
|
497
|
-
{buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}
|
|
498
|
-
]
|
|
499
|
-
|
|
500
|
-
const buttonMessage = {
|
|
501
|
-
image: {url: 'https://example.com/image.jpeg'},
|
|
502
|
-
caption: "Hi it's button message",
|
|
503
|
-
footer: 'Hello World',
|
|
504
|
-
buttons: buttons,
|
|
505
|
-
headerType: 4
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
const sendMsg = await sock.sendMessage(id, buttonMessage)
|
|
509
|
-
|
|
510
|
-
//send a template message with an image **attached**!
|
|
511
|
-
const templateButtons = [
|
|
512
|
-
{index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}},
|
|
513
|
-
{index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}},
|
|
514
|
-
{index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}},
|
|
515
|
-
]
|
|
516
|
-
|
|
517
|
-
const buttonMessage = {
|
|
518
|
-
text: "Hi it's a template message",
|
|
519
|
-
footer: 'Hello World',
|
|
520
|
-
templateButtons: templateButtons,
|
|
521
|
-
image: {url: 'https://example.com/image.jpeg'}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const sendMsg = await sock.sendMessage(id, templateMessage)
|
|
525
433
|
```
|
|
526
434
|
|
|
527
435
|
### Notes
|
|
@@ -648,6 +556,17 @@ await sock.sendMessage(jid, { delete: response.key })
|
|
|
648
556
|
|
|
649
557
|
**Note:** deleting for oneself is supported via `chatModify` (next section)
|
|
650
558
|
|
|
559
|
+
## Updating Messages
|
|
560
|
+
|
|
561
|
+
``` ts
|
|
562
|
+
const jid = '1234@s.whatsapp.net'
|
|
563
|
+
|
|
564
|
+
await sock.sendMessage(jid, {
|
|
565
|
+
text: 'updated text goes here',
|
|
566
|
+
edit: response.key,
|
|
567
|
+
});
|
|
568
|
+
```
|
|
569
|
+
|
|
651
570
|
## Modifying Chats
|
|
652
571
|
|
|
653
572
|
WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
|
|
@@ -698,6 +617,15 @@ WA uses an encrypted form of communication to send chat/app updates. This has be
|
|
|
698
617
|
},
|
|
699
618
|
'123456@s.whatsapp.net')
|
|
700
619
|
```
|
|
620
|
+
|
|
621
|
+
- Star/unstar a message
|
|
622
|
+
``` ts
|
|
623
|
+
await sock.chatModify({
|
|
624
|
+
star: {
|
|
625
|
+
messages: [{ id: 'messageID', fromMe: true // or `false` }],
|
|
626
|
+
star: true // - true: Star Message; false: Unstar Message
|
|
627
|
+
}},'123456@s.whatsapp.net');
|
|
628
|
+
```
|
|
701
629
|
|
|
702
630
|
**Note:** if you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
|
|
703
631
|
|
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -271,8 +271,9 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
|
271
271
|
'md-app-state': string;
|
|
272
272
|
'product-catalog-image': string;
|
|
273
273
|
'payment-bg-image': string;
|
|
274
|
+
ptv: string;
|
|
274
275
|
};
|
|
275
|
-
export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image")[];
|
|
276
|
+
export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
|
|
276
277
|
export declare const MIN_PREKEY_COUNT = 5;
|
|
277
278
|
export declare const INITIAL_PREKEY_COUNT = 30;
|
|
278
279
|
export declare const DEFAULT_CACHE_TTLS: {
|
package/lib/Defaults/index.js
CHANGED
|
@@ -103,6 +103,7 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
|
103
103
|
'md-app-state': 'App State',
|
|
104
104
|
'product-catalog-image': '',
|
|
105
105
|
'payment-bg-image': 'Payment Background',
|
|
106
|
+
'ptv': 'Video'
|
|
106
107
|
};
|
|
107
108
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
108
109
|
exports.MIN_PREKEY_COUNT = 5;
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
23
23
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
24
24
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
25
25
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
|
+
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
27
|
+
[key: string]: string;
|
|
28
|
+
};
|
|
26
29
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
27
30
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
28
31
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -95,6 +98,10 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
95
98
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
96
99
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
97
100
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
101
|
+
star: (jid: string, messages: {
|
|
102
|
+
id: string;
|
|
103
|
+
fromMe?: boolean | undefined;
|
|
104
|
+
}[], star: boolean) => Promise<void>;
|
|
98
105
|
type: "md";
|
|
99
106
|
ws: any;
|
|
100
107
|
ev: import("../Types").BaileysEventEmitter & {
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
44
44
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
45
45
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
46
46
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
47
|
+
star: (jid: string, messages: {
|
|
48
|
+
id: string;
|
|
49
|
+
fromMe?: boolean;
|
|
50
|
+
}[], star: boolean) => Promise<void>;
|
|
47
51
|
type: "md";
|
|
48
52
|
ws: any;
|
|
49
53
|
ev: import("../Types").BaileysEventEmitter & {
|
package/lib/Socket/chats.js
CHANGED
|
@@ -648,6 +648,17 @@ const makeChatsSocket = (config) => {
|
|
|
648
648
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
649
649
|
return appPatch(patch);
|
|
650
650
|
};
|
|
651
|
+
/**
|
|
652
|
+
* Star or Unstar a message
|
|
653
|
+
*/
|
|
654
|
+
const star = (jid, messages, star) => {
|
|
655
|
+
return chatModify({
|
|
656
|
+
star: {
|
|
657
|
+
messages,
|
|
658
|
+
star
|
|
659
|
+
}
|
|
660
|
+
}, jid);
|
|
661
|
+
};
|
|
651
662
|
/**
|
|
652
663
|
* Adds label for the chats
|
|
653
664
|
*/
|
|
@@ -836,7 +847,8 @@ const makeChatsSocket = (config) => {
|
|
|
836
847
|
addChatLabel,
|
|
837
848
|
removeChatLabel,
|
|
838
849
|
addMessageLabel,
|
|
839
|
-
removeMessageLabel
|
|
850
|
+
removeMessageLabel,
|
|
851
|
+
star
|
|
840
852
|
};
|
|
841
853
|
};
|
|
842
854
|
exports.makeChatsSocket = makeChatsSocket;
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -75,6 +75,10 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
75
75
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
76
76
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
77
77
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
78
|
+
star: (jid: string, messages: {
|
|
79
|
+
id: string;
|
|
80
|
+
fromMe?: boolean | undefined;
|
|
81
|
+
}[], star: boolean) => Promise<void>;
|
|
78
82
|
type: "md";
|
|
79
83
|
ws: any;
|
|
80
84
|
ev: import("../Types").BaileysEventEmitter & {
|
package/lib/Socket/groups.js
CHANGED
|
@@ -266,6 +266,7 @@ const extractGroupMetadata = (result) => {
|
|
|
266
266
|
}
|
|
267
267
|
const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
|
|
268
268
|
const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
|
|
269
|
+
const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
|
|
269
270
|
const metadata = {
|
|
270
271
|
id: groupId,
|
|
271
272
|
subject: group.attrs.subject,
|
|
@@ -278,6 +279,9 @@ const extractGroupMetadata = (result) => {
|
|
|
278
279
|
descId,
|
|
279
280
|
restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
|
|
280
281
|
announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
|
|
282
|
+
isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
|
|
283
|
+
isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
|
|
284
|
+
memberAddMode,
|
|
281
285
|
participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
282
286
|
return {
|
|
283
287
|
id: attrs.jid,
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
24
24
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
25
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
26
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
|
+
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
28
|
+
[key: string]: string;
|
|
29
|
+
};
|
|
27
30
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
28
31
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
29
32
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -96,6 +99,10 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
96
99
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
97
100
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
98
101
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
102
|
+
star: (jid: string, messages: {
|
|
103
|
+
id: string;
|
|
104
|
+
fromMe?: boolean | undefined;
|
|
105
|
+
}[], star: boolean) => Promise<void>;
|
|
99
106
|
type: "md";
|
|
100
107
|
ws: any;
|
|
101
108
|
ev: import("../Types").BaileysEventEmitter & {
|
|
@@ -12,6 +12,9 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
12
12
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
13
13
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
14
14
|
sendReceipts: (keys: proto.IMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
15
|
+
getButtonArgs: (message: proto.IMessage) => {
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
};
|
|
15
18
|
readMessages: (keys: proto.IMessageKey[]) => Promise<void>;
|
|
16
19
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
17
20
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -84,6 +87,10 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
84
87
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
85
88
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
86
89
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
90
|
+
star: (jid: string, messages: {
|
|
91
|
+
id: string;
|
|
92
|
+
fromMe?: boolean | undefined;
|
|
93
|
+
}[], star: boolean) => Promise<void>;
|
|
87
94
|
type: "md";
|
|
88
95
|
ws: any;
|
|
89
96
|
ev: import("../Types").BaileysEventEmitter & {
|
|
@@ -300,6 +300,14 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
300
300
|
}
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
+
else if (child.tag === 'blocklist') {
|
|
304
|
+
const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
|
|
305
|
+
for (const { attrs } of blocklists) {
|
|
306
|
+
const blocklist = [attrs.jid];
|
|
307
|
+
const type = (attrs.action === 'block') ? 'add' : 'remove';
|
|
308
|
+
ev.emit('blocklist.update', { blocklist, type });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
303
311
|
break;
|
|
304
312
|
case 'link_code_companion_reg':
|
|
305
313
|
const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
|
|
@@ -423,9 +431,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
423
431
|
}
|
|
424
432
|
};
|
|
425
433
|
const handleReceipt = async (node) => {
|
|
426
|
-
var _a;
|
|
434
|
+
var _a, _b;
|
|
427
435
|
const { attrs, content } = node;
|
|
428
|
-
const
|
|
436
|
+
const isLid = attrs.from.includes('lid');
|
|
437
|
+
const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
|
|
429
438
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
430
439
|
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
|
431
440
|
const key = {
|
|
@@ -528,7 +537,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
528
537
|
]);
|
|
529
538
|
};
|
|
530
539
|
const handleMessage = async (node) => {
|
|
531
|
-
|
|
540
|
+
var _a, _b;
|
|
541
|
+
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
542
|
+
if (((_b = (_a = msg.message) === null || _a === void 0 ? void 0 : _a.protocolMessage) === null || _b === void 0 ? void 0 : _b.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
|
|
543
|
+
if (node.attrs.sender_pn) {
|
|
544
|
+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
545
|
+
}
|
|
546
|
+
}
|
|
532
547
|
if (shouldIgnoreJid(msg.key.remoteJid)) {
|
|
533
548
|
logger.debug({ key: msg.key }, 'ignored message');
|
|
534
549
|
await sendMessageAck(node);
|
|
@@ -599,7 +614,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
599
614
|
};
|
|
600
615
|
if (status === 'offer') {
|
|
601
616
|
call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
|
|
602
|
-
call.isGroup = infoChild.attrs.type === 'group';
|
|
617
|
+
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
618
|
+
call.groupJid = infoChild.attrs['group-jid'];
|
|
603
619
|
callOfferCache.set(call.id, call);
|
|
604
620
|
}
|
|
605
621
|
const existingCall = callOfferCache.get(call.id);
|
|
@@ -9,6 +9,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
9
9
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
10
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
11
11
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
12
|
+
getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
|
|
12
13
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
13
14
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
|
14
15
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -81,6 +82,10 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
81
82
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
82
83
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
83
84
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
85
|
+
star: (jid: string, messages: {
|
|
86
|
+
id: string;
|
|
87
|
+
fromMe?: boolean | undefined;
|
|
88
|
+
}[], star: boolean) => Promise<void>;
|
|
84
89
|
type: "md";
|
|
85
90
|
ws: any;
|
|
86
91
|
ev: import("../Types").BaileysEventEmitter & {
|
|
@@ -253,10 +253,11 @@ const makeMessagesSocket = (config) => {
|
|
|
253
253
|
const statusJid = 'status@broadcast';
|
|
254
254
|
const isGroup = server === 'g.us';
|
|
255
255
|
const isStatus = jid === statusJid;
|
|
256
|
+
const isLid = server === 'lid';
|
|
256
257
|
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
257
258
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
258
259
|
const participants = [];
|
|
259
|
-
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
|
|
260
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
|
|
260
261
|
const binaryNodeContent = [];
|
|
261
262
|
const devices = [];
|
|
262
263
|
const meMsg = {
|
|
@@ -276,6 +277,7 @@ const makeMessagesSocket = (config) => {
|
|
|
276
277
|
devices.push({ user, device });
|
|
277
278
|
}
|
|
278
279
|
await authState.keys.transaction(async () => {
|
|
280
|
+
var _a, _b;
|
|
279
281
|
const mediaType = getMediaType(message);
|
|
280
282
|
if (isGroup || isStatus) {
|
|
281
283
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
@@ -305,7 +307,7 @@ const makeMessagesSocket = (config) => {
|
|
|
305
307
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
306
308
|
devices.push(...additionalDevices);
|
|
307
309
|
}
|
|
308
|
-
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, 's.whatsapp.net', d.device)));
|
|
310
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
309
311
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
310
312
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
311
313
|
group: destinationJid,
|
|
@@ -315,7 +317,7 @@ const makeMessagesSocket = (config) => {
|
|
|
315
317
|
const senderKeyJids = [];
|
|
316
318
|
// ensure a connection is established with every device
|
|
317
319
|
for (const { user, device } of devices) {
|
|
318
|
-
const jid = (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device);
|
|
320
|
+
const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
319
321
|
if (!senderKeyMap[jid] || !!participant) {
|
|
320
322
|
senderKeyJids.push(jid);
|
|
321
323
|
// store that this person has had the sender keys sent to them
|
|
@@ -359,8 +361,8 @@ const makeMessagesSocket = (config) => {
|
|
|
359
361
|
const meJids = [];
|
|
360
362
|
const otherJids = [];
|
|
361
363
|
for (const { user, device } of devices) {
|
|
362
|
-
const jid = (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device);
|
|
363
364
|
const isMe = user === meUser;
|
|
365
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_b = (_a = authState.creds) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
364
366
|
if (isMe) {
|
|
365
367
|
meJids.push(jid);
|
|
366
368
|
}
|
|
@@ -552,6 +554,7 @@ const makeMessagesSocket = (config) => {
|
|
|
552
554
|
relayMessage,
|
|
553
555
|
sendReceipt,
|
|
554
556
|
sendReceipts,
|
|
557
|
+
getButtonArgs,
|
|
555
558
|
readMessages,
|
|
556
559
|
refreshMediaConn,
|
|
557
560
|
waUploadToServer,
|
|
@@ -25,6 +25,9 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
25
25
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
26
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
27
|
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
28
|
+
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
29
|
+
[key: string]: string;
|
|
30
|
+
};
|
|
28
31
|
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
29
32
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
30
33
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
@@ -97,6 +100,10 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
97
100
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
98
101
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
99
102
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
103
|
+
star: (jid: string, messages: {
|
|
104
|
+
id: string;
|
|
105
|
+
fromMe?: boolean | undefined;
|
|
106
|
+
}[], star: boolean) => Promise<void>;
|
|
100
107
|
type: "md";
|
|
101
108
|
ws: any;
|
|
102
109
|
ev: import("../Types").BaileysEventEmitter & {
|
package/lib/Socket/socket.js
CHANGED
|
@@ -403,7 +403,7 @@ const makeSocket = (config) => {
|
|
|
403
403
|
{
|
|
404
404
|
tag: 'companion_platform_display',
|
|
405
405
|
attrs: {},
|
|
406
|
-
content:
|
|
406
|
+
content: `${browser[1]} (${browser[0]})`
|
|
407
407
|
},
|
|
408
408
|
{
|
|
409
409
|
tag: 'link_code_pairing_nonce',
|
|
@@ -488,11 +488,12 @@ const makeSocket = (config) => {
|
|
|
488
488
|
}
|
|
489
489
|
});
|
|
490
490
|
// login complete
|
|
491
|
-
ws.on('CB:success', async () => {
|
|
491
|
+
ws.on('CB:success', async (node) => {
|
|
492
492
|
await uploadPreKeysToServerIfRequired();
|
|
493
493
|
await sendPassiveIq('active');
|
|
494
494
|
logger.info('opened connection to WA');
|
|
495
495
|
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
496
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
496
497
|
ev.emit('connection.update', { connection: 'open' });
|
|
497
498
|
});
|
|
498
499
|
ws.on('CB:stream:error', (node) => {
|
|
@@ -24,40 +24,40 @@ exports.waLabelAssociationKey = {
|
|
|
24
24
|
};
|
|
25
25
|
const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.default)(exports.waMessageID);
|
|
26
26
|
const predefinedLabels = Object.freeze({
|
|
27
|
-
'0': {
|
|
28
|
-
id: '0',
|
|
29
|
-
name: 'New customer',
|
|
30
|
-
predefinedId: '0',
|
|
31
|
-
color: 0,
|
|
32
|
-
deleted: false
|
|
33
|
-
},
|
|
34
27
|
'1': {
|
|
35
28
|
id: '1',
|
|
36
|
-
name: 'New
|
|
29
|
+
name: 'New customer',
|
|
37
30
|
predefinedId: '1',
|
|
38
31
|
color: 1,
|
|
39
32
|
deleted: false
|
|
40
33
|
},
|
|
41
34
|
'2': {
|
|
42
35
|
id: '2',
|
|
43
|
-
name: '
|
|
36
|
+
name: 'New order',
|
|
44
37
|
predefinedId: '2',
|
|
45
38
|
color: 2,
|
|
46
39
|
deleted: false
|
|
47
40
|
},
|
|
48
41
|
'3': {
|
|
49
42
|
id: '3',
|
|
50
|
-
name: '
|
|
43
|
+
name: 'Pending payment',
|
|
51
44
|
predefinedId: '3',
|
|
52
45
|
color: 3,
|
|
53
46
|
deleted: false
|
|
54
47
|
},
|
|
55
48
|
'4': {
|
|
56
49
|
id: '4',
|
|
57
|
-
name: '
|
|
50
|
+
name: 'Paid',
|
|
58
51
|
predefinedId: '4',
|
|
59
52
|
color: 4,
|
|
60
53
|
deleted: false
|
|
54
|
+
},
|
|
55
|
+
'5': {
|
|
56
|
+
id: '5',
|
|
57
|
+
name: 'Order completed',
|
|
58
|
+
predefinedId: '5',
|
|
59
|
+
color: 5,
|
|
60
|
+
deleted: false
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
exports.default = ({ logger: _logger, chatKey, labelAssociationKey }) => {
|
package/lib/Types/Call.d.ts
CHANGED
package/lib/Types/Contact.d.ts
CHANGED
package/lib/Types/Events.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export type BaileysEventMap = {
|
|
|
25
25
|
'chats.upsert': Chat[];
|
|
26
26
|
/** update the given chats */
|
|
27
27
|
'chats.update': ChatUpdate[];
|
|
28
|
+
'chats.phoneNumberShare': {
|
|
29
|
+
lid: string;
|
|
30
|
+
jid: string;
|
|
31
|
+
};
|
|
28
32
|
/** delete chats with given ID */
|
|
29
33
|
'chats.delete': string[];
|
|
30
34
|
/** presence of contact in a chat updated */
|
|
@@ -70,6 +74,7 @@ export type BaileysEventMap = {
|
|
|
70
74
|
/** apply an action to participants in a group */
|
|
71
75
|
'group-participants.update': {
|
|
72
76
|
id: string;
|
|
77
|
+
author: string;
|
|
73
78
|
participants: string[];
|
|
74
79
|
action: ParticipantAction;
|
|
75
80
|
};
|
|
@@ -21,6 +21,12 @@ export interface GroupMetadata {
|
|
|
21
21
|
restrict?: boolean;
|
|
22
22
|
/** is set when the group only allows admins to write messages */
|
|
23
23
|
announce?: boolean;
|
|
24
|
+
/** is set when the group also allows members to add participants */
|
|
25
|
+
memberAddMode?: boolean;
|
|
26
|
+
/** is this a community */
|
|
27
|
+
isCommunity?: boolean;
|
|
28
|
+
/** is this the announce of a community */
|
|
29
|
+
isCommunityAnnounce?: boolean;
|
|
24
30
|
/** number of group participants */
|
|
25
31
|
size?: number;
|
|
26
32
|
participants: GroupParticipant[];
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ export type PollMessageOptions = {
|
|
|
94
94
|
/** 32 byte message secret to encrypt poll selections */
|
|
95
95
|
messageSecret?: Uint8Array;
|
|
96
96
|
};
|
|
97
|
+
type SharePhoneNumber = {
|
|
98
|
+
sharePhoneNumber: boolean;
|
|
99
|
+
};
|
|
100
|
+
type RequestPhoneNumber = {
|
|
101
|
+
requestPhoneNumber: boolean;
|
|
102
|
+
};
|
|
97
103
|
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
|
|
98
104
|
export type AnyMediaMessageContent = (({
|
|
99
105
|
image: WAMediaUpload;
|
|
@@ -153,7 +159,7 @@ export type AnyRegularMessageContent = (({
|
|
|
153
159
|
businessOwnerJid?: string;
|
|
154
160
|
body?: string;
|
|
155
161
|
footer?: string;
|
|
156
|
-
}) & ViewOnce;
|
|
162
|
+
} | SharePhoneNumber | RequestPhoneNumber) & ViewOnce;
|
|
157
163
|
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
158
164
|
forward: WAMessage;
|
|
159
165
|
force?: boolean;
|
package/lib/Types/index.d.ts
CHANGED
|
@@ -22,7 +22,9 @@ export declare enum DisconnectReason {
|
|
|
22
22
|
loggedOut = 401,
|
|
23
23
|
badSession = 500,
|
|
24
24
|
restartRequired = 515,
|
|
25
|
-
multideviceMismatch = 411
|
|
25
|
+
multideviceMismatch = 411,
|
|
26
|
+
forbidden = 403,
|
|
27
|
+
unavailableService = 503
|
|
26
28
|
}
|
|
27
29
|
export type WAInitResponse = {
|
|
28
30
|
ref: string;
|
package/lib/Types/index.js
CHANGED
|
@@ -36,4 +36,6 @@ var DisconnectReason;
|
|
|
36
36
|
DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
|
|
37
37
|
DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
|
|
38
38
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
39
|
+
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
40
|
+
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
39
41
|
})(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -451,6 +451,20 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
451
451
|
operation: OP.SET
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
|
+
else if ('star' in mod) {
|
|
455
|
+
const key = mod.star.messages[0];
|
|
456
|
+
patch = {
|
|
457
|
+
syncAction: {
|
|
458
|
+
starAction: {
|
|
459
|
+
starred: !!mod.star.star
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
463
|
+
type: 'regular_low',
|
|
464
|
+
apiVersion: 2,
|
|
465
|
+
operation: OP.SET
|
|
466
|
+
};
|
|
467
|
+
}
|
|
454
468
|
else if ('delete' in mod) {
|
|
455
469
|
patch = {
|
|
456
470
|
syncAction: {
|
|
@@ -6,12 +6,12 @@ import { BinaryNode } from '../WABinary';
|
|
|
6
6
|
* Decode the received node as a message.
|
|
7
7
|
* @note this will only parse the message, not decrypt it
|
|
8
8
|
*/
|
|
9
|
-
export declare function decodeMessageNode(stanza: BinaryNode, meId: string): {
|
|
9
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
10
10
|
fullMessage: proto.IWebMessageInfo;
|
|
11
11
|
author: string;
|
|
12
12
|
sender: string;
|
|
13
13
|
};
|
|
14
|
-
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, repository: SignalRepository, logger: Logger) => {
|
|
14
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
|
|
15
15
|
fullMessage: proto.IWebMessageInfo;
|
|
16
16
|
category: string;
|
|
17
17
|
author: string;
|
|
@@ -10,7 +10,7 @@ const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
|
10
10
|
* Decode the received node as a message.
|
|
11
11
|
* @note this will only parse the message, not decrypt it
|
|
12
12
|
*/
|
|
13
|
-
function decodeMessageNode(stanza, meId) {
|
|
13
|
+
function decodeMessageNode(stanza, meId, meLid) {
|
|
14
14
|
let msgType;
|
|
15
15
|
let chatId;
|
|
16
16
|
let author;
|
|
@@ -19,6 +19,7 @@ function decodeMessageNode(stanza, meId) {
|
|
|
19
19
|
const participant = stanza.attrs.participant;
|
|
20
20
|
const recipient = stanza.attrs.recipient;
|
|
21
21
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
22
|
+
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
22
23
|
if ((0, WABinary_1.isJidUser)(from)) {
|
|
23
24
|
if (recipient) {
|
|
24
25
|
if (!isMe(from)) {
|
|
@@ -32,6 +33,19 @@ function decodeMessageNode(stanza, meId) {
|
|
|
32
33
|
msgType = 'chat';
|
|
33
34
|
author = from;
|
|
34
35
|
}
|
|
36
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
37
|
+
if (recipient) {
|
|
38
|
+
if (!isMeLid(from)) {
|
|
39
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
40
|
+
}
|
|
41
|
+
chatId = recipient;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
chatId = from;
|
|
45
|
+
}
|
|
46
|
+
msgType = 'chat';
|
|
47
|
+
author = from;
|
|
48
|
+
}
|
|
35
49
|
else if ((0, WABinary_1.isJidGroup)(from)) {
|
|
36
50
|
if (!participant) {
|
|
37
51
|
throw new boom_1.Boom('No participant in group message');
|
|
@@ -57,7 +71,7 @@ function decodeMessageNode(stanza, meId) {
|
|
|
57
71
|
else {
|
|
58
72
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
59
73
|
}
|
|
60
|
-
const fromMe = isMe(stanza.attrs.participant || stanza.attrs.from);
|
|
74
|
+
const fromMe = ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
61
75
|
const pushname = stanza.attrs.notify;
|
|
62
76
|
const key = {
|
|
63
77
|
remoteJid: chatId,
|
|
@@ -81,8 +95,8 @@ function decodeMessageNode(stanza, meId) {
|
|
|
81
95
|
};
|
|
82
96
|
}
|
|
83
97
|
exports.decodeMessageNode = decodeMessageNode;
|
|
84
|
-
const decryptMessageNode = (stanza, meId, repository, logger) => {
|
|
85
|
-
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId);
|
|
98
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
99
|
+
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
86
100
|
return {
|
|
87
101
|
fullMessage,
|
|
88
102
|
category: stanza.attrs.category,
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare const extractMessageContent: (content: WAMessageContent | undefin
|
|
|
39
39
|
/**
|
|
40
40
|
* Returns the device predicted by message ID
|
|
41
41
|
*/
|
|
42
|
-
export declare const getDevice: (id: string) => "android" | "web" | "ios";
|
|
42
|
+
export declare const getDevice: (id: string) => "android" | "unknown" | "web" | "ios" | "desktop";
|
|
43
43
|
/** Upserts a receipt in the message */
|
|
44
44
|
export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void;
|
|
45
45
|
/** Update the message with a new reaction */
|
package/lib/Utils/messages.js
CHANGED
|
@@ -357,6 +357,14 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
357
357
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
+
else if ('sharePhoneNumber' in message) {
|
|
361
|
+
m.protocolMessage = {
|
|
362
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
else if ('requestPhoneNumber' in message) {
|
|
366
|
+
m.requestPhoneNumberMessage = {};
|
|
367
|
+
}
|
|
360
368
|
else {
|
|
361
369
|
m = await (0, exports.prepareWAMessageMedia)(message, options);
|
|
362
370
|
}
|
|
@@ -517,7 +525,7 @@ exports.generateWAMessage = generateWAMessage;
|
|
|
517
525
|
const getContentType = (content) => {
|
|
518
526
|
if (content) {
|
|
519
527
|
const keys = Object.keys(content);
|
|
520
|
-
const key = keys.find(k => (k === 'conversation' || k.
|
|
528
|
+
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage');
|
|
521
529
|
return key;
|
|
522
530
|
}
|
|
523
531
|
};
|
|
@@ -596,10 +604,7 @@ exports.extractMessageContent = extractMessageContent;
|
|
|
596
604
|
/**
|
|
597
605
|
* Returns the device predicted by message ID
|
|
598
606
|
*/
|
|
599
|
-
const getDevice = (id) => {
|
|
600
|
-
const deviceType = id.length > 21 ? 'android' : id.substring(0, 2) === '3A' ? 'ios' : 'web';
|
|
601
|
-
return deviceType;
|
|
602
|
-
};
|
|
607
|
+
const getDevice = (id) => /^3A/.test(id) ? 'ios' : /^3E/.test(id) ? 'web' : /^.{21}/.test(id) ? 'android' : /^.{18}/.test(id) ? 'desktop' : 'unknown';
|
|
603
608
|
exports.getDevice = getDevice;
|
|
604
609
|
/** Upserts a receipt in the message */
|
|
605
610
|
const updateMessageWithReceipt = (msg, receipt) => {
|
|
@@ -184,6 +184,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
184
184
|
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
185
185
|
});
|
|
186
186
|
break;
|
|
187
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
188
|
+
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
189
|
+
if (response) {
|
|
190
|
+
const { peerDataOperationResult } = response;
|
|
191
|
+
for (const result of peerDataOperationResult) {
|
|
192
|
+
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
193
|
+
if (retryResponse) {
|
|
194
|
+
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
195
|
+
ev.emit('messages.update', [
|
|
196
|
+
{ key: webMessageInfo.key, update: { message: webMessageInfo.message } }
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
187
202
|
}
|
|
188
203
|
}
|
|
189
204
|
else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
@@ -200,7 +215,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
200
215
|
const jid = message.key.remoteJid;
|
|
201
216
|
//let actor = whatsappID (message.participant)
|
|
202
217
|
let participants;
|
|
203
|
-
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, participants, action }));
|
|
218
|
+
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
204
219
|
const emitGroupUpdate = (update) => {
|
|
205
220
|
ev.emit('groups.update', [{ id: jid, ...update }]);
|
|
206
221
|
};
|
|
@@ -76,6 +76,10 @@ const generateLoginNode = (userJid, config) => {
|
|
|
76
76
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
77
77
|
};
|
|
78
78
|
exports.generateLoginNode = generateLoginNode;
|
|
79
|
+
const getPlatformType = (platform) => {
|
|
80
|
+
const platformType = platform.toUpperCase();
|
|
81
|
+
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
|
|
82
|
+
};
|
|
79
83
|
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
80
84
|
// the app version needs to be md5 hashed
|
|
81
85
|
// and passed in
|
|
@@ -84,7 +88,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
84
88
|
.digest();
|
|
85
89
|
const companion = {
|
|
86
90
|
os: config.browser[0],
|
|
87
|
-
platformType:
|
|
91
|
+
platformType: getPlatformType(config.browser[1]),
|
|
88
92
|
requireFullSync: config.syncFullHistory,
|
|
89
93
|
};
|
|
90
94
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -147,7 +147,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
147
147
|
const agent = readByte();
|
|
148
148
|
const device = readByte();
|
|
149
149
|
const user = readString(readByte());
|
|
150
|
-
return (0, jid_utils_1.jidEncode)(user, 's.whatsapp.net', device
|
|
150
|
+
return (0, jid_utils_1.jidEncode)(user, agent === 0 ? 's.whatsapp.net' : 'lid', device);
|
|
151
151
|
};
|
|
152
152
|
const readString = (tag) => {
|
|
153
153
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -62,10 +62,10 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
62
62
|
writeByteLength(bytes.length);
|
|
63
63
|
pushBytes(bytes);
|
|
64
64
|
};
|
|
65
|
-
const writeJid = ({
|
|
66
|
-
if (typeof
|
|
65
|
+
const writeJid = ({ domainType, device, user, server }) => {
|
|
66
|
+
if (typeof device !== 'undefined') {
|
|
67
67
|
pushByte(TAGS.AD_JID);
|
|
68
|
-
pushByte(
|
|
68
|
+
pushByte(domainType || 0);
|
|
69
69
|
pushByte(device || 0);
|
|
70
70
|
writeString(user);
|
|
71
71
|
}
|
|
@@ -3,14 +3,14 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
|
3
3
|
export declare const SERVER_JID = "server@c.us";
|
|
4
4
|
export declare const PSA_WID = "0@c.us";
|
|
5
5
|
export declare const STORIES_JID = "status@broadcast";
|
|
6
|
-
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call';
|
|
6
|
+
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
|
|
7
7
|
export type JidWithDevice = {
|
|
8
8
|
user: string;
|
|
9
9
|
device?: number;
|
|
10
10
|
};
|
|
11
11
|
export type FullJid = JidWithDevice & {
|
|
12
12
|
server: JidServer | string;
|
|
13
|
-
|
|
13
|
+
domainType?: number;
|
|
14
14
|
};
|
|
15
15
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
|
16
16
|
export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
|
|
@@ -18,6 +18,8 @@ export declare const jidDecode: (jid: string | undefined) => FullJid | undefined
|
|
|
18
18
|
export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
|
|
19
19
|
/** is the jid a user */
|
|
20
20
|
export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
|
|
21
|
+
/** is the jid a group */
|
|
22
|
+
export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
|
|
21
23
|
/** is the jid a broadcast */
|
|
22
24
|
export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
|
|
23
25
|
/** is the jid a group */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
3
|
+
exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
|
@@ -18,11 +18,11 @@ const jidDecode = (jid) => {
|
|
|
18
18
|
const server = jid.slice(sepIdx + 1);
|
|
19
19
|
const userCombined = jid.slice(0, sepIdx);
|
|
20
20
|
const [userAgent, device] = userCombined.split(':');
|
|
21
|
-
const
|
|
21
|
+
const user = userAgent.split('_')[0];
|
|
22
22
|
return {
|
|
23
23
|
server,
|
|
24
24
|
user,
|
|
25
|
-
|
|
25
|
+
domainType: server === 'lid' ? 1 : 0,
|
|
26
26
|
device: device ? +device : undefined
|
|
27
27
|
};
|
|
28
28
|
};
|
|
@@ -36,6 +36,9 @@ exports.areJidsSameUser = areJidsSameUser;
|
|
|
36
36
|
/** is the jid a user */
|
|
37
37
|
const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
|
|
38
38
|
exports.isJidUser = isJidUser;
|
|
39
|
+
/** is the jid a group */
|
|
40
|
+
const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
|
|
41
|
+
exports.isLidUser = isLidUser;
|
|
39
42
|
/** is the jid a broadcast */
|
|
40
43
|
const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
|
|
41
44
|
exports.isJidBroadcast = isJidBroadcast;
|