@d0v3riz/baileys 6.7.18 → 6.7.20

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 (114) hide show
  1. package/README.md +1263 -4
  2. package/WAProto/GenerateStatics.sh +2 -0
  3. package/WAProto/WAProto.proto +4633 -0
  4. package/WAProto/index.d.ts +3212 -122
  5. package/WAProto/index.js +9635 -299
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +1 -1
  8. package/lib/Defaults/index.js +16 -16
  9. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  10. package/lib/Signal/Group/ciphertext-message.js +15 -0
  11. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  14. package/lib/Signal/Group/group_cipher.js +96 -0
  15. package/lib/Signal/Group/index.d.ts +11 -0
  16. package/lib/Signal/Group/index.js +57 -0
  17. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  18. package/lib/Signal/Group/keyhelper.js +55 -0
  19. package/lib/Signal/Group/queue-job.d.ts +1 -0
  20. package/lib/Signal/Group/queue-job.js +57 -0
  21. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  22. package/lib/Signal/Group/sender-chain-key.js +34 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  24. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  25. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  26. package/lib/Signal/Group/sender-key-message.js +69 -0
  27. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-name.js +51 -0
  29. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  30. package/lib/Signal/Group/sender-key-record.js +53 -0
  31. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  32. package/lib/Signal/Group/sender-key-state.js +99 -0
  33. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  34. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
  35. package/lib/Signal/libsignal.js +33 -20
  36. package/lib/Socket/Client/websocket.js +1 -1
  37. package/lib/Socket/business.d.ts +5 -5
  38. package/lib/Socket/business.js +5 -5
  39. package/lib/Socket/chats.d.ts +4 -4
  40. package/lib/Socket/chats.js +70 -70
  41. package/lib/Socket/groups.d.ts +6 -6
  42. package/lib/Socket/groups.js +39 -24
  43. package/lib/Socket/index.d.ts +5 -5
  44. package/lib/Socket/index.js +2 -2
  45. package/lib/Socket/messages-recv.d.ts +5 -5
  46. package/lib/Socket/messages-recv.js +73 -56
  47. package/lib/Socket/messages-send.d.ts +5 -5
  48. package/lib/Socket/messages-send.js +53 -46
  49. package/lib/Socket/socket.d.ts +3 -3
  50. package/lib/Socket/socket.js +22 -29
  51. package/lib/Socket/usync.d.ts +3 -3
  52. package/lib/Socket/usync.js +10 -15
  53. package/lib/Types/Auth.d.ts +1 -1
  54. package/lib/Types/Chat.d.ts +1 -1
  55. package/lib/Types/Chat.js +7 -1
  56. package/lib/Types/Contact.d.ts +4 -0
  57. package/lib/Types/Events.d.ts +1 -1
  58. package/lib/Types/GroupMetadata.d.ts +7 -3
  59. package/lib/Types/Message.d.ts +7 -2
  60. package/lib/Types/Socket.d.ts +3 -3
  61. package/lib/Utils/auth-utils.js +8 -9
  62. package/lib/Utils/baileys-event-stream.js +1 -1
  63. package/lib/Utils/business.js +17 -11
  64. package/lib/Utils/chat-utils.d.ts +4 -4
  65. package/lib/Utils/chat-utils.js +64 -69
  66. package/lib/Utils/crypto.js +4 -10
  67. package/lib/Utils/decode-wa-message.js +6 -2
  68. package/lib/Utils/event-buffer.d.ts +2 -2
  69. package/lib/Utils/event-buffer.js +9 -13
  70. package/lib/Utils/generics.d.ts +1 -1
  71. package/lib/Utils/generics.js +28 -30
  72. package/lib/Utils/history.js +10 -5
  73. package/lib/Utils/link-preview.js +5 -9
  74. package/lib/Utils/lt-hash.js +2 -2
  75. package/lib/Utils/make-mutex.js +1 -1
  76. package/lib/Utils/messages-media.d.ts +2 -3
  77. package/lib/Utils/messages-media.js +80 -95
  78. package/lib/Utils/messages.d.ts +1 -1
  79. package/lib/Utils/messages.js +83 -75
  80. package/lib/Utils/process-message.d.ts +1 -1
  81. package/lib/Utils/process-message.js +25 -30
  82. package/lib/Utils/signal.js +9 -7
  83. package/lib/Utils/use-multi-file-auth-state.js +2 -3
  84. package/lib/Utils/validate-connection.js +17 -22
  85. package/lib/WABinary/constants.d.ts +4 -4
  86. package/lib/WABinary/constants.js +1271 -8
  87. package/lib/WABinary/decode.js +2 -1
  88. package/lib/WABinary/encode.js +2 -2
  89. package/lib/WABinary/generic-utils.js +1 -1
  90. package/lib/WABinary/jid-utils.js +8 -11
  91. package/lib/WAM/constants.js +2252 -2359
  92. package/lib/WAM/encode.js +5 -7
  93. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  95. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  96. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  97. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  98. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  99. package/lib/WAUSync/USyncQuery.js +17 -13
  100. package/package.json +11 -6
  101. package/WASignalGroup/GroupProtocol.js +0 -1697
  102. package/WASignalGroup/ciphertext_message.js +0 -16
  103. package/WASignalGroup/group_cipher.js +0 -120
  104. package/WASignalGroup/group_session_builder.js +0 -46
  105. package/WASignalGroup/index.js +0 -5
  106. package/WASignalGroup/keyhelper.js +0 -21
  107. package/WASignalGroup/protobufs.js +0 -3
  108. package/WASignalGroup/queue_job.js +0 -69
  109. package/WASignalGroup/sender_chain_key.js +0 -50
  110. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  111. package/WASignalGroup/sender_key_message.js +0 -92
  112. package/WASignalGroup/sender_key_name.js +0 -70
  113. package/WASignalGroup/sender_key_record.js +0 -56
  114. package/WASignalGroup/sender_key_state.js +0 -129
@@ -9,15 +9,15 @@ const chats_1 = require("./chats");
9
9
  const makeGroupsSocket = (config) => {
10
10
  const sock = (0, chats_1.makeChatsSocket)(config);
11
11
  const { authState, ev, query, upsertMessage } = sock;
12
- const groupQuery = async (jid, type, content) => (query({
12
+ const groupQuery = async (jid, type, content) => query({
13
13
  tag: 'iq',
14
14
  attrs: {
15
15
  type,
16
16
  xmlns: 'w:g2',
17
- to: jid,
17
+ to: jid
18
18
  },
19
19
  content
20
- }));
20
+ });
21
21
  const groupMetadata = async (jid) => {
22
22
  const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
23
  return (0, exports.extractGroupMetadata)(result);
@@ -28,7 +28,7 @@ const makeGroupsSocket = (config) => {
28
28
  attrs: {
29
29
  to: '@g.us',
30
30
  xmlns: 'w:g2',
31
- type: 'get',
31
+ type: 'get'
32
32
  },
33
33
  content: [
34
34
  {
@@ -90,9 +90,7 @@ const makeGroupsSocket = (config) => {
90
90
  {
91
91
  tag: 'leave',
92
92
  attrs: {},
93
- content: [
94
- { tag: 'group', attrs: { id } }
95
- ]
93
+ content: [{ tag: 'group', attrs: { id } }]
96
94
  }
97
95
  ]);
98
96
  },
@@ -117,7 +115,8 @@ const makeGroupsSocket = (config) => {
117
115
  return participants.map(v => v.attrs);
118
116
  },
119
117
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
120
- const result = await groupQuery(jid, 'set', [{
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
121
120
  tag: 'membership_requests_action',
122
121
  attrs: {},
123
122
  content: [
@@ -130,7 +129,8 @@ const makeGroupsSocket = (config) => {
130
129
  }))
131
130
  }
132
131
  ]
133
- }]);
132
+ }
133
+ ]);
134
134
  const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
135
135
  const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
136
136
  const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
@@ -166,9 +166,7 @@ const makeGroupsSocket = (config) => {
166
166
  ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
167
167
  ...(prev ? { prev } : {})
168
168
  },
169
- content: description ? [
170
- { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
171
- ] : undefined
169
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
172
170
  }
173
171
  ]);
174
172
  },
@@ -194,7 +192,9 @@ const makeGroupsSocket = (config) => {
194
192
  * @returns true if successful
195
193
  */
196
194
  groupRevokeInviteV4: async (groupJid, invitedJid) => {
197
- const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
195
+ const result = await groupQuery(groupJid, 'set', [
196
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
197
+ ]);
198
198
  return !!result;
199
199
  },
200
200
  /**
@@ -205,14 +205,16 @@ const makeGroupsSocket = (config) => {
205
205
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
206
206
  var _a;
207
207
  key = typeof key === 'string' ? { remoteJid: key } : key;
208
- const results = await groupQuery(inviteMessage.groupJid, 'set', [{
208
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
209
+ {
209
210
  tag: 'accept',
210
211
  attrs: {
211
212
  code: inviteMessage.inviteCode,
212
213
  expiration: inviteMessage.inviteExpiration.toString(),
213
214
  admin: key.remoteJid
214
215
  }
215
- }]);
216
+ }
217
+ ]);
216
218
  // if we have the full message key
217
219
  // update the invite message to be expired
218
220
  if (key.id) {
@@ -237,12 +239,10 @@ const makeGroupsSocket = (config) => {
237
239
  remoteJid: inviteMessage.groupJid,
238
240
  id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
239
241
  fromMe: false,
240
- participant: key.remoteJid,
242
+ participant: key.remoteJid
241
243
  },
242
244
  messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
243
- messageStubParameters: [
244
- authState.creds.me.id
245
- ],
245
+ messageStubParameters: [authState.creds.me.id],
246
246
  participant: key.remoteJid,
247
247
  messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
248
248
  }, 'notify');
@@ -253,9 +253,9 @@ const makeGroupsSocket = (config) => {
253
253
  return (0, exports.extractGroupMetadata)(results);
254
254
  },
255
255
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
256
- const content = ephemeralExpiration ?
257
- { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
258
- { tag: 'not_ephemeral', attrs: {} };
256
+ const content = ephemeralExpiration
257
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
258
+ : { tag: 'not_ephemeral', attrs: {} };
259
259
  await groupQuery(jid, 'set', [content]);
260
260
  },
261
261
  groupSettingUpdate: async (jid, setting) => {
@@ -265,7 +265,9 @@ const makeGroupsSocket = (config) => {
265
265
  await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
266
266
  },
267
267
  groupJoinApprovalMode: async (jid, mode) => {
268
- await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
268
+ await groupQuery(jid, 'set', [
269
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
270
+ ]);
269
271
  },
270
272
  groupFetchAllParticipating
271
273
  };
@@ -277,8 +279,14 @@ const extractGroupMetadata = (result) => {
277
279
  const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
278
280
  let desc;
279
281
  let descId;
282
+ let descOwner;
283
+ let descOwnerJid;
284
+ let descTime;
280
285
  if (descChild) {
281
286
  desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
287
+ descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined;
288
+ descOwnerJid = descChild.attrs.participant_pn ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
289
+ descTime = +descChild.attrs.t;
282
290
  descId = descChild.attrs.id;
283
291
  }
284
292
  const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
@@ -289,12 +297,17 @@ const extractGroupMetadata = (result) => {
289
297
  addressingMode: group.attrs.addressing_mode,
290
298
  subject: group.attrs.subject,
291
299
  subjectOwner: group.attrs.s_o,
300
+ subjectOwnerJid: group.attrs.s_o_pn,
292
301
  subjectTime: +group.attrs.s_t,
293
302
  size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
294
303
  creation: +group.attrs.creation,
295
304
  owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
305
+ ownerJid: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
296
306
  desc,
297
307
  descId,
308
+ descOwner,
309
+ descOwnerJid,
310
+ descTime,
298
311
  linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
299
312
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
300
313
  announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
@@ -305,7 +318,9 @@ const extractGroupMetadata = (result) => {
305
318
  participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
306
319
  return {
307
320
  id: attrs.jid,
308
- admin: (attrs.type || null),
321
+ jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
322
+ lid: (0, WABinary_1.isLidUser)(attrs.jid) ? attrs.jid : attrs.lid,
323
+ admin: (attrs.type || null)
309
324
  };
310
325
  }),
311
326
  ephemeralDuration: eph ? +eph : undefined
@@ -59,7 +59,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
59
59
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
60
60
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
61
61
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
62
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
62
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
63
63
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
64
64
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
65
65
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -100,7 +100,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
100
100
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
101
101
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
102
102
  getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
103
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
103
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
104
104
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
105
105
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
106
106
  addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
@@ -116,9 +116,9 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
116
116
  type: "md";
117
117
  ws: import("./Client").WebSocketClient;
118
118
  ev: import("../Types").BaileysEventEmitter & {
119
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
119
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
120
120
  buffer(): void;
121
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
121
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
122
122
  flush(force?: boolean): boolean;
123
123
  isBuffering(): boolean;
124
124
  };
@@ -139,7 +139,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
139
139
  onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
140
140
  uploadPreKeys: (count?: number) => Promise<void>;
141
141
  uploadPreKeysToServerIfRequired: () => Promise<void>;
142
- requestPairingCode: (phoneNumber: string) => Promise<string>;
142
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
143
143
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
144
144
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
145
145
  };
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
4
  const business_1 = require("./business");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
6
+ const makeWASocket = (config) => (0, business_1.makeBusinessSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
- }));
9
+ });
10
10
  exports.default = makeWASocket;
@@ -49,7 +49,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
49
49
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
50
50
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
51
51
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
52
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
52
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
53
53
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
54
54
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
55
55
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -90,7 +90,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
90
90
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
91
91
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
92
92
  getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
93
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
93
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
94
94
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
95
95
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
96
96
  addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
@@ -106,9 +106,9 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
106
106
  type: "md";
107
107
  ws: import("./Client").WebSocketClient;
108
108
  ev: import("../Types").BaileysEventEmitter & {
109
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
109
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
110
110
  buffer(): void;
111
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
111
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
112
112
  flush(force?: boolean): boolean;
113
113
  isBuffering(): boolean;
114
114
  };
@@ -129,7 +129,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
129
129
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
130
130
  uploadPreKeys: (count?: number) => Promise<void>;
131
131
  uploadPreKeysToServerIfRequired: () => Promise<void>;
132
- requestPairingCode: (phoneNumber: string) => Promise<string>;
132
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
133
133
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
134
134
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
135
135
  };
@@ -18,21 +18,24 @@ const messages_send_1 = require("./messages-send");
18
18
  const makeMessagesRecvSocket = (config) => {
19
19
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
20
20
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
21
- const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, } = sock;
21
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage } = sock;
22
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
23
23
  const retryMutex = (0, make_mutex_1.makeMutex)();
24
- const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
25
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
26
- useClones: false
27
- });
28
- const callOfferCache = config.callOfferCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
30
- useClones: false
31
- });
32
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
33
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
34
- useClones: false
35
- });
24
+ const msgRetryCache = config.msgRetryCounterCache ||
25
+ new node_cache_1.default({
26
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
+ useClones: false
28
+ });
29
+ const callOfferCache = config.callOfferCache ||
30
+ new node_cache_1.default({
31
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
32
+ useClones: false
33
+ });
34
+ const placeholderResendCache = config.placeholderResendCache ||
35
+ new node_cache_1.default({
36
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
37
+ useClones: false
38
+ });
36
39
  let sendActiveReceipts = false;
37
40
  const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
38
41
  const stanza = {
@@ -52,7 +55,8 @@ const makeMessagesRecvSocket = (config) => {
52
55
  if (!!attrs.recipient) {
53
56
  stanza.attrs.recipient = attrs.recipient;
54
57
  }
55
- if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
58
+ if (!!attrs.type &&
59
+ (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
56
60
  stanza.attrs.type = attrs.type;
57
61
  }
58
62
  if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
@@ -62,22 +66,24 @@ const makeMessagesRecvSocket = (config) => {
62
66
  await sendNode(stanza);
63
67
  };
64
68
  const rejectCall = async (callId, callFrom) => {
65
- const stanza = ({
69
+ const stanza = {
66
70
  tag: 'call',
67
71
  attrs: {
68
72
  from: authState.creds.me.id,
69
- to: callFrom,
73
+ to: callFrom
70
74
  },
71
- content: [{
75
+ content: [
76
+ {
72
77
  tag: 'reject',
73
78
  attrs: {
74
79
  'call-id': callId,
75
80
  'call-creator': callFrom,
76
- count: '0',
81
+ count: '0'
77
82
  },
78
- content: undefined,
79
- }],
80
- });
83
+ content: undefined
84
+ }
85
+ ]
86
+ };
81
87
  await query(stanza);
82
88
  };
83
89
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
@@ -185,15 +191,19 @@ const makeMessagesRecvSocket = (config) => {
185
191
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
186
192
  msg.messageStubParameters = [metadata.subject];
187
193
  msg.key = { participant: metadata.owner };
188
- ev.emit('chats.upsert', [{
194
+ ev.emit('chats.upsert', [
195
+ {
189
196
  id: metadata.id,
190
197
  name: metadata.subject,
191
- conversationTimestamp: metadata.creation,
192
- }]);
193
- ev.emit('groups.upsert', [{
198
+ conversationTimestamp: metadata.creation
199
+ }
200
+ ]);
201
+ ev.emit('groups.upsert', [
202
+ {
194
203
  ...metadata,
195
204
  author: participant
196
- }]);
205
+ }
206
+ ]);
197
207
  break;
198
208
  case 'ephemeral':
199
209
  case 'not_ephemeral':
@@ -238,12 +248,12 @@ const makeMessagesRecvSocket = (config) => {
238
248
  case 'announcement':
239
249
  case 'not_announcement':
240
250
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
241
- msg.messageStubParameters = [(child.tag === 'announcement') ? 'on' : 'off'];
251
+ msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
242
252
  break;
243
253
  case 'locked':
244
254
  case 'unlocked':
245
255
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
246
- msg.messageStubParameters = [(child.tag === 'locked') ? 'on' : 'off'];
256
+ msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
247
257
  break;
248
258
  case 'invite':
249
259
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
@@ -321,10 +331,12 @@ const makeMessagesRecvSocket = (config) => {
321
331
  case 'picture':
322
332
  const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
323
333
  const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
324
- ev.emit('contacts.update', [{
334
+ ev.emit('contacts.update', [
335
+ {
325
336
  id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
326
337
  imgUrl: setPicture ? 'changed' : 'removed'
327
- }]);
338
+ }
339
+ ]);
328
340
  if ((0, WABinary_1.isJidGroup)(from)) {
329
341
  const node = setPicture || delPicture;
330
342
  result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
@@ -333,7 +345,7 @@ const makeMessagesRecvSocket = (config) => {
333
345
  }
334
346
  result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
335
347
  result.key = {
336
- ...result.key || {},
348
+ ...(result.key || {}),
337
349
  participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
338
350
  };
339
351
  }
@@ -348,8 +360,8 @@ const makeMessagesRecvSocket = (config) => {
348
360
  ...authState.creds.accountSettings,
349
361
  defaultDisappearingMode: {
350
362
  ephemeralExpiration: newDuration,
351
- ephemeralSettingTimestamp: timestamp,
352
- },
363
+ ephemeralSettingTimestamp: timestamp
364
+ }
353
365
  }
354
366
  });
355
367
  }
@@ -357,7 +369,7 @@ const makeMessagesRecvSocket = (config) => {
357
369
  const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
358
370
  for (const { attrs } of blocklists) {
359
371
  const blocklist = [attrs.jid];
360
- const type = (attrs.action === 'block') ? 'add' : 'remove';
372
+ const type = attrs.action === 'block' ? 'add' : 'remove';
361
373
  ev.emit('blocklist.update', { blocklist, type });
362
374
  }
363
375
  }
@@ -375,7 +387,11 @@ const makeMessagesRecvSocket = (config) => {
375
387
  salt: linkCodeSalt,
376
388
  info: 'link_code_pairing_key_bundle_encryption_key'
377
389
  });
378
- const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
390
+ const encryptPayload = Buffer.concat([
391
+ Buffer.from(authState.creds.signedIdentityKey.public),
392
+ primaryIdentityPublicKey,
393
+ random
394
+ ]);
379
395
  const encryptIv = (0, crypto_1.randomBytes)(12);
380
396
  const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
381
397
  const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
@@ -395,7 +411,7 @@ const makeMessagesRecvSocket = (config) => {
395
411
  tag: 'link_code_companion_reg',
396
412
  attrs: {
397
413
  jid: authState.creds.me.id,
398
- stage: 'companion_finish',
414
+ stage: 'companion_finish'
399
415
  },
400
416
  content: [
401
417
  {
@@ -489,7 +505,7 @@ const makeMessagesRecvSocket = (config) => {
489
505
  const isLid = attrs.from.includes('lid');
490
506
  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);
491
507
  const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
492
- const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
508
+ const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
493
509
  const key = {
494
510
  remoteJid,
495
511
  id: '',
@@ -511,11 +527,9 @@ const makeMessagesRecvSocket = (config) => {
511
527
  processingMutex.mutex(async () => {
512
528
  const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
513
529
  if (typeof status !== 'undefined' &&
514
- (
515
530
  // basically, we only want to know when a message from us has been delivered to/read by the other person
516
531
  // or another device of ours has read some messages
517
- status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK ||
518
- !isNodeFromMe)) {
532
+ (status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
519
533
  if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
520
534
  if (attrs.participant) {
521
535
  const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
@@ -630,7 +644,8 @@ const makeMessagesRecvSocket = (config) => {
630
644
  if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
631
645
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
632
646
  }
633
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
647
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
648
+ node.attrs.sender_pn) {
634
649
  ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
635
650
  }
636
651
  try {
@@ -663,10 +678,12 @@ const makeMessagesRecvSocket = (config) => {
663
678
  // no type in the receipt => message delivered
664
679
  let type = undefined;
665
680
  let participant = msg.key.participant;
666
- if (category === 'peer') { // special peer message
681
+ if (category === 'peer') {
682
+ // special peer message
667
683
  type = 'peer_msg';
668
684
  }
669
- else if (msg.key.fromMe) { // message was sent by us from a different device
685
+ else if (msg.key.fromMe) {
686
+ // message was sent by us from a different device
670
687
  type = 'sender';
671
688
  // need to specially handle this case
672
689
  if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
@@ -729,9 +746,11 @@ const makeMessagesRecvSocket = (config) => {
729
746
  return 'RESOLVED';
730
747
  }
731
748
  const pdoMessage = {
732
- placeholderMessageResendRequest: [{
749
+ placeholderMessageResendRequest: [
750
+ {
733
751
  messageKey
734
- }],
752
+ }
753
+ ],
735
754
  peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
736
755
  };
737
756
  setTimeout(() => {
@@ -754,7 +773,7 @@ const makeMessagesRecvSocket = (config) => {
754
773
  id: callId,
755
774
  date: new Date(+attrs.t * 1000),
756
775
  offline: !!attrs.offline,
757
- status,
776
+ status
758
777
  };
759
778
  if (status === 'offer') {
760
779
  call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
@@ -799,9 +818,7 @@ const makeMessagesRecvSocket = (config) => {
799
818
  key,
800
819
  update: {
801
820
  status: Types_1.WAMessageStatus.ERROR,
802
- messageStubParameters: [
803
- attrs.error
804
- ]
821
+ messageStubParameters: [attrs.error]
805
822
  }
806
823
  }
807
824
  ]);
@@ -814,8 +831,7 @@ const makeMessagesRecvSocket = (config) => {
814
831
  await execTask();
815
832
  ev.flush();
816
833
  function execTask() {
817
- return exec(node, false)
818
- .catch(err => onUnexpectedError(err, identifier));
834
+ return exec(node, false).catch(err => onUnexpectedError(err, identifier));
819
835
  }
820
836
  };
821
837
  const makeOfflineNodeProcessor = () => {
@@ -873,8 +889,7 @@ const makeMessagesRecvSocket = (config) => {
873
889
  processNode('notification', node, 'handling notification', handleNotification);
874
890
  });
875
891
  ws.on('CB:ack,class:message', (node) => {
876
- handleBadAck(node)
877
- .catch(error => onUnexpectedError(error, 'handling bad ack'));
892
+ handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
878
893
  });
879
894
  ev.on('call', ([call]) => {
880
895
  // missed call + group call notification message generation
@@ -885,11 +900,13 @@ const makeMessagesRecvSocket = (config) => {
885
900
  id: call.id,
886
901
  fromMe: false
887
902
  },
888
- messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date),
903
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date)
889
904
  };
890
905
  if (call.status === 'timeout') {
891
906
  if (call.isGroup) {
892
- msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
907
+ msg.messageStubType = call.isVideo
908
+ ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO
909
+ : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
893
910
  }
894
911
  else {
895
912
  msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
@@ -914,7 +931,7 @@ const makeMessagesRecvSocket = (config) => {
914
931
  sendRetryRequest,
915
932
  rejectCall,
916
933
  fetchMessageHistory,
917
- requestPlaceholderResend,
934
+ requestPlaceholderResend
918
935
  };
919
936
  };
920
937
  exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
@@ -44,7 +44,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
44
44
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
45
45
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
46
46
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
47
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
47
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
48
48
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
49
49
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
50
50
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -85,7 +85,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
85
85
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
86
86
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
87
87
  getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
88
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
88
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
89
89
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
90
90
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
91
91
  addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
@@ -101,9 +101,9 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
101
101
  type: "md";
102
102
  ws: import("./Client").WebSocketClient;
103
103
  ev: import("../Types").BaileysEventEmitter & {
104
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
104
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
105
105
  buffer(): void;
106
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
106
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
107
107
  flush(force?: boolean): boolean;
108
108
  isBuffering(): boolean;
109
109
  };
@@ -124,7 +124,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
124
124
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
125
125
  uploadPreKeys: (count?: number) => Promise<void>;
126
126
  uploadPreKeysToServerIfRequired: () => Promise<void>;
127
- requestPairingCode: (phoneNumber: string) => Promise<string>;
127
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
128
128
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
129
129
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
130
130
  };