@queenanya/baileys 7.4.13 → 7.5.11

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 (88) hide show
  1. package/README.md +26 -26
  2. package/WAProto/index.js +66875 -96112
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +1 -231
  5. package/lib/Defaults/index.js +11 -23
  6. package/lib/Socket/Client/index.d.ts +2 -3
  7. package/lib/Socket/Client/index.js +2 -3
  8. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  9. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  10. package/lib/Socket/business.d.ts +29 -22
  11. package/lib/Socket/chats.d.ts +14 -3
  12. package/lib/Socket/chats.js +76 -48
  13. package/lib/Socket/groups.d.ts +21 -4
  14. package/lib/Socket/groups.js +12 -1
  15. package/lib/Socket/index.d.ts +37 -32
  16. package/lib/Socket/index.js +2 -2
  17. package/lib/Socket/messages-recv.d.ts +28 -22
  18. package/lib/Socket/messages-recv.js +291 -180
  19. package/lib/Socket/messages-send.d.ts +23 -13
  20. package/lib/Socket/messages-send.js +110 -76
  21. package/lib/Socket/newsletter.d.ts +17 -7
  22. package/lib/Socket/newsletter.js +67 -54
  23. package/lib/Socket/socket.d.ts +3 -1
  24. package/lib/Socket/socket.js +15 -17
  25. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  26. package/lib/Store/make-in-memory-store.js +13 -11
  27. package/lib/Store/make-ordered-dictionary.js +2 -2
  28. package/lib/Types/Auth.d.ts +1 -6
  29. package/lib/Types/Call.d.ts +1 -1
  30. package/lib/Types/Chat.d.ts +12 -7
  31. package/lib/Types/Contact.d.ts +1 -1
  32. package/lib/Types/Events.d.ts +44 -2
  33. package/lib/Types/GroupMetadata.d.ts +3 -1
  34. package/lib/Types/Label.d.ts +11 -0
  35. package/lib/Types/Message.d.ts +37 -30
  36. package/lib/Types/Newsletter.d.ts +0 -13
  37. package/lib/Types/Newsletter.js +1 -15
  38. package/lib/Types/Socket.d.ts +10 -3
  39. package/lib/Types/index.d.ts +8 -0
  40. package/lib/Utils/auth-utils.js +1 -7
  41. package/lib/Utils/chat-utils.d.ts +5 -4
  42. package/lib/Utils/chat-utils.js +41 -20
  43. package/lib/Utils/crypto.d.ts +2 -1
  44. package/lib/Utils/crypto.js +4 -2
  45. package/lib/Utils/decode-wa-message.d.ts +1 -0
  46. package/lib/Utils/decode-wa-message.js +34 -14
  47. package/lib/Utils/event-buffer.js +14 -8
  48. package/lib/Utils/generics.d.ts +37 -13
  49. package/lib/Utils/generics.js +102 -18
  50. package/lib/Utils/history.d.ts +6 -2
  51. package/lib/Utils/history.js +3 -0
  52. package/lib/Utils/index.d.ts +1 -0
  53. package/lib/Utils/index.js +1 -0
  54. package/lib/Utils/link-preview.js +24 -1
  55. package/lib/Utils/logger.d.ts +1 -3
  56. package/lib/Utils/make-mutex.js +1 -0
  57. package/lib/Utils/messages-media.d.ts +3 -2
  58. package/lib/Utils/messages-media.js +17 -32
  59. package/lib/Utils/messages.d.ts +1 -0
  60. package/lib/Utils/messages.js +67 -72
  61. package/lib/Utils/noise-handler.d.ts +3 -3
  62. package/lib/Utils/noise-handler.js +7 -12
  63. package/lib/Utils/process-message.d.ts +3 -2
  64. package/lib/Utils/process-message.js +55 -21
  65. package/lib/Utils/signal.js +23 -16
  66. package/lib/Utils/use-multi-file-auth-state.js +17 -3
  67. package/lib/Utils/validate-connection.d.ts +0 -1
  68. package/lib/Utils/validate-connection.js +10 -44
  69. package/lib/WABinary/constants.js +5 -5
  70. package/lib/WABinary/decode.d.ts +3 -2
  71. package/lib/WABinary/decode.js +6 -4
  72. package/lib/WABinary/encode.d.ts +1 -2
  73. package/lib/WABinary/encode.js +8 -6
  74. package/lib/WABinary/generic-utils.d.ts +1 -0
  75. package/lib/WABinary/jid-utils.d.ts +3 -3
  76. package/lib/WABinary/jid-utils.js +5 -5
  77. package/lib/WAM/BinaryInfo.d.ts +3 -2
  78. package/lib/WAM/constants.d.ts +3 -2
  79. package/lib/WAM/encode.d.ts +1 -0
  80. package/lib/WAM/encode.js +2 -2
  81. package/package.json +38 -36
  82. package/lib/Defaults/phonenumber-mcc.json +0 -223
  83. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  84. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  85. package/lib/Socket/registration.d.ts +0 -267
  86. package/lib/Socket/registration.js +0 -166
  87. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  88. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Boom } from '@hapi/boom';
3
4
  import { proto } from '../../WAProto';
4
5
  import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
@@ -6,21 +7,21 @@ import { BinaryNode, JidWithDevice } from '../WABinary';
6
7
  export declare const makeMessagesSocket: (config: SocketConfig) => {
7
8
  getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
8
9
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
9
- relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
10
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
10
11
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
11
12
  sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
12
- getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
13
13
  readMessages: (keys: WAMessageKey[]) => Promise<void>;
14
14
  refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
15
- getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
16
- createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
17
- nodes: BinaryNode[];
18
- shouldIncludeDeviceIdentity: boolean;
19
- }>;
20
15
  waUploadToServer: import("../Types").WAMediaUploadFunction;
21
16
  fetchPrivacySettings: (force?: boolean) => Promise<{
22
17
  [_: string]: string;
23
18
  }>;
19
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
20
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
21
+ nodes: BinaryNode[];
22
+ shouldIncludeDeviceIdentity: boolean;
23
+ }>;
24
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
24
25
  updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
25
26
  sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
26
27
  subscribeNewsletterUpdates: (jid: string) => Promise<{
@@ -35,14 +36,13 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
35
36
  newsletterFollow: (jid: string) => Promise<void>;
36
37
  newsletterUnmute: (jid: string) => Promise<void>;
37
38
  newsletterMute: (jid: string) => Promise<void>;
38
- newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
39
- newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
39
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
40
40
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
41
41
  newsletterAdminCount: (jid: string) => Promise<number>;
42
42
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
43
43
  newsletterDemote: (jid: string, user: string) => Promise<void>;
44
44
  newsletterDelete: (jid: string) => Promise<void>;
45
- newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
45
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
46
46
  newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
47
47
  newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
48
48
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
@@ -65,7 +65,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
65
65
  groupInviteCode: (jid: string) => Promise<string | undefined>;
66
66
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
67
67
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
68
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
68
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
69
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
69
70
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
70
71
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
71
72
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -87,26 +88,35 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
87
88
  jid: string;
88
89
  }[]>;
89
90
  fetchBlocklist: () => Promise<string[]>;
91
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
92
+ user: string;
93
+ duration: number;
94
+ setAt: Date;
95
+ }[]>;
90
96
  fetchStatus: (jid: string) => Promise<{
91
97
  status: string | undefined;
92
98
  setAt: Date;
93
99
  } | undefined>;
94
100
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
101
+ updateProfilePictureFull: (jid: any, content: any) => Promise<void>;
102
+ updateProfilePictureFull2: (jid: any, content: any) => Promise<void>;
95
103
  removeProfilePicture: (jid: string) => Promise<void>;
96
104
  updateProfileStatus: (status: string) => Promise<void>;
97
105
  updateProfileName: (name: string) => Promise<void>;
98
106
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
107
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
99
108
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
100
109
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
101
110
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
102
111
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
103
112
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
104
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
113
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
105
114
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
106
115
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
107
116
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
108
117
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
109
118
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
119
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
110
120
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
111
121
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
112
122
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -116,7 +126,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
116
126
  fromMe?: boolean | undefined;
117
127
  }[], star: boolean) => Promise<void>;
118
128
  type: "md";
119
- ws: any;
129
+ ws: import("./Client").WebSocketClient;
120
130
  ev: import("../Types").BaileysEventEmitter & {
121
131
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
122
132
  buffer(): void;
@@ -14,9 +14,9 @@ const WABinary_1 = require("../WABinary");
14
14
  const newsletter_1 = require("./newsletter");
15
15
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
16
  const makeMessagesSocket = (config) => {
17
- const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
17
+ const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
18
18
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
19
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
20
20
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
21
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
22
  useClones: false
@@ -77,7 +77,7 @@ const makeMessagesSocket = (config) => {
77
77
  }
78
78
  }
79
79
  if (type) {
80
- node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
80
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
81
81
  }
82
82
  const remainingMessageIds = messageIds.slice(1);
83
83
  if (remainingMessageIds.length) {
@@ -222,6 +222,28 @@ const makeMessagesSocket = (config) => {
222
222
  }
223
223
  return didFetchNewSession;
224
224
  };
225
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
226
+ var _a;
227
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
228
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
229
+ throw new boom_1.Boom('Not authenticated');
230
+ }
231
+ const protocolMessage = {
232
+ protocolMessage: {
233
+ peerDataOperationRequestMessage: pdoMessage,
234
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
235
+ }
236
+ };
237
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
238
+ const msgId = await relayMessage(meJid, protocolMessage, {
239
+ additionalAttributes: {
240
+ category: 'peer',
241
+ // eslint-disable-next-line camelcase
242
+ push_priority: 'high_force',
243
+ },
244
+ });
245
+ return msgId;
246
+ };
225
247
  const createParticipantNodes = async (jids, message, extraAttrs) => {
226
248
  const patched = await patchMessageBeforeSending(message, jids);
227
249
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
@@ -248,18 +270,20 @@ const makeMessagesSocket = (config) => {
248
270
  return node;
249
271
  }));
250
272
  return { nodes, shouldIncludeDeviceIdentity };
251
- }; //apela
252
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
273
+ };
274
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
275
+ var _a;
253
276
  const meId = authState.creds.me.id;
254
277
  let shouldIncludeDeviceIdentity = false;
255
278
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
256
279
  const statusJid = 'status@broadcast';
257
280
  const isGroup = server === 'g.us';
281
+ const isNewsletter = server == 'newsletter';
258
282
  const isStatus = jid === statusJid;
259
283
  const isLid = server === 'lid';
260
- const isNewsletter = server === 'newsletter';
261
- msgId = msgId || (0, Utils_1.generateMessageID)();
284
+ msgId = msgId || (0, Utils_1.generateMessageIDV3)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
262
285
  useUserDevicesCache = useUserDevicesCache !== false;
286
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
263
287
  const participants = [];
264
288
  const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
265
289
  const binaryNodeContent = [];
@@ -270,6 +294,7 @@ const makeMessagesSocket = (config) => {
270
294
  message
271
295
  }
272
296
  };
297
+ const extraAttrs = {};
273
298
  if (participant) {
274
299
  // when the retry request is not for a group
275
300
  // only send to the specific device that asked for a retry
@@ -281,16 +306,22 @@ const makeMessagesSocket = (config) => {
281
306
  devices.push({ user, device });
282
307
  }
283
308
  await authState.keys.transaction(async () => {
284
- var _a, _b, _c, _d, _e, _f;
309
+ var _a, _b, _c, _d, _e;
285
310
  const mediaType = getMediaType(message);
311
+ if (mediaType) {
312
+ extraAttrs['mediatype'] = mediaType;
313
+ }
314
+ if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
315
+ extraAttrs['decrypt-fail'] = 'hide';
316
+ }
286
317
  if (isGroup || isStatus) {
287
318
  const [groupData, senderKeyMap] = await Promise.all([
288
319
  (async () => {
289
- let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
290
- if (groupData) {
320
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
321
+ if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
291
322
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
292
323
  }
293
- if (!groupData && !isStatus) {
324
+ else if (!isStatus) {
294
325
  groupData = await groupMetadata(jid);
295
326
  }
296
327
  return groupData;
@@ -339,7 +370,7 @@ const makeMessagesSocket = (config) => {
339
370
  }
340
371
  };
341
372
  await assertSessions(senderKeyJids, false);
342
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
373
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
343
374
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
344
375
  participants.push(...result.nodes);
345
376
  }
@@ -351,41 +382,32 @@ const makeMessagesSocket = (config) => {
351
382
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
352
383
  }
353
384
  else if (isNewsletter) {
354
- // Message edit
355
- if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
356
- msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
357
- message = message.protocolMessage.editedMessage;
358
- }
359
- // Message delete
360
- if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
361
- msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
362
- message = {};
363
- }
364
385
  const patched = await patchMessageBeforeSending(message, []);
365
- const bytes = WAProto_1.proto.Message.encode(patched).finish();
386
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
366
387
  binaryNodeContent.push({
367
388
  tag: 'plaintext',
368
- attrs: mediaType ? { mediatype: mediaType } : {},
389
+ attrs: {},
369
390
  content: bytes
370
391
  });
371
392
  }
372
393
  else {
373
- const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
394
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
374
395
  if (!participant) {
375
396
  devices.push({ user });
376
- // do not send message to self if the device is 0 (mobile)
377
- if (meDevice !== undefined && meDevice !== 0) {
397
+ if (user !== meUser) {
378
398
  devices.push({ user: meUser });
379
399
  }
380
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
381
- devices.push(...additionalDevices);
400
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
401
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
402
+ devices.push(...additionalDevices);
403
+ }
382
404
  }
383
405
  const allJids = [];
384
406
  const meJids = [];
385
407
  const otherJids = [];
386
408
  for (const { user, device } of devices) {
387
409
  const isMe = user === meUser;
388
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
410
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_c = (_b = authState.creds) === null || _b === void 0 ? void 0 : _b.me) === null || _c === void 0 ? void 0 : _c.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
389
411
  if (isMe) {
390
412
  meJids.push(jid);
391
413
  }
@@ -396,25 +418,33 @@ const makeMessagesSocket = (config) => {
396
418
  }
397
419
  await assertSessions(allJids, false);
398
420
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
399
- createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
400
- createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
421
+ createParticipantNodes(meJids, meMsg, extraAttrs),
422
+ createParticipantNodes(otherJids, message, extraAttrs)
401
423
  ]);
402
424
  participants.push(...meNodes);
403
425
  participants.push(...otherNodes);
404
426
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
405
427
  }
406
428
  if (participants.length) {
407
- binaryNodeContent.push({
408
- tag: 'participants',
409
- attrs: {},
410
- content: participants
411
- });
429
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
430
+ const peerNode = (_e = (_d = participants[0]) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0];
431
+ if (peerNode) {
432
+ binaryNodeContent.push(peerNode); // push only enc
433
+ }
434
+ }
435
+ else {
436
+ binaryNodeContent.push({
437
+ tag: 'participants',
438
+ attrs: {},
439
+ content: participants
440
+ });
441
+ }
412
442
  }
413
443
  const stanza = {
414
444
  tag: 'message',
415
445
  attrs: {
416
446
  id: msgId,
417
- type: isNewsletter ? getTypeMessage(message) : 'text',
447
+ type: getMessageType(message),
418
448
  ...(additionalAttributes || {})
419
449
  },
420
450
  content: binaryNodeContent
@@ -449,39 +479,23 @@ const makeMessagesSocket = (config) => {
449
479
  if (additionalNodes && additionalNodes.length > 0) {
450
480
  stanza.content.push(...additionalNodes);
451
481
  }
452
- else {
453
- if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
454
- stanza.content.push({
455
- tag: 'biz',
456
- attrs: {},
457
- content: [{
458
- tag: 'interactive',
459
- attrs: {
460
- type: 'native_flow',
461
- v: '1'
462
- },
463
- content: [{
464
- tag: 'native_flow',
465
- attrs: { name: 'quick_reply' }
466
- }]
467
- }]
468
- });
469
- }
470
- }
471
- const buttonType = getButtonType(message);
472
- if (buttonType) {
473
- stanza.content.push({
482
+ /**
483
+ const buttonType = getButtonType(message)
484
+ if(buttonType) {
485
+ (stanza.content as BinaryNode[]).push({
474
486
  tag: 'biz',
475
- attrs: {},
487
+ attrs: { },
476
488
  content: [
477
489
  {
478
490
  tag: buttonType,
479
491
  attrs: getButtonArgs(message),
480
492
  }
481
493
  ]
482
- });
483
- logger.debug({ jid }, 'adding business node');
484
- }
494
+ })
495
+
496
+ logger.debug({ jid }, 'adding business node')
497
+ }
498
+ */
485
499
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
486
500
  await sendNode(stanza);
487
501
  });
@@ -516,6 +530,12 @@ const makeMessagesSocket = (config) => {
516
530
  return 'text';
517
531
  }
518
532
  };
533
+ const getMessageType = (message) => {
534
+ if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
535
+ return 'poll';
536
+ }
537
+ return 'text';
538
+ };
519
539
  const getMediaType = (message) => {
520
540
  if (message.imageMessage) {
521
541
  return 'image';
@@ -559,6 +579,9 @@ const makeMessagesSocket = (config) => {
559
579
  else if (message.interactiveResponseMessage) {
560
580
  return 'native_flow_response';
561
581
  }
582
+ else if (message.groupInviteMessage) {
583
+ return 'url';
584
+ }
562
585
  };
563
586
  const getButtonType = (message) => {
564
587
  if (message.buttonsMessage) {
@@ -628,13 +651,14 @@ const makeMessagesSocket = (config) => {
628
651
  relayMessage,
629
652
  sendReceipt,
630
653
  sendReceipts,
631
- getButtonArgs,
654
+ // getButtonArgs,
632
655
  readMessages,
633
656
  refreshMediaConn,
634
- getUSyncDevices,
635
- createParticipantNodes,
636
657
  waUploadToServer,
637
658
  fetchPrivacySettings,
659
+ sendPeerDataOperationMessage,
660
+ createParticipantNodes,
661
+ getUSyncDevices,
638
662
  updateMediaMessage: async (message) => {
639
663
  const content = (0, Utils_1.assertMediaContent)(message.message);
640
664
  const mediaKey = content.mediaKey;
@@ -677,7 +701,7 @@ const makeMessagesSocket = (config) => {
677
701
  return message;
678
702
  },
679
703
  sendMessage: async (jid, content, options = {}) => {
680
- var _a, _b;
704
+ var _a, _b, _c;
681
705
  const userJid = authState.creds.me.id;
682
706
  if (typeof content === 'object' &&
683
707
  'disappearingMessagesInChat' in content &&
@@ -705,24 +729,31 @@ const makeMessagesSocket = (config) => {
705
729
  ? waUploadToServer
706
730
  : undefined
707
731
  }),
732
+ //TODO: CACHE
733
+ getProfilePicUrl: sock.profilePictureUrl,
708
734
  upload: async (readStream, opts) => {
709
- const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
735
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
710
736
  mediaHandle = up.handle;
711
737
  return up;
712
738
  },
739
+ /**
740
+ upload: waUploadToServer,
741
+ */
713
742
  mediaCache: config.mediaCache,
714
743
  options: config.options,
744
+ messageId: (0, Utils_1.generateMessageIDV3)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
715
745
  ...options,
716
746
  });
717
747
  const isDeleteMsg = 'delete' in content && !!content.delete;
718
748
  const isEditMsg = 'edit' in content && !!content.edit;
719
- const isAiMsg = 'ai' in content && !!content.ai;
749
+ const isPinMsg = 'pin' in content && !!content.pin;
750
+ const isPollMessage = 'poll' in content && !!content.poll;
720
751
  const additionalAttributes = {};
721
752
  const additionalNodes = [];
722
753
  // required for delete
723
754
  if (isDeleteMsg) {
724
755
  // if the chat is a group, and I am not the author, then delete the message as an admin
725
- if (((0, WABinary_1.isJidGroup)((_a = content.delete) === null || _a === void 0 ? void 0 : _a.remoteJid) && !((_b = content.delete) === null || _b === void 0 ? void 0 : _b.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
756
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsletter)(jid)) {
726
757
  additionalAttributes.edit = '8';
727
758
  }
728
759
  else {
@@ -730,14 +761,17 @@ const makeMessagesSocket = (config) => {
730
761
  }
731
762
  }
732
763
  else if (isEditMsg) {
733
- additionalAttributes.edit = (0, WABinary_1.isJidNewsLetter)(jid) ? '3' : '1';
764
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
765
+ }
766
+ else if (isPinMsg) {
767
+ additionalAttributes.edit = '2';
734
768
  }
735
- else if (isAiMsg) {
769
+ else if (isPollMessage) {
736
770
  additionalNodes.push({
771
+ tag: 'meta',
737
772
  attrs: {
738
- biz_bot: '1'
773
+ polltype: 'creation'
739
774
  },
740
- tag: "bot"
741
775
  });
742
776
  }
743
777
  if (mediaHandle) {
@@ -746,7 +780,7 @@ const makeMessagesSocket = (config) => {
746
780
  if ('cachedGroupMetadata' in options) {
747
781
  console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
748
782
  }
749
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, additionalAttributes, statusJidList: options.statusJidList });
783
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes });
750
784
  if (config.emitOwnEvents) {
751
785
  process.nextTick(() => {
752
786
  processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { NewsletterFetchedUpdate, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, SocketConfig, WAMediaUpload } from '../Types';
2
+ /// <reference types="node" />
3
+ import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
3
4
  import { BinaryNode } from '../WABinary';
4
5
  export declare const makeNewsletterSocket: (config: SocketConfig) => {
5
6
  subscribeNewsletterUpdates: (jid: string) => Promise<{
@@ -14,8 +15,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
14
15
  newsletterFollow: (jid: string) => Promise<void>;
15
16
  newsletterUnmute: (jid: string) => Promise<void>;
16
17
  newsletterMute: (jid: string) => Promise<void>;
17
- newsletterAction: (jid: string, type: 'follow' | 'unfollow' | 'mute' | 'unmute') => Promise<void>;
18
- newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<NewsletterMetadata>;
18
+ newsletterCreate: (name: string, description: string) => Promise<NewsletterMetadata>;
19
19
  newsletterMetadata: (type: 'invite' | 'jid', key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
20
20
  newsletterAdminCount: (jid: string) => Promise<number>;
21
21
  /**user is Lid, not Jid */
@@ -24,7 +24,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
24
24
  newsletterDemote: (jid: string, user: string) => Promise<void>;
25
25
  newsletterDelete: (jid: string) => Promise<void>;
26
26
  /**if code wasn't passed, the reaction will be removed (if is reacted) */
27
- newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
27
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
28
28
  newsletterFetchMessages: (type: 'invite' | 'jid', key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
29
29
  newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
30
30
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
@@ -47,7 +47,8 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
47
47
  groupInviteCode: (jid: string) => Promise<string | undefined>;
48
48
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
49
49
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
50
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
50
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
51
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
51
52
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
52
53
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
53
54
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -72,26 +73,35 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
72
73
  jid: string;
73
74
  }[]>;
74
75
  fetchBlocklist: () => Promise<string[]>;
76
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
77
+ user: string;
78
+ duration: number;
79
+ setAt: Date;
80
+ }[]>;
75
81
  fetchStatus: (jid: string) => Promise<{
76
82
  status: string | undefined;
77
83
  setAt: Date;
78
84
  } | undefined>;
79
85
  updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
86
+ updateProfilePictureFull: (jid: any, content: any) => Promise<void>;
87
+ updateProfilePictureFull2: (jid: any, content: any) => Promise<void>;
80
88
  removeProfilePicture: (jid: string) => Promise<void>;
81
89
  updateProfileStatus: (status: string) => Promise<void>;
82
90
  updateProfileName: (name: string) => Promise<void>;
83
91
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
92
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
84
93
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
85
94
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
86
95
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
87
96
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
88
97
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
89
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
98
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
90
99
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
91
100
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
92
101
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
93
102
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
94
103
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
104
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
95
105
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
96
106
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
97
107
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -101,7 +111,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
101
111
  fromMe?: boolean | undefined;
102
112
  }[], star: boolean) => Promise<void>;
103
113
  type: "md";
104
- ws: any;
114
+ ws: import("./Client").WebSocketClient;
105
115
  ev: import("../Types").BaileysEventEmitter & {
106
116
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
107
117
  buffer(): void;