alipclutch-baileys 8.5.3 → 8.5.4

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 (113) hide show
  1. package/WAProto/index.js +77698 -117050
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +2 -2
  4. package/lib/Defaults/index.d.ts +7 -16
  5. package/lib/Defaults/index.js +119 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  8. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  9. package/lib/Socket/Client/index.d.ts +3 -2
  10. package/lib/Socket/Client/index.js +3 -2
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/web-socket-client.js +62 -0
  15. package/lib/Socket/business.d.ts +58 -59
  16. package/lib/Socket/chats.d.ts +230 -45
  17. package/lib/Socket/chats.js +238 -139
  18. package/lib/Socket/groups.d.ts +32 -41
  19. package/lib/Socket/groups.js +23 -38
  20. package/lib/Socket/index.d.ts +64 -63
  21. package/lib/Socket/index.js +3 -2
  22. package/lib/Socket/messages-recv.js +65 -9
  23. package/lib/Socket/messages-send.d.ts +47 -49
  24. package/lib/Socket/messages-send.js +395 -543
  25. package/lib/Socket/newsletter.d.ts +37 -39
  26. package/lib/Socket/newsletter.js +123 -88
  27. package/lib/Socket/registration.d.ts +267 -0
  28. package/lib/Socket/registration.js +166 -0
  29. package/lib/Socket/setup.d.ts +253 -0
  30. package/lib/Socket/setup.js +4 -5
  31. package/lib/Socket/socket.d.ts +43 -270
  32. package/lib/Socket/socket.js +38 -62
  33. package/lib/Socket/usync.d.ts +3 -3
  34. package/lib/Store/index.d.ts +2 -1
  35. package/lib/Store/index.js +3 -1
  36. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.d.ts +24 -24
  39. package/lib/Store/make-in-memory-store.js +14 -26
  40. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  41. package/lib/Store/make-ordered-dictionary.js +2 -2
  42. package/lib/Types/Auth.d.ts +7 -0
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +7 -14
  45. package/lib/Types/Contact.d.ts +1 -5
  46. package/lib/Types/Events.d.ts +2 -44
  47. package/lib/Types/GroupMetadata.d.ts +2 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +21 -148
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.d.ts +97 -73
  53. package/lib/Types/Newsletter.js +38 -18
  54. package/lib/Types/Socket.d.ts +9 -17
  55. package/lib/Types/index.d.ts +1 -8
  56. package/lib/Types/index.js +2 -2
  57. package/lib/Utils/auth-utils.d.ts +3 -3
  58. package/lib/Utils/auth-utils.js +13 -6
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +16 -15
  61. package/lib/Utils/chat-utils.js +35 -36
  62. package/lib/Utils/crypto.d.ts +16 -15
  63. package/lib/Utils/crypto.js +29 -71
  64. package/lib/Utils/decode-wa-message.d.ts +6 -22
  65. package/lib/Utils/decode-wa-message.js +56 -65
  66. package/lib/Utils/event-buffer.d.ts +2 -2
  67. package/lib/Utils/event-buffer.js +7 -11
  68. package/lib/Utils/generics.d.ts +20 -17
  69. package/lib/Utils/generics.js +75 -95
  70. package/lib/Utils/history.d.ts +0 -4
  71. package/lib/Utils/history.js +6 -4
  72. package/lib/Utils/link-preview.d.ts +2 -2
  73. package/lib/Utils/link-preview.js +1 -34
  74. package/lib/Utils/logger.d.ts +3 -10
  75. package/lib/Utils/lt-hash.d.ts +2 -2
  76. package/lib/Utils/lt-hash.js +6 -6
  77. package/lib/Utils/make-mutex.d.ts +2 -2
  78. package/lib/Utils/messages-media.d.ts +24 -28
  79. package/lib/Utils/messages-media.js +111 -272
  80. package/lib/Utils/messages.d.ts +10 -13
  81. package/lib/Utils/messages.js +51 -336
  82. package/lib/Utils/noise-handler.d.ts +12 -10
  83. package/lib/Utils/noise-handler.js +23 -18
  84. package/lib/Utils/process-message.d.ts +4 -5
  85. package/lib/Utils/process-message.js +25 -108
  86. package/lib/Utils/signal.d.ts +1 -2
  87. package/lib/Utils/signal.js +26 -26
  88. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  89. package/lib/Utils/use-multi-file-auth-state.js +6 -51
  90. package/lib/Utils/validate-connection.d.ts +4 -3
  91. package/lib/Utils/validate-connection.js +1 -1
  92. package/lib/WABinary/constants.d.ts +27 -24
  93. package/lib/WABinary/constants.js +13 -1276
  94. package/lib/WABinary/decode.d.ts +4 -3
  95. package/lib/WABinary/decode.js +13 -26
  96. package/lib/WABinary/encode.d.ts +2 -1
  97. package/lib/WABinary/encode.js +152 -137
  98. package/lib/WABinary/generic-utils.d.ts +4 -1
  99. package/lib/WABinary/generic-utils.js +125 -37
  100. package/lib/WABinary/jid-utils.d.ts +5 -11
  101. package/lib/WABinary/jid-utils.js +5 -28
  102. package/lib/WAM/BinaryInfo.d.ts +11 -2
  103. package/lib/WAM/encode.d.ts +2 -1
  104. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  105. package/lib/index.d.ts +1 -0
  106. package/lib/index.js +15 -27
  107. package/package.json +31 -18
  108. package/WAProto/GenerateStatics.sh +0 -4
  109. package/WAProto/WAProto.proto +0 -4775
  110. package/WAProto/index.d.ts +0 -55057
  111. package/WAProto/index.ts.ts +0 -53473
  112. package/lib/Socket/setup.ts +0 -623
  113. package/lib/WABinary/jid-utils.js.bak +0 -83
@@ -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 alip = require('./setup');
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 = {};
400
- }
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');
438
+ if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
439
+ msgId = message.protocolMessage.key?.id
440
+ message = {}
404
441
  }
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,162 @@ 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
- return msgId;
588
+
589
+ message = Types_1.WAProto.Message.fromObject(message)
590
+
591
+ const messageJSON = {
592
+ key: {
593
+ remoteJid: jid,
594
+ fromMe: true,
595
+ id: msgId
596
+ },
597
+ message: message,
598
+ messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
599
+ messageStubParameters: [],
600
+ participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
601
+ status: Types_1.WAMessageStatus.PENDING
602
+ }
603
+
604
+ return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
605
+ // return msgId;
551
606
  };
552
607
  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';
576
- }
608
+ const message = Utils_1.normalizeMessageContent(msg)
609
+ if (message.reactionMessage) {
610
+ return 'reaction'
611
+ }
612
+ else if (getMediaType(message)) {
613
+ return 'media'
614
+ }
577
615
  else {
578
- return 'text';
616
+ return 'text'
579
617
  }
580
- };
618
+ }
619
+
581
620
  const getMediaType = (message) => {
582
621
  if (message.imageMessage) {
583
- return 'image';
622
+ return 'image'
584
623
  }
585
624
  else if (message.videoMessage) {
586
- return message.videoMessage.gifPlayback ? 'gif' : 'video';
625
+ return message.videoMessage.gifPlayback ? 'gif' : 'video'
587
626
  }
588
627
  else if (message.audioMessage) {
589
- return message.audioMessage.ptt ? 'ptt' : 'audio';
628
+ return message.audioMessage.ptt ? 'ptt' : 'audio'
590
629
  }
591
630
  else if (message.contactMessage) {
592
- return 'vcard';
631
+ return 'vcard'
593
632
  }
594
633
  else if (message.documentMessage) {
595
- return 'document';
634
+ return 'document'
596
635
  }
597
636
  else if (message.contactsArrayMessage) {
598
- return 'contact_array';
637
+ return 'contact_array'
599
638
  }
600
639
  else if (message.liveLocationMessage) {
601
- return 'livelocation';
640
+ return 'livelocation'
602
641
  }
603
642
  else if (message.stickerMessage) {
604
- return 'sticker';
643
+ return 'sticker'
605
644
  }
606
645
  else if (message.listMessage) {
607
- return 'list';
646
+ return 'list'
608
647
  }
609
648
  else if (message.listResponseMessage) {
610
- return 'list_response';
649
+ return 'list_response'
611
650
  }
612
651
  else if (message.buttonsResponseMessage) {
613
- return 'buttons_response';
652
+ return 'buttons_response'
614
653
  }
615
654
  else if (message.orderMessage) {
616
- return 'order';
655
+ return 'order'
617
656
  }
618
657
  else if (message.productMessage) {
619
- return 'product';
658
+ return 'product'
620
659
  }
621
660
  else if (message.interactiveResponseMessage) {
622
- return 'native_flow_response';
661
+ return 'native_flow_response'
623
662
  }
624
663
  else if (message.groupInviteMessage) {
625
- return 'url';
664
+ return 'url'
626
665
  }
627
- };
666
+ else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
667
+ return 'productlink'
668
+ }
669
+ }
670
+
671
+ const getButtonType = (message) => {
672
+ if (message.listMessage) {
673
+ return 'list'
674
+ }
675
+ else if (message.buttonsMessage) {
676
+ return 'buttons'
677
+ }
678
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
679
+ return 'review_and_pay'
680
+ }
681
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
682
+ return 'review_order'
683
+ }
684
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
685
+ return 'payment_info'
686
+ }
687
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
688
+ return 'payment_status'
689
+ }
690
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
691
+ return 'payment_method'
692
+ }
693
+ else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
694
+ return 'interactive'
695
+ }
696
+ else if (message.interactiveMessage?.nativeFlowMessage) {
697
+ return 'native_flow'
698
+ }
699
+ }
628
700
  const getPrivacyTokens = async (jids) => {
629
- const t = (0, Utils_1.unixTimestampSeconds)().toString();
701
+ const t = Utils_1.unixTimestampSeconds().toString();
630
702
  const result = await query({
631
703
  tag: 'iq',
632
704
  attrs: {
@@ -641,7 +713,7 @@ const makeMessagesSocket = (config) => {
641
713
  content: jids.map(jid => ({
642
714
  tag: 'token',
643
715
  attrs: {
644
- jid: (0, WABinary_1.jidNormalizedUser)(jid),
716
+ jid: WABinary_1.jidNormalizedUser(jid),
645
717
  t,
646
718
  type: 'trusted_contact'
647
719
  }
@@ -650,9 +722,9 @@ const makeMessagesSocket = (config) => {
650
722
  ]
651
723
  });
652
724
  return result;
653
- };
725
+ }
654
726
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
655
- const NotForralll = new NotForrAll(Utils_1, waUploadToServer, relayMessage); // Instansiasi wrapper
727
+ const rahmi = new alip(Utils_1, waUploadToServer, relayMessage);
656
728
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
657
729
  return {
658
730
  ...sock,
@@ -661,23 +733,23 @@ const makeMessagesSocket = (config) => {
661
733
  relayMessage,
662
734
  sendReceipt,
663
735
  sendReceipts,
664
- NotForralll,
736
+ rahmi,
665
737
  readMessages,
666
738
  refreshMediaConn,
667
- waUploadToServer,
668
- fetchPrivacySettings,
669
739
  getUSyncDevices,
670
740
  createParticipantNodes,
741
+ waUploadToServer,
671
742
  sendPeerDataOperationMessage,
743
+ fetchPrivacySettings,
672
744
  updateMediaMessage: async (message) => {
673
745
  const content = (0, Utils_1.assertMediaContent)(message.message);
674
746
  const mediaKey = content.mediaKey;
675
747
  const meId = authState.creds.me.id;
676
- const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
748
+ const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
677
749
  let error = undefined;
678
750
  await Promise.all([
679
751
  sendNode(node),
680
- waitForMsgMediaUpdate(async (update) => {
752
+ waitForMsgMediaUpdate(update => {
681
753
  const result = update.find(c => c.key.id === message.key.id);
682
754
  if (result) {
683
755
  if (result.error) {
@@ -685,7 +757,7 @@ const makeMessagesSocket = (config) => {
685
757
  }
686
758
  else {
687
759
  try {
688
- const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
760
+ const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
689
761
  if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
690
762
  const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
691
763
  throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
@@ -706,352 +778,132 @@ const makeMessagesSocket = (config) => {
706
778
  throw error;
707
779
  }
708
780
  ev.emit('messages.update', [
709
- { key: message.key, update: { message: message.message } }
781
+ {
782
+ key: message.key,
783
+ update: {
784
+ message: message.message
785
+ }
786
+ }
710
787
  ]);
711
788
  return message;
712
789
  },
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
- }
764
-
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
769
-
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
- )
790
+ sendMessage: async (jid, content, options = {}) => {
791
+ const userJid = authState.creds.me.id;
792
+ delete options.ephemeralExpiration
793
+ const { filter = false, quoted } = options;
794
+ const getParticipantAttr = () => filter ? { participant: { jid } } : {};
795
+ const messageType = rahmi.detectType(content);
796
+ if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
797
+ typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
798
+ const { disappearingMessagesInChat } = content
846
799
 
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
- )
800
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
801
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
802
+ disappearingMessagesInChat
860
803
 
861
- await Utils_1.delay(2000)
862
- } catch (error) {
863
- logger.error(`Error sending to ${id}: ${error}`)
864
- }
804
+ await groupToggleEphemeral(jid, value)
865
805
  }
806
+
807
+ else {
808
+ let mediaHandle
866
809
 
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
-
810
+
876
811
  if (messageType) {
877
- switch (messageType) {
812
+ switch(messageType) {
878
813
  case 'PAYMENT':
879
- const paymentContent = await NotForralll.handlePayment(content, quoted);
814
+ const paymentContent = await rahmi.handlePayment(content, quoted);
880
815
  return await relayMessage(jid, paymentContent, {
881
816
  messageId: Utils_1.generateMessageID(),
882
817
  ...getParticipantAttr()
883
818
  });
884
-
819
+
885
820
  case 'PRODUCT':
886
- const productContent = await NotForralll.handleProduct(content, jid, quoted);
821
+ const productContent = await rahmi.handleProduct(content, jid, quoted);
887
822
  const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
888
823
  return await relayMessage(jid, productMsg.message, {
889
824
  messageId: productMsg.key.id,
890
825
  ...getParticipantAttr()
891
826
  });
892
-
827
+
893
828
  case 'INTERACTIVE':
894
- const interactiveContent = await NotForralll.handleInteractive(content, jid, quoted);
829
+ const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
895
830
  const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
896
831
  return await relayMessage(jid, interactiveMsg.message, {
897
832
  messageId: interactiveMsg.key.id,
898
833
  ...getParticipantAttr()
899
834
  });
900
-
901
835
  case 'ALBUM':
902
- // Handler custom ini melakukan relay message sendiri
903
- return await NotForralll.handleAlbum(content, jid, quoted);
904
-
836
+ return await rahmi.handleAlbum(content, jid, quoted)
905
837
  case 'EVENT':
906
- // Handler custom ini melakukan relay message sendiri
907
- return await NotForralll.handleEvent(content, jid, quoted);
908
-
838
+ return await rahmi.handleEvent(content, jid, quoted)
909
839
  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
-
840
+ return await rahmi.handlePollResult(content, jid, quoted)
917
841
  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;
842
+ return await rahmi.handleGroupStory(content, jid, quoted)
843
+ }
844
+ }
845
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
846
+ logger,
847
+ userJid,
848
+ quoted,
849
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
850
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
851
+ fetchOpts: {
852
+ timeout: 3000,
853
+ ...axiosOptions || {}
985
854
  },
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
- },
855
+ logger,
856
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
857
+ }),
858
+ upload: async (readStream, opts) => {
859
+ const up = await waUploadToServer(readStream, {
860
+ ...opts,
861
+ newsletter: WABinary_1.isJidNewsLetter(jid)
1028
862
  });
1029
- // required to display AI icon on message
1030
- }
1031
- else if (isAiMsg) {
1032
- additionalNodes.push({
863
+ return up;
864
+ },
865
+ mediaCache: config.mediaCache,
866
+ options: config.options,
867
+ ...options
868
+ });
869
+
870
+ const isDeleteMsg = 'delete' in content && !!content.delete;
871
+ const isEditMsg = 'edit' in content && !!content.edit;
872
+ const isAiMsg = 'ai' in content && !!content.ai;
873
+
874
+ const additionalAttributes = {};
875
+ const additionalNodes = [];
876
+
877
+ if (isDeleteMsg) {
878
+ const fromMe = content.delete?.fromMe;
879
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
880
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
881
+ } else if (isEditMsg) {
882
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
883
+ } else if (isAiMsg) {
884
+ additionalNodes.push({
1033
885
  attrs: {
1034
886
  biz_bot: '1'
1035
887
  }, tag: "bot"
1036
888
  });
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
- */
889
+ }
890
+
891
+ await relayMessage(jid, fullMsg.message, {
892
+ messageId: fullMsg.key.id,
893
+ cachedGroupMetadata: options.cachedGroupMetadata,
894
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
895
+ additionalAttributes,
896
+ statusJidList: options.statusJidList
897
+ });
898
+
899
+ if (config.emitOwnEvents) {
900
+ process.nextTick(() => {
901
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
902
+ });
903
+ }
904
+ return fullMsg;
905
+ }
1054
906
  }
1055
- };
907
+ }
1056
908
  };
1057
909
  exports.makeMessagesSocket = makeMessagesSocket;