@d0v3riz/baileys 6.5.0 → 6.6.1

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.
Files changed (43) hide show
  1. package/README.md +31 -93
  2. package/WAProto/WAProto.proto +473 -8
  3. package/WAProto/index.d.ts +4793 -22
  4. package/WAProto/index.js +32548 -19335
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +3 -2
  7. package/lib/Defaults/index.js +7 -2
  8. package/lib/Socket/business.d.ts +9 -0
  9. package/lib/Socket/chats.d.ts +4 -0
  10. package/lib/Socket/chats.js +13 -1
  11. package/lib/Socket/groups.d.ts +6 -0
  12. package/lib/Socket/groups.js +12 -1
  13. package/lib/Socket/index.d.ts +9 -0
  14. package/lib/Socket/messages-recv.d.ts +9 -0
  15. package/lib/Socket/messages-recv.js +37 -7
  16. package/lib/Socket/messages-send.d.ts +7 -0
  17. package/lib/Socket/messages-send.js +7 -4
  18. package/lib/Socket/registration.d.ts +9 -0
  19. package/lib/Socket/socket.js +3 -2
  20. package/lib/Store/make-cache-manager-store.d.ts +0 -1
  21. package/lib/Store/make-in-memory-store.js +11 -11
  22. package/lib/Types/Call.d.ts +1 -0
  23. package/lib/Types/Contact.d.ts +1 -0
  24. package/lib/Types/Events.d.ts +5 -0
  25. package/lib/Types/GroupMetadata.d.ts +8 -0
  26. package/lib/Types/Message.d.ts +7 -1
  27. package/lib/Types/Socket.d.ts +2 -0
  28. package/lib/Types/index.d.ts +3 -1
  29. package/lib/Types/index.js +2 -0
  30. package/lib/Utils/chat-utils.js +14 -0
  31. package/lib/Utils/decode-wa-message.d.ts +2 -2
  32. package/lib/Utils/decode-wa-message.js +18 -4
  33. package/lib/Utils/generics.d.ts +1 -0
  34. package/lib/Utils/generics.js +1 -0
  35. package/lib/Utils/messages.d.ts +1 -1
  36. package/lib/Utils/messages.js +11 -5
  37. package/lib/Utils/process-message.js +27 -4
  38. package/lib/Utils/validate-connection.js +5 -1
  39. package/lib/WABinary/decode.js +1 -1
  40. package/lib/WABinary/encode.js +3 -3
  41. package/lib/WABinary/jid-utils.d.ts +4 -2
  42. package/lib/WABinary/jid-utils.js +6 -3
  43. package/package.json +4 -4
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 2329, 9]
2
+ "version": [2, 2403, 2]
3
3
  }
@@ -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 = "WhatsApp/2.23.13.82 iOS/15.3.1 Device/Apple-iPhone_7";
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;
@@ -271,8 +271,9 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
271
271
  'md-app-state': string;
272
272
  'product-catalog-image': string;
273
273
  'payment-bg-image': string;
274
+ ptv: string;
274
275
  };
275
- export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image")[];
276
+ export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
276
277
  export declare const MIN_PREKEY_COUNT = 5;
277
278
  export declare const INITIAL_PREKEY_COUNT = 30;
278
279
  export declare const DEFAULT_CACHE_TTLS: {
@@ -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
- exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM3d3683e76445591c0591bc3c034c3bca');
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 = 'WhatsApp/2.23.13.82 iOS/15.3.1 Device/Apple-iPhone_7';
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,
@@ -103,6 +107,7 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
103
107
  'md-app-state': 'App State',
104
108
  'product-catalog-image': '',
105
109
  'payment-bg-image': 'Payment Background',
110
+ 'ptv': 'Video'
106
111
  };
107
112
  exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
108
113
  exports.MIN_PREKEY_COUNT = 5;
@@ -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 & {
@@ -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 & {
@@ -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;
@@ -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 & {
@@ -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,18 +272,23 @@ 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;
275
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
269
276
  const metadata = {
270
277
  id: groupId,
271
278
  subject: group.attrs.subject,
272
279
  subjectOwner: group.attrs.s_o,
273
280
  subjectTime: +group.attrs.s_t,
274
- size: +group.attrs.size,
281
+ size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
275
282
  creation: +group.attrs.creation,
276
283
  owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
277
284
  desc,
278
285
  descId,
279
286
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
280
287
  announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
288
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
289
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
290
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
291
+ memberAddMode,
281
292
  participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
282
293
  return {
283
294
  id: attrs.jid,
@@ -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 >= 5) {
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) => {
@@ -300,6 +314,14 @@ const makeMessagesRecvSocket = (config) => {
300
314
  }
301
315
  });
302
316
  }
317
+ else if (child.tag === 'blocklist') {
318
+ const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
319
+ for (const { attrs } of blocklists) {
320
+ const blocklist = [attrs.jid];
321
+ const type = (attrs.action === 'block') ? 'add' : 'remove';
322
+ ev.emit('blocklist.update', { blocklist, type });
323
+ }
324
+ }
303
325
  break;
304
326
  case 'link_code_companion_reg':
305
327
  const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
@@ -380,7 +402,7 @@ const makeMessagesRecvSocket = (config) => {
380
402
  const willSendMessageAgain = (id, participant) => {
381
403
  const key = `${id}:${participant}`;
382
404
  const retryCount = msgRetryCache.get(key) || 0;
383
- return retryCount < 5;
405
+ return retryCount < maxMsgRetryCount;
384
406
  };
385
407
  const updateSendMessageAgainCount = (id, participant) => {
386
408
  const key = `${id}:${participant}`;
@@ -423,9 +445,10 @@ const makeMessagesRecvSocket = (config) => {
423
445
  }
424
446
  };
425
447
  const handleReceipt = async (node) => {
426
- var _a;
448
+ var _a, _b;
427
449
  const { attrs, content } = node;
428
- const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
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);
429
452
  const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
430
453
  const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
431
454
  const key = {
@@ -528,7 +551,13 @@ const makeMessagesRecvSocket = (config) => {
528
551
  ]);
529
552
  };
530
553
  const handleMessage = async (node) => {
531
- const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, signalRepository, logger);
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
+ }
532
561
  if (shouldIgnoreJid(msg.key.remoteJid)) {
533
562
  logger.debug({ key: msg.key }, 'ignored message');
534
563
  await sendMessageAck(node);
@@ -599,7 +628,8 @@ const makeMessagesRecvSocket = (config) => {
599
628
  };
600
629
  if (status === 'offer') {
601
630
  call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
602
- call.isGroup = infoChild.attrs.type === 'group';
631
+ call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
632
+ call.groupJid = infoChild.attrs['group-jid'];
603
633
  callOfferCache.set(call.id, call);
604
634
  }
605
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;
@@ -57,6 +60,8 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
57
60
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
58
61
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
59
62
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
63
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
64
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
60
65
  groupFetchAllParticipating: () => Promise<{
61
66
  [_: string]: import("../Types").GroupMetadata;
62
67
  }>;
@@ -97,6 +102,10 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
97
102
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
98
103
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
99
104
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
105
+ star: (jid: string, messages: {
106
+ id: string;
107
+ fromMe?: boolean | undefined;
108
+ }[], star: boolean) => Promise<void>;
100
109
  type: "md";
101
110
  ws: any;
102
111
  ev: import("../Types").BaileysEventEmitter & {
@@ -403,7 +403,7 @@ const makeSocket = (config) => {
403
403
  {
404
404
  tag: 'companion_platform_display',
405
405
  attrs: {},
406
- content: config.browser[0]
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) => {
@@ -1,4 +1,3 @@
1
- import { Store } from 'cache-manager';
2
1
  import { AuthenticationCreds } from '../Types';
3
2
  declare const makeCacheManagerAuthState: (store: Store, sessionKey: string) => Promise<{
4
3
  clearState: () => Promise<void>;
@@ -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 order',
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: 'Pending payment',
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: 'Paid',
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: 'Order completed',
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 }) => {
@@ -3,6 +3,7 @@ export type WACallEvent = {
3
3
  chatId: string;
4
4
  from: string;
5
5
  isGroup?: boolean;
6
+ groupJid?: string;
6
7
  id: string;
7
8
  date: Date;
8
9
  isVideo?: boolean;
@@ -1,5 +1,6 @@
1
1
  export interface Contact {
2
2
  id: string;
3
+ lid?: string;
3
4
  /** name of the contact, you have saved on your WA */
4
5
  name?: string;
5
6
  /** name of the contact, the contact has set on their own on WA */
@@ -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,14 @@ 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
+ /** Request approval to join the group */
27
+ joinApprovalMode?: boolean;
28
+ /** is this a community */
29
+ isCommunity?: boolean;
30
+ /** is this the announce of a community */
31
+ isCommunityAnnounce?: boolean;
24
32
  /** number of group participants */
25
33
  size?: number;
26
34
  participants: GroupParticipant[];
@@ -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;
@@ -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 */