@periskope/baileys 6.7.18-alpha.1 → 6.7.18-alpha.3

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 (67) hide show
  1. package/lib/Defaults/index.d.ts +1 -1
  2. package/lib/Defaults/index.js +16 -16
  3. package/lib/Signal/libsignal.js +5 -5
  4. package/lib/Socket/Client/websocket.js +1 -1
  5. package/lib/Socket/business.d.ts +4 -4
  6. package/lib/Socket/business.js +5 -5
  7. package/lib/Socket/chats.d.ts +3 -3
  8. package/lib/Socket/chats.js +65 -67
  9. package/lib/Socket/groups.d.ts +5 -5
  10. package/lib/Socket/groups.js +38 -23
  11. package/lib/Socket/index.d.ts +4 -4
  12. package/lib/Socket/index.js +2 -2
  13. package/lib/Socket/messages-recv.d.ts +4 -4
  14. package/lib/Socket/messages-recv.js +73 -57
  15. package/lib/Socket/messages-send.d.ts +4 -4
  16. package/lib/Socket/messages-send.js +53 -46
  17. package/lib/Socket/socket.d.ts +2 -2
  18. package/lib/Socket/socket.js +16 -27
  19. package/lib/Socket/usync.d.ts +2 -2
  20. package/lib/Socket/usync.js +10 -15
  21. package/lib/Types/Auth.d.ts +1 -1
  22. package/lib/Types/Chat.d.ts +1 -1
  23. package/lib/Types/Chat.js +7 -1
  24. package/lib/Types/Contact.d.ts +4 -0
  25. package/lib/Types/Events.d.ts +1 -1
  26. package/lib/Types/GroupMetadata.d.ts +8 -3
  27. package/lib/Types/Message.d.ts +5 -1
  28. package/lib/Types/Socket.d.ts +3 -3
  29. package/lib/Utils/auth-utils.js +8 -9
  30. package/lib/Utils/baileys-event-stream.js +1 -1
  31. package/lib/Utils/business.js +9 -11
  32. package/lib/Utils/chat-utils.d.ts +4 -4
  33. package/lib/Utils/chat-utils.js +64 -69
  34. package/lib/Utils/crypto.js +4 -10
  35. package/lib/Utils/decode-wa-message.js +5 -2
  36. package/lib/Utils/event-buffer.d.ts +2 -2
  37. package/lib/Utils/event-buffer.js +9 -13
  38. package/lib/Utils/generics.d.ts +1 -1
  39. package/lib/Utils/generics.js +28 -30
  40. package/lib/Utils/history.js +10 -5
  41. package/lib/Utils/link-preview.js +9 -10
  42. package/lib/Utils/lt-hash.js +2 -2
  43. package/lib/Utils/make-mutex.js +1 -1
  44. package/lib/Utils/messages-media.js +34 -46
  45. package/lib/Utils/messages.d.ts +1 -1
  46. package/lib/Utils/messages.js +71 -61
  47. package/lib/Utils/process-message.d.ts +1 -1
  48. package/lib/Utils/process-message.js +28 -33
  49. package/lib/Utils/signal.js +9 -7
  50. package/lib/Utils/use-multi-file-auth-state.js +2 -3
  51. package/lib/Utils/validate-connection.js +17 -22
  52. package/lib/WABinary/constants.d.ts +4 -4
  53. package/lib/WABinary/constants.js +1271 -8
  54. package/lib/WABinary/decode.js +2 -1
  55. package/lib/WABinary/encode.js +2 -2
  56. package/lib/WABinary/generic-utils.js +1 -1
  57. package/lib/WABinary/jid-utils.js +8 -11
  58. package/lib/WAM/constants.js +2252 -2359
  59. package/lib/WAM/encode.js +5 -7
  60. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  61. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  62. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  63. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  64. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  65. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  66. package/lib/WAUSync/USyncQuery.js +17 -13
  67. package/package.json +11 -5
@@ -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'),
@@ -306,6 +319,8 @@ const extractGroupMetadata = (result) => {
306
319
  return {
307
320
  ...attrs,
308
321
  id: attrs.jid,
322
+ jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
323
+ lid: (0, WABinary_1.isLidUser)(attrs.jid) ? attrs.jid : attrs.lid,
309
324
  admin: (attrs.type || null)
310
325
  };
311
326
  }),
@@ -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
  };
@@ -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
  };
@@ -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
  var _a, _b, _c, _d, _e;
@@ -53,7 +56,8 @@ const makeMessagesRecvSocket = (config) => {
53
56
  if (!!attrs.recipient) {
54
57
  stanza.attrs.recipient = attrs.recipient;
55
58
  }
56
- if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
59
+ if (!!attrs.type &&
60
+ (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
57
61
  stanza.attrs.type = attrs.type;
58
62
  }
59
63
  if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
@@ -85,22 +89,24 @@ const makeMessagesRecvSocket = (config) => {
85
89
  await sendNode(stanza);
86
90
  };
87
91
  const rejectCall = async (callId, callFrom) => {
88
- const stanza = ({
92
+ const stanza = {
89
93
  tag: 'call',
90
94
  attrs: {
91
95
  from: authState.creds.me.id,
92
- to: callFrom,
96
+ to: callFrom
93
97
  },
94
- content: [{
98
+ content: [
99
+ {
95
100
  tag: 'reject',
96
101
  attrs: {
97
102
  'call-id': callId,
98
103
  'call-creator': callFrom,
99
- count: '0',
104
+ count: '0'
100
105
  },
101
- content: undefined,
102
- }],
103
- });
106
+ content: undefined
107
+ }
108
+ ]
109
+ };
104
110
  await query(stanza);
105
111
  };
106
112
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
@@ -208,15 +214,19 @@ const makeMessagesRecvSocket = (config) => {
208
214
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
209
215
  msg.messageStubParameters = [metadata.subject];
210
216
  msg.key = { participant: metadata.owner };
211
- ev.emit('chats.upsert', [{
217
+ ev.emit('chats.upsert', [
218
+ {
212
219
  id: metadata.id,
213
220
  name: metadata.subject,
214
- conversationTimestamp: metadata.creation,
215
- }]);
216
- ev.emit('groups.upsert', [{
221
+ conversationTimestamp: metadata.creation
222
+ }
223
+ ]);
224
+ ev.emit('groups.upsert', [
225
+ {
217
226
  ...metadata,
218
227
  author: participant
219
- }]);
228
+ }
229
+ ]);
220
230
  break;
221
231
  case 'ephemeral':
222
232
  case 'not_ephemeral':
@@ -261,12 +271,12 @@ const makeMessagesRecvSocket = (config) => {
261
271
  case 'announcement':
262
272
  case 'not_announcement':
263
273
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
264
- msg.messageStubParameters = [(child.tag === 'announcement') ? 'on' : 'off'];
274
+ msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
265
275
  break;
266
276
  case 'locked':
267
277
  case 'unlocked':
268
278
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
269
- msg.messageStubParameters = [(child.tag === 'locked') ? 'on' : 'off'];
279
+ msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
270
280
  break;
271
281
  case 'invite':
272
282
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
@@ -344,10 +354,12 @@ const makeMessagesRecvSocket = (config) => {
344
354
  case 'picture':
345
355
  const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
346
356
  const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
347
- ev.emit('contacts.update', [{
357
+ ev.emit('contacts.update', [
358
+ {
348
359
  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) || '',
349
360
  imgUrl: setPicture ? 'changed' : 'removed'
350
- }]);
361
+ }
362
+ ]);
351
363
  if ((0, WABinary_1.isJidGroup)(from)) {
352
364
  const node = setPicture || delPicture;
353
365
  result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
@@ -356,7 +368,7 @@ const makeMessagesRecvSocket = (config) => {
356
368
  }
357
369
  result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
358
370
  result.key = {
359
- ...result.key || {},
371
+ ...(result.key || {}),
360
372
  participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
361
373
  };
362
374
  }
@@ -371,8 +383,8 @@ const makeMessagesRecvSocket = (config) => {
371
383
  ...authState.creds.accountSettings,
372
384
  defaultDisappearingMode: {
373
385
  ephemeralExpiration: newDuration,
374
- ephemeralSettingTimestamp: timestamp,
375
- },
386
+ ephemeralSettingTimestamp: timestamp
387
+ }
376
388
  }
377
389
  });
378
390
  }
@@ -380,7 +392,7 @@ const makeMessagesRecvSocket = (config) => {
380
392
  const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
381
393
  for (const { attrs } of blocklists) {
382
394
  const blocklist = [attrs.jid];
383
- const type = (attrs.action === 'block') ? 'add' : 'remove';
395
+ const type = attrs.action === 'block' ? 'add' : 'remove';
384
396
  ev.emit('blocklist.update', { blocklist, type });
385
397
  }
386
398
  }
@@ -398,7 +410,11 @@ const makeMessagesRecvSocket = (config) => {
398
410
  salt: linkCodeSalt,
399
411
  info: 'link_code_pairing_key_bundle_encryption_key'
400
412
  });
401
- const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
413
+ const encryptPayload = Buffer.concat([
414
+ Buffer.from(authState.creds.signedIdentityKey.public),
415
+ primaryIdentityPublicKey,
416
+ random
417
+ ]);
402
418
  const encryptIv = (0, crypto_1.randomBytes)(12);
403
419
  const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
404
420
  const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
@@ -418,7 +434,7 @@ const makeMessagesRecvSocket = (config) => {
418
434
  tag: 'link_code_companion_reg',
419
435
  attrs: {
420
436
  jid: authState.creds.me.id,
421
- stage: 'companion_finish',
437
+ stage: 'companion_finish'
422
438
  },
423
439
  content: [
424
440
  {
@@ -512,8 +528,7 @@ const makeMessagesRecvSocket = (config) => {
512
528
  const isLid = attrs.from.includes('lid');
513
529
  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);
514
530
  const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
515
- const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender')
516
- && isNodeFromMe);
531
+ const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
517
532
  const key = {
518
533
  remoteJid,
519
534
  id: '',
@@ -535,11 +550,9 @@ const makeMessagesRecvSocket = (config) => {
535
550
  processingMutex.mutex(async () => {
536
551
  const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
537
552
  if (typeof status !== 'undefined' &&
538
- (
539
553
  // basically, we only want to know when a message from us has been delivered to/read by the other person
540
554
  // or another device of ours has read some messages
541
- status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK ||
542
- !isNodeFromMe)) {
555
+ (status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
543
556
  if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
544
557
  if (attrs.participant) {
545
558
  const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
@@ -659,7 +672,8 @@ const makeMessagesRecvSocket = (config) => {
659
672
  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) {
660
673
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
661
674
  }
662
- 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) {
675
+ 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 &&
676
+ node.attrs.sender_pn) {
663
677
  ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
664
678
  }
665
679
  try {
@@ -692,10 +706,12 @@ const makeMessagesRecvSocket = (config) => {
692
706
  // no type in the receipt => message delivered
693
707
  let type = undefined;
694
708
  let participant = msg.key.participant;
695
- if (category === 'peer') { // special peer message
709
+ if (category === 'peer') {
710
+ // special peer message
696
711
  type = 'peer_msg';
697
712
  }
698
- else if (msg.key.fromMe) { // message was sent by us from a different device
713
+ else if (msg.key.fromMe) {
714
+ // message was sent by us from a different device
699
715
  type = 'sender';
700
716
  // need to specially handle this case
701
717
  if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
@@ -758,9 +774,11 @@ const makeMessagesRecvSocket = (config) => {
758
774
  return 'RESOLVED';
759
775
  }
760
776
  const pdoMessage = {
761
- placeholderMessageResendRequest: [{
777
+ placeholderMessageResendRequest: [
778
+ {
762
779
  messageKey
763
- }],
780
+ }
781
+ ],
764
782
  peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
765
783
  };
766
784
  setTimeout(() => {
@@ -783,7 +801,7 @@ const makeMessagesRecvSocket = (config) => {
783
801
  id: callId,
784
802
  date: new Date(+attrs.t * 1000),
785
803
  offline: !!attrs.offline,
786
- status,
804
+ status
787
805
  };
788
806
  if (status === 'offer') {
789
807
  call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
@@ -828,9 +846,7 @@ const makeMessagesRecvSocket = (config) => {
828
846
  key,
829
847
  update: {
830
848
  status: Types_1.WAMessageStatus.ERROR,
831
- messageStubParameters: [
832
- attrs.error
833
- ]
849
+ messageStubParameters: [attrs.error]
834
850
  }
835
851
  }
836
852
  ]);
@@ -843,8 +859,7 @@ const makeMessagesRecvSocket = (config) => {
843
859
  await execTask();
844
860
  ev.flush();
845
861
  function execTask() {
846
- return exec(node, false)
847
- .catch(err => onUnexpectedError(err, identifier));
862
+ return exec(node, false).catch(err => onUnexpectedError(err, identifier));
848
863
  }
849
864
  };
850
865
  const makeOfflineNodeProcessor = () => {
@@ -902,8 +917,7 @@ const makeMessagesRecvSocket = (config) => {
902
917
  processNode('notification', node, 'handling notification', handleNotification);
903
918
  });
904
919
  ws.on('CB:ack,class:message', (node) => {
905
- handleBadAck(node)
906
- .catch(error => onUnexpectedError(error, 'handling bad ack'));
920
+ handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
907
921
  });
908
922
  ev.on('call', ([call]) => {
909
923
  // missed call + group call notification message generation
@@ -914,11 +928,13 @@ const makeMessagesRecvSocket = (config) => {
914
928
  id: call.id,
915
929
  fromMe: false
916
930
  },
917
- messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date),
931
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date)
918
932
  };
919
933
  if (call.status === 'timeout') {
920
934
  if (call.isGroup) {
921
- msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
935
+ msg.messageStubType = call.isVideo
936
+ ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO
937
+ : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
922
938
  }
923
939
  else {
924
940
  msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
@@ -943,7 +959,7 @@ const makeMessagesRecvSocket = (config) => {
943
959
  sendRetryRequest,
944
960
  rejectCall,
945
961
  fetchMessageHistory,
946
- requestPlaceholderResend,
962
+ requestPlaceholderResend
947
963
  };
948
964
  };
949
965
  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
  };