@d0v3riz/baileys 6.4.1 → 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/LICENSE +21 -0
- package/README.md +25 -94
- package/lib/Defaults/index.d.ts +3 -3
- package/lib/Defaults/index.js +3 -2
- package/lib/Signal/libsignal.js +3 -2
- package/lib/Socket/business.d.ts +8 -1
- package/lib/Socket/chats.d.ts +5 -1
- package/lib/Socket/chats.js +26 -10
- package/lib/Socket/groups.d.ts +5 -1
- package/lib/Socket/groups.js +4 -0
- package/lib/Socket/index.d.ts +8 -1
- package/lib/Socket/messages-recv.d.ts +8 -1
- package/lib/Socket/messages-recv.js +20 -4
- package/lib/Socket/messages-send.d.ts +6 -1
- package/lib/Socket/messages-send.js +12 -6
- package/lib/Socket/registration.d.ts +18 -4
- package/lib/Socket/registration.js +4 -4
- package/lib/Socket/socket.d.ts +1 -2
- package/lib/Socket/socket.js +4 -3
- package/lib/Store/make-in-memory-store.js +14 -12
- 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/Socket.d.ts +2 -0
- 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 +12 -7
- 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 +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 WhiskeySockets
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
### Important Note
|
|
4
4
|
|
|
5
|
-
This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this.
|
|
6
|
-
We hold no liability for your use of this tool, in fact, depending on how you use this library, you'll be in violation of WhatsApp's Terms of Service. We discourage any stalkerware, bulk or automated messaging usage.
|
|
5
|
+
This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
|
|
7
6
|
|
|
7
|
+
#### Liability and License Notice
|
|
8
|
+
Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/WhiskeySockets/Baileys/blob/master/LICENSE).
|
|
9
|
+
The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used.
|
|
10
|
+
##
|
|
8
11
|
|
|
9
12
|
Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
|
|
10
13
|
Not running Selenium or Chromimum saves you like **half a gig** of ram :/
|
|
@@ -373,65 +376,6 @@ const sentMsg = await sock.sendMessage(
|
|
|
373
376
|
}
|
|
374
377
|
)
|
|
375
378
|
|
|
376
|
-
// send a buttons message!
|
|
377
|
-
const buttons = [
|
|
378
|
-
{buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},
|
|
379
|
-
{buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},
|
|
380
|
-
{buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}
|
|
381
|
-
]
|
|
382
|
-
|
|
383
|
-
const buttonMessage = {
|
|
384
|
-
text: "Hi it's button message",
|
|
385
|
-
footer: 'Hello World',
|
|
386
|
-
buttons: buttons,
|
|
387
|
-
headerType: 1
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const sendMsg = await sock.sendMessage(id, buttonMessage)
|
|
391
|
-
|
|
392
|
-
//send a template message!
|
|
393
|
-
const templateButtons = [
|
|
394
|
-
{index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}},
|
|
395
|
-
{index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}},
|
|
396
|
-
{index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}},
|
|
397
|
-
]
|
|
398
|
-
|
|
399
|
-
const templateMessage = {
|
|
400
|
-
text: "Hi it's a template message",
|
|
401
|
-
footer: 'Hello World',
|
|
402
|
-
templateButtons: templateButtons
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const sendMsg = await sock.sendMessage(id, templateMessage)
|
|
406
|
-
|
|
407
|
-
// send a list message!
|
|
408
|
-
const sections = [
|
|
409
|
-
{
|
|
410
|
-
title: "Section 1",
|
|
411
|
-
rows: [
|
|
412
|
-
{title: "Option 1", rowId: "option1"},
|
|
413
|
-
{title: "Option 2", rowId: "option2", description: "This is a description"}
|
|
414
|
-
]
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
title: "Section 2",
|
|
418
|
-
rows: [
|
|
419
|
-
{title: "Option 3", rowId: "option3"},
|
|
420
|
-
{title: "Option 4", rowId: "option4", description: "This is a description V2"}
|
|
421
|
-
]
|
|
422
|
-
},
|
|
423
|
-
]
|
|
424
|
-
|
|
425
|
-
const listMessage = {
|
|
426
|
-
text: "This is a list",
|
|
427
|
-
footer: "nice footer, link: https://google.com",
|
|
428
|
-
title: "Amazing boldfaced list title",
|
|
429
|
-
buttonText: "Required, text on the button to view the list",
|
|
430
|
-
sections
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const sendMsg = await sock.sendMessage(id, listMessage)
|
|
434
|
-
|
|
435
379
|
const reactionMessage = {
|
|
436
380
|
react: {
|
|
437
381
|
text: "💖", // use an empty string to remove the reaction
|
|
@@ -486,39 +430,6 @@ await sock.sendMessage(
|
|
|
486
430
|
{ audio: { url: "./Media/audio.mp3" }, mimetype: 'audio/mp4' }
|
|
487
431
|
{ url: "Media/audio.mp3" }, // can send mp3, mp4, & ogg
|
|
488
432
|
)
|
|
489
|
-
|
|
490
|
-
// send a buttons message with image header!
|
|
491
|
-
const buttons = [
|
|
492
|
-
{buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},
|
|
493
|
-
{buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},
|
|
494
|
-
{buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}
|
|
495
|
-
]
|
|
496
|
-
|
|
497
|
-
const buttonMessage = {
|
|
498
|
-
image: {url: 'https://example.com/image.jpeg'},
|
|
499
|
-
caption: "Hi it's button message",
|
|
500
|
-
footer: 'Hello World',
|
|
501
|
-
buttons: buttons,
|
|
502
|
-
headerType: 4
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const sendMsg = await sock.sendMessage(id, buttonMessage)
|
|
506
|
-
|
|
507
|
-
//send a template message with an image **attached**!
|
|
508
|
-
const templateButtons = [
|
|
509
|
-
{index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}},
|
|
510
|
-
{index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}},
|
|
511
|
-
{index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}},
|
|
512
|
-
]
|
|
513
|
-
|
|
514
|
-
const buttonMessage = {
|
|
515
|
-
text: "Hi it's a template message",
|
|
516
|
-
footer: 'Hello World',
|
|
517
|
-
templateButtons: templateButtons,
|
|
518
|
-
image: {url: 'https://example.com/image.jpeg'}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const sendMsg = await sock.sendMessage(id, templateMessage)
|
|
522
433
|
```
|
|
523
434
|
|
|
524
435
|
### Notes
|
|
@@ -645,6 +556,17 @@ await sock.sendMessage(jid, { delete: response.key })
|
|
|
645
556
|
|
|
646
557
|
**Note:** deleting for oneself is supported via `chatModify` (next section)
|
|
647
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
|
+
|
|
648
570
|
## Modifying Chats
|
|
649
571
|
|
|
650
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:
|
|
@@ -695,6 +617,15 @@ WA uses an encrypted form of communication to send chat/app updates. This has be
|
|
|
695
617
|
},
|
|
696
618
|
'123456@s.whatsapp.net')
|
|
697
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
|
+
```
|
|
698
629
|
|
|
699
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.
|
|
700
631
|
|
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -122,7 +122,6 @@ export declare const PHONENUMBER_MCC: {
|
|
|
122
122
|
"356": number;
|
|
123
123
|
"692": number;
|
|
124
124
|
"222": number;
|
|
125
|
-
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
126
125
|
"230": number;
|
|
127
126
|
"52": number;
|
|
128
127
|
"691": number;
|
|
@@ -235,7 +234,7 @@ export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
|
235
234
|
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
236
235
|
export declare const MOBILE_TOKEN: Buffer;
|
|
237
236
|
export declare const MOBILE_REGISTRATION_ENDPOINT = "https://v.whatsapp.net/v2";
|
|
238
|
-
export declare const MOBILE_USERAGENT = "WhatsApp/2.
|
|
237
|
+
export declare const MOBILE_USERAGENT = "WhatsApp/2.23.13.82 iOS/15.3.1 Device/Apple-iPhone_7";
|
|
239
238
|
export declare const REGISTRATION_PUBLIC_KEY: Buffer;
|
|
240
239
|
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
241
240
|
export declare const DICT_VERSION = 2;
|
|
@@ -272,8 +271,9 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
|
272
271
|
'md-app-state': string;
|
|
273
272
|
'product-catalog-image': string;
|
|
274
273
|
'payment-bg-image': string;
|
|
274
|
+
ptv: string;
|
|
275
275
|
};
|
|
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")[];
|
|
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")[];
|
|
277
277
|
export declare const MIN_PREKEY_COUNT = 5;
|
|
278
278
|
export declare const INITIAL_PREKEY_COUNT = 30;
|
|
279
279
|
export declare const DEFAULT_CACHE_TTLS: {
|
package/lib/Defaults/index.js
CHANGED
|
@@ -19,9 +19,9 @@ exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
|
19
19
|
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
20
20
|
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
21
21
|
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
22
|
-
exports.MOBILE_TOKEN = Buffer.from('
|
|
22
|
+
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM3d3683e76445591c0591bc3c034c3bca');
|
|
23
23
|
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
24
|
-
exports.MOBILE_USERAGENT = 'WhatsApp/2.
|
|
24
|
+
exports.MOBILE_USERAGENT = 'WhatsApp/2.23.13.82 iOS/15.3.1 Device/Apple-iPhone_7';
|
|
25
25
|
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
26
26
|
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
|
|
27
27
|
34, 251, 111, 18, 37, 18, 48, 45,
|
|
@@ -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/Signal/libsignal.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.makeLibSignalRepository = void 0;
|
|
|
27
27
|
const libsignal = __importStar(require("libsignal"));
|
|
28
28
|
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
29
29
|
const Utils_1 = require("../Utils");
|
|
30
|
+
const WABinary_1 = require("../WABinary");
|
|
30
31
|
function makeLibSignalRepository(auth) {
|
|
31
32
|
const storage = signalStorage(auth);
|
|
32
33
|
return {
|
|
@@ -91,9 +92,9 @@ function makeLibSignalRepository(auth) {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
94
|
-
const jidToSignalAddress = (jid) => jid.split('@')[0];
|
|
95
95
|
const jidToSignalProtocolAddress = (jid) => {
|
|
96
|
-
|
|
96
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
97
|
+
return new libsignal.ProtocolAddress(user, device || 0);
|
|
97
98
|
};
|
|
98
99
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
99
100
|
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
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,8 +98,12 @@ 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
|
-
ws:
|
|
106
|
+
ws: any;
|
|
100
107
|
ev: import("../Types").BaileysEventEmitter & {
|
|
101
108
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
102
109
|
buffer(): void;
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -44,8 +44,12 @@ 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
|
-
ws:
|
|
52
|
+
ws: any;
|
|
49
53
|
ev: import("../Types").BaileysEventEmitter & {
|
|
50
54
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
51
55
|
buffer(): void;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -141,15 +141,19 @@ const makeChatsSocket = (config) => {
|
|
|
141
141
|
};
|
|
142
142
|
const onWhatsApp = async (...jids) => {
|
|
143
143
|
const query = { tag: 'contact', attrs: {} };
|
|
144
|
-
const list = jids.map((jid) =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
const list = jids.map((jid) => {
|
|
145
|
+
// insures only 1 + is there
|
|
146
|
+
const content = `+${jid.replace('+', '')}`;
|
|
147
|
+
return {
|
|
148
|
+
tag: 'user',
|
|
149
|
+
attrs: {},
|
|
150
|
+
content: [{
|
|
151
|
+
tag: 'contact',
|
|
152
|
+
attrs: {},
|
|
153
|
+
content,
|
|
154
|
+
}],
|
|
155
|
+
};
|
|
156
|
+
});
|
|
153
157
|
const results = await interactiveQuery(list, query);
|
|
154
158
|
return results.map(user => {
|
|
155
159
|
const contact = (0, WABinary_1.getBinaryNodeChild)(user, 'contact');
|
|
@@ -644,6 +648,17 @@ const makeChatsSocket = (config) => {
|
|
|
644
648
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
645
649
|
return appPatch(patch);
|
|
646
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
|
+
};
|
|
647
662
|
/**
|
|
648
663
|
* Adds label for the chats
|
|
649
664
|
*/
|
|
@@ -832,7 +847,8 @@ const makeChatsSocket = (config) => {
|
|
|
832
847
|
addChatLabel,
|
|
833
848
|
removeChatLabel,
|
|
834
849
|
addMessageLabel,
|
|
835
|
-
removeMessageLabel
|
|
850
|
+
removeMessageLabel,
|
|
851
|
+
star
|
|
836
852
|
};
|
|
837
853
|
};
|
|
838
854
|
exports.makeChatsSocket = makeChatsSocket;
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -75,8 +75,12 @@ 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
|
-
ws:
|
|
83
|
+
ws: any;
|
|
80
84
|
ev: import("../Types").BaileysEventEmitter & {
|
|
81
85
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
82
86
|
buffer(): void;
|
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,8 +99,12 @@ 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
|
-
ws:
|
|
107
|
+
ws: any;
|
|
101
108
|
ev: import("../Types").BaileysEventEmitter & {
|
|
102
109
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
103
110
|
buffer(): void;
|
|
@@ -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,8 +87,12 @@ 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
|
-
ws:
|
|
95
|
+
ws: any;
|
|
89
96
|
ev: import("../Types").BaileysEventEmitter & {
|
|
90
97
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
91
98
|
buffer(): void;
|
|
@@ -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,8 +82,12 @@ 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
|
-
ws:
|
|
90
|
+
ws: any;
|
|
86
91
|
ev: import("../Types").BaileysEventEmitter & {
|
|
87
92
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
88
93
|
buffer(): void;
|
|
@@ -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
|
|
@@ -345,10 +347,13 @@ const makeMessagesSocket = (config) => {
|
|
|
345
347
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
346
348
|
}
|
|
347
349
|
else {
|
|
348
|
-
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
350
|
+
const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
|
|
349
351
|
if (!participant) {
|
|
350
352
|
devices.push({ user });
|
|
351
|
-
|
|
353
|
+
// do not send message to self if the device is 0 (mobile)
|
|
354
|
+
if (meDevice !== undefined && meDevice !== 0) {
|
|
355
|
+
devices.push({ user: meUser });
|
|
356
|
+
}
|
|
352
357
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
353
358
|
devices.push(...additionalDevices);
|
|
354
359
|
}
|
|
@@ -356,8 +361,8 @@ const makeMessagesSocket = (config) => {
|
|
|
356
361
|
const meJids = [];
|
|
357
362
|
const otherJids = [];
|
|
358
363
|
for (const { user, device } of devices) {
|
|
359
|
-
const jid = (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device);
|
|
360
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);
|
|
361
366
|
if (isMe) {
|
|
362
367
|
meJids.push(jid);
|
|
363
368
|
}
|
|
@@ -549,6 +554,7 @@ const makeMessagesSocket = (config) => {
|
|
|
549
554
|
relayMessage,
|
|
550
555
|
sendReceipt,
|
|
551
556
|
sendReceipts,
|
|
557
|
+
getButtonArgs,
|
|
552
558
|
readMessages,
|
|
553
559
|
refreshMediaConn,
|
|
554
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,8 +100,12 @@ 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
|
-
ws:
|
|
108
|
+
ws: any;
|
|
102
109
|
ev: import("../Types").BaileysEventEmitter & {
|
|
103
110
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
104
111
|
buffer(): void;
|
|
@@ -154,7 +161,11 @@ export interface RegistrationOptions {
|
|
|
154
161
|
/**
|
|
155
162
|
* How to send the one time code
|
|
156
163
|
*/
|
|
157
|
-
method?: 'sms' | 'voice';
|
|
164
|
+
method?: 'sms' | 'voice' | 'captcha';
|
|
165
|
+
/**
|
|
166
|
+
* The captcha code if it was requested
|
|
167
|
+
*/
|
|
168
|
+
captcha?: string;
|
|
158
169
|
}
|
|
159
170
|
export type RegistrationParams = RegistrationData & RegistrationOptions;
|
|
160
171
|
export declare function registrationParams(params: RegistrationParams): {
|
|
@@ -180,6 +191,7 @@ export declare function registrationParams(params: RegistrationParams): {
|
|
|
180
191
|
id: string;
|
|
181
192
|
backup_token: string;
|
|
182
193
|
token: string;
|
|
194
|
+
fraud_checkpoint_code: string | undefined;
|
|
183
195
|
};
|
|
184
196
|
/**
|
|
185
197
|
* Requests a registration code for the given phone number.
|
|
@@ -198,16 +210,18 @@ export declare function mobileRegister(params: RegistrationParams & {
|
|
|
198
210
|
export declare function mobileRegisterEncrypt(data: string): string;
|
|
199
211
|
export declare function mobileRegisterFetch(path: string, opts?: AxiosRequestConfig): Promise<ExistsResponse>;
|
|
200
212
|
export interface ExistsResponse {
|
|
201
|
-
status: 'fail';
|
|
213
|
+
status: 'fail' | 'sent';
|
|
202
214
|
voice_length?: number;
|
|
203
215
|
voice_wait?: number;
|
|
204
216
|
sms_length?: number;
|
|
205
217
|
sms_wait?: number;
|
|
206
|
-
reason?: 'incorrect' | 'missing_param';
|
|
218
|
+
reason?: 'incorrect' | 'missing_param' | 'code_checkpoint';
|
|
207
219
|
login?: string;
|
|
208
220
|
flash_type?: number;
|
|
209
221
|
ab_hash?: string;
|
|
210
222
|
ab_key?: string;
|
|
211
223
|
exp_cfg?: string;
|
|
212
224
|
lid?: string;
|
|
225
|
+
image_blob?: string;
|
|
226
|
+
audio_blob?: string;
|
|
213
227
|
}
|
|
@@ -86,6 +86,7 @@ function registrationParams(params) {
|
|
|
86
86
|
id: convertBufferToUrlHex(params.identityId),
|
|
87
87
|
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
88
88
|
token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
|
|
89
|
+
fraud_checkpoint_code: params.captcha,
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
exports.registrationParams = registrationParams;
|
|
@@ -141,11 +142,10 @@ async function mobileRegisterFetch(path, opts = {}) {
|
|
|
141
142
|
if (opts.params) {
|
|
142
143
|
const parameter = [];
|
|
143
144
|
for (const param in opts.params) {
|
|
144
|
-
|
|
145
|
+
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
146
|
+
parameter.push(param + '=' + urlencode(opts.params[param]));
|
|
147
|
+
}
|
|
145
148
|
}
|
|
146
|
-
console.log('parameter', opts.params, parameter);
|
|
147
|
-
// const params = urlencode(mobileRegisterEncrypt(parameter.join('&')))
|
|
148
|
-
// url += `?ENC=${params}`
|
|
149
149
|
url += `?${parameter.join('&')}`;
|
|
150
150
|
delete opts.params;
|
|
151
151
|
}
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { SocketConfig } from '../Types';
|
|
4
4
|
import { BinaryNode } from '../WABinary';
|
|
5
|
-
import { MobileSocketClient, WebSocketClient } from './Client';
|
|
6
5
|
/**
|
|
7
6
|
* Connects to WA servers and performs:
|
|
8
7
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -11,7 +10,7 @@ import { MobileSocketClient, WebSocketClient } from './Client';
|
|
|
11
10
|
*/
|
|
12
11
|
export declare const makeSocket: (config: SocketConfig) => {
|
|
13
12
|
type: "md";
|
|
14
|
-
ws:
|
|
13
|
+
ws: any;
|
|
15
14
|
ev: import("../Types").BaileysEventEmitter & {
|
|
16
15
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
17
16
|
buffer(): void;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -24,7 +24,7 @@ const makeSocket = (config) => {
|
|
|
24
24
|
if (config.mobile && url.protocol !== 'tcp:') {
|
|
25
25
|
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
26
26
|
}
|
|
27
|
-
const ws = config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
27
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
28
28
|
ws.connect();
|
|
29
29
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
30
30
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -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 }) => {
|
|
@@ -184,7 +184,9 @@ exports.default = ({ logger: _logger, chatKey, labelAssociationKey }) => {
|
|
|
184
184
|
});
|
|
185
185
|
ev.on('chats.delete', deletions => {
|
|
186
186
|
for (const item of deletions) {
|
|
187
|
-
chats.
|
|
187
|
+
if (chats.get(item)) {
|
|
188
|
+
chats.deleteById(item);
|
|
189
|
+
}
|
|
188
190
|
}
|
|
189
191
|
});
|
|
190
192
|
ev.on('messages.upsert', ({ messages: newMessages, type }) => {
|
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/Socket.d.ts
CHANGED
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
|
@@ -111,8 +111,8 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
111
111
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
112
112
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
113
113
|
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
114
|
-
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt ===
|
|
115
|
-
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt ===
|
|
114
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
115
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
116
116
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
117
117
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
118
118
|
logger,
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0v3riz/baileys",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"description": "WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"jest": "^27.0.6",
|
|
71
71
|
"jimp": "^0.16.1",
|
|
72
72
|
"link-preview-js": "^3.0.0",
|
|
73
|
+
"open": "^8.4.2",
|
|
73
74
|
"qrcode-terminal": "^0.12.0",
|
|
74
75
|
"release-it": "^15.10.3",
|
|
75
76
|
"sharp": "^0.30.5",
|