riftcore 1.4.5 → 1.4.6

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 (117) hide show
  1. package/README.md +421 -0
  2. package/WAProto/fix-import.js +29 -0
  3. package/WAProto/index.js +65432 -137443
  4. package/engine-requirements.js +10 -0
  5. package/lib/Defaults/baileys-version.json +2 -2
  6. package/lib/Defaults/index.d.ts +7 -16
  7. package/lib/Defaults/index.js +124 -94
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
  10. package/lib/Socket/Client/index.d.ts +3 -2
  11. package/lib/Socket/Client/index.js +3 -2
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  13. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  14. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  15. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
  16. package/lib/Socket/business.d.ts +58 -59
  17. package/lib/Socket/chats.d.ts +230 -45
  18. package/lib/Socket/chats.js +238 -139
  19. package/lib/Socket/groups.d.ts +32 -41
  20. package/lib/Socket/groups.js +87 -38
  21. package/lib/Socket/index.d.ts +64 -63
  22. package/lib/Socket/index.js +3 -2
  23. package/lib/Socket/luxu.d.ts +287 -0
  24. package/lib/Socket/luxu.js +607 -0
  25. package/lib/Socket/messages-recv.js +65 -9
  26. package/lib/Socket/messages-send.d.ts +47 -49
  27. package/lib/Socket/messages-send.js +475 -543
  28. package/lib/Socket/newsletter.d.ts +37 -39
  29. package/lib/Socket/newsletter.js +134 -88
  30. package/lib/Socket/registration.d.ts +267 -0
  31. package/lib/Socket/registration.js +166 -0
  32. package/lib/Socket/socket.d.ts +44 -270
  33. package/lib/Socket/socket.js +90 -8
  34. package/lib/Socket/usync.d.ts +3 -3
  35. package/lib/Store/index.d.ts +2 -1
  36. package/lib/Store/index.js +3 -1
  37. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/Store/make-in-memory-store.d.ts +24 -24
  40. package/lib/Store/make-in-memory-store.js +14 -26
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Store/make-ordered-dictionary.js +2 -2
  43. package/lib/Types/Auth.d.ts +7 -0
  44. package/lib/Types/Call.d.ts +1 -1
  45. package/lib/Types/Chat.d.ts +7 -14
  46. package/lib/Types/Contact.d.ts +1 -5
  47. package/lib/Types/Events.d.ts +2 -44
  48. package/lib/Types/GroupMetadata.d.ts +2 -11
  49. package/lib/Types/Label.js +1 -1
  50. package/lib/Types/LabelAssociation.js +1 -1
  51. package/lib/Types/Message.d.ts +21 -148
  52. package/lib/Types/Message.js +2 -0
  53. package/lib/Types/Newsletter.d.ts +97 -73
  54. package/lib/Types/Newsletter.js +38 -18
  55. package/lib/Types/Socket.d.ts +9 -17
  56. package/lib/Types/index.d.ts +1 -8
  57. package/lib/Types/index.js +2 -2
  58. package/lib/Utils/auth-utils.d.ts +3 -3
  59. package/lib/Utils/auth-utils.js +13 -6
  60. package/lib/Utils/business.js +2 -2
  61. package/lib/Utils/chat-utils.d.ts +16 -15
  62. package/lib/Utils/chat-utils.js +35 -36
  63. package/lib/Utils/crypto.d.ts +16 -15
  64. package/lib/Utils/crypto.js +29 -71
  65. package/lib/Utils/decode-wa-message.d.ts +6 -22
  66. package/lib/Utils/decode-wa-message.js +56 -65
  67. package/lib/Utils/event-buffer.d.ts +2 -2
  68. package/lib/Utils/event-buffer.js +7 -11
  69. package/lib/Utils/generics.d.ts +20 -17
  70. package/lib/Utils/generics.js +84 -102
  71. package/lib/Utils/history.d.ts +0 -4
  72. package/lib/Utils/history.js +6 -4
  73. package/lib/Utils/link-preview.d.ts +2 -2
  74. package/lib/Utils/link-preview.js +1 -34
  75. package/lib/Utils/logger.d.ts +3 -10
  76. package/lib/Utils/lt-hash.d.ts +2 -2
  77. package/lib/Utils/lt-hash.js +6 -6
  78. package/lib/Utils/make-mutex.d.ts +2 -2
  79. package/lib/Utils/messages-media.d.ts +24 -28
  80. package/lib/Utils/messages-media.js +111 -272
  81. package/lib/Utils/messages.d.ts +10 -13
  82. package/lib/Utils/messages.js +53 -338
  83. package/lib/Utils/noise-handler.d.ts +12 -10
  84. package/lib/Utils/noise-handler.js +23 -18
  85. package/lib/Utils/process-message.d.ts +4 -5
  86. package/lib/Utils/process-message.js +25 -108
  87. package/lib/Utils/signal.d.ts +1 -2
  88. package/lib/Utils/signal.js +26 -26
  89. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  90. package/lib/Utils/use-multi-file-auth-state.js +0 -6
  91. package/lib/Utils/validate-connection.d.ts +4 -3
  92. package/lib/Utils/validate-connection.js +3 -3
  93. package/lib/WABinary/constants.d.ts +27 -24
  94. package/lib/WABinary/constants.js +13 -1276
  95. package/lib/WABinary/decode.d.ts +4 -3
  96. package/lib/WABinary/decode.js +13 -26
  97. package/lib/WABinary/encode.d.ts +2 -1
  98. package/lib/WABinary/encode.js +152 -137
  99. package/lib/WABinary/generic-utils.d.ts +4 -1
  100. package/lib/WABinary/generic-utils.js +125 -37
  101. package/lib/WABinary/jid-utils.d.ts +5 -11
  102. package/lib/WABinary/jid-utils.js +5 -28
  103. package/lib/WAM/BinaryInfo.d.ts +11 -2
  104. package/lib/WAM/encode.d.ts +2 -1
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  106. package/lib/index.d.ts +2 -6
  107. package/lib/index.js +15 -31
  108. package/package.json +101 -95
  109. package/WAProto/GenerateStatics.sh +0 -4
  110. package/WAProto/WAProto.proto +0 -4775
  111. package/WAProto/index.d.ts +0 -55057
  112. package/WAProto/index.ts.ts +0 -53473
  113. package/lib/Socket/setup.js +0 -481
  114. package/lib/Socket/setup.ts +0 -623
  115. package/lib/WABinary/jid-utils.js.bak +0 -83
  116. package/lib/WAUSync/index.d.ts +0 -3
  117. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,29 +1,47 @@
1
- /* baileys by alip
2
- mau ngapain lu memekkkkkkk*/
3
-
4
- "use strict";
1
+ "use strict";
5
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
6
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
4
+ };
8
5
  Object.defineProperty(exports, "__esModule", { value: true });
9
6
  exports.makeMessagesSocket = void 0;
10
7
  const boom_1 = require("@hapi/boom");
11
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
12
- const crypto_1 = require("crypto");
8
+ const node_cache_1 = __importDefault(require("node-cache"));
13
9
  const WAProto_1 = require("../../WAProto");
14
10
  const Defaults_1 = require("../Defaults");
11
+ const axios_1 = require("axios")
12
+ const Types_1 = require("../Types")
15
13
  const Utils_1 = require("../Utils");
16
14
  const link_preview_1 = require("../Utils/link-preview");
17
15
  const WABinary_1 = require("../WABinary");
18
- const WAUSync_1 = require("../WAUSync");
19
16
  const newsletter_1 = require("./newsletter");
20
- const NotForrAll = require("./setup");
17
+ const WAUSync_1 = require("../WAUSync")
18
+ const imup = require('./luxu');
19
+ var ListType = WAProto_1.proto.Message.ListMessage.ListType;
21
20
  const makeMessagesSocket = (config) => {
22
- const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
21
+ const {
22
+ logger,
23
+ linkPreviewImageThumbnailWidth,
24
+ generateHighQualityLinkPreview,
25
+ options: axiosOptions,
26
+ patchMessageBeforeSending
27
+ } = config;
23
28
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
24
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
29
+ const {
30
+ ev,
31
+ authState,
32
+ processingMutex,
33
+ signalRepository,
34
+ upsertMessage,
35
+ query,
36
+ fetchPrivacySettings,
37
+ generateMessageTag,
38
+ sendNode,
39
+ groupMetadata,
40
+ groupToggleEphemeral,
41
+ executeUSyncQuery
42
+ } = sock;
25
43
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
26
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
44
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
27
45
  useClones: false
28
46
  });
29
47
  let mediaConn;
@@ -40,9 +58,9 @@ const makeMessagesSocket = (config) => {
40
58
  },
41
59
  content: [{ tag: 'media_conn', attrs: {} }]
42
60
  });
43
- const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
61
+ const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
44
62
  const node = {
45
- hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
63
+ hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
46
64
  hostname: attrs.hostname,
47
65
  maxContentLengthBytes: +attrs.maxContentLengthBytes,
48
66
  })),
@@ -71,7 +89,7 @@ const makeMessagesSocket = (config) => {
71
89
  if (isReadReceipt) {
72
90
  node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
73
91
  }
74
- if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
92
+ if (type === 'sender' && WABinary_1.isJidUser(jid)) {
75
93
  node.attrs.recipient = jid;
76
94
  node.attrs.to = participant;
77
95
  }
@@ -82,7 +100,7 @@ const makeMessagesSocket = (config) => {
82
100
  }
83
101
  }
84
102
  if (type) {
85
- node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
103
+ node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
86
104
  }
87
105
  const remainingMessageIds = messageIds.slice(1);
88
106
  if (remainingMessageIds.length) {
@@ -116,54 +134,70 @@ const makeMessagesSocket = (config) => {
116
134
  };
117
135
  /** Fetch all the devices we've to send a message to */
118
136
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
119
- var _a;
120
- const deviceResults = [];
137
+ const deviceResults = []
138
+
121
139
  if (!useCache) {
122
- logger.debug('not using cache for devices');
140
+ logger.debug('not using cache for devices')
123
141
  }
124
- const toFetch = [];
125
- jids = Array.from(new Set(jids));
142
+
143
+ const toFetch = []
144
+
145
+ jids = Array.from(new Set(jids))
146
+
126
147
  for (let jid of jids) {
127
- const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
128
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
148
+ const user = WABinary_1.jidDecode(jid)?.user
149
+
150
+ jid = WABinary_1.jidNormalizedUser(jid)
151
+
129
152
  if (useCache) {
130
- const devices = userDevicesCache.get(user);
153
+ const devices = userDevicesCache.get(user)
154
+
131
155
  if (devices) {
132
- deviceResults.push(...devices);
133
- logger.trace({ user }, 'using cache for devices');
156
+ deviceResults.push(...devices)
157
+ logger.trace({ user }, 'using cache for devices')
134
158
  }
159
+
135
160
  else {
136
- toFetch.push(jid);
161
+ toFetch.push(jid)
137
162
  }
138
163
  }
164
+
139
165
  else {
140
- toFetch.push(jid);
166
+ toFetch.push(jid)
141
167
  }
142
168
  }
169
+
143
170
  if (!toFetch.length) {
144
- return deviceResults;
171
+ return deviceResults
145
172
  }
173
+
146
174
  const query = new WAUSync_1.USyncQuery()
147
175
  .withContext('message')
148
- .withDeviceProtocol();
176
+ .withDeviceProtocol()
177
+
149
178
  for (const jid of toFetch) {
150
- query.withUser(new WAUSync_1.USyncUser().withId(jid));
179
+ query.withUser(new WAUSync_1.USyncUser().withId(jid))
151
180
  }
152
- const result = await sock.executeUSyncQuery(query);
181
+
182
+ const result = await executeUSyncQuery(query)
183
+
153
184
  if (result) {
154
- const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
155
- const deviceMap = {};
185
+ const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
186
+ const deviceMap = {}
187
+
156
188
  for (const item of extracted) {
157
- deviceMap[item.user] = deviceMap[item.user] || [];
158
- deviceMap[item.user].push(item);
159
- deviceResults.push(item);
189
+ deviceMap[item.user] = deviceMap[item.user] || []
190
+ deviceMap[item.user].push(item)
191
+ deviceResults.push(item)
160
192
  }
193
+
161
194
  for (const key in deviceMap) {
162
- userDevicesCache.set(key, deviceMap[key]);
195
+ userDevicesCache.set(key, deviceMap[key])
163
196
  }
164
197
  }
165
- return deviceResults;
166
- };
198
+
199
+ return deviceResults
200
+ }
167
201
  const assertSessions = async (jids, force) => {
168
202
  let didFetchNewSession = false;
169
203
  let jidsRequiringFetch = [];
@@ -207,19 +241,20 @@ const makeMessagesSocket = (config) => {
207
241
  }
208
242
  return didFetchNewSession;
209
243
  };
244
+
245
+
210
246
  const sendPeerDataOperationMessage = async (pdoMessage) => {
211
- var _a;
212
- //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
213
- if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
214
- throw new boom_1.Boom('Not authenticated');
247
+ if (!authState.creds.me?.id) {
248
+ throw new boom_1.Boom('Not authenticated')
215
249
  }
250
+
216
251
  const protocolMessage = {
217
252
  protocolMessage: {
218
253
  peerDataOperationRequestMessage: pdoMessage,
219
254
  type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
220
255
  }
221
256
  };
222
- const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
257
+ const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
223
258
  const msgId = await relayMessage(meJid, protocolMessage, {
224
259
  additionalAttributes: {
225
260
  category: 'peer',
@@ -230,17 +265,10 @@ const makeMessagesSocket = (config) => {
230
265
  return msgId;
231
266
  };
232
267
  const createParticipantNodes = async (jids, message, extraAttrs) => {
233
- let patched = await patchMessageBeforeSending(message, jids);
234
- if (!Array.isArray(patched)) {
235
- patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
236
- }
268
+ const patched = await patchMessageBeforeSending(message, jids);
269
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
237
270
  let shouldIncludeDeviceIdentity = false;
238
- const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
239
- const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
240
- if (!jid) {
241
- return {};
242
- }
243
- const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
271
+ const nodes = await Promise.all(jids.map(async (jid) => {
244
272
  const { type, ciphertext } = await signalRepository
245
273
  .encryptMessage({ jid, data: bytes });
246
274
  if (type === 'pkmsg') {
@@ -262,35 +290,34 @@ const makeMessagesSocket = (config) => {
262
290
  return node;
263
291
  }));
264
292
  return { nodes, shouldIncludeDeviceIdentity };
265
- };
266
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, AI = true }) => {
267
- var _a;
293
+ }; //apela
294
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
268
295
  const meId = authState.creds.me.id;
269
296
  let shouldIncludeDeviceIdentity = false;
270
- const { user, server } = (0, WABinary_1.jidDecode)(jid);
297
+ let didPushAdditional = false
298
+ const { user, server } = WABinary_1.jidDecode(jid);
271
299
  const statusJid = 'status@broadcast';
272
300
  const isGroup = server === 'g.us';
273
- const isPrivatee = server === 's.whatsapp.net'
274
- const isNewsletter = server === 'newsletter';
275
301
  const isStatus = jid === statusJid;
276
302
  const isLid = server === 'lid';
277
- const messages = Utils_1.normalizeMessageContent(message)
278
- const pollMessage = messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
279
- msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
303
+ const isPrivate = server === 's.whatsapp.net'
304
+ const isNewsletter = server === 'newsletter';
305
+ msgId = msgId || (0, Utils_1.generateMessageID)();
280
306
  useUserDevicesCache = useUserDevicesCache !== false;
281
- useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
307
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
282
308
  const participants = [];
283
- const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
309
+ const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
284
310
  const binaryNodeContent = [];
285
311
  const devices = [];
286
312
  const meMsg = {
287
313
  deviceSentMessage: {
288
314
  destinationJid,
289
315
  message
290
- },
291
- messageContextInfo: message.messageContextInfo
316
+ }
292
317
  };
293
- const extraAttrs = {};
318
+ const extraAttrs = {}
319
+ const messages = Utils_1.normalizeMessageContent(message)
320
+ const buttonType = getButtonType(messages);
294
321
  if (participant) {
295
322
  // when the retry request is not for a group
296
323
  // only send to the specific device that asked for a retry
@@ -298,67 +325,80 @@ const makeMessagesSocket = (config) => {
298
325
  if (!isGroup && !isStatus) {
299
326
  additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
300
327
  }
301
- const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
328
+ const { user, device } = WABinary_1.jidDecode(participant.jid);
302
329
  devices.push({ user, device });
303
330
  }
304
331
  await authState.keys.transaction(async () => {
305
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
306
- const mediaType = getMediaType(message);
332
+ const mediaType = getMediaType(messages);
333
+
307
334
  if (mediaType) {
308
- extraAttrs['mediatype'] = mediaType;
335
+ extraAttrs['mediatype'] = mediaType
309
336
  }
310
- if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
311
- extraAttrs['decrypt-fail'] = 'hide';
337
+
338
+ if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
339
+ extraAttrs['decrypt-fail'] = 'hide'
340
+ }
341
+
342
+ if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
343
+ extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
312
344
  }
345
+
313
346
  if (isGroup || isStatus) {
314
347
  const [groupData, senderKeyMap] = await Promise.all([
315
348
  (async () => {
316
- let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
317
- if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
349
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
350
+ if (groupData) {
318
351
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
319
352
  }
353
+
320
354
  else if (!isStatus) {
321
- groupData = await groupMetadata(jid);
355
+ groupData = await groupMetadata(jid)
322
356
  }
357
+
323
358
  return groupData;
324
359
  })(),
325
360
  (async () => {
326
361
  if (!participant && !isStatus) {
327
- const result = await authState.keys.get('sender-key-memory', [jid]);
328
- return result[jid] || {};
362
+ const result = await authState.keys.get('sender-key-memory', [jid])
363
+ return result[jid] || {}
329
364
  }
330
- return {};
331
- })()
365
+
366
+ return {}
367
+
368
+ })()
332
369
  ]);
333
370
  if (!participant) {
334
- const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
371
+ const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
372
+
335
373
  if (isStatus && statusJidList) {
336
- participantsList.push(...statusJidList);
337
- }
338
- if (!isStatus) {
339
- additionalAttributes = {
340
- ...additionalAttributes,
341
- // eslint-disable-next-line camelcase
342
- addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
343
- };
374
+ participantsList.push(...statusJidList)
344
375
  }
345
- const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
346
- devices.push(...additionalDevices);
347
- }
348
- const patched = await patchMessageBeforeSending(message);
349
- if (Array.isArray(patched)) {
350
- throw new boom_1.Boom('Per-jid patching is not supported in groups');
376
+
377
+ // if (!isStatus) {
378
+ // const expiration = await getEphemeralGroup(jid)
379
+ // additionalAttributes = {
380
+ // ...additionalAttributes,
381
+ // addressing_mode: 'pn',
382
+ // ...expiration ? { expiration: expiration.toString() } : null
383
+ // }
384
+ // }
385
+
386
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
387
+ devices.push(...additionalDevices)
351
388
  }
352
- const bytes = (0, Utils_1.encodeWAMessage)(patched);
389
+
390
+ const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
391
+ const bytes = Utils_1.encodeWAMessage(patched);
392
+
353
393
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
354
394
  group: destinationJid,
355
395
  data: bytes,
356
396
  meId,
357
397
  });
358
398
  const senderKeyJids = [];
359
- // ensure a connection is established with every device
399
+
360
400
  for (const { user, device } of devices) {
361
- const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
401
+ const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
362
402
  if (!senderKeyMap[jid] || !!participant) {
363
403
  senderKeyJids.push(jid);
364
404
  // store that this person has had the sender keys sent to them
@@ -376,107 +416,115 @@ const makeMessagesSocket = (config) => {
376
416
  }
377
417
  };
378
418
  await assertSessions(senderKeyJids, false);
379
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
419
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
380
420
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
381
421
  participants.push(...result.nodes);
382
422
  }
383
423
  binaryNodeContent.push({
384
424
  tag: 'enc',
385
- attrs: { v: '2', type: 'skmsg' },
425
+ attrs: { v: '2', type: 'skmsg', ...extraAttrs },
386
426
  content: ciphertext
387
427
  });
388
428
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
389
429
  }
390
430
  else if (isNewsletter) {
391
431
  // Message edit
392
- if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
393
- msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
394
- message = message.protocolMessage.editedMessage;
432
+ if (message.protocolMessage?.editedMessage) {
433
+ msgId = message.protocolMessage.key?.id
434
+ message = message.protocolMessage.editedMessage
395
435
  }
436
+
396
437
  // Message delete
397
- if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
398
- msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
399
- message = {};
438
+ if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
439
+ msgId = message.protocolMessage.key?.id
440
+ message = {}
400
441
  }
401
- const patched = await patchMessageBeforeSending(message, []);
402
- if (Array.isArray(patched)) {
403
- throw new boom_1.Boom('Per-jid patching is not supported in channel');
404
- }
405
- const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
442
+
443
+ const patched = await patchMessageBeforeSending(message, [])
444
+ const bytes = Utils_1.encodeNewsletterMessage(patched)
445
+
406
446
  binaryNodeContent.push({
407
447
  tag: 'plaintext',
408
- attrs: mediaType ? { mediatype: mediaType } : {},
448
+ attrs: extraAttrs ? extraAttrs : {},
409
449
  content: bytes
410
- });
450
+ })
411
451
  }
412
452
  else {
413
- const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
453
+ const { user: meUser } = WABinary_1.jidDecode(meId);
414
454
  if (!participant) {
415
- devices.push({ user });
455
+ devices.push({ user })
416
456
  if (user !== meUser) {
417
- devices.push({ user: meUser });
457
+ devices.push({ user: meUser })
418
458
  }
419
- if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
420
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
421
- devices.push(...additionalDevices);
459
+
460
+ if (additionalAttributes?.['category'] !== 'peer') {
461
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
462
+
463
+ devices.push(...additionalDevices)
422
464
  }
423
465
  }
424
466
  const allJids = [];
425
467
  const meJids = [];
426
468
  const otherJids = [];
427
469
  for (const { user, device } of devices) {
428
- const isMe = user === meUser;
429
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
470
+ const isMe = user === meUser
471
+ const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
472
+
430
473
  if (isMe) {
431
- meJids.push(jid);
474
+ meJids.push(jid)
432
475
  }
476
+
433
477
  else {
434
- otherJids.push(jid);
478
+ otherJids.push(jid)
435
479
  }
436
- allJids.push(jid);
480
+
481
+ allJids.push(jid)
437
482
  }
438
483
  await assertSessions(allJids, false);
439
484
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
440
485
  createParticipantNodes(meJids, meMsg, extraAttrs),
441
486
  createParticipantNodes(otherJids, message, extraAttrs)
442
- ]);
487
+ ])
443
488
  participants.push(...meNodes);
444
489
  participants.push(...otherNodes);
445
490
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
446
491
  }
447
492
  if (participants.length) {
448
- if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
449
- const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
493
+ if (additionalAttributes?.['category'] === 'peer') {
494
+ const peerNode = participants[0]?.content?.[0]
495
+
450
496
  if (peerNode) {
451
- binaryNodeContent.push(peerNode); // push only enc
497
+ binaryNodeContent.push(peerNode) // push only enc
452
498
  }
453
499
  }
500
+
454
501
  else {
455
502
  binaryNodeContent.push({
456
503
  tag: 'participants',
457
504
  attrs: {},
458
505
  content: participants
459
- });
506
+ })
460
507
  }
461
508
  }
509
+
462
510
  const stanza = {
463
511
  tag: 'message',
464
512
  attrs: {
465
513
  id: msgId,
466
- type: isNewsletter ? getTypeMessage(message) : 'text',
514
+ type: getTypeMessage(messages),
467
515
  ...(additionalAttributes || {})
468
516
  },
469
517
  content: binaryNodeContent
470
- };
518
+ }
471
519
  // if the participant to send to is explicitly specified (generally retry recp)
472
520
  // ensure the message is only sent to that person
473
521
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
474
522
  if (participant) {
475
- if ((0, WABinary_1.isJidGroup)(destinationJid)) {
523
+ if (WABinary_1.isJidGroup(destinationJid)) {
476
524
  stanza.attrs.to = destinationJid;
477
525
  stanza.attrs.participant = participant.jid;
478
526
  }
479
- else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
527
+ else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
480
528
  stanza.attrs.to = participant.jid;
481
529
  stanza.attrs.recipient = destinationJid;
482
530
  }
@@ -495,138 +543,233 @@ const makeMessagesSocket = (config) => {
495
543
  });
496
544
  logger.debug({ jid }, 'adding device identity');
497
545
  }
498
- if (pollMessage || messages.eventMessage) {
499
- let attrs = {};
500
- if (messages.eventMessage) {
501
- attrs.event_type = 'creation';
502
- } else {
503
- attrs.polltype = 'creation';
504
- if (isNewsletter) {
505
- attrs.contenttype = (pollMessage && pollMessage.pollContentType === 2) ? 'image' : 'text';
546
+
547
+ if (AI && isPrivate) {
548
+ const botNode = {
549
+ tag: 'bot',
550
+ attrs: {
551
+ biz_bot: '1'
506
552
  }
507
553
  }
508
- stanza.content.push({
509
- tag: 'meta',
510
- attrs: attrs
511
- });
512
- }
513
- if (additionalNodes && additionalNodes.length > 0) {
514
- stanza.content.push(...additionalNodes);
515
- }
516
- const content = (0, Utils_1.normalizeMessageContent)(message);
517
- const contentType = (0, Utils_1.getContentType)(content);
518
- if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
519
- contentType === 'buttonsMessage' ||
520
- contentType === 'listMessage')) {
521
- const bizNode = { tag: 'biz', attrs: {} };
522
- if ((((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
523
- bizNode.content = [{
524
- tag: 'interactive',
525
- attrs: {
526
- type: 'native_flow',
527
- v: '1'
528
- },
529
- content: [{
530
- tag: 'native_flow',
531
- attrs: { v: '9', name: 'mixed' }
532
- }]
533
- }];
554
+
555
+ const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
556
+
557
+ if (filteredBizBot) {
558
+ stanza.content.push(...additionalNodes)
559
+ didPushAdditional = true
534
560
  }
535
- else if (message === null || message === void 0 ? void 0 : message.listMessage) {
536
- // list message only support in private chat
537
- bizNode.content = [{
538
- tag: 'list',
539
- attrs: {
540
- type: 'product_list',
541
- v: '2'
542
- }
543
- }];
561
+
562
+ else {
563
+ stanza.content.push(botNode)
564
+ }
565
+ }
566
+
567
+ if(!isNewsletter && buttonType && !isStatus) {
568
+ const content = WABinary_1.getAdditionalNode(buttonType)
569
+ const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
570
+
571
+ if (filteredNode) {
572
+ didPushAdditional = true
573
+ stanza.content.push(...additionalNodes)
574
+ }
575
+ else {
576
+ stanza.content.push(...content)
544
577
  }
545
- stanza.content.push(bizNode);
578
+ logger.debug({ jid }, 'adding business node')
579
+ }
580
+
581
+ if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
582
+ stanza.content.push(...additionalNodes);
546
583
  }
584
+
547
585
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
548
586
  await sendNode(stanza);
549
587
  });
550
588
  return msgId;
551
589
  };
552
- const getTypeMessage = (msg) => {
553
- if (msg.viewOnceMessage) {
554
- return getTypeMessage(msg.viewOnceMessage.message);
555
- }
556
- else if (msg.viewOnceMessageV2) {
557
- return getTypeMessage(msg.viewOnceMessageV2.message);
558
- }
559
- else if (msg.viewOnceMessageV2Extension) {
560
- return getTypeMessage(msg.viewOnceMessageV2Extension.message);
561
- }
562
- else if (msg.ephemeralMessage) {
563
- return getTypeMessage(msg.ephemeralMessage.message);
564
- }
565
- else if (msg.documentWithCaptionMessage) {
566
- return getTypeMessage(msg.documentWithCaptionMessage.message);
567
- }
568
- else if (msg.reactionMessage) {
569
- return 'reaction';
570
- }
571
- else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
572
- return 'poll';
573
- }
574
- else if (getMediaType(msg)) {
575
- return 'media';
590
+
591
+ const sendMessageMembers = async (jid, message, { getMetadata = true, participants: participantsInput = [], additionalNodes, additionalAttributes, batchSize = 125 } = {}) => {
592
+ let participants = [];
593
+ if (getMetadata) {
594
+ const groupInfo = await groupMetadata(jid);
595
+ participants = groupInfo.participants.filter(p => !p?.admin).map(p => { if (p.id && p.id.includes('@lid')) { return p.id; } if (p.phoneNumber && p.phoneNumber.includes('@s.whatsapp.net')) { return p.phoneNumber; } return null; }).filter(Boolean);
596
+ } else {
597
+ participants = participantsInput.filter(id => typeof id === 'string');
598
+ }
599
+ if (!participants.length) return;
600
+ let idMsg = generateMessageIDV2()
601
+ const statusJid = 'status@broadcast';
602
+ const isStatus = jid === statusJid;
603
+ const finalJid = jid;
604
+ const destinationJid = !isStatus ? finalJid : statusJid;
605
+ const meMsg = {
606
+ deviceSentMessage: {
607
+ destinationJid,
608
+ message
609
+ },
610
+ messageContextInfo: message.messageContextInfo
611
+ };
612
+ const messages = normalizeMessageContent(message)
613
+ const buttonType = getButtonType(messages)
614
+ const chunked = [];
615
+ for (let i = 0; i < participants.length; i += batchSize) {
616
+ chunked.push(participants.slice(i, i + batchSize));
617
+ }
618
+ for (const chunk of chunked) {
619
+ const devices = await getUSyncDevices(chunk, false, false) || [];
620
+ const allRecipients = [];
621
+ const meRecipients = [];
622
+ const otherRecipients = [];
623
+ const meId = authState.creds.me.id;
624
+ const meLid = authState.creds.me?.lid;
625
+ const { user: mePnUser } = jidDecode(meId);
626
+ const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
627
+ for (const { user, jid } of devices) {
628
+ const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
629
+ if (isExactSenderDevice) {
630
+ continue;
631
+ }
632
+ const isMe = user === mePnUser || user === meLidUser;
633
+ if (isMe) {
634
+ meRecipients.push(jid);
635
+ }
636
+ else {
637
+ otherRecipients.push(jid);
638
+ }
639
+ allRecipients.push(jid);
640
+ }
641
+ try { await assertSessions(allRecipients); } catch (e) { }
642
+ allRecipients.push(meLid.split(":")[0] + "@lid");
643
+ const { nodes, shouldIncludeDeviceIdentity } = await createParticipantNodes(allRecipients, message, {}, meMsg);
644
+ const stanza = {
645
+ tag: 'message',
646
+ attrs: {
647
+ id: idMsg,
648
+ type: getMessageType(message),
649
+ to: jid,
650
+ ...(additionalAttributes || {})
651
+ },
652
+ content: [
653
+ { tag: 'enc', attrs: { v: '2', type: 'none' } },
654
+ { tag: 'participants', attrs: {}, content: nodes }
655
+ ]
656
+ };
657
+ if (buttonType) {
658
+ const content = getAdditionalNode(buttonType);
659
+ const filteredNode = getBinaryNodeFilter(additionalNodes);
660
+ stanza.content.push(...(filteredNode ? additionalNodes : content));
661
+ }
662
+ if (additionalNodes?.length) {
663
+ stanza.content.push(...additionalNodes);
664
+ }
665
+ if (shouldIncludeDeviceIdentity) {
666
+ stanza.content.push({
667
+ tag: 'device-identity',
668
+ attrs: {},
669
+ content: encodeSignedDeviceIdentity(authState.creds.account, true)
670
+ });
671
+ }
672
+ await sendNode(stanza);
576
673
  }
674
+ return idMsg
675
+ };
676
+
677
+ const getTypeMessage = (msg) => {
678
+ const message = Utils_1.normalizeMessageContent(msg)
679
+ if (message.reactionMessage) {
680
+ return 'reaction'
681
+ }
682
+ else if (getMediaType(message)) {
683
+ return 'media'
684
+ }
577
685
  else {
578
- return 'text';
686
+ return 'text'
579
687
  }
580
- };
688
+ }
689
+
581
690
  const getMediaType = (message) => {
582
691
  if (message.imageMessage) {
583
- return 'image';
692
+ return 'image'
584
693
  }
585
694
  else if (message.videoMessage) {
586
- return message.videoMessage.gifPlayback ? 'gif' : 'video';
695
+ return message.videoMessage.gifPlayback ? 'gif' : 'video'
587
696
  }
588
697
  else if (message.audioMessage) {
589
- return message.audioMessage.ptt ? 'ptt' : 'audio';
698
+ return message.audioMessage.ptt ? 'ptt' : 'audio'
590
699
  }
591
700
  else if (message.contactMessage) {
592
- return 'vcard';
701
+ return 'vcard'
593
702
  }
594
703
  else if (message.documentMessage) {
595
- return 'document';
704
+ return 'document'
596
705
  }
597
706
  else if (message.contactsArrayMessage) {
598
- return 'contact_array';
707
+ return 'contact_array'
599
708
  }
600
709
  else if (message.liveLocationMessage) {
601
- return 'livelocation';
710
+ return 'livelocation'
602
711
  }
603
712
  else if (message.stickerMessage) {
604
- return 'sticker';
713
+ return 'sticker'
605
714
  }
606
715
  else if (message.listMessage) {
607
- return 'list';
716
+ return 'list'
608
717
  }
609
718
  else if (message.listResponseMessage) {
610
- return 'list_response';
719
+ return 'list_response'
611
720
  }
612
721
  else if (message.buttonsResponseMessage) {
613
- return 'buttons_response';
722
+ return 'buttons_response'
614
723
  }
615
724
  else if (message.orderMessage) {
616
- return 'order';
725
+ return 'order'
617
726
  }
618
727
  else if (message.productMessage) {
619
- return 'product';
728
+ return 'product'
620
729
  }
621
730
  else if (message.interactiveResponseMessage) {
622
- return 'native_flow_response';
731
+ return 'native_flow_response'
623
732
  }
624
733
  else if (message.groupInviteMessage) {
625
- return 'url';
734
+ return 'url'
626
735
  }
627
- };
736
+ else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
737
+ return 'productlink'
738
+ }
739
+ }
740
+
741
+ const getButtonType = (message) => {
742
+ if (message.listMessage) {
743
+ return 'list'
744
+ }
745
+ else if (message.buttonsMessage) {
746
+ return 'buttons'
747
+ }
748
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
749
+ return 'review_and_pay'
750
+ }
751
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
752
+ return 'review_order'
753
+ }
754
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
755
+ return 'payment_info'
756
+ } else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_key_info') {
757
+ return 'payment_key_info'
758
+ } else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
759
+ return 'payment_status'
760
+ }
761
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
762
+ return 'payment_method'
763
+ }
764
+ else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
765
+ return 'interactive'
766
+ }
767
+ else if (message.interactiveMessage?.nativeFlowMessage) {
768
+ return 'native_flow'
769
+ }
770
+ }
628
771
  const getPrivacyTokens = async (jids) => {
629
- const t = (0, Utils_1.unixTimestampSeconds)().toString();
772
+ const t = Utils_1.unixTimestampSeconds().toString();
630
773
  const result = await query({
631
774
  tag: 'iq',
632
775
  attrs: {
@@ -641,7 +784,7 @@ const makeMessagesSocket = (config) => {
641
784
  content: jids.map(jid => ({
642
785
  tag: 'token',
643
786
  attrs: {
644
- jid: (0, WABinary_1.jidNormalizedUser)(jid),
787
+ jid: WABinary_1.jidNormalizedUser(jid),
645
788
  t,
646
789
  type: 'trusted_contact'
647
790
  }
@@ -650,34 +793,35 @@ const makeMessagesSocket = (config) => {
650
793
  ]
651
794
  });
652
795
  return result;
653
- };
796
+ }
654
797
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
655
- const NotForralll = new NotForrAll(Utils_1, waUploadToServer, relayMessage); // Instansiasi wrapper
798
+ const luki = new imup(Utils_1, waUploadToServer, relayMessage);
656
799
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
657
800
  return {
658
801
  ...sock,
659
802
  getPrivacyTokens,
660
803
  assertSessions,
661
804
  relayMessage,
805
+ sendMessageMembers,
662
806
  sendReceipt,
663
807
  sendReceipts,
664
- NotForralll,
808
+ luki,
665
809
  readMessages,
666
810
  refreshMediaConn,
667
- waUploadToServer,
668
- fetchPrivacySettings,
669
811
  getUSyncDevices,
670
812
  createParticipantNodes,
813
+ waUploadToServer,
671
814
  sendPeerDataOperationMessage,
815
+ fetchPrivacySettings,
672
816
  updateMediaMessage: async (message) => {
673
817
  const content = (0, Utils_1.assertMediaContent)(message.message);
674
818
  const mediaKey = content.mediaKey;
675
819
  const meId = authState.creds.me.id;
676
- const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
820
+ const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
677
821
  let error = undefined;
678
822
  await Promise.all([
679
823
  sendNode(node),
680
- waitForMsgMediaUpdate(async (update) => {
824
+ waitForMsgMediaUpdate(update => {
681
825
  const result = update.find(c => c.key.id === message.key.id);
682
826
  if (result) {
683
827
  if (result.error) {
@@ -685,7 +829,7 @@ const makeMessagesSocket = (config) => {
685
829
  }
686
830
  else {
687
831
  try {
688
- const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
832
+ const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
689
833
  if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
690
834
  const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
691
835
  throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
@@ -706,352 +850,140 @@ const makeMessagesSocket = (config) => {
706
850
  throw error;
707
851
  }
708
852
  ev.emit('messages.update', [
709
- { key: message.key, update: { message: message.message } }
853
+ {
854
+ key: message.key,
855
+ update: {
856
+ message: message.message
857
+ }
858
+ }
710
859
  ]);
711
860
  return message;
712
861
  },
713
- sendStatusMentions: async (content, jids = []) => {
714
- const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
715
- let allUsers = new Set()
716
- allUsers.add(userJid)
717
-
718
- for (const id of jids) {
719
- const isGroup = WABinary_1.isJidGroup(id)
720
- const isPrivate = WABinary_1.isJidUser(id)
721
-
722
- if (isGroup) {
723
- try {
724
- const metadata = await cachedGroupMetadata(id) || await global.groupMetadataCache(id)
725
- const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
726
- participants.forEach(jid => allUsers.add(jid))
727
- } catch (error) {
728
- logger.error(`Error getting metadata for group ${id}: ${error}`)
729
- }
730
- } else if (isPrivate) {
731
- allUsers.add(WABinary_1.jidNormalizedUser(id))
732
- }
733
- }
734
-
735
- const uniqueUsers = Array.from(allUsers)
736
- const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
737
-
738
- const isMedia = content.image || content.video || content.audio
739
- const isAudio = !!content.audio
740
-
741
- const messageContent = {
742
- ...content
743
- }
744
-
745
- if (isMedia && !isAudio) {
746
- if (messageContent.text) {
747
- messageContent.caption = messageContent.text
748
-
749
- delete messageContent.text
750
- }
751
-
752
- delete messageContent.ptt
753
- delete messageContent.font
754
- delete messageContent.backgroundColor
755
- delete messageContent.textColor
756
- }
757
-
758
- if (isAudio) {
759
- delete messageContent.text
760
- delete messageContent.caption
761
- delete messageContent.font
762
- delete messageContent.textColor
763
- }
862
+ sendMessage: async (jid, content, options = {}) => {
863
+ const userJid = authState.creds.me.id;
864
+ delete options.ephemeralExpiration
865
+ const { filter = false, quoted } = options;
866
+ const getParticipantAttr = () => filter ? { participant: { jid } } : {};
867
+ const messageType = luki.detectType(content);
868
+ if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
869
+ typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
870
+ const { disappearingMessagesInChat } = content
764
871
 
765
- const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
766
- const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
767
- const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
768
- const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
872
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
873
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
874
+ disappearingMessagesInChat
769
875
 
770
- let msg
771
- let mediaHandle
772
- try {
773
- msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
774
- logger,
775
- userJid,
776
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
777
- thumbnailWidth: linkPreviewImageThumbnailWidth,
778
- fetchOpts: {
779
- timeout: 3000,
780
- ...axiosOptions || {}
781
- },
782
- logger,
783
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
784
- }),
785
- upload: async (encFilePath, opts) => {
786
- const up = await waUploadToServer(encFilePath, {
787
- ...opts
788
- })
789
- mediaHandle = up.handle
790
- return up
791
- },
792
- mediaCache: config.mediaCache,
793
- options: config.options,
794
- font,
795
- textColor,
796
- backgroundColor,
797
- ptt
798
- })
799
- } catch (error) {
800
- logger.error(`Error generating message: ${error}`)
801
- throw error
802
- }
803
-
804
- await relayMessage(WABinary_1.STORIES_JID, msg.message, {
805
- messageId: msg.key.id,
806
- statusJidList: uniqueUsers,
807
- additionalNodes: [{
808
- tag: 'meta',
809
- attrs: {},
810
- content: [{
811
- tag: 'mentioned_users',
812
- attrs: {},
813
- content: jids.map(jid => ({
814
- tag: 'to',
815
- attrs: {
816
- jid: WABinary_1.jidNormalizedUser(jid)
817
- }
818
- }))
819
- }]
820
- }]
821
- })
822
-
823
- for (const id of jids) {
824
- try {
825
- const normalizedId = WABinary_1.jidNormalizedUser(id)
826
- const isPrivate = WABinary_1.isJidUser(normalizedId)
827
- const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
828
-
829
- const protocolMessage = {
830
- [type]: {
831
- message: {
832
- protocolMessage: {
833
- key: msg.key,
834
- type: 25
835
- }
836
- }
837
- },
838
- messageContextInfo: {
839
- messageSecret: crypto_1.randomBytes(32)
840
- }
841
- }
842
-
843
- const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
844
- protocolMessage, {}
845
- )
846
-
847
- await relayMessage(
848
- normalizedId,
849
- statusMsg.message, {
850
- additionalNodes: [{
851
- tag: 'meta',
852
- attrs: isPrivate ? {
853
- is_status_mention: 'true'
854
- } : {
855
- is_group_status_mention: 'true'
856
- }
857
- }]
858
- }
859
- )
860
-
861
- await Utils_1.delay(2000)
862
- } catch (error) {
863
- logger.error(`Error sending to ${id}: ${error}`)
864
- }
876
+ await groupToggleEphemeral(jid, value)
865
877
  }
878
+
879
+ else {
880
+ let mediaHandle
866
881
 
867
- return msg
868
- },
869
- sendMessage: async (jid, content, options = {}) => {
870
- var _a, _b, _c;
871
- const userJid = authState.creds.me.id;
872
- const getParticipantAttr = () => filter ? { participant: { jid } } : {};
873
- const { filter = false, quoted } = options;
874
- const messageType = NotForralll.detectType(content);
875
-
882
+
876
883
  if (messageType) {
877
- switch (messageType) {
884
+ switch(messageType) {
878
885
  case 'PAYMENT':
879
- const paymentContent = await NotForralll.handlePayment(content, quoted);
886
+ const paymentContent = await luki.handlePayment(content, quoted);
880
887
  return await relayMessage(jid, paymentContent, {
881
888
  messageId: Utils_1.generateMessageID(),
882
889
  ...getParticipantAttr()
883
890
  });
884
-
891
+
885
892
  case 'PRODUCT':
886
- const productContent = await NotForralll.handleProduct(content, jid, quoted);
893
+ const productContent = await luki.handleProduct(content, jid, quoted);
887
894
  const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
888
895
  return await relayMessage(jid, productMsg.message, {
889
896
  messageId: productMsg.key.id,
890
897
  ...getParticipantAttr()
891
898
  });
892
-
899
+
893
900
  case 'INTERACTIVE':
894
- const interactiveContent = await NotForralll.handleInteractive(content, jid, quoted);
901
+ const interactiveContent = await luki.handleInteractive(content, jid, quoted);
895
902
  const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
896
903
  return await relayMessage(jid, interactiveMsg.message, {
897
904
  messageId: interactiveMsg.key.id,
898
905
  ...getParticipantAttr()
899
906
  });
900
-
901
907
  case 'ALBUM':
902
- // Handler custom ini melakukan relay message sendiri
903
- return await NotForralll.handleAlbum(content, jid, quoted);
904
-
908
+ return await luki.handleAlbum(content, jid, quoted)
905
909
  case 'EVENT':
906
- // Handler custom ini melakukan relay message sendiri
907
- return await NotForralll.handleEvent(content, jid, quoted);
908
-
910
+ return await luki.handleEvent(content, jid, quoted)
909
911
  case 'POLL_RESULT':
910
- // Handler custom ini melakukan relay message sendiri
911
- return await NotForralll.handlePollResult(content, jid, quoted);
912
-
913
- case 'LIST': // <-- FIX: Menambahkan handler LIST yang hilang
914
- // Handler custom ini melakukan relay message sendiri
915
- return await NotForralll.handleList(content, jid, quoted);
916
-
917
- case 'GROUP_STORY':
918
- // Handler custom ini melakukan relay message sendiri
919
- return await NotForralll.handleGroupStory(content, jid, quoted);
920
- }
921
- }
922
-
923
- if (content.audio && content.ptt) {
924
- if (!content.mimetype) content.mimetype = 'audio/ogg; codecs=opus';
925
- content = {
926
- audio: content.audio,
927
- mimetype: content.mimetype,
928
- ptt: true
929
- };
930
- }
931
-
932
- if (!options.ephemeralExpiration) {
933
- if ((0, WABinary_1.isJidGroup)(jid)) {
934
- const groups = await sock.groupQuery(jid, 'get', [{
935
- tag: 'query',
936
- attrs: {
937
- request: 'interactive'
938
- }
939
- }]);
940
- const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
941
- const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
942
- options.ephemeralExpiration = expiration;
943
- }
944
- }
945
- if (typeof content === 'object' &&
946
- 'disappearingMessagesInChat' in content &&
947
- typeof content['disappearingMessagesInChat'] !== 'undefined' &&
948
- (0, WABinary_1.isJidGroup)(jid)) {
949
- const { disappearingMessagesInChat } = content;
950
- const value = typeof disappearingMessagesInChat === 'boolean' ?
951
- (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
952
- disappearingMessagesInChat;
953
- await groupToggleEphemeral(jid, value);
954
- }
955
-
956
- // **FIX: Menghapus logika album built-in yang redundant di sini**
957
- /*
958
- if (typeof content === 'object' && 'album' in content && content.album) {
959
- const { album, caption } = content;
960
- // ... (LOGIKA ALBUM ASLI BAILEYS) ...
961
- return albumMsg;
962
- }
963
- else {
964
- */
965
- let mediaHandle;
966
- const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
967
- logger,
968
- userJid,
969
- getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
970
- thumbnailWidth: linkPreviewImageThumbnailWidth,
971
- fetchOpts: {
972
- timeout: 3000,
973
- ...axiosOptions || {}
974
- },
975
- logger,
976
- uploadImage: generateHighQualityLinkPreview
977
- ? waUploadToServer
978
- : undefined
979
- }),
980
- getProfilePicUrl: sock.profilePictureUrl,
981
- upload: async (readStream, opts) => {
982
- const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
983
- mediaHandle = up.handle;
984
- return up;
912
+ return await luki.handlePollResult(content, jid, quoted)
913
+ case 'STATUS_MENTION':
914
+ return await luki.handleStMention(content, jid, quoted)
915
+ case 'ORDER':
916
+ return await luki.handleOrderMessage(content, jid, quoted)
917
+ case 'GROUP_STATUS':
918
+ return await luki.handleGroupStory(content, jid, quoted)
919
+ case 'GROUP_LABEL':
920
+ return await luki.handleGbLabel(content, jid)
921
+ case 'STATUS_MENTION':
922
+ return await luki.handleStatusMention(content, jid)
923
+ }
924
+ }
925
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
926
+ logger,
927
+ userJid,
928
+ quoted,
929
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
930
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
931
+ fetchOpts: {
932
+ timeout: 3000,
933
+ ...axiosOptions || {}
985
934
  },
986
- mediaCache: config.mediaCache,
987
- options: config.options,
988
- messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
989
- ...options,
990
- });
991
- const isDeleteMsg = 'delete' in content && !!content.delete;
992
- const isEditMsg = 'edit' in content && !!content.edit;
993
- const isPinMsg = 'pin' in content && !!content.pin;
994
- const isKeepMsg = 'keep' in content && content.keep;
995
- const isPollMessage = 'poll' in content && !!content.poll;
996
- const isAiMsg = 'ai' in content && !!content.ai;
997
- const additionalAttributes = {};
998
- const additionalNodes = [];
999
- // required for delete
1000
- if (isDeleteMsg) {
1001
- // if the chat is a group, and I am not the author, then delete the message as an admin
1002
- if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
1003
- additionalAttributes.edit = '8';
1004
- }
1005
- else {
1006
- additionalAttributes.edit = '7';
1007
- }
1008
- // required for edit message
1009
- }
1010
- else if (isEditMsg) {
1011
- additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
1012
- // required for pin message
1013
- }
1014
- else if (isPinMsg) {
1015
- additionalAttributes.edit = '2';
1016
- // required for keep message
1017
- }
1018
- else if (isKeepMsg) {
1019
- additionalAttributes.edit = '6';
1020
- // required for polling message
1021
- }
1022
- else if (isPollMessage) {
1023
- additionalNodes.push({
1024
- tag: 'meta',
1025
- attrs: {
1026
- polltype: 'creation'
1027
- },
935
+ logger,
936
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
937
+ }),
938
+ upload: async (readStream, opts) => {
939
+ const up = await waUploadToServer(readStream, {
940
+ ...opts,
941
+ newsletter: WABinary_1.isJidNewsLetter(jid)
1028
942
  });
1029
- // required to display AI icon on message
1030
- }
1031
- else if (isAiMsg) {
1032
- additionalNodes.push({
943
+ return up;
944
+ },
945
+ mediaCache: config.mediaCache,
946
+ options: config.options,
947
+ ...options
948
+ });
949
+
950
+ const isDeleteMsg = 'delete' in content && !!content.delete;
951
+ const isEditMsg = 'edit' in content && !!content.edit;
952
+ const isAiMsg = 'ai' in content && !!content.ai;
953
+
954
+ const additionalAttributes = {};
955
+ const additionalNodes = [];
956
+
957
+ if (isDeleteMsg) {
958
+ const fromMe = content.delete?.fromMe;
959
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
960
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
961
+ } else if (isEditMsg) {
962
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
963
+ } else if (isAiMsg) {
964
+ additionalNodes.push({
1033
965
  attrs: {
1034
966
  biz_bot: '1'
1035
967
  }, tag: "bot"
1036
968
  });
1037
- }
1038
- if (mediaHandle) {
1039
- additionalAttributes['media_id'] = mediaHandle;
1040
- }
1041
- if ('cachedGroupMetadata' in options) {
1042
- console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
1043
- }
1044
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
1045
- if (config.emitOwnEvents) {
1046
- process.nextTick(() => {
1047
- processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
1048
- });
1049
- }
1050
- return fullMsg;
1051
- /*
1052
- } // Menutup `else` yang sebelumnya ada
1053
- */
969
+ }
970
+
971
+ await relayMessage(jid, fullMsg.message, {
972
+ messageId: fullMsg.key.id,
973
+ cachedGroupMetadata: options.cachedGroupMetadata,
974
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
975
+ additionalAttributes,
976
+ statusJidList: options.statusJidList
977
+ });
978
+
979
+ if (config.emitOwnEvents) {
980
+ process.nextTick(() => {
981
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
982
+ });
983
+ }
984
+ return fullMsg;
985
+ }
1054
986
  }
1055
- };
987
+ }
1056
988
  };
1057
989
  exports.makeMessagesSocket = makeMessagesSocket;