@queenanya/baileys 7.4.10 → 7.4.14

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