@queenanya/baileys 6.6.6 → 6.7.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/CHANGELOG.md +1 -5
- package/README.md +31 -93
- package/WAProto/WAProto.proto +473 -8
- package/WAProto/index.d.ts +4793 -22
- package/WAProto/index.js +32548 -19335
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +2 -2
- package/lib/Defaults/index.js +6 -2
- package/lib/Socket/business.d.ts +9 -0
- package/lib/Socket/chats.d.ts +4 -0
- package/lib/Socket/chats.js +13 -1
- package/lib/Socket/groups.d.ts +6 -0
- package/lib/Socket/groups.js +9 -2
- package/lib/Socket/index.d.ts +9 -0
- package/lib/Socket/messages-recv.d.ts +9 -0
- package/lib/Socket/messages-recv.js +29 -7
- package/lib/Socket/messages-send.d.ts +7 -0
- package/lib/Socket/messages-send.js +7 -4
- package/lib/Socket/registration.d.ts +9 -0
- package/lib/Socket/socket.js +3 -2
- package/lib/Store/make-cache-manager-store.d.ts +0 -1
- 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 +2 -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/generics.d.ts +1 -0
- package/lib/Utils/generics.js +1 -0
- package/lib/Utils/messages-media.js +1 -1
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +11 -5
- package/lib/Utils/process-message.js +27 -4
- package/lib/Utils/validate-connection.js +33 -2
- 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 +5 -5
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ export declare const PHONENUMBER_MCC: {
|
|
|
138
138
|
"977": number;
|
|
139
139
|
"31": number;
|
|
140
140
|
"687": number;
|
|
141
|
-
"64": number;
|
|
141
|
+
"64": number; /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
142
142
|
"505": number;
|
|
143
143
|
"227": number;
|
|
144
144
|
"234": number;
|
|
@@ -234,7 +234,7 @@ export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
|
234
234
|
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
235
235
|
export declare const MOBILE_TOKEN: Buffer;
|
|
236
236
|
export declare const MOBILE_REGISTRATION_ENDPOINT = "https://v.whatsapp.net/v2";
|
|
237
|
-
export declare const MOBILE_USERAGENT
|
|
237
|
+
export declare const MOBILE_USERAGENT: string;
|
|
238
238
|
export declare const REGISTRATION_PUBLIC_KEY: Buffer;
|
|
239
239
|
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
240
240
|
export declare const DICT_VERSION = 2;
|
package/lib/Defaults/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_EXCLUDE_REGEX = exports.URL_REGEX = exports.MOBILE_NOISE_HEADER = exports.PROTOCOL_VERSION = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.REGISTRATION_PUBLIC_KEY = exports.MOBILE_USERAGENT = exports.MOBILE_REGISTRATION_ENDPOINT = exports.MOBILE_TOKEN = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.MOBILE_PORT = exports.MOBILE_ENDPOINT = exports.DEFAULT_ORIGIN = exports.PHONENUMBER_MCC = exports.UNAUTHORIZED_CODES = void 0;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
7
8
|
const WAProto_1 = require("../../WAProto");
|
|
8
9
|
const libsignal_1 = require("../Signal/libsignal");
|
|
9
10
|
const Utils_1 = require("../Utils");
|
|
@@ -19,9 +20,11 @@ exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
|
19
20
|
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
20
21
|
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
21
22
|
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
22
|
-
|
|
23
|
+
const WA_VERSION = '2.23.14.82';
|
|
24
|
+
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
|
|
25
|
+
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
23
26
|
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
24
|
-
exports.MOBILE_USERAGENT =
|
|
27
|
+
exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/15.3.1 Device/Apple-iPhone_7`;
|
|
25
28
|
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
26
29
|
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
30
|
34, 251, 111, 18, 37, 18, 48, 45,
|
|
@@ -56,6 +59,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
56
59
|
defaultQueryTimeoutMs: 60000,
|
|
57
60
|
customUploadHosts: [],
|
|
58
61
|
retryRequestDelayMs: 250,
|
|
62
|
+
maxMsgRetryCount: 5,
|
|
59
63
|
fireInitQueries: true,
|
|
60
64
|
auth: undefined,
|
|
61
65
|
markOnlineOnConnect: true,
|
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;
|
|
@@ -55,6 +58,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
55
58
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
56
59
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
57
60
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
61
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
62
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
58
63
|
groupFetchAllParticipating: () => Promise<{
|
|
59
64
|
[_: string]: import("../Types").GroupMetadata;
|
|
60
65
|
}>;
|
|
@@ -95,6 +100,10 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
95
100
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
96
101
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
97
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>;
|
|
98
107
|
type: "md";
|
|
99
108
|
ws: any;
|
|
100
109
|
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
|
@@ -32,6 +32,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
32
32
|
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
33
33
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
34
34
|
groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
|
|
35
|
+
groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>;
|
|
36
|
+
groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>;
|
|
35
37
|
groupFetchAllParticipating: () => Promise<{
|
|
36
38
|
[_: string]: GroupMetadata;
|
|
37
39
|
}>;
|
|
@@ -75,6 +77,10 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
75
77
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
76
78
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
77
79
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
80
|
+
star: (jid: string, messages: {
|
|
81
|
+
id: string;
|
|
82
|
+
fromMe?: boolean | undefined;
|
|
83
|
+
}[], star: boolean) => Promise<void>;
|
|
78
84
|
type: "md";
|
|
79
85
|
ws: any;
|
|
80
86
|
ev: import("../Types").BaileysEventEmitter & {
|
package/lib/Socket/groups.js
CHANGED
|
@@ -250,6 +250,12 @@ const makeGroupsSocket = (config) => {
|
|
|
250
250
|
groupSettingUpdate: async (jid, setting) => {
|
|
251
251
|
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
252
252
|
},
|
|
253
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
254
|
+
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
255
|
+
},
|
|
256
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
257
|
+
await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
|
|
258
|
+
},
|
|
253
259
|
groupFetchAllParticipating
|
|
254
260
|
};
|
|
255
261
|
};
|
|
@@ -266,13 +272,13 @@ const extractGroupMetadata = (result) => {
|
|
|
266
272
|
}
|
|
267
273
|
const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
|
|
268
274
|
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')
|
|
275
|
+
const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
|
|
270
276
|
const metadata = {
|
|
271
277
|
id: groupId,
|
|
272
278
|
subject: group.attrs.subject,
|
|
273
279
|
subjectOwner: group.attrs.s_o,
|
|
274
280
|
subjectTime: +group.attrs.s_t,
|
|
275
|
-
size:
|
|
281
|
+
size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
|
|
276
282
|
creation: +group.attrs.creation,
|
|
277
283
|
owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
|
|
278
284
|
desc,
|
|
@@ -281,6 +287,7 @@ const extractGroupMetadata = (result) => {
|
|
|
281
287
|
announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
|
|
282
288
|
isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
|
|
283
289
|
isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
|
|
290
|
+
joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
|
|
284
291
|
memberAddMode,
|
|
285
292
|
participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
286
293
|
return {
|
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;
|
|
@@ -56,6 +59,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
56
59
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
57
60
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
58
61
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
62
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
63
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
59
64
|
groupFetchAllParticipating: () => Promise<{
|
|
60
65
|
[_: string]: import("../Types").GroupMetadata;
|
|
61
66
|
}>;
|
|
@@ -96,6 +101,10 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
96
101
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
97
102
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
98
103
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
104
|
+
star: (jid: string, messages: {
|
|
105
|
+
id: string;
|
|
106
|
+
fromMe?: boolean | undefined;
|
|
107
|
+
}[], star: boolean) => Promise<void>;
|
|
99
108
|
type: "md";
|
|
100
109
|
ws: any;
|
|
101
110
|
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;
|
|
@@ -44,6 +47,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
44
47
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
45
48
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
46
49
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
50
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
51
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
47
52
|
groupFetchAllParticipating: () => Promise<{
|
|
48
53
|
[_: string]: import("../Types").GroupMetadata;
|
|
49
54
|
}>;
|
|
@@ -84,6 +89,10 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
84
89
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
85
90
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
86
91
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
92
|
+
star: (jid: string, messages: {
|
|
93
|
+
id: string;
|
|
94
|
+
fromMe?: boolean | undefined;
|
|
95
|
+
}[], star: boolean) => Promise<void>;
|
|
87
96
|
type: "md";
|
|
88
97
|
ws: any;
|
|
89
98
|
ev: import("../Types").BaileysEventEmitter & {
|
|
@@ -17,7 +17,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
17
17
|
const groups_1 = require("./groups");
|
|
18
18
|
const messages_send_1 = require("./messages-send");
|
|
19
19
|
const makeMessagesRecvSocket = (config) => {
|
|
20
|
-
const { logger, retryRequestDelayMs, getMessage, shouldIgnoreJid } = config;
|
|
20
|
+
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
|
21
21
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
22
22
|
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, } = sock;
|
|
23
23
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
@@ -74,7 +74,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
74
74
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
75
75
|
const msgId = node.attrs.id;
|
|
76
76
|
let retryCount = msgRetryCache.get(msgId) || 0;
|
|
77
|
-
if (retryCount >=
|
|
77
|
+
if (retryCount >= maxMsgRetryCount) {
|
|
78
78
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
79
79
|
msgRetryCache.del(msgId);
|
|
80
80
|
return;
|
|
@@ -220,6 +220,20 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
220
220
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
221
221
|
msg.messageStubParameters = [child.attrs.code];
|
|
222
222
|
break;
|
|
223
|
+
case 'member_add_mode':
|
|
224
|
+
const addMode = child.content;
|
|
225
|
+
if (addMode) {
|
|
226
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
227
|
+
msg.messageStubParameters = [addMode.toString()];
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
case 'membership_approval_mode':
|
|
231
|
+
const approvalMode = (0, WABinary_1.getBinaryNodeChild)(child, 'group_join');
|
|
232
|
+
if (approvalMode) {
|
|
233
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
234
|
+
msg.messageStubParameters = [approvalMode.attrs.state];
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
223
237
|
}
|
|
224
238
|
};
|
|
225
239
|
const processNotification = async (node) => {
|
|
@@ -388,7 +402,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
388
402
|
const willSendMessageAgain = (id, participant) => {
|
|
389
403
|
const key = `${id}:${participant}`;
|
|
390
404
|
const retryCount = msgRetryCache.get(key) || 0;
|
|
391
|
-
return retryCount <
|
|
405
|
+
return retryCount < maxMsgRetryCount;
|
|
392
406
|
};
|
|
393
407
|
const updateSendMessageAgainCount = (id, participant) => {
|
|
394
408
|
const key = `${id}:${participant}`;
|
|
@@ -431,9 +445,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
431
445
|
}
|
|
432
446
|
};
|
|
433
447
|
const handleReceipt = async (node) => {
|
|
434
|
-
var _a;
|
|
448
|
+
var _a, _b;
|
|
435
449
|
const { attrs, content } = node;
|
|
436
|
-
const
|
|
450
|
+
const isLid = attrs.from.includes('lid');
|
|
451
|
+
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);
|
|
437
452
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
438
453
|
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
|
439
454
|
const key = {
|
|
@@ -536,7 +551,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
536
551
|
]);
|
|
537
552
|
};
|
|
538
553
|
const handleMessage = async (node) => {
|
|
539
|
-
|
|
554
|
+
var _a, _b;
|
|
555
|
+
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
556
|
+
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) {
|
|
557
|
+
if (node.attrs.sender_pn) {
|
|
558
|
+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
559
|
+
}
|
|
560
|
+
}
|
|
540
561
|
if (shouldIgnoreJid(msg.key.remoteJid)) {
|
|
541
562
|
logger.debug({ key: msg.key }, 'ignored message');
|
|
542
563
|
await sendMessageAck(node);
|
|
@@ -607,7 +628,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
607
628
|
};
|
|
608
629
|
if (status === 'offer') {
|
|
609
630
|
call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
|
|
610
|
-
call.isGroup = infoChild.attrs.type === 'group';
|
|
631
|
+
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
632
|
+
call.groupJid = infoChild.attrs['group-jid'];
|
|
611
633
|
callOfferCache.set(call.id, call);
|
|
612
634
|
}
|
|
613
635
|
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;
|
|
@@ -41,6 +42,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
41
42
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
42
43
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
43
44
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
45
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
46
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
44
47
|
groupFetchAllParticipating: () => Promise<{
|
|
45
48
|
[_: string]: import("../Types").GroupMetadata;
|
|
46
49
|
}>;
|
|
@@ -81,6 +84,10 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
81
84
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
82
85
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
83
86
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
87
|
+
star: (jid: string, messages: {
|
|
88
|
+
id: string;
|
|
89
|
+
fromMe?: boolean | undefined;
|
|
90
|
+
}[], star: boolean) => Promise<void>;
|
|
84
91
|
type: "md";
|
|
85
92
|
ws: any;
|
|
86
93
|
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;
|
|
@@ -60,6 +63,8 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
60
63
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
61
64
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
62
65
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
66
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
67
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
63
68
|
groupFetchAllParticipating: () => Promise<{
|
|
64
69
|
[_: string]: import("../Types").GroupMetadata;
|
|
65
70
|
}>;
|
|
@@ -100,6 +105,10 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
100
105
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
101
106
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
102
107
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
108
|
+
star: (jid: string, messages: {
|
|
109
|
+
id: string;
|
|
110
|
+
fromMe?: boolean | undefined;
|
|
111
|
+
}[], star: boolean) => Promise<void>;
|
|
103
112
|
type: "md";
|
|
104
113
|
ws: any;
|
|
105
114
|
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) => {
|
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
|
};
|
|
@@ -23,6 +23,8 @@ export interface GroupMetadata {
|
|
|
23
23
|
announce?: boolean;
|
|
24
24
|
/** is set when the group also allows members to add participants */
|
|
25
25
|
memberAddMode?: boolean;
|
|
26
|
+
/** Request approval to join the group */
|
|
27
|
+
joinApprovalMode?: boolean;
|
|
26
28
|
/** is this a community */
|
|
27
29
|
isCommunity?: boolean;
|
|
28
30
|
/** is this the announce of a community */
|
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
|
@@ -49,6 +49,8 @@ export type SocketConfig = {
|
|
|
49
49
|
customUploadHosts: MediaConnInfo['hosts'];
|
|
50
50
|
/** time to wait between sending new retry requests */
|
|
51
51
|
retryRequestDelayMs: number;
|
|
52
|
+
/** max retry count */
|
|
53
|
+
maxMsgRetryCount: number;
|
|
52
54
|
/** time to wait for the generation of the next QR in ms */
|
|
53
55
|
qrTimeout?: number;
|
|
54
56
|
/** provide an auth state object to maintain the auth state */
|
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;
|