@jkt48connect-corp/baileys 7.3.0 → 7.3.2

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1119 -1407
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +7 -9
  5. package/lib/Defaults/index.js +4 -6
  6. package/lib/Socket/Client/index.d.ts +3 -2
  7. package/lib/Socket/Client/index.js +3 -2
  8. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  9. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
  10. package/lib/Socket/business.d.ts +3 -8
  11. package/lib/Socket/chats.d.ts +19 -21
  12. package/lib/Socket/chats.js +48 -51
  13. package/lib/Socket/groups.d.ts +26 -28
  14. package/lib/Socket/groups.js +1 -2
  15. package/lib/Socket/index.d.ts +3 -6
  16. package/lib/Socket/messages-recv.d.ts +3 -8
  17. package/lib/Socket/messages-recv.js +149 -308
  18. package/lib/Socket/messages-send.d.ts +26 -23
  19. package/lib/Socket/messages-send.js +166 -193
  20. package/lib/Socket/newsletter.d.ts +2 -2
  21. package/lib/Socket/newsletter.js +3 -3
  22. package/lib/Socket/registration.d.ts +3 -8
  23. package/lib/Socket/socket.d.ts +6 -8
  24. package/lib/Socket/socket.js +14 -19
  25. package/lib/Store/make-cache-manager-store.d.ts +2 -2
  26. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  27. package/lib/Types/Call.d.ts +1 -1
  28. package/lib/Types/Chat.d.ts +7 -12
  29. package/lib/Types/Events.d.ts +2 -17
  30. package/lib/Types/GroupMetadata.d.ts +1 -3
  31. package/lib/Types/Label.d.ts +0 -11
  32. package/lib/Types/Message.d.ts +328 -324
  33. package/lib/Types/Socket.d.ts +0 -7
  34. package/lib/Types/index.d.ts +0 -9
  35. package/lib/Utils/chat-utils.d.ts +4 -4
  36. package/lib/Utils/chat-utils.js +20 -41
  37. package/lib/Utils/crypto.d.ts +1 -1
  38. package/lib/Utils/crypto.js +2 -4
  39. package/lib/Utils/decode-wa-message.d.ts +0 -17
  40. package/lib/Utils/decode-wa-message.js +14 -42
  41. package/lib/Utils/generics.d.ts +10 -4
  42. package/lib/Utils/generics.js +14 -30
  43. package/lib/Utils/history.d.ts +2 -6
  44. package/lib/Utils/history.js +0 -3
  45. package/lib/Utils/messages.d.ts +1 -0
  46. package/lib/Utils/messages.js +41 -249
  47. package/lib/Utils/signal.d.ts +1 -2
  48. package/lib/Utils/signal.js +19 -11
  49. package/lib/Utils/use-multi-file-auth-state.js +3 -11
  50. package/lib/Utils/validate-connection.d.ts +2 -2
  51. package/lib/Utils/validate-connection.js +1 -1
  52. package/lib/WABinary/encode.d.ts +1 -1
  53. package/lib/WABinary/encode.js +10 -16
  54. package/lib/index.d.ts +11 -0
  55. package/lib/index.js +0 -1
  56. package/lib/index.ts +13 -0
  57. package/package.json +15 -27
  58. package/lib/Socket/Client/types.d.ts +0 -17
  59. package/lib/Socket/Client/types.js +0 -13
  60. package/lib/Socket/usync.d.ts +0 -37
  61. package/lib/Socket/usync.js +0 -70
  62. package/lib/Types/USync.d.ts +0 -25
  63. package/lib/Types/USync.js +0 -2
  64. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  65. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  66. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  67. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  68. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  70. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  71. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  72. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  73. package/lib/WAUSync/Protocols/index.js +0 -20
  74. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  75. package/lib/WAUSync/USyncQuery.js +0 -79
  76. package/lib/WAUSync/USyncUser.d.ts +0 -10
  77. package/lib/WAUSync/USyncUser.js +0 -22
  78. package/lib/WAUSync/index.d.ts +0 -3
  79. package/lib/WAUSync/index.js +0 -19
@@ -1,35 +1,31 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Boom } from '@hapi/boom';
3
4
  import { proto } from '../../WAProto';
4
- import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, QueryIds, SocketConfig, WAMessageKey } from '../Types';
5
+ import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
5
6
  import { BinaryNode, JidWithDevice } from '../WABinary';
6
- import { USyncQuery } from '../WAUSync';
7
7
  export declare const makeMessagesSocket: (config: SocketConfig) => {
8
8
  getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
9
9
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
10
- 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, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
11
11
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
12
12
  sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
13
13
  getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
14
14
  readMessages: (keys: WAMessageKey[]) => Promise<void>;
15
15
  refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
16
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
17
+ fetchPrivacySettings: (force?: boolean) => Promise<{
18
+ [_: string]: string;
19
+ }>;
16
20
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
17
- sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
18
21
  createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
19
22
  nodes: BinaryNode[];
20
23
  shouldIncludeDeviceIdentity: boolean;
21
24
  }>;
22
- profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
23
- waUploadToServer: import("../Types").WAMediaUploadFunction;
24
- fetchPrivacySettings: (force?: boolean) => Promise<{
25
- [_: string]: string;
26
- }>;
27
25
  updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
28
26
  sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
29
27
  sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
30
28
  sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
31
- newsletterQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
32
- newsletterWMexQuery: (jid: string | undefined, queryId: QueryIds, content?: object | undefined) => Promise<BinaryNode>;
33
29
  subscribeNewsletterUpdates: (jid: string) => Promise<{
34
30
  duration: string;
35
31
  }>;
@@ -42,17 +38,15 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
42
38
  newsletterFollow: (jid: string) => Promise<void>;
43
39
  newsletterUnmute: (jid: string) => Promise<void>;
44
40
  newsletterMute: (jid: string) => Promise<void>;
45
- newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
46
41
  newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
47
42
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
48
43
  newsletterAdminCount: (jid: string) => Promise<number>;
49
44
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
50
45
  newsletterDemote: (jid: string, user: string) => Promise<void>;
51
46
  newsletterDelete: (jid: string) => Promise<void>;
52
- newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
47
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
53
48
  newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
54
49
  newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
55
- groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
56
50
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
57
51
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
58
52
  groupLeave: (id: string) => Promise<void>;
@@ -73,7 +67,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
73
67
  groupInviteCode: (jid: string) => Promise<string | undefined>;
74
68
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
75
69
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
76
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
70
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
71
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
77
72
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
78
73
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
79
74
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -82,27 +77,35 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
82
77
  groupFetchAllParticipating: () => Promise<{
83
78
  [_: string]: import("../Types").GroupMetadata;
84
79
  }>;
85
- interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
86
80
  processingMutex: {
87
81
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
88
82
  };
89
83
  upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
90
84
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
91
- fetchUserLid: (jid: string) => Promise<string | undefined>;
92
85
  sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
93
86
  presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
87
+ profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
94
88
  onWhatsApp: (...jids: string[]) => Promise<{
89
+ exists: boolean;
95
90
  jid: string;
96
- exists: unknown;
97
- }[] | undefined>;
91
+ }[]>;
98
92
  fetchBlocklist: () => Promise<string[]>;
99
- fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
100
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
93
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
94
+ user: string;
95
+ duration: number;
96
+ setAt: Date;
97
+ }[]>;
98
+ fetchStatus: (...jids: string[]) => Promise<{
99
+ user: string;
100
+ status: string | null;
101
+ setAt: Date;
102
+ }[]>;
101
103
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
102
104
  removeProfilePicture: (jid: string) => Promise<void>;
103
105
  updateProfileStatus: (status: string) => Promise<void>;
104
106
  updateProfileName: (name: string) => Promise<void>;
105
107
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
108
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
106
109
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
107
110
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
108
111
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -122,7 +125,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
122
125
  id: string;
123
126
  fromMe?: boolean | undefined;
124
127
  }[], star: boolean) => Promise<void>;
125
- executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
126
128
  type: "md";
127
129
  ws: any;
128
130
  ev: import("../Types").BaileysEventEmitter & {
@@ -149,7 +151,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
149
151
  onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
150
152
  uploadPreKeys: (count?: number) => Promise<void>;
151
153
  uploadPreKeysToServerIfRequired: () => Promise<void>;
152
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
154
+ getPairingCode: (phoneNumber: string) => Promise<string>;
155
+ interaktiveMeta: (phoneNumber: string) => Promise<string>;
153
156
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
154
157
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
155
158
  };
@@ -8,19 +8,17 @@ const boom_1 = require("@hapi/boom");
8
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
- const Types_1 = require("../Types");
12
11
  const Utils_1 = require("../Utils");
13
12
  const link_preview_1 = require("../Utils/link-preview");
14
13
  const WABinary_1 = require("../WABinary");
15
- const WAUSync_1 = require("../WAUSync");
16
14
  const newsletter_1 = require("./newsletter");
17
15
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
18
16
  const makeMessagesSocket = (config) => {
19
17
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
20
18
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
21
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupQuery, newsletterWMexQuery, groupToggleEphemeral } = sock;
19
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
22
20
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
23
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
21
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
24
22
  useClones: false
25
23
  });
26
24
  let mediaConn;
@@ -111,43 +109,6 @@ const makeMessagesSocket = (config) => {
111
109
  const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
112
110
  await sendReceipts(keys, readType);
113
111
  };
114
- const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
115
- var _a, _b, _c, _d;
116
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
117
- if ((0, WABinary_1.isJidNewsLetter)(jid)) {
118
- const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
119
- input: {
120
- key: jid,
121
- type: "JID",
122
- 'view_role': 'GUEST'
123
- },
124
- 'fetch_viewer_metadata': true,
125
- 'fetch_full_image': true,
126
- 'fetch_creation_time': true
127
- });
128
- const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
129
- const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
130
- const pictype = type === 'image' ? 'picture' : 'preview';
131
- const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
132
- return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
133
- }
134
- else {
135
- const result = await query({
136
- tag: 'iq',
137
- attrs: {
138
- target: jid,
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- type: 'get',
141
- xmlns: 'w:profile:picture'
142
- },
143
- content: [
144
- { tag: 'picture', attrs: { type, query: 'url' } }
145
- ]
146
- }, timeoutMs);
147
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
148
- return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
149
- }
150
- };
151
112
  /** Fetch all the devices we've to send a message to */
152
113
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
153
114
  var _a;
@@ -155,46 +116,66 @@ const makeMessagesSocket = (config) => {
155
116
  if (!useCache) {
156
117
  logger.debug('not using cache for devices');
157
118
  }
158
- const toFetch = [];
119
+ const users = [];
159
120
  jids = Array.from(new Set(jids));
160
121
  for (let jid of jids) {
161
122
  const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
162
123
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
163
- if (useCache) {
164
- const devices = userDevicesCache.get(user);
165
- if (devices) {
166
- deviceResults.push(...devices);
167
- logger.trace({ user }, 'using cache for devices');
168
- }
169
- else {
170
- toFetch.push(jid);
171
- }
124
+ const devices = userDevicesCache.get(user);
125
+ if (devices && useCache) {
126
+ deviceResults.push(...devices);
127
+ logger.trace({ user }, 'using cache for devices');
172
128
  }
173
129
  else {
174
- toFetch.push(jid);
130
+ users.push({ tag: 'user', attrs: { jid } });
175
131
  }
176
132
  }
177
- if (!toFetch.length) {
133
+ if (!users.length) {
178
134
  return deviceResults;
179
135
  }
180
- const query = new WAUSync_1.USyncQuery()
181
- .withContext('message')
182
- .withDeviceProtocol();
183
- for (const jid of toFetch) {
184
- query.withUser(new WAUSync_1.USyncUser().withId(jid));
185
- }
186
- const result = await sock.executeUSyncQuery(query);
187
- if (result) {
188
- const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
189
- const deviceMap = {};
190
- for (const item of extracted) {
191
- deviceMap[item.user] = deviceMap[item.user] || [];
192
- deviceMap[item.user].push(item);
193
- deviceResults.push(item);
194
- }
195
- for (const key in deviceMap) {
196
- userDevicesCache.set(key, deviceMap[key]);
197
- }
136
+ const iq = {
137
+ tag: 'iq',
138
+ attrs: {
139
+ to: WABinary_1.S_WHATSAPP_NET,
140
+ type: 'get',
141
+ xmlns: 'usync',
142
+ },
143
+ content: [
144
+ {
145
+ tag: 'usync',
146
+ attrs: {
147
+ sid: generateMessageTag(),
148
+ mode: 'query',
149
+ last: 'true',
150
+ index: '0',
151
+ context: 'message',
152
+ },
153
+ content: [
154
+ {
155
+ tag: 'query',
156
+ attrs: {},
157
+ content: [
158
+ {
159
+ tag: 'devices',
160
+ attrs: { version: '2' }
161
+ }
162
+ ]
163
+ },
164
+ { tag: 'list', attrs: {}, content: users }
165
+ ]
166
+ },
167
+ ],
168
+ };
169
+ const result = await query(iq);
170
+ const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
171
+ const deviceMap = {};
172
+ for (const item of extracted) {
173
+ deviceMap[item.user] = deviceMap[item.user] || [];
174
+ deviceMap[item.user].push(item);
175
+ deviceResults.push(item);
176
+ }
177
+ for (const key in deviceMap) {
178
+ userDevicesCache.set(key, deviceMap[key]);
198
179
  }
199
180
  return deviceResults;
200
181
  };
@@ -241,28 +222,6 @@ const makeMessagesSocket = (config) => {
241
222
  }
242
223
  return didFetchNewSession;
243
224
  };
244
- const sendPeerDataOperationMessage = async (pdoMessage) => {
245
- var _a;
246
- //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
247
- if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
248
- throw new boom_1.Boom('Not authenticated');
249
- }
250
- const protocolMessage = {
251
- protocolMessage: {
252
- peerDataOperationRequestMessage: pdoMessage,
253
- type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
254
- }
255
- };
256
- const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
257
- const msgId = await relayMessage(meJid, protocolMessage, {
258
- additionalAttributes: {
259
- category: 'peer',
260
- // eslint-disable-next-line camelcase
261
- push_priority: 'high_force',
262
- },
263
- });
264
- return msgId;
265
- };
266
225
  const createParticipantNodes = async (jids, message, extraAttrs) => {
267
226
  const patched = await patchMessageBeforeSending(message, jids);
268
227
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
@@ -296,9 +255,9 @@ const makeMessagesSocket = (config) => {
296
255
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
297
256
  const statusJid = 'status@broadcast';
298
257
  const isGroup = server === 'g.us';
258
+ const isPrivate = server === 's.whatsapp.net';
299
259
  const isStatus = jid === statusJid;
300
260
  const isLid = server === 'lid';
301
- const isPrivate = server === 's.whatsapp.net';
302
261
  const isNewsletter = server === 'newsletter';
303
262
  msgId = msgId || (0, Utils_1.generateMessageID)();
304
263
  useUserDevicesCache = useUserDevicesCache !== false;
@@ -323,7 +282,7 @@ const makeMessagesSocket = (config) => {
323
282
  devices.push({ user, device });
324
283
  }
325
284
  await authState.keys.transaction(async () => {
326
- var _a, _b, _c, _d, _e, _f;
285
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
327
286
  const mediaType = getMediaType(message);
328
287
  if (isGroup || isStatus) {
329
288
  const [groupData, senderKeyMap] = await Promise.all([
@@ -488,95 +447,94 @@ const makeMessagesSocket = (config) => {
488
447
  });
489
448
  logger.debug({ jid }, 'adding device identity');
490
449
  }
491
- if (additionalNodes && additionalNodes.length > 0) {
492
- stanza.content.push(...additionalNodes);
493
- }
494
- const inMsg = (0, Utils_1.normalizeMessageContent)(message) || null;
495
- const key = inMsg ? (0, Utils_1.getContentType)(inMsg) : null;
496
- if (!isNewsletter && (key === 'interactiveMessage' || key === 'buttonsMessage')) {
497
- const nativeNode = {
498
- tag: 'biz',
499
- attrs: {},
500
- content: [{
501
- tag: 'interactive',
450
+
451
+ if (!isNewsletter) {
452
+ if (message?.interactiveMessage?.nativeFlowMessage || message?.buttonsMessage) {
453
+ if (!stanza.content || !Array.isArray(stanza.content)) {
454
+ stanza.content = [];
455
+ }
456
+ if (message?.interactiveMessage?.nativeFlowMessage?.buttons && message.interactiveMessage.nativeFlowMessage.buttons.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0]?.name === "review_and_pay") {
457
+ stanza.content.push({
458
+ tag: 'biz',
502
459
  attrs: {
503
- type: 'native_flow',
504
- v: '1'
505
- },
460
+ native_flow_name: 'order_details'
461
+ }
462
+ })
463
+ } else {
464
+ stanza.content.push({
465
+ tag: 'biz',
466
+ attrs: {},
506
467
  content: [{
468
+ tag: 'interactive',
469
+ attrs: {
470
+ type: 'native_flow',
471
+ v: '1'
472
+ },
473
+ content: [{
507
474
  tag: 'native_flow',
508
- attrs: {
509
- name: 'quick_reply'
510
- }
475
+ attrs: { name: 'quick_reply' }
511
476
  }]
512
- }]
513
- };
514
- const resultNativeNode = filterNativeNode(additionalNodes);
515
- if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
516
- stanza.content.push(...resultNativeNode);
477
+ }]
478
+ })
479
+ }
517
480
  }
518
- else {
519
- stanza.content.push(nativeNode);
481
+
482
+ if (message?.listMessage) {
483
+ if (!stanza.content || !Array.isArray(stanza.content)) {
484
+ stanza.content = [];
485
+ }
486
+ stanza.content.push({
487
+ tag: "biz",
488
+ attrs: {},
489
+ content: [
490
+ {
491
+ tag: "list",
492
+ attrs: {
493
+ v: "2",
494
+ type: "product_list"
495
+ }
496
+ }
497
+ ]
498
+ })
520
499
  }
500
+
501
+ /*if (message?.templateMessage) {
502
+ if (!stanza.content || !Array.isArray(stanza.content)) {
503
+ stanza.content = [];
504
+ }
505
+ stanza.content.push({
506
+ tag: "hsm",
507
+ attrs: {
508
+ category: '',
509
+ tag: 'AUTHENTICATION'
510
+ }
511
+ }, {
512
+ tag: 'biz',
513
+ attrs: {}
514
+ })
515
+ }*/
521
516
  }
522
- if (isPrivate) {
523
- const botNode = {
524
- tag: 'bot',
525
- attrs: { biz_bot: '1' }
526
- };
527
- const resultBotNode = filterBotNode(additionalNodes);
528
- if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
529
- stanza.content.push(...resultBotNode);
530
- }
531
- else {
532
- stanza.content.push(botNode);
517
+
518
+ if (additionalNodes && additionalNodes.length > 0) {
519
+ if (!stanza.content || !Array.isArray(stanza.content)) {
520
+ stanza.content = [];
533
521
  }
522
+ stanza.content.push(...additionalNodes);
534
523
  }
535
- if (message && message.listMessage) {
536
- stanza.content.push({
537
- tag: 'biz',
538
- attrs: {},
539
- content: [
540
- {
541
- tag: 'list',
542
- attrs: getButtonArgs(message)
543
- }
544
- ]
545
- });
546
- logger.debug({ jid }, 'adding business node');
524
+
525
+ if (isPrivate && !additionalNodes) {
526
+ if (!stanza.content || !Array.isArray(stanza.content)) {
527
+ stanza.content = [];
528
+ }
529
+ const botsChat = [ { attrs: { biz_bot: '1' }, tag: 'bot' }]
530
+ stanza.content.push(...botsChat);
547
531
  }
532
+
548
533
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
549
534
  await sendNode(stanza);
550
535
  });
551
536
  return msgId;
552
537
  };
553
- const filterNativeNode = (nodeContent) => {
554
- if (Array.isArray(nodeContent)) {
555
- return nodeContent.filter((item) => {
556
- var _a, _b, _c, _d, _e, _f, _g, _h;
557
- if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
558
- return false;
559
- }
560
- return true;
561
- });
562
- }
563
- else {
564
- return nodeContent;
565
- }
566
- };
567
- const filterBotNode = (nodeContent) => {
568
- if (Array.isArray(nodeContent)) {
569
- return nodeContent.filter((item) => {
570
- if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
571
- return false;
572
- }
573
- return true;
574
- });
575
- }
576
- else {
577
- return nodeContent;
578
- }
579
- };
580
538
  const getTypeMessage = (msg) => {
581
539
  if (msg.viewOnceMessage) {
582
540
  return getTypeMessage(msg.viewOnceMessage.message);
@@ -653,6 +611,23 @@ const makeMessagesSocket = (config) => {
653
611
  return 'url';
654
612
  }
655
613
  };
614
+ const getButtonType = (message) => {
615
+ if (message.buttonsMessage) {
616
+ return 'buttons';
617
+ }
618
+ else if (message.buttonsResponseMessage) {
619
+ return 'buttons_response';
620
+ }
621
+ else if (message.interactiveResponseMessage) {
622
+ return 'interactive_response';
623
+ }
624
+ else if (message.listMessage) {
625
+ return 'list';
626
+ }
627
+ else if (message.listResponseMessage) {
628
+ return 'list_response';
629
+ }
630
+ };
656
631
  const getButtonArgs = (message) => {
657
632
  if (message.templateMessage) {
658
633
  // TODO: Add attributes
@@ -708,9 +683,7 @@ const makeMessagesSocket = (config) => {
708
683
  readMessages,
709
684
  refreshMediaConn,
710
685
  getUSyncDevices,
711
- sendPeerDataOperationMessage,
712
686
  createParticipantNodes,
713
- profilePictureUrl,
714
687
  waUploadToServer,
715
688
  fetchPrivacySettings,
716
689
  updateMediaMessage: async (message) => {
@@ -730,7 +703,7 @@ const makeMessagesSocket = (config) => {
730
703
  else {
731
704
  try {
732
705
  const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
733
- if (media && media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
706
+ if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
734
707
  const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
735
708
  throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
736
709
  }
@@ -914,7 +887,7 @@ const makeMessagesSocket = (config) => {
914
887
  return album;
915
888
  },
916
889
  sendMessage: async (jid, content, options = {}) => {
917
- var _a, _b, _c;
890
+ var _a, _b;
918
891
  const userJid = authState.creds.me.id;
919
892
  if (typeof content === 'object' &&
920
893
  'disappearingMessagesInChat' in content &&
@@ -928,24 +901,9 @@ const makeMessagesSocket = (config) => {
928
901
  }
929
902
  else {
930
903
  let mediaHandle;
931
- const { server } = (0, WABinary_1.jidDecode)(jid);
932
- const isGroup = server === 'g.us';
933
- let eph;
934
- if (isGroup) {
935
- const disappearingNode = await groupQuery(jid, 'get', [
936
- {
937
- tag: 'query',
938
- attrs: { request: 'interactive' }
939
- }
940
- ]);
941
- const group = (0, WABinary_1.getBinaryNodeChild)(disappearingNode, 'group');
942
- const expiration = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral');
943
- eph = (_a = expiration === null || expiration === void 0 ? void 0 : expiration.attrs) === null || _a === void 0 ? void 0 : _a.expiration;
944
- }
945
904
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
946
905
  logger,
947
906
  userJid,
948
- ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
949
907
  getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
950
908
  thumbnailWidth: linkPreviewImageThumbnailWidth,
951
909
  fetchOpts: {
@@ -972,12 +930,16 @@ const makeMessagesSocket = (config) => {
972
930
  const isPollMsg = 'poll' in content && !!content.poll;
973
931
  const isEditMsg = 'edit' in content && !!content.edit;
974
932
  const isDeleteMsg = 'delete' in content && !!content.delete;
933
+ const isButtonsMsg = 'buttons' in content && !!content.buttons;
934
+ const isListMsg = 'sections' in content && !!content.sections;
935
+ const isTemplateButtons = 'templateButtons' in content && !!content.templateButtons;
936
+ const isInteractiveButtons = 'interactiveButtons' in content && !!content.interactiveButtons;
975
937
  const additionalAttributes = {};
976
938
  const additionalNodes = [];
977
939
  // required for delete
978
940
  if (isDeleteMsg) {
979
941
  // if the chat is a group, and I am not the author, then delete the message as an admin
980
- 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)) {
942
+ 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)) {
981
943
  additionalAttributes.edit = '8';
982
944
  }
983
945
  else {
@@ -990,16 +952,27 @@ const makeMessagesSocket = (config) => {
990
952
  else if (isPinMsg) {
991
953
  additionalAttributes.edit = '2';
992
954
  }
955
+ else if (isKeepMsg) {
956
+ additionalAttributes.edit = '6';
957
+ }
958
+ else if (isButtonsMsg) {
959
+ }
960
+ else if (isListMsg) {
961
+ }
962
+ else if (isTemplateButtons) {
963
+ }
964
+ else if (isInteractiveButtons) {
965
+ }
993
966
  else if (isAiMsg) {
994
967
  additionalNodes.push({
995
968
  attrs: {
996
969
  biz_bot: '1'
997
970
  },
998
- tag: 'bot'
971
+ tag: "bot"
972
+ }, {
973
+ attrs: {},
974
+ tag: "biz"
999
975
  });
1000
- if (options.additionalNodes) {
1001
- additionalNodes.push(...options.additionalNodes);
1002
- }
1003
976
  }
1004
977
  if (mediaHandle) {
1005
978
  additionalAttributes['media_id'] = mediaHandle;
@@ -14,7 +14,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
14
14
  newsletterUnmute: (jid: string) => Promise<void>;
15
15
  newsletterMute: (jid: string) => Promise<void>;
16
16
  newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
17
- newsletterCreate: (name: string, description: string) => Promise<NewsletterMetadata>;
17
+ newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<NewsletterMetadata>;
18
18
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
19
19
  newsletterAdminCount: (jid: string) => Promise<number>;
20
20
  /**user is Lid, not Jid */
@@ -125,7 +125,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
125
125
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
126
126
  uploadPreKeys: (count?: number) => Promise<void>;
127
127
  uploadPreKeysToServerIfRequired: () => Promise<void>;
128
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
128
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
129
129
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
130
130
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
131
131
  };