@queenanya/baileys 7.1.9 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -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);
@@ -249,7 +271,7 @@ const makeMessagesSocket = (config) => {
249
271
  }));
250
272
  return { nodes, shouldIncludeDeviceIdentity };
251
273
  };
252
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
274
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
253
275
  var _a;
254
276
  const meId = authState.creds.me.id;
255
277
  let shouldIncludeDeviceIdentity = false;
@@ -261,6 +283,7 @@ const makeMessagesSocket = (config) => {
261
283
  const isLid = server === 'lid';
262
284
  msgId = msgId || (0, Utils_1.generateMessageIDV3)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
263
285
  useUserDevicesCache = useUserDevicesCache !== false;
286
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
264
287
  const participants = [];
265
288
  const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
266
289
  const binaryNodeContent = [];
@@ -271,6 +294,7 @@ const makeMessagesSocket = (config) => {
271
294
  message
272
295
  }
273
296
  };
297
+ const extraAttrs = {};
274
298
  if (participant) {
275
299
  // when the retry request is not for a group
276
300
  // only send to the specific device that asked for a retry
@@ -282,16 +306,22 @@ const makeMessagesSocket = (config) => {
282
306
  devices.push({ user, device });
283
307
  }
284
308
  await authState.keys.transaction(async () => {
285
- var _a, _b;
309
+ var _a, _b, _c, _d, _e;
286
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
+ }
287
317
  if (isGroup || isStatus) {
288
318
  const [groupData, senderKeyMap] = await Promise.all([
289
319
  (async () => {
290
- let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
291
- 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)) {
292
322
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
293
323
  }
294
- if (!groupData && !isStatus) {
324
+ else if (!isStatus) {
295
325
  groupData = await groupMetadata(jid);
296
326
  }
297
327
  return groupData;
@@ -340,7 +370,7 @@ const makeMessagesSocket = (config) => {
340
370
  }
341
371
  };
342
372
  await assertSessions(senderKeyJids, false);
343
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
373
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
344
374
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
345
375
  participants.push(...result.nodes);
346
376
  }
@@ -365,18 +395,20 @@ const makeMessagesSocket = (config) => {
365
395
  if (!participant) {
366
396
  devices.push({ user });
367
397
  // do not send message to self if the device is 0 (mobile)
368
- if (meDevice !== undefined && meDevice !== 0) {
369
- devices.push({ user: meUser });
398
+ if (!((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer' && user === meUser)) {
399
+ if (meDevice !== undefined && meDevice !== 0) {
400
+ devices.push({ user: meUser });
401
+ }
402
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
403
+ devices.push(...additionalDevices);
370
404
  }
371
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
372
- devices.push(...additionalDevices);
373
405
  }
374
406
  const allJids = [];
375
407
  const meJids = [];
376
408
  const otherJids = [];
377
409
  for (const { user, device } of devices) {
378
410
  const isMe = user === meUser;
379
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_b = (_a = authState.creds) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
411
+ 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);
380
412
  if (isMe) {
381
413
  meJids.push(jid);
382
414
  }
@@ -387,19 +419,27 @@ const makeMessagesSocket = (config) => {
387
419
  }
388
420
  await assertSessions(allJids, false);
389
421
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
390
- createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
391
- createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
422
+ createParticipantNodes(meJids, meMsg, extraAttrs),
423
+ createParticipantNodes(otherJids, message, extraAttrs)
392
424
  ]);
393
425
  participants.push(...meNodes);
394
426
  participants.push(...otherNodes);
395
427
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
396
428
  }
397
429
  if (participants.length) {
398
- binaryNodeContent.push({
399
- tag: 'participants',
400
- attrs: {},
401
- content: participants
402
- });
430
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
431
+ const peerNode = (_e = (_d = participants[0]) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0];
432
+ if (peerNode) {
433
+ binaryNodeContent.push(peerNode); // push only enc
434
+ }
435
+ }
436
+ else {
437
+ binaryNodeContent.push({
438
+ tag: 'participants',
439
+ attrs: {},
440
+ content: participants
441
+ });
442
+ }
403
443
  }
404
444
  const stanza = {
405
445
  tag: 'message',
@@ -437,20 +477,26 @@ const makeMessagesSocket = (config) => {
437
477
  });
438
478
  logger.debug({ jid }, 'adding device identity');
439
479
  }
440
- const buttonType = getButtonType(message);
441
- if (buttonType) {
442
- stanza.content.push({
480
+ if (additionalNodes && additionalNodes.length > 0) {
481
+ stanza.content.push(...additionalNodes);
482
+ }
483
+ /**
484
+ const buttonType = getButtonType(message)
485
+ if(buttonType) {
486
+ (stanza.content as BinaryNode[]).push({
443
487
  tag: 'biz',
444
- attrs: {},
488
+ attrs: { },
445
489
  content: [
446
490
  {
447
491
  tag: buttonType,
448
492
  attrs: getButtonArgs(message),
449
493
  }
450
494
  ]
451
- });
452
- logger.debug({ jid }, 'adding business node');
453
- }
495
+ })
496
+
497
+ logger.debug({ jid }, 'adding business node')
498
+ }
499
+ */
454
500
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
455
501
  await sendNode(stanza);
456
502
  });
@@ -600,11 +646,14 @@ const makeMessagesSocket = (config) => {
600
646
  relayMessage,
601
647
  sendReceipt,
602
648
  sendReceipts,
603
- getButtonArgs,
649
+ // getButtonArgs,
604
650
  readMessages,
605
651
  refreshMediaConn,
606
652
  waUploadToServer,
607
653
  fetchPrivacySettings,
654
+ sendPeerDataOperationMessage,
655
+ createParticipantNodes,
656
+ getUSyncDevices,
608
657
  updateMediaMessage: async (message) => {
609
658
  const content = (0, Utils_1.assertMediaContent)(message.message);
610
659
  const mediaKey = content.mediaKey;
@@ -675,13 +724,16 @@ const makeMessagesSocket = (config) => {
675
724
  ? waUploadToServer
676
725
  : undefined
677
726
  }),
727
+ //TODO: CACHE
728
+ getProfilePicUrl: sock.profilePictureUrl,
678
729
  upload: async (readStream, opts) => {
679
730
  const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
680
731
  mediaHandle = up.handle;
681
732
  return up;
682
733
  },
683
- //TODO: CACHE
684
- getProfilePicUrl: sock.profilePictureUrl,
734
+ /**
735
+ upload: waUploadToServer,
736
+ */
685
737
  mediaCache: config.mediaCache,
686
738
  options: config.options,
687
739
  messageId: (0, Utils_1.generateMessageIDV3)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
@@ -689,6 +741,7 @@ const makeMessagesSocket = (config) => {
689
741
  });
690
742
  const isDeleteMsg = 'delete' in content && !!content.delete;
691
743
  const isEditMsg = 'edit' in content && !!content.edit;
744
+ const isPinMsg = 'pin' in content && !!content.pin;
692
745
  const additionalAttributes = {};
693
746
  // required for delete
694
747
  if (isDeleteMsg) {
@@ -703,10 +756,16 @@ const makeMessagesSocket = (config) => {
703
756
  else if (isEditMsg) {
704
757
  additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
705
758
  }
759
+ else if (isPinMsg) {
760
+ additionalAttributes.edit = '2';
761
+ }
706
762
  if (mediaHandle) {
707
763
  additionalAttributes['media_id'] = mediaHandle;
708
764
  }
709
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
765
+ if ('cachedGroupMetadata' in options) {
766
+ console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
767
+ }
768
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
710
769
  if (config.emitOwnEvents) {
711
770
  process.nextTick(() => {
712
771
  processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
@@ -92,7 +92,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
92
92
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
93
93
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
94
94
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
95
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
95
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
96
96
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
97
97
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
98
98
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="long" />
1
2
  /// <reference types="node" />
2
3
  import { AxiosRequestConfig } from 'axios';
3
4
  import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
@@ -21,20 +22,27 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
21
22
  sendMessageAck: ({ tag, attrs, content }: import("../WABinary").BinaryNode) => Promise<void>;
22
23
  sendRetryRequest: (node: import("../WABinary").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
23
24
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
25
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
26
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
24
27
  getPrivacyTokens: (jids: string[]) => Promise<import("../WABinary").BinaryNode>;
25
28
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
26
- relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
29
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
27
30
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
28
31
  sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
29
- getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
30
- [key: string]: string;
31
- };
32
32
  readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
33
33
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
34
34
  waUploadToServer: import("../Types").WAMediaUploadFunction;
35
35
  fetchPrivacySettings: (force?: boolean) => Promise<{
36
36
  [_: string]: string;
37
37
  }>;
38
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
39
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
40
+ [key: string]: string;
41
+ } | undefined) => Promise<{
42
+ nodes: import("../WABinary").BinaryNode[];
43
+ shouldIncludeDeviceIdentity: boolean;
44
+ }>;
45
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
38
46
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
39
47
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
40
48
  subscribeNewsletterUpdates: (jid: string) => Promise<{
@@ -121,7 +129,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
121
129
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
122
130
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
123
131
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
124
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
132
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
125
133
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
126
134
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
127
135
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
@@ -66,7 +66,11 @@ exports.default = (config) => {
66
66
  ev.on('connection.update', update => {
67
67
  Object.assign(state, update);
68
68
  });
69
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
69
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
70
+ if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
71
+ return; // FOR NOW,
72
+ //TODO: HANDLE
73
+ }
70
74
  if (isLatest) {
71
75
  chats.clear();
72
76
  for (const id in messages) {
@@ -8,6 +8,7 @@ import type { LabelActionBody } from './Label';
8
8
  /** privacy settings in WhatsApp Web */
9
9
  export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
10
10
  export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
11
+ export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
11
12
  export type WAReadReceiptsValue = 'all' | 'none';
12
13
  export type WAPrivacyCallValue = 'all' | 'known';
13
14
  /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
@@ -20,7 +20,9 @@ export type BaileysEventMap = {
20
20
  chats: Chat[];
21
21
  contacts: Contact[];
22
22
  messages: WAMessage[];
23
- isLatest: boolean;
23
+ isLatest?: boolean;
24
+ progress?: number | null;
25
+ syncType?: proto.HistorySync.HistorySyncType;
24
26
  };
25
27
  /** upsert chats */
26
28
  'chats.upsert': Chat[];
@@ -59,10 +61,12 @@ export type BaileysEventMap = {
59
61
  /**
60
62
  * add/update the given messages. If they were received while the connection was online,
61
63
  * the update will have type: "notify"
64
+ * if requestId is provided, then the messages was received from the phone due to it being unavailable
62
65
  * */
63
66
  'messages.upsert': {
64
67
  messages: WAMessage[];
65
68
  type: MessageUpsertType;
69
+ requestId?: string;
66
70
  };
67
71
  /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
68
72
  'messages.reaction': {
@@ -7,6 +7,7 @@ import type { Readable } from 'stream';
7
7
  import type { URL } from 'url';
8
8
  import { proto } from '../../WAProto';
9
9
  import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults';
10
+ import { BinaryNode } from '../WABinary';
10
11
  import type { GroupMetadata } from './GroupMetadata';
11
12
  import { CacheStore } from './Socket';
12
13
  export { proto as WAProto };
@@ -65,26 +66,9 @@ type Contextable = {
65
66
  type ViewOnce = {
66
67
  viewOnce?: boolean;
67
68
  };
68
- type Buttonable = {
69
- /** add buttons to the message */
70
- buttons?: proto.Message.ButtonsMessage.IButton[];
71
- };
72
- type Templatable = {
73
- /** add buttons to the message (conflicts with normal buttons)*/
74
- templateButtons?: proto.IHydratedTemplateButton[];
75
- footer?: string;
76
- };
77
69
  type Editable = {
78
70
  edit?: WAMessageKey;
79
71
  };
80
- type Listable = {
81
- /** Sections of the List */
82
- sections?: proto.Message.ListMessage.ISection[];
83
- /** Title of a List Message only */
84
- title?: string;
85
- /** Text of the bnutton on the list (required) */
86
- buttonText?: string;
87
- };
88
72
  type WithDimensions = {
89
73
  width?: number;
90
74
  height?: number;
@@ -95,6 +79,7 @@ export type PollMessageOptions = {
95
79
  values: string[];
96
80
  /** 32 byte message secret to encrypt poll selections */
97
81
  messageSecret?: Uint8Array;
82
+ toAnnouncementGroup?: boolean;
98
83
  };
99
84
  type SharePhoneNumber = {
100
85
  sharePhoneNumber: boolean;
@@ -107,14 +92,14 @@ export type AnyMediaMessageContent = (({
107
92
  image: WAMediaUpload;
108
93
  caption?: string;
109
94
  jpegThumbnail?: string;
110
- } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions) | ({
95
+ } & Mentionable & Contextable & WithDimensions) | ({
111
96
  video: WAMediaUpload;
112
97
  caption?: string;
113
98
  gifPlayback?: boolean;
114
99
  jpegThumbnail?: string;
115
100
  /** if set to true, will send as a `video note` */
116
101
  ptv?: boolean;
117
- } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions) | {
102
+ } & Mentionable & Contextable & WithDimensions) | {
118
103
  audio: WAMediaUpload;
119
104
  /** if set to true, will send as a `voice note` */
120
105
  ptt?: boolean;
@@ -128,7 +113,7 @@ export type AnyMediaMessageContent = (({
128
113
  mimetype: string;
129
114
  fileName?: string;
130
115
  caption?: string;
131
- } & Contextable & Buttonable & Templatable)) & {
116
+ } & Contextable)) & {
132
117
  mimetype?: string;
133
118
  } & Editable;
134
119
  export type ButtonReplyInfo = {
@@ -149,9 +134,9 @@ export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapsh
149
134
  export type AnyRegularMessageContent = (({
150
135
  text: string;
151
136
  linkPreview?: WAUrlInfo | null;
152
- } & Mentionable & Contextable & Buttonable & Templatable & Listable & Editable) | AnyMediaMessageContent | ({
137
+ } & Mentionable & Contextable & Editable) | AnyMediaMessageContent | ({
153
138
  poll: PollMessageOptions;
154
- } & Mentionable & Contextable & Buttonable & Templatable & Editable) | {
139
+ } & Mentionable & Contextable & Editable) | {
155
140
  contacts: {
156
141
  displayName?: string;
157
142
  contacts: proto.Message.IContactMessage[];
@@ -169,7 +154,11 @@ export type AnyRegularMessageContent = (({
169
154
  listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>;
170
155
  } | {
171
156
  pin: WAMessageKey;
172
- time: 86400 | 604800 | 2592000;
157
+ type: proto.PinInChat.Type;
158
+ /**
159
+ * 24 hours, 7 days, 30 days
160
+ */
161
+ time?: 86400 | 604800 | 2592000;
173
162
  } | {
174
163
  unpin: WAMessageKey;
175
164
  } | {
@@ -191,8 +180,8 @@ export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>;
191
180
  type MinimalRelayOptions = {
192
181
  /** override the message ID with a custom provided string */
193
182
  messageId?: string;
194
- /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
195
- cachedGroupMetadata?: (jid: string) => Promise<GroupMetadataParticipants | undefined>;
183
+ /** should we use group metadata cache, or fetch afresh from the server; default assumed to be "true" */
184
+ useCachedGroupMetadata?: boolean;
196
185
  };
197
186
  export type MessageRelayOptions = MinimalRelayOptions & {
198
187
  /** only send to a specific participant; used when a message decryption fails for a single user */
@@ -204,6 +193,7 @@ export type MessageRelayOptions = MinimalRelayOptions & {
204
193
  additionalAttributes?: {
205
194
  [_: string]: string;
206
195
  };
196
+ additionalNodes?: BinaryNode[];
207
197
  /** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
208
198
  useUserDevicesCache?: boolean;
209
199
  /** jid list of participants for status@broadcast */
@@ -6,6 +6,7 @@ import type { Logger } from 'pino';
6
6
  import type { URL } from 'url';
7
7
  import { proto } from '../../WAProto';
8
8
  import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
9
+ import { GroupMetadata } from './GroupMetadata';
9
10
  import { MediaConnInfo } from './Message';
10
11
  import { SignalRepository } from './Signal';
11
12
  export type WAVersion = [number, number, number];
@@ -71,6 +72,8 @@ export type SocketConfig = {
71
72
  userDevicesCache?: CacheStore;
72
73
  /** cache to store call offers */
73
74
  callOfferCache?: CacheStore;
75
+ /** cache to track placeholder resends */
76
+ placeholderResendCache?: CacheStore;
74
77
  /** width for link preview images */
75
78
  linkPreviewImageThumbnailWidth: number;
76
79
  /** Should Baileys ask the phone for full history, will be received async */
@@ -107,6 +110,8 @@ export type SocketConfig = {
107
110
  * (solves the "this message can take a while" issue) can be retried
108
111
  * */
109
112
  getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
113
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
114
+ cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
110
115
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
111
116
  /** Socket passthrough */
112
117
  socket?: any;
@@ -2,6 +2,7 @@ import { Logger } from 'pino';
2
2
  import { proto } from '../../WAProto';
3
3
  import { SignalRepository } from '../Types';
4
4
  import { BinaryNode } from '../WABinary';
5
+ export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
5
6
  /**
6
7
  * Decode the received node as a message.
7
8
  * @note this will only parse the message, not decrypt it
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptMessageNode = exports.decodeMessageNode = void 0;
3
+ exports.decryptMessageNode = exports.decodeMessageNode = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const WAProto_1 = require("../../WAProto");
6
6
  const WABinary_1 = require("../WABinary");
7
7
  const generics_1 = require("./generics");
8
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
8
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
9
  /**
10
10
  * Decode the received node as a message.
11
11
  * @note this will only parse the message, not decrypt it
@@ -155,7 +155,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
155
155
  decryptables += 1;
156
156
  let msgBuffer;
157
157
  try {
158
- const e2eType = attrs.type;
158
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
159
159
  switch (e2eType) {
160
160
  case 'skmsg':
161
161
  msgBuffer = await repository.decryptGroupMessage({
@@ -173,7 +173,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
173
173
  ciphertext: content
174
174
  });
175
175
  break;
176
- case undefined:
176
+ case 'plaintext':
177
177
  msgBuffer = content;
178
178
  break;
179
179
  default:
@@ -199,7 +199,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
199
199
  // if nothing was found to decrypt
200
200
  if (!decryptables) {
201
201
  fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
202
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
202
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
203
203
  }
204
204
  }
205
205
  };
@@ -50,10 +50,23 @@ export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: Ba
50
50
  export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
51
51
  export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
52
52
  /**
53
- * utility that fetches latest baileys version from the master branch.
53
+ * utility that fetches latest baileys version from the main branch.
54
54
  * Use to ensure your WA connection is always on the latest version
55
55
  */
56
56
  export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
57
+ version: number[];
58
+ isLatest: boolean;
59
+ error?: undefined;
60
+ } | {
61
+ version: WAVersion;
62
+ isLatest: boolean;
63
+ error: any;
64
+ }>;
65
+ /**
66
+ * utility that fetches latest baileys version from the master branch.
67
+ * Use to ensure your WA connection is always on the latest version
68
+ */
69
+ export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<any>) => Promise<{
57
70
  version: WAVersion;
58
71
  isLatest: boolean;
59
72
  error?: undefined;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV3 = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
6
+ exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion2 = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV3 = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const crypto_1 = require("crypto");
@@ -238,10 +238,36 @@ const printQRIfNecessaryListener = (ev, logger) => {
238
238
  };
239
239
  exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
240
240
  /**
241
- * utility that fetches latest baileys version from the master branch.
241
+ * utility that fetches latest baileys version from the main branch.
242
242
  * Use to ensure your WA connection is always on the latest version
243
243
  */
244
244
  const fetchLatestBaileysVersion = async (options = {}) => {
245
+ try {
246
+ const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
247
+ ...options,
248
+ responseType: 'json'
249
+ });
250
+ const version = result.data.currentVersion.split('.');
251
+ const version2 = version[2].replace('-alpha', '');
252
+ return {
253
+ version: [+version[0], +version[1], +version2],
254
+ isLatest: true
255
+ };
256
+ }
257
+ catch (error) {
258
+ return {
259
+ version: baileys_version_json_1.version,
260
+ isLatest: false,
261
+ error
262
+ };
263
+ }
264
+ };
265
+ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
266
+ /**
267
+ * utility that fetches latest baileys version from the master branch.
268
+ * Use to ensure your WA connection is always on the latest version
269
+ */
270
+ const fetchLatestBaileysVersion2 = async (options = {}) => {
245
271
  const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
246
272
  try {
247
273
  const result = await axios_1.default.get(URL, {
@@ -261,7 +287,7 @@ const fetchLatestBaileysVersion = async (options = {}) => {
261
287
  };
262
288
  }
263
289
  };
264
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
290
+ exports.fetchLatestBaileysVersion2 = fetchLatestBaileysVersion2;
265
291
  /**
266
292
  * A utility that fetches the latest web version of whatsapp.
267
293
  * Use to ensure your WA connection is always on the latest version
@@ -6,10 +6,14 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
6
  chats: Chat[];
7
7
  contacts: Contact[];
8
8
  messages: proto.IWebMessageInfo[];
9
+ syncType: proto.HistorySync.HistorySyncType;
10
+ progress: number | null | undefined;
9
11
  };
10
12
  export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
11
13
  chats: Chat[];
12
14
  contacts: Contact[];
13
15
  messages: proto.IWebMessageInfo[];
16
+ syncType: proto.HistorySync.HistorySyncType;
17
+ progress: number | null | undefined;
14
18
  }>;
15
19
  export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;