riftcore 1.4.6 → 1.4.7

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.
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
@@ -9,13 +9,11 @@ const node_cache_1 = __importDefault(require("node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const axios_1 = require("axios")
12
- const Types_1 = require("../Types")
13
12
  const Utils_1 = require("../Utils");
14
13
  const link_preview_1 = require("../Utils/link-preview");
15
14
  const WABinary_1 = require("../WABinary");
16
15
  const newsletter_1 = require("./newsletter");
17
- const WAUSync_1 = require("../WAUSync")
18
- const imup = require('./luxu');
16
+ const erlangga = require('./erlanggaofficial');
19
17
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
20
18
  const makeMessagesSocket = (config) => {
21
19
  const {
@@ -37,8 +35,7 @@ const makeMessagesSocket = (config) => {
37
35
  generateMessageTag,
38
36
  sendNode,
39
37
  groupMetadata,
40
- groupToggleEphemeral,
41
- executeUSyncQuery
38
+ groupToggleEphemeral
42
39
  } = sock;
43
40
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
44
41
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
@@ -58,9 +55,9 @@ const makeMessagesSocket = (config) => {
58
55
  },
59
56
  content: [{ tag: 'media_conn', attrs: {} }]
60
57
  });
61
- const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
58
+ const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
62
59
  const node = {
63
- hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
60
+ hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
64
61
  hostname: attrs.hostname,
65
62
  maxContentLengthBytes: +attrs.maxContentLengthBytes,
66
63
  })),
@@ -89,7 +86,7 @@ const makeMessagesSocket = (config) => {
89
86
  if (isReadReceipt) {
90
87
  node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
91
88
  }
92
- if (type === 'sender' && WABinary_1.isJidUser(jid)) {
89
+ if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
93
90
  node.attrs.recipient = jid;
94
91
  node.attrs.to = participant;
95
92
  }
@@ -100,7 +97,7 @@ const makeMessagesSocket = (config) => {
100
97
  }
101
98
  }
102
99
  if (type) {
103
- node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
100
+ node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
104
101
  }
105
102
  const remainingMessageIds = messageIds.slice(1);
106
103
  if (remainingMessageIds.length) {
@@ -134,70 +131,74 @@ const makeMessagesSocket = (config) => {
134
131
  };
135
132
  /** Fetch all the devices we've to send a message to */
136
133
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
137
- const deviceResults = []
138
-
134
+ var _a;
135
+ const deviceResults = [];
139
136
  if (!useCache) {
140
- logger.debug('not using cache for devices')
137
+ logger.debug('not using cache for devices');
141
138
  }
142
-
143
- const toFetch = []
144
-
145
- jids = Array.from(new Set(jids))
146
-
139
+ const users = [];
140
+ jids = Array.from(new Set(jids));
147
141
  for (let jid of jids) {
148
- const user = WABinary_1.jidDecode(jid)?.user
149
-
150
- jid = WABinary_1.jidNormalizedUser(jid)
151
-
152
- if (useCache) {
153
- const devices = userDevicesCache.get(user)
154
-
155
- if (devices) {
156
- deviceResults.push(...devices)
157
- logger.trace({ user }, 'using cache for devices')
158
- }
159
-
160
- else {
161
- toFetch.push(jid)
162
- }
142
+ const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
143
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
144
+ const devices = userDevicesCache.get(user);
145
+ if (devices && useCache) {
146
+ deviceResults.push(...devices);
147
+ logger.trace({ user }, 'using cache for devices');
163
148
  }
164
-
165
149
  else {
166
- toFetch.push(jid)
150
+ users.push({ tag: 'user', attrs: { jid } });
167
151
  }
168
152
  }
169
-
170
- if (!toFetch.length) {
171
- return deviceResults
172
- }
173
-
174
- const query = new WAUSync_1.USyncQuery()
175
- .withContext('message')
176
- .withDeviceProtocol()
177
-
178
- for (const jid of toFetch) {
179
- query.withUser(new WAUSync_1.USyncUser().withId(jid))
180
- }
181
-
182
- const result = await executeUSyncQuery(query)
183
-
184
- if (result) {
185
- const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
186
- const deviceMap = {}
187
-
188
- for (const item of extracted) {
189
- deviceMap[item.user] = deviceMap[item.user] || []
190
- deviceMap[item.user].push(item)
191
- deviceResults.push(item)
192
- }
193
-
194
- for (const key in deviceMap) {
195
- userDevicesCache.set(key, deviceMap[key])
196
- }
153
+ if (!users.length) {
154
+ return deviceResults;
197
155
  }
198
-
199
- return deviceResults
200
- }
156
+ const iq = {
157
+ tag: 'iq',
158
+ attrs: {
159
+ to: WABinary_1.S_WHATSAPP_NET,
160
+ type: 'get',
161
+ xmlns: 'usync',
162
+ },
163
+ content: [
164
+ {
165
+ tag: 'usync',
166
+ attrs: {
167
+ sid: generateMessageTag(),
168
+ mode: 'query',
169
+ last: 'true',
170
+ index: '0',
171
+ context: 'message',
172
+ },
173
+ content: [
174
+ {
175
+ tag: 'query',
176
+ attrs: {},
177
+ content: [
178
+ {
179
+ tag: 'devices',
180
+ attrs: { version: '2' }
181
+ }
182
+ ]
183
+ },
184
+ { tag: 'list', attrs: {}, content: users }
185
+ ]
186
+ },
187
+ ],
188
+ };
189
+ const result = await query(iq);
190
+ const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
191
+ const deviceMap = {};
192
+ for (const item of extracted) {
193
+ deviceMap[item.user] = deviceMap[item.user] || [];
194
+ deviceMap[item.user].push(item);
195
+ deviceResults.push(item);
196
+ }
197
+ for (const key in deviceMap) {
198
+ userDevicesCache.set(key, deviceMap[key]);
199
+ }
200
+ return deviceResults;
201
+ };
201
202
  const assertSessions = async (jids, force) => {
202
203
  let didFetchNewSession = false;
203
204
  let jidsRequiringFetch = [];
@@ -241,29 +242,6 @@ const makeMessagesSocket = (config) => {
241
242
  }
242
243
  return didFetchNewSession;
243
244
  };
244
-
245
-
246
- const sendPeerDataOperationMessage = async (pdoMessage) => {
247
- if (!authState.creds.me?.id) {
248
- throw new boom_1.Boom('Not authenticated')
249
- }
250
-
251
- const protocolMessage = {
252
- protocolMessage: {
253
- peerDataOperationRequestMessage: pdoMessage,
254
- type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
255
- }
256
- };
257
- const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
258
- const msgId = await relayMessage(meJid, protocolMessage, {
259
- additionalAttributes: {
260
- category: 'peer',
261
- // eslint-disable-next-line camelcase
262
- push_priority: 'high_force',
263
- },
264
- });
265
- return msgId;
266
- };
267
245
  const createParticipantNodes = async (jids, message, extraAttrs) => {
268
246
  const patched = await patchMessageBeforeSending(message, jids);
269
247
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
@@ -291,11 +269,11 @@ const makeMessagesSocket = (config) => {
291
269
  }));
292
270
  return { nodes, shouldIncludeDeviceIdentity };
293
271
  }; //apela
294
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
272
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList, AI = true }) => {
295
273
  const meId = authState.creds.me.id;
296
274
  let shouldIncludeDeviceIdentity = false;
297
275
  let didPushAdditional = false
298
- const { user, server } = WABinary_1.jidDecode(jid);
276
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
299
277
  const statusJid = 'status@broadcast';
300
278
  const isGroup = server === 'g.us';
301
279
  const isStatus = jid === statusJid;
@@ -304,9 +282,8 @@ const makeMessagesSocket = (config) => {
304
282
  const isNewsletter = server === 'newsletter';
305
283
  msgId = msgId || (0, Utils_1.generateMessageID)();
306
284
  useUserDevicesCache = useUserDevicesCache !== false;
307
- useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
308
285
  const participants = [];
309
- const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
286
+ const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
310
287
  const binaryNodeContent = [];
311
288
  const devices = [];
312
289
  const meMsg = {
@@ -315,9 +292,6 @@ const makeMessagesSocket = (config) => {
315
292
  message
316
293
  }
317
294
  };
318
- const extraAttrs = {}
319
- const messages = Utils_1.normalizeMessageContent(message)
320
- const buttonType = getButtonType(messages);
321
295
  if (participant) {
322
296
  // when the retry request is not for a group
323
297
  // only send to the specific device that asked for a retry
@@ -325,80 +299,51 @@ const makeMessagesSocket = (config) => {
325
299
  if (!isGroup && !isStatus) {
326
300
  additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
327
301
  }
328
- const { user, device } = WABinary_1.jidDecode(participant.jid);
302
+ const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
329
303
  devices.push({ user, device });
330
304
  }
331
305
  await authState.keys.transaction(async () => {
332
- const mediaType = getMediaType(messages);
333
-
334
- if (mediaType) {
335
- extraAttrs['mediatype'] = mediaType
336
- }
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
344
- }
345
-
306
+ var _a, _b, _c, _d, _e, _f;
307
+ const mediaType = getMediaType(message);
346
308
  if (isGroup || isStatus) {
347
309
  const [groupData, senderKeyMap] = await Promise.all([
348
310
  (async () => {
349
- let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
311
+ let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
350
312
  if (groupData) {
351
313
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
352
314
  }
353
-
354
- else if (!isStatus) {
355
- groupData = await groupMetadata(jid)
315
+ if (!groupData && !isStatus) {
316
+ groupData = await groupMetadata(jid);
356
317
  }
357
-
358
318
  return groupData;
359
319
  })(),
360
320
  (async () => {
361
321
  if (!participant && !isStatus) {
362
- const result = await authState.keys.get('sender-key-memory', [jid])
363
- return result[jid] || {}
322
+ const result = await authState.keys.get('sender-key-memory', [jid]);
323
+ return result[jid] || {};
364
324
  }
365
-
366
- return {}
367
-
368
- })()
325
+ return {};
326
+ })()
369
327
  ]);
370
328
  if (!participant) {
371
- const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
372
-
329
+ const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
373
330
  if (isStatus && statusJidList) {
374
- participantsList.push(...statusJidList)
331
+ participantsList.push(...statusJidList);
375
332
  }
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)
333
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
334
+ devices.push(...additionalDevices);
388
335
  }
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
-
336
+ const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
337
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
393
338
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
394
339
  group: destinationJid,
395
340
  data: bytes,
396
341
  meId,
397
342
  });
398
343
  const senderKeyJids = [];
399
-
344
+ // ensure a connection is established with every device
400
345
  for (const { user, device } of devices) {
401
- const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
346
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
402
347
  if (!senderKeyMap[jid] || !!participant) {
403
348
  senderKeyJids.push(jid);
404
349
  // store that this person has had the sender keys sent to them
@@ -416,115 +361,95 @@ const makeMessagesSocket = (config) => {
416
361
  }
417
362
  };
418
363
  await assertSessions(senderKeyJids, false);
419
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
364
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
420
365
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
421
366
  participants.push(...result.nodes);
422
367
  }
423
368
  binaryNodeContent.push({
424
369
  tag: 'enc',
425
- attrs: { v: '2', type: 'skmsg', ...extraAttrs },
370
+ attrs: { v: '2', type: 'skmsg' },
426
371
  content: ciphertext
427
372
  });
428
373
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
429
374
  }
430
375
  else if (isNewsletter) {
431
376
  // Message edit
432
- if (message.protocolMessage?.editedMessage) {
433
- msgId = message.protocolMessage.key?.id
434
- message = message.protocolMessage.editedMessage
377
+ if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
378
+ msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
379
+ message = message.protocolMessage.editedMessage;
435
380
  }
436
-
437
381
  // Message delete
438
- if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
439
- msgId = message.protocolMessage.key?.id
440
- message = {}
382
+ if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
383
+ msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
384
+ message = {};
441
385
  }
442
-
443
- const patched = await patchMessageBeforeSending(message, [])
444
- const bytes = Utils_1.encodeNewsletterMessage(patched)
445
-
386
+ const patched = await patchMessageBeforeSending(message, []);
387
+ const bytes = WAProto_1.proto.Message.encode(patched).finish();
446
388
  binaryNodeContent.push({
447
389
  tag: 'plaintext',
448
- attrs: extraAttrs ? extraAttrs : {},
390
+ attrs: mediaType ? { mediatype: mediaType } : {},
449
391
  content: bytes
450
- })
392
+ });
451
393
  }
452
394
  else {
453
- const { user: meUser } = WABinary_1.jidDecode(meId);
395
+ const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
454
396
  if (!participant) {
455
- devices.push({ user })
456
- if (user !== meUser) {
457
- devices.push({ user: meUser })
458
- }
459
-
460
- if (additionalAttributes?.['category'] !== 'peer') {
461
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
462
-
463
- devices.push(...additionalDevices)
397
+ devices.push({ user });
398
+ // do not send message to self if the device is 0 (mobile)
399
+ if (meDevice !== undefined && meDevice !== 0) {
400
+ devices.push({ user: meUser });
464
401
  }
402
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
403
+ devices.push(...additionalDevices);
465
404
  }
466
405
  const allJids = [];
467
406
  const meJids = [];
468
407
  const otherJids = [];
469
408
  for (const { user, device } of devices) {
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
-
409
+ const isMe = user === meUser;
410
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
473
411
  if (isMe) {
474
- meJids.push(jid)
412
+ meJids.push(jid);
475
413
  }
476
-
477
414
  else {
478
- otherJids.push(jid)
415
+ otherJids.push(jid);
479
416
  }
480
-
481
- allJids.push(jid)
417
+ allJids.push(jid);
482
418
  }
483
419
  await assertSessions(allJids, false);
484
420
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
485
- createParticipantNodes(meJids, meMsg, extraAttrs),
486
- createParticipantNodes(otherJids, message, extraAttrs)
487
- ])
421
+ createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
422
+ createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
423
+ ]);
488
424
  participants.push(...meNodes);
489
425
  participants.push(...otherNodes);
490
426
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
491
427
  }
492
428
  if (participants.length) {
493
- if (additionalAttributes?.['category'] === 'peer') {
494
- const peerNode = participants[0]?.content?.[0]
495
-
496
- if (peerNode) {
497
- binaryNodeContent.push(peerNode) // push only enc
498
- }
499
- }
500
-
501
- else {
502
- binaryNodeContent.push({
503
- tag: 'participants',
504
- attrs: {},
505
- content: participants
506
- })
507
- }
429
+ binaryNodeContent.push({
430
+ tag: 'participants',
431
+ attrs: {},
432
+ content: participants
433
+ });
508
434
  }
509
-
510
435
  const stanza = {
511
436
  tag: 'message',
512
437
  attrs: {
513
438
  id: msgId,
514
- type: getTypeMessage(messages),
439
+ type: isNewsletter ? getTypeMessage(message) : 'text',
515
440
  ...(additionalAttributes || {})
516
441
  },
517
442
  content: binaryNodeContent
518
- }
443
+ };
519
444
  // if the participant to send to is explicitly specified (generally retry recp)
520
445
  // ensure the message is only sent to that person
521
446
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
522
447
  if (participant) {
523
- if (WABinary_1.isJidGroup(destinationJid)) {
448
+ if ((0, WABinary_1.isJidGroup)(destinationJid)) {
524
449
  stanza.attrs.to = destinationJid;
525
450
  stanza.attrs.participant = participant.jid;
526
451
  }
527
- else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
452
+ else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
528
453
  stanza.attrs.to = participant.jid;
529
454
  stanza.attrs.recipient = destinationJid;
530
455
  }
@@ -543,6 +468,28 @@ const makeMessagesSocket = (config) => {
543
468
  });
544
469
  logger.debug({ jid }, 'adding device identity');
545
470
  }
471
+ if (additionalNodes && additionalNodes.length > 0) {
472
+ stanza.content.push(...additionalNodes);
473
+ }
474
+ else {
475
+ if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
476
+ stanza.content.push({
477
+ tag: 'biz',
478
+ attrs: {},
479
+ content: [{
480
+ tag: 'interactive',
481
+ attrs: {
482
+ type: 'native_flow',
483
+ v: '1'
484
+ },
485
+ content: [{
486
+ tag: 'native_flow',
487
+ attrs: { v: '9', name: 'mixed' }
488
+ }]
489
+ }]
490
+ });
491
+ }
492
+ }
546
493
 
547
494
  if (AI && isPrivate) {
548
495
  const botNode = {
@@ -552,7 +499,7 @@ const makeMessagesSocket = (config) => {
552
499
  }
553
500
  }
554
501
 
555
- const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
502
+ const filteredBizBot = WABinary_1.getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
556
503
 
557
504
  if (filteredBizBot) {
558
505
  stanza.content.push(...additionalNodes)
@@ -563,117 +510,25 @@ const makeMessagesSocket = (config) => {
563
510
  stanza.content.push(botNode)
564
511
  }
565
512
  }
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)
577
- }
578
- logger.debug({ jid }, 'adding business node')
579
- }
580
-
581
- if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
582
- stanza.content.push(...additionalNodes);
583
- }
584
-
585
- logger.debug({ msgId }, `sending message to ${participants.length} devices`);
586
- await sendNode(stanza);
587
- });
588
- return msgId;
589
- };
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
- };
513
+ const buttonType = getButtonType(message);
657
514
  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
515
  stanza.content.push({
667
- tag: 'device-identity',
516
+ tag: 'biz',
668
517
  attrs: {},
669
- content: encodeSignedDeviceIdentity(authState.creds.account, true)
518
+ content: [
519
+ {
520
+ tag: buttonType,
521
+ attrs: getButtonArgs(message),
522
+ }
523
+ ]
670
524
  });
525
+ logger.debug({ jid }, 'adding business node');
671
526
  }
527
+ logger.debug({ msgId }, `sending message to ${participants.length} devices`);
672
528
  await sendNode(stanza);
673
- }
674
- return idMsg
529
+ });
530
+ return msgId;
675
531
  };
676
-
677
532
  const getTypeMessage = (msg) => {
678
533
  const message = Utils_1.normalizeMessageContent(msg)
679
534
  if (message.reactionMessage) {
@@ -737,39 +592,93 @@ const makeMessagesSocket = (config) => {
737
592
  return 'productlink'
738
593
  }
739
594
  }
740
-
741
595
  const getButtonType = (message) => {
742
- if (message.listMessage) {
743
- return 'list'
744
- }
596
+ if (message.listMessage) {
597
+ return 'list'
598
+ }
745
599
  else if (message.buttonsMessage) {
746
600
  return 'buttons'
747
601
  }
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) {
602
+ else if(message.interactiveMessage?.nativeFlowMessage) {
768
603
  return 'native_flow'
769
604
  }
770
605
  }
606
+ const getButtonArgs = (message) => {
607
+ if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'review_and_pay') {
608
+ return {
609
+ tag: 'biz',
610
+ attrs: {
611
+ native_flow_name: 'order_details'
612
+ }
613
+ }
614
+ } else if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'payment_info') {
615
+ return {
616
+ tag: 'biz',
617
+ attrs: {
618
+ native_flow_name: 'payment_info'
619
+ }
620
+ }
621
+ } else if (message.interactiveMessage?.nativeFlowMessage &&message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 &&
622
+ ['mpm', 'cta_catalog', 'send_location', 'call_permission_request', 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog']
623
+ .includes(message.interactiveMessage.nativeFlowMessage.buttons[0].name)) {
624
+ return {
625
+ tag: 'biz',
626
+ attrs: {},
627
+ content: [{
628
+ tag: 'interactive',
629
+ attrs: {
630
+ type: 'native_flow',
631
+ v: '1'
632
+ },
633
+ content: [{
634
+ tag: 'native_flow',
635
+ attrs: {
636
+ v: '2',
637
+ name: message.interactiveMessage.nativeFlowMessage.buttons[0].name
638
+ }
639
+ }]
640
+ }]
641
+ }
642
+ } else if (message.interactiveMessage?.nativeFlowMessage || message.buttonsMessage) {
643
+ return {
644
+ tag: 'biz',
645
+ attrs: {},
646
+ content: [{
647
+ tag: 'interactive',
648
+ attrs: {
649
+ type: 'native_flow',
650
+ v: '1'
651
+ },
652
+ content: [{
653
+ tag: 'native_flow',
654
+ attrs: {
655
+ v: '9',
656
+ name: 'mixed'
657
+ }
658
+ }]
659
+ }]
660
+ }
661
+ } else if (message.listMessage) {
662
+ return {
663
+ tag: 'biz',
664
+ attrs: {},
665
+ content: [{
666
+ tag: 'list',
667
+ attrs: {
668
+ v: '2',
669
+ type: 'product_list'
670
+ }
671
+ }]
672
+ }
673
+ } else {
674
+ return {
675
+ tag: 'biz',
676
+ attrs: {}
677
+ }
678
+ }
679
+ }
771
680
  const getPrivacyTokens = async (jids) => {
772
- const t = Utils_1.unixTimestampSeconds().toString();
681
+ const t = (0, Utils_1.unixTimestampSeconds)().toString();
773
682
  const result = await query({
774
683
  tag: 'iq',
775
684
  attrs: {
@@ -784,7 +693,7 @@ const makeMessagesSocket = (config) => {
784
693
  content: jids.map(jid => ({
785
694
  tag: 'token',
786
695
  attrs: {
787
- jid: WABinary_1.jidNormalizedUser(jid),
696
+ jid: (0, WABinary_1.jidNormalizedUser)(jid),
788
697
  t,
789
698
  type: 'trusted_contact'
790
699
  }
@@ -793,19 +702,42 @@ const makeMessagesSocket = (config) => {
793
702
  ]
794
703
  });
795
704
  return result;
796
- }
705
+ }
706
+
707
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
708
+ var _a;
709
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
710
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
711
+ throw new boom_1.Boom('Not authenticated');
712
+ }
713
+ const protocolMessage = {
714
+ protocolMessage: {
715
+ peerDataOperationRequestMessage: pdoMessage,
716
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
717
+ }
718
+ };
719
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
720
+ const msgId = await relayMessage(meJid, protocolMessage, {
721
+ additionalAttributes: {
722
+ category: 'peer',
723
+ // eslint-disable-next-line camelcase
724
+ push_priority: 'high_force',
725
+ },
726
+ });
727
+ return msgId;
728
+ };
797
729
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
798
- const luki = new imup(Utils_1, waUploadToServer, relayMessage);
730
+ const rahmi = new erlangga(Utils_1, waUploadToServer, relayMessage);
799
731
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
800
732
  return {
801
733
  ...sock,
802
734
  getPrivacyTokens,
803
735
  assertSessions,
804
736
  relayMessage,
805
- sendMessageMembers,
806
737
  sendReceipt,
807
738
  sendReceipts,
808
- luki,
739
+ rahmi,
740
+ getButtonArgs,
809
741
  readMessages,
810
742
  refreshMediaConn,
811
743
  getUSyncDevices,
@@ -850,47 +782,27 @@ const makeMessagesSocket = (config) => {
850
782
  throw error;
851
783
  }
852
784
  ev.emit('messages.update', [
853
- {
854
- key: message.key,
855
- update: {
856
- message: message.message
857
- }
858
- }
785
+ { key: message.key, update: { message: message.message } }
859
786
  ]);
860
787
  return message;
861
788
  },
862
789
  sendMessage: async (jid, content, options = {}) => {
863
790
  const userJid = authState.creds.me.id;
864
- delete options.ephemeralExpiration
865
791
  const { filter = false, quoted } = options;
866
792
  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
871
-
872
- const value = typeof disappearingMessagesInChat === 'boolean' ?
873
- (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
874
- disappearingMessagesInChat
875
-
876
- await groupToggleEphemeral(jid, value)
877
- }
878
-
879
- else {
880
- let mediaHandle
881
-
793
+ const messageType = rahmi.detectType(content);
882
794
 
883
795
  if (messageType) {
884
796
  switch(messageType) {
885
797
  case 'PAYMENT':
886
- const paymentContent = await luki.handlePayment(content, quoted);
798
+ const paymentContent = await rahmi.handlePayment(content, quoted);
887
799
  return await relayMessage(jid, paymentContent, {
888
800
  messageId: Utils_1.generateMessageID(),
889
801
  ...getParticipantAttr()
890
802
  });
891
803
 
892
804
  case 'PRODUCT':
893
- const productContent = await luki.handleProduct(content, jid, quoted);
805
+ const productContent = await rahmi.handleProduct(content, jid, quoted);
894
806
  const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
895
807
  return await relayMessage(jid, productMsg.message, {
896
808
  messageId: productMsg.key.id,
@@ -898,28 +810,21 @@ const makeMessagesSocket = (config) => {
898
810
  });
899
811
 
900
812
  case 'INTERACTIVE':
901
- const interactiveContent = await luki.handleInteractive(content, jid, quoted);
813
+ const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
902
814
  const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
903
815
  return await relayMessage(jid, interactiveMsg.message, {
904
816
  messageId: interactiveMsg.key.id,
905
817
  ...getParticipantAttr()
906
818
  });
907
819
  case 'ALBUM':
908
- return await luki.handleAlbum(content, jid, quoted)
820
+ const albumContent = await rahmi.handleAlbum(content, jid, quoted)
821
+ return albumContent;
822
+
909
823
  case 'EVENT':
910
- return await luki.handleEvent(content, jid, quoted)
824
+ return await rahmi.handleEvent(content, jid, quoted)
825
+
911
826
  case 'POLL_RESULT':
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)
827
+ return await rahmi.handlePollResult(content, jid, quoted)
923
828
  }
924
829
  }
925
830
  const fullMsg = await Utils_1.generateWAMessage(jid, content, {
@@ -982,7 +887,6 @@ const makeMessagesSocket = (config) => {
982
887
  });
983
888
  }
984
889
  return fullMsg;
985
- }
986
890
  }
987
891
  }
988
892
  };