@fvckerss/baileys 1.0.17 → 1.0.19
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.
- package/README.md +65 -0
- package/lib/Socket/messages-send.js +163 -311
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/messages.js +10 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -283,6 +283,71 @@ await sock.sendMessage(jid, {
|
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
286
|
+
### 📍 Button Location
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
const fs = require("fs");
|
|
290
|
+
const sharp = require("sharp");
|
|
291
|
+
const axios = require("axios");
|
|
292
|
+
let prefix = ".";
|
|
293
|
+
async function getLocationThumb(input = './media/image/thumbnail.jpg') {
|
|
294
|
+
try {
|
|
295
|
+
let buffer;
|
|
296
|
+
if (/^https?:\/\//.test(input)) {
|
|
297
|
+
const res = await axios.get(input, { responseType: 'arraybuffer', timeout: 15000 });
|
|
298
|
+
buffer = Buffer.from(res.data);
|
|
299
|
+
} else {
|
|
300
|
+
if (!fs.existsSync(input)) return Buffer.alloc(0);
|
|
301
|
+
buffer = fs.readFileSync(input);
|
|
302
|
+
}
|
|
303
|
+
return await sharp(buffer).resize(300, 180, { fit: 'cover' }).jpeg({ quality: 70 }).toBuffer();
|
|
304
|
+
} catch (e) {
|
|
305
|
+
console.error("Gagal mengompres gambar menu:", e);
|
|
306
|
+
return Buffer.alloc(0);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const thumb = await getLocationThumb('./media/image/thumbnail.jpg');
|
|
310
|
+
const buttonMessage = {
|
|
311
|
+
location: {
|
|
312
|
+
degreesLatitude: 0,
|
|
313
|
+
degreesLongitude: 0,
|
|
314
|
+
name: 'Swiper Fvck',
|
|
315
|
+
address: 'Fvckers',
|
|
316
|
+
jpegThumbnail: thumb
|
|
317
|
+
},
|
|
318
|
+
caption: `Swiper Fvck`,
|
|
319
|
+
footer: `Fvckers`,
|
|
320
|
+
headerType: 6,
|
|
321
|
+
viewOnce: true,
|
|
322
|
+
buttons: [
|
|
323
|
+
{
|
|
324
|
+
buttonId: 'action',
|
|
325
|
+
buttonText: { displayText: 'Touch Me' },
|
|
326
|
+
type: 1,
|
|
327
|
+
nativeFlowInfo: {
|
|
328
|
+
name: 'single_select',
|
|
329
|
+
paramsJson: JSON.stringify({
|
|
330
|
+
title: `Fvckers Botz`,
|
|
331
|
+
sections: [{
|
|
332
|
+
title: "",
|
|
333
|
+
highlight_label: "Fvckers",
|
|
334
|
+
rows: [
|
|
335
|
+
{ title: "Swiper", description: "", id: `${prefix}menu` },
|
|
336
|
+
{ title: "Swiper", description: "", id: `${prefix}menu`}
|
|
337
|
+
]
|
|
338
|
+
}]
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
{ buttonId: `${prefix}tools`, buttonText: { displayText: 'Tools' }, type: 1 },
|
|
343
|
+
],
|
|
344
|
+
};
|
|
345
|
+
await sock.sendMessage(m.chat, buttonMessage, { quoted: m });
|
|
346
|
+
})()
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
286
351
|
### 📋 List Message
|
|
287
352
|
|
|
288
353
|
```
|
|
@@ -14,33 +14,25 @@ import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, res
|
|
|
14
14
|
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, getBizBinaryNode, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isJidNewsletter, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
15
15
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
16
16
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
17
|
+
|
|
17
18
|
export const makeMessagesSocket = (config) => {
|
|
18
19
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
19
20
|
const sock = makeNewsletterSocket(config);
|
|
20
21
|
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, waitUntilSocketOpen, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
21
22
|
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
22
|
-
/**
|
|
23
|
-
* Set of tctoken storage JIDs with a fire-and-forget `issuePrivacyTokens` IQ in flight.
|
|
24
|
-
* Prevents duplicate IQs from rapid back-to-back sends before `senderTimestamp` persists.
|
|
25
|
-
* Entries are always removed in `.finally()`, so the set is bounded by concurrency.
|
|
26
|
-
*/
|
|
27
23
|
const inFlightTcTokenIssuance = new Set();
|
|
28
24
|
const userDevicesCache = config.userDevicesCache ||
|
|
29
25
|
new NodeCache({
|
|
30
26
|
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
31
27
|
useClones: false
|
|
32
28
|
});
|
|
33
|
-
/** Serializes writes to userDevicesCache across USync refresh and device-notification handling. */
|
|
34
29
|
const devicesMutex = makeMutex();
|
|
35
|
-
// Initialize message retry manager if enabled
|
|
36
30
|
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
37
|
-
// Prevent race conditions in Signal session encryption by user
|
|
38
31
|
const encryptionMutex = makeKeyedMutex();
|
|
39
|
-
// Prevent race conditions in media connection refresh
|
|
40
32
|
const mediaConnMutex = makeKeyedMutex();
|
|
41
33
|
let mediaConn;
|
|
42
|
-
/** Per-socket media host; updated whenever media_conn is fetched. Defaults to the public WhatsApp host. */
|
|
43
34
|
let mediaHost = DEF_MEDIA_HOST;
|
|
35
|
+
|
|
44
36
|
const refreshMediaConn = async (forceGet = false) => {
|
|
45
37
|
return mediaConnMutex.mutex('media-conn', async () => {
|
|
46
38
|
const media = await mediaConn;
|
|
@@ -56,7 +48,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
56
48
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
57
49
|
});
|
|
58
50
|
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
59
|
-
// TODO: explore full length of data that whatsapp provides
|
|
60
51
|
const node = {
|
|
61
52
|
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
62
53
|
hostname: attrs.hostname,
|
|
@@ -76,10 +67,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
76
67
|
return mediaConn;
|
|
77
68
|
});
|
|
78
69
|
};
|
|
79
|
-
|
|
80
|
-
* generic send receipt function
|
|
81
|
-
* used for receipts of phone call, read, delivery etc.
|
|
82
|
-
* */
|
|
70
|
+
|
|
83
71
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
84
72
|
if (!messageIds || messageIds.length === 0) {
|
|
85
73
|
throw new Boom('missing ids in receipt');
|
|
@@ -123,21 +111,20 @@ export const makeMessagesSocket = (config) => {
|
|
|
123
111
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
124
112
|
await sendNode(node);
|
|
125
113
|
};
|
|
126
|
-
|
|
114
|
+
|
|
127
115
|
const sendReceipts = async (keys, type) => {
|
|
128
116
|
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
129
117
|
for (const { jid, participant, messageIds } of recps) {
|
|
130
118
|
await sendReceipt(jid, participant, messageIds, type);
|
|
131
119
|
}
|
|
132
120
|
};
|
|
133
|
-
|
|
121
|
+
|
|
134
122
|
const readMessages = async (keys) => {
|
|
135
123
|
const privacySettings = await fetchPrivacySettings();
|
|
136
|
-
// based on privacy settings, we have to change the read type
|
|
137
124
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
138
125
|
await sendReceipts(keys, readType);
|
|
139
126
|
};
|
|
140
|
-
|
|
127
|
+
|
|
141
128
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
142
129
|
const deviceResults = [];
|
|
143
130
|
if (!useCache) {
|
|
@@ -200,16 +187,14 @@ export const makeMessagesSocket = (config) => {
|
|
|
200
187
|
}
|
|
201
188
|
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
202
189
|
for (const jid of toFetch) {
|
|
203
|
-
query.withUser(new USyncUser().withId(jid));
|
|
190
|
+
query.withUser(new USyncUser().withId(jid));
|
|
204
191
|
}
|
|
205
192
|
const result = await sock.executeUSyncQuery(query);
|
|
206
193
|
if (result) {
|
|
207
|
-
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
|
208
194
|
const lidResults = result.list.filter(a => !!a.lid);
|
|
209
195
|
if (lidResults.length > 0) {
|
|
210
196
|
logger.trace('Storing LID maps from device call');
|
|
211
197
|
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
212
|
-
// Force-refresh sessions for newly mapped LIDs to align identity addressing
|
|
213
198
|
try {
|
|
214
199
|
const lids = lidResults.map(a => a.lid);
|
|
215
200
|
if (lids.length) {
|
|
@@ -226,10 +211,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
226
211
|
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
227
212
|
deviceMap[item.user]?.push(item);
|
|
228
213
|
}
|
|
229
|
-
// Process each user's devices as a group for bulk LID migration
|
|
230
214
|
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
231
215
|
const isLidUser = requestedLidUsers.has(user);
|
|
232
|
-
// Process all devices for this user
|
|
233
216
|
for (const item of userDevices) {
|
|
234
217
|
const finalJid = isLidUser
|
|
235
218
|
? jidEncode(user, item.server, item.device)
|
|
@@ -248,7 +231,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
248
231
|
}
|
|
249
232
|
await devicesMutex.mutex(async () => {
|
|
250
233
|
if (userDevicesCache.mset) {
|
|
251
|
-
// if the cache supports mset, we can set all devices in one go
|
|
252
234
|
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
253
235
|
}
|
|
254
236
|
else {
|
|
@@ -276,9 +258,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
276
258
|
}
|
|
277
259
|
return deviceResults;
|
|
278
260
|
};
|
|
279
|
-
|
|
280
|
-
* Update Member Label
|
|
281
|
-
*/
|
|
261
|
+
|
|
282
262
|
const updateMemberLabel = (jid, memberLabel) => {
|
|
283
263
|
return relayMessage(jid, {
|
|
284
264
|
protocolMessage: {
|
|
@@ -301,6 +281,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
301
281
|
]
|
|
302
282
|
});
|
|
303
283
|
};
|
|
284
|
+
|
|
304
285
|
const assertSessions = async (jids, force) => {
|
|
305
286
|
let didFetchNewSession = false;
|
|
306
287
|
const uniqueJids = [...new Set(jids)];
|
|
@@ -316,7 +297,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
316
297
|
jidsRequiringFetch.push(jid);
|
|
317
298
|
}
|
|
318
299
|
if (jidsRequiringFetch.length) {
|
|
319
|
-
// LID if mapped, otherwise original
|
|
320
300
|
const wireJids = [
|
|
321
301
|
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
322
302
|
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
@@ -347,8 +327,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
347
327
|
}
|
|
348
328
|
return didFetchNewSession;
|
|
349
329
|
};
|
|
330
|
+
|
|
350
331
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
351
|
-
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
352
332
|
if (!authState.creds.me?.id) {
|
|
353
333
|
throw new Boom('Not authenticated');
|
|
354
334
|
}
|
|
@@ -373,6 +353,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
373
353
|
});
|
|
374
354
|
return msgId;
|
|
375
355
|
};
|
|
356
|
+
|
|
376
357
|
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
377
358
|
if (!recipientJids.length) {
|
|
378
359
|
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
@@ -433,91 +414,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
433
414
|
}
|
|
434
415
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
435
416
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const isConnectionClosedError = err => {
|
|
439
|
-
const msg = String(err?.message || err?.output?.payload?.message || '');
|
|
440
|
-
const status = err?.output?.statusCode || err?.data?.statusCode;
|
|
441
|
-
|
|
442
|
-
return (
|
|
443
|
-
status === 428 ||
|
|
444
|
-
status === 428 ||
|
|
445
|
-
msg.includes('Connection Closed') ||
|
|
446
|
-
msg.includes('Connection Terminated') ||
|
|
447
|
-
msg.includes('Precondition Required') ||
|
|
448
|
-
msg.includes('WebSocket Error')
|
|
449
|
-
);
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
const sendNodeSafe = async (node, retry = 10) => {
|
|
453
|
-
let lastError;
|
|
454
|
-
|
|
455
|
-
for (let i = 0; i <= retry; i++) {
|
|
456
|
-
try {
|
|
457
|
-
if (waitUntilSocketOpen) {
|
|
458
|
-
await waitUntilSocketOpen();
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return await sendNode(node);
|
|
462
|
-
}
|
|
463
|
-
catch (err) {
|
|
464
|
-
lastError = err;
|
|
465
|
-
|
|
466
|
-
if (!isConnectionClosedError(err) || i >= retry) {
|
|
467
|
-
throw err;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
logger.warn({
|
|
471
|
-
attempt: i + 1,
|
|
472
|
-
err: err?.message
|
|
473
|
-
}, 'sendNode failed, retrying after socket reconnect');
|
|
474
|
-
|
|
475
|
-
await sleep(1500 + i * 1000);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
throw lastError;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
const sanitizeContextInfo = ctx => {
|
|
483
|
-
if (!ctx || typeof ctx !== 'object') return ctx;
|
|
484
|
-
|
|
485
|
-
const clean = { ...ctx };
|
|
486
|
-
|
|
487
|
-
if (typeof clean.stanzaId === 'string' && clean.stanzaId.length > 99999999999999999) {
|
|
488
|
-
clean.stanzaId = clean.stanzaId.slice(0, 99999999999999999);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (Array.isArray(clean.mentionedJid) && clean.mentionedJid.length > 99999999999999999) {
|
|
492
|
-
clean.mentionedJid = clean.mentionedJid.slice(0, 99999999999999999);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
if (clean.quotedMessage && typeof clean.quotedMessage === 'object') {
|
|
496
|
-
clean.quotedMessage = clean.quotedMessage;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
return clean;
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
const sanitizeMessagePayload = message => {
|
|
503
|
-
if (!message || typeof message !== 'object') return message;
|
|
504
|
-
|
|
505
|
-
const walk = obj => {
|
|
506
|
-
if (!obj || typeof obj !== 'object') return;
|
|
507
|
-
|
|
508
|
-
if (obj.contextInfo) {
|
|
509
|
-
obj.contextInfo = sanitizeContextInfo(obj.contextInfo);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
for (const key of Object.keys(obj)) {
|
|
513
|
-
walk(obj[key]);
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
walk(message);
|
|
518
|
-
return message;
|
|
519
|
-
};
|
|
520
|
-
|
|
417
|
+
|
|
521
418
|
const relayMessage = async (jid, message, { messageId: msgId, participant, quoted, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, addBizAttributes, statusJidList, fireAndForget, ptcp = true } = {}) => {
|
|
522
419
|
const meId = assertMeId(authState.creds);
|
|
523
420
|
const meLid = authState.creds.me?.lid;
|
|
@@ -532,63 +429,64 @@ const sanitizeMessagePayload = message => {
|
|
|
532
429
|
const isGroupOrStatus = isGroup || isStatus;
|
|
533
430
|
const finalJid = jid;
|
|
534
431
|
const protoKeys = [
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
]
|
|
432
|
+
"conversation",
|
|
433
|
+
"extendedTextMessage",
|
|
434
|
+
"imageMessage",
|
|
435
|
+
"videoMessage",
|
|
436
|
+
"audioMessage",
|
|
437
|
+
"documentMessage",
|
|
438
|
+
"stickerMessage",
|
|
439
|
+
"contactMessage",
|
|
440
|
+
"contactsArrayMessage",
|
|
441
|
+
"locationMessage",
|
|
442
|
+
"liveLocationMessage",
|
|
443
|
+
"pollCreationMessage",
|
|
444
|
+
"reactionMessage",
|
|
445
|
+
"protocolMessage",
|
|
446
|
+
"listMessage",
|
|
447
|
+
"buttonsMessage",
|
|
448
|
+
"templateMessage",
|
|
449
|
+
"interactiveMessage",
|
|
450
|
+
"viewOnceMessage",
|
|
451
|
+
"groupStatusMessageV2"
|
|
452
|
+
]
|
|
556
453
|
|
|
557
|
-
const isProto = protoKeys.some(k => k in (message || {}))
|
|
454
|
+
const isProto = protoKeys.some(k => k in (message || {}))
|
|
558
455
|
|
|
559
|
-
if (!isProto) {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
456
|
+
if (!isProto) {
|
|
457
|
+
const full = await generateWAMessage(
|
|
458
|
+
jid,
|
|
459
|
+
message,
|
|
460
|
+
{
|
|
461
|
+
logger,
|
|
462
|
+
userJid: meId,
|
|
463
|
+
upload: waUploadToServer,
|
|
464
|
+
mediaCache: config.mediaCache,
|
|
465
|
+
options: config.options
|
|
466
|
+
}
|
|
467
|
+
)
|
|
571
468
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
469
|
+
message = full.message
|
|
470
|
+
msgId = full.key.id
|
|
471
|
+
}
|
|
575
472
|
msgId = msgId || generateMessageIDV2(meId);
|
|
576
|
-
|
|
473
|
+
// 👇 SANITIZE DIHAPUS 👇
|
|
474
|
+
|
|
577
475
|
if (quoted?.key && quoted?.message) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
476
|
+
const inner = normalizeMessageContent(message);
|
|
477
|
+
const msgType = Object.keys(inner || message)[0];
|
|
478
|
+
const target = (inner || message)?.[msgType];
|
|
581
479
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
480
|
+
if (target && typeof target === 'object') {
|
|
481
|
+
target.contextInfo = {
|
|
482
|
+
...(target.contextInfo || {}),
|
|
483
|
+
stanzaId: quoted.key.id,
|
|
484
|
+
participant: quoted.key.participant || quoted.participant || quoted.key.remoteJid,
|
|
485
|
+
remoteJid: quoted.key.remoteJid || jid,
|
|
486
|
+
quotedMessage: quoted.message
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
}
|
|
592
490
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
593
491
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
594
492
|
const participants = [];
|
|
@@ -616,7 +514,6 @@ if (!isProto) {
|
|
|
616
514
|
});
|
|
617
515
|
}
|
|
618
516
|
await authState.keys.transaction(async () => {
|
|
619
|
-
// Lia@Changes 02-02-26 --- Normalize message first to extract the original message and valid media type
|
|
620
517
|
const innerMessage = normalizeMessageContent(message);
|
|
621
518
|
const mediaType = getMediaType(innerMessage);
|
|
622
519
|
if (mediaType) {
|
|
@@ -625,14 +522,12 @@ if (!isProto) {
|
|
|
625
522
|
if (isNewsletter) {
|
|
626
523
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
627
524
|
const bytes = encodeNewsletterMessage(patched);
|
|
628
|
-
// Lia@Changes 08-02-26 --- Add "additionalNodes" for newsletter too (っ˘̩╭╮˘̩)っ
|
|
629
525
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
630
|
-
;
|
|
631
526
|
binaryNodeContent.push(...additionalNodes);
|
|
632
527
|
}
|
|
633
528
|
binaryNodeContent.push({
|
|
634
529
|
tag: 'plaintext',
|
|
635
|
-
attrs: extraAttrs,
|
|
530
|
+
attrs: extraAttrs,
|
|
636
531
|
content: bytes
|
|
637
532
|
});
|
|
638
533
|
const stanza = {
|
|
@@ -647,17 +542,15 @@ if (!isProto) {
|
|
|
647
542
|
};
|
|
648
543
|
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
649
544
|
if (fireAndForget) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
} else {
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
return;
|
|
545
|
+
sendNode(stanza).catch(err => {
|
|
546
|
+
logger.warn({ err: err?.message }, 'fireAndForget newsletter failed');
|
|
547
|
+
});
|
|
548
|
+
} else {
|
|
549
|
+
await sendNode(stanza); // 👈 LANGSUNG SENDNODE
|
|
550
|
+
}
|
|
551
|
+
return;
|
|
657
552
|
}
|
|
658
|
-
// Lia@Changes 02-02-26 --- Add keepInChat, editedMessage, mediaNotifyMessage and pollUpdateMessage
|
|
659
553
|
const isNeedMetaAttrs = innerMessage?.pinInChatMessage || innerMessage?.keepInChatMessage || innerMessage?.reactionMessage;
|
|
660
|
-
// Lia@Changes 12-05-26 --- Add groupStatusMessage attributes
|
|
661
554
|
const isGroupStatus = message?.groupStatusMessage || message?.groupStatusMessageV2;
|
|
662
555
|
const isPollUpdate = innerMessage?.pollUpdateMessage;
|
|
663
556
|
if (isNeedMetaAttrs || isGroupStatus || isPollUpdate) {
|
|
@@ -678,29 +571,26 @@ return;
|
|
|
678
571
|
});
|
|
679
572
|
}
|
|
680
573
|
if (isNeedMetaAttrs || innerMessage?.protocolMessage?.memberLabel || innerMessage?.protocolMessage?.editedMessage || innerMessage?.protocolMessage?.mediaNotifyMessage) {
|
|
681
|
-
extraAttrs['decrypt-fail'] = 'hide';
|
|
574
|
+
extraAttrs['decrypt-fail'] = 'hide';
|
|
682
575
|
}
|
|
683
|
-
// Lia@Changes 02-02-26 --- Add native_flow_name to extraAttrs when sending interactiveResponseMessage
|
|
684
576
|
if (innerMessage?.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
685
577
|
extraAttrs['native_flow_name'] = innerMessage.interactiveResponseMessage.nativeFlowResponseMessage.name;
|
|
686
578
|
}
|
|
687
579
|
if (isGroupOrStatus && !isRetryResend) {
|
|
688
580
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
689
581
|
(async () => {
|
|
690
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
582
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
691
583
|
if (groupData && Array.isArray(groupData?.participants)) {
|
|
692
584
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
693
585
|
}
|
|
694
586
|
else if (!isStatus) {
|
|
695
|
-
groupData = await groupMetadata(jid);
|
|
587
|
+
groupData = await groupMetadata(jid);
|
|
696
588
|
}
|
|
697
589
|
return groupData;
|
|
698
590
|
})(),
|
|
699
591
|
(async () => {
|
|
700
592
|
if (!participant && !isStatus) {
|
|
701
|
-
|
|
702
|
-
// on participant change in group, we should do sender memory manipulation
|
|
703
|
-
const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
593
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
704
594
|
return result[jid] || {};
|
|
705
595
|
}
|
|
706
596
|
return {};
|
|
@@ -745,8 +635,6 @@ return;
|
|
|
745
635
|
!isHostedLidUser(deviceJid) &&
|
|
746
636
|
!isHostedPnUser(deviceJid) &&
|
|
747
637
|
device.device !== 99) {
|
|
748
|
-
//todo: revamp all this logic
|
|
749
|
-
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
|
750
638
|
senderKeyRecipients.push(deviceJid);
|
|
751
639
|
senderKeyMap[deviceJid] = true;
|
|
752
640
|
}
|
|
@@ -773,8 +661,6 @@ return;
|
|
|
773
661
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
774
662
|
}
|
|
775
663
|
else {
|
|
776
|
-
// ADDRESSING CONSISTENCY: Match own identity to conversation context
|
|
777
|
-
// TODO: investigate if this is true
|
|
778
664
|
let ownId = meId;
|
|
779
665
|
if (isLid && meLid) {
|
|
780
666
|
ownId = meLid;
|
|
@@ -795,7 +681,7 @@ return;
|
|
|
795
681
|
devices.push({
|
|
796
682
|
user,
|
|
797
683
|
device: 0,
|
|
798
|
-
jid: jidEncode(user, targetUserServer, 0)
|
|
684
|
+
jid: jidEncode(user, targetUserServer, 0)
|
|
799
685
|
});
|
|
800
686
|
if (user !== ownUser) {
|
|
801
687
|
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
@@ -807,30 +693,25 @@ return;
|
|
|
807
693
|
});
|
|
808
694
|
}
|
|
809
695
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
810
|
-
// Clear placeholders and enumerate actual devices
|
|
811
696
|
devices.length = 0;
|
|
812
|
-
// Use conversation-appropriate sender identity
|
|
813
697
|
const senderIdentity = isLid && meLid
|
|
814
698
|
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
815
699
|
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
816
|
-
// Enumerate devices for sender and target with consistent addressing
|
|
817
700
|
if (ptcp) {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
devices.push(...sessionDevices)
|
|
833
|
-
}
|
|
701
|
+
const sessionDevices = await getUSyncDevices(
|
|
702
|
+
[senderIdentity, jid],
|
|
703
|
+
true,
|
|
704
|
+
false
|
|
705
|
+
)
|
|
706
|
+
devices.push(...sessionDevices)
|
|
707
|
+
} else {
|
|
708
|
+
const sessionDevices = await getUSyncDevices(
|
|
709
|
+
[jid],
|
|
710
|
+
true,
|
|
711
|
+
false
|
|
712
|
+
)
|
|
713
|
+
devices.push(...sessionDevices)
|
|
714
|
+
}
|
|
834
715
|
logger.debug({
|
|
835
716
|
deviceCount: devices.length,
|
|
836
717
|
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
@@ -838,35 +719,33 @@ return;
|
|
|
838
719
|
}
|
|
839
720
|
}
|
|
840
721
|
const allRecipients = []
|
|
841
|
-
const meRecipients = []
|
|
842
|
-
const otherRecipients = []
|
|
722
|
+
const meRecipients = []
|
|
723
|
+
const otherRecipients = []
|
|
843
724
|
|
|
844
|
-
const { user: mePnUser } = jidDecode(meId)
|
|
845
|
-
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
|
|
725
|
+
const { user: mePnUser } = jidDecode(meId)
|
|
726
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
|
|
846
727
|
|
|
847
|
-
for (const { user, jid } of devices) {
|
|
848
|
-
|
|
849
|
-
|
|
728
|
+
for (const { user, jid } of devices) {
|
|
729
|
+
const isExactSenderDevice =
|
|
730
|
+
jid === meId || (meLid && jid === meLid)
|
|
850
731
|
|
|
851
|
-
|
|
852
|
-
|
|
732
|
+
if (isExactSenderDevice)
|
|
733
|
+
continue
|
|
853
734
|
|
|
854
|
-
|
|
735
|
+
const isMe = user === mePnUser || user === meLidUser
|
|
855
736
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
continue
|
|
737
|
+
if (!ptcp && isMe)
|
|
738
|
+
continue
|
|
859
739
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
740
|
+
if (isMe)
|
|
741
|
+
meRecipients.push(jid)
|
|
742
|
+
else
|
|
743
|
+
otherRecipients.push(jid)
|
|
864
744
|
|
|
865
|
-
|
|
866
|
-
}
|
|
745
|
+
allRecipients.push(jid)
|
|
746
|
+
}
|
|
867
747
|
await assertSessions(allRecipients);
|
|
868
748
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
869
|
-
// For own devices: use DSM if available (1:1 chats only)
|
|
870
749
|
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
871
750
|
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
872
751
|
]);
|
|
@@ -934,7 +813,7 @@ for (const { user, jid } of devices) {
|
|
|
934
813
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
935
814
|
const peerNode = participants[0]?.content?.[0];
|
|
936
815
|
if (peerNode) {
|
|
937
|
-
binaryNodeContent.push(peerNode);
|
|
816
|
+
binaryNodeContent.push(peerNode);
|
|
938
817
|
}
|
|
939
818
|
}
|
|
940
819
|
else {
|
|
@@ -955,9 +834,6 @@ for (const { user, jid } of devices) {
|
|
|
955
834
|
},
|
|
956
835
|
content: binaryNodeContent
|
|
957
836
|
};
|
|
958
|
-
// if the participant to send to is explicitly specified (generally retry recp)
|
|
959
|
-
// ensure the message is only sent to that person
|
|
960
|
-
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
961
837
|
if (participant) {
|
|
962
838
|
if (isJidGroup(destinationJid)) {
|
|
963
839
|
stanza.attrs.to = destinationJid;
|
|
@@ -975,7 +851,6 @@ for (const { user, jid } of devices) {
|
|
|
975
851
|
stanza.attrs.to = destinationJid;
|
|
976
852
|
}
|
|
977
853
|
if (shouldIncludeDeviceIdentity) {
|
|
978
|
-
;
|
|
979
854
|
stanza.content.push({
|
|
980
855
|
tag: 'device-identity',
|
|
981
856
|
attrs: {},
|
|
@@ -997,7 +872,6 @@ for (const { user, jid } of devices) {
|
|
|
997
872
|
};
|
|
998
873
|
const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey);
|
|
999
874
|
if (reportingNode) {
|
|
1000
|
-
;
|
|
1001
875
|
stanza.content.push(reportingNode);
|
|
1002
876
|
logger.trace({ jid }, 'added reporting token to message');
|
|
1003
877
|
}
|
|
@@ -1006,19 +880,15 @@ for (const { user, jid } of devices) {
|
|
|
1006
880
|
logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token');
|
|
1007
881
|
}
|
|
1008
882
|
}
|
|
1009
|
-
// WA Web never attaches tctoken to peer (AppStateSync) messages — server rejects with 479
|
|
1010
883
|
const isPeerMessage = additionalAttributes?.['category'] === 'peer';
|
|
1011
884
|
const is1on1Send = !isGroup && !isRetryResend && !isStatus && !isNewsletter && !isPeerMessage;
|
|
1012
|
-
// Resolve destination to LID for tctoken storage — matches Signal session key pattern
|
|
1013
885
|
const tcTokenJid = is1on1Send ? await resolveTcTokenJid(destinationJid, getLIDForPN) : destinationJid;
|
|
1014
886
|
const contactTcTokenData = is1on1Send ? await authState.keys.get('tctoken', [tcTokenJid]) : {};
|
|
1015
887
|
const existingTokenEntry = contactTcTokenData[tcTokenJid];
|
|
1016
888
|
let tcTokenBuffer = existingTokenEntry?.token;
|
|
1017
|
-
// Treat expired tokens the same as missing — clear from cache
|
|
1018
889
|
if (tcTokenBuffer?.length && isTcTokenExpired(existingTokenEntry?.timestamp)) {
|
|
1019
890
|
logger.debug({ jid: destinationJid, timestamp: existingTokenEntry?.timestamp }, 'tctoken expired, clearing');
|
|
1020
891
|
tcTokenBuffer = undefined;
|
|
1021
|
-
// Preserve senderTimestamp so the fire-and-forget issuance dedupe survives cleanup.
|
|
1022
892
|
const cleared = existingTokenEntry?.senderTimestamp !== undefined
|
|
1023
893
|
? { token: Buffer.alloc(0), senderTimestamp: existingTokenEntry.senderTimestamp }
|
|
1024
894
|
: null;
|
|
@@ -1030,7 +900,6 @@ for (const { user, jid } of devices) {
|
|
|
1030
900
|
}
|
|
1031
901
|
}
|
|
1032
902
|
if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
|
|
1033
|
-
;
|
|
1034
903
|
stanza.content.push({
|
|
1035
904
|
tag: 'tctoken',
|
|
1036
905
|
attrs: {},
|
|
@@ -1039,26 +908,22 @@ for (const { user, jid } of devices) {
|
|
|
1039
908
|
}
|
|
1040
909
|
let alreadyHasBizNode = false;
|
|
1041
910
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
1042
|
-
;
|
|
1043
911
|
stanza.content.push(...additionalNodes);
|
|
1044
912
|
alreadyHasBizNode = !addBizAttributes &&
|
|
1045
913
|
additionalNodes.some(node => node.tag === 'biz');
|
|
1046
914
|
}
|
|
1047
|
-
// Lia@Changes 30-01-26 --- Add Biz Binary Node to support button messages
|
|
1048
915
|
if ((!alreadyHasBizNode && shouldIncludeBizBinaryNode(innerMessage)) || addBizAttributes) {
|
|
1049
916
|
const bizNode = getBizBinaryNode(innerMessage);
|
|
1050
917
|
stanza.content.push(bizNode);
|
|
1051
918
|
}
|
|
1052
919
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
1053
920
|
if (fireAndForget) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
} else {
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
// Fire-and-forget: issue our token to the contact AFTER message send.
|
|
1061
|
-
// WA Web skips protocol messages and PSA/bot contacts (TcTokenChatAction: isRegularUser)
|
|
921
|
+
sendNode(stanza).catch(err => {
|
|
922
|
+
logger.warn({ err: err?.message }, 'fireAndForget sendNode failed');
|
|
923
|
+
});
|
|
924
|
+
} else {
|
|
925
|
+
await sendNode(stanza); // 👈 LANGSUNG SENDNODE
|
|
926
|
+
}
|
|
1062
927
|
const isProtocolMsg = !!innerMessage?.protocolMessage;
|
|
1063
928
|
const isBotOrPSA = destinationJid === PSA_WID || isJidBot(destinationJid) || isJidMetaAI(destinationJid);
|
|
1064
929
|
if (is1on1Send &&
|
|
@@ -1099,7 +964,6 @@ for (const { user, jid } of devices) {
|
|
|
1099
964
|
inFlightTcTokenIssuance.delete(tcTokenJid);
|
|
1100
965
|
});
|
|
1101
966
|
}
|
|
1102
|
-
// Add message to retry cache if enabled
|
|
1103
967
|
if (messageRetryManager && !participant) {
|
|
1104
968
|
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
1105
969
|
}
|
|
@@ -1108,58 +972,54 @@ for (const { user, jid } of devices) {
|
|
|
1108
972
|
};
|
|
1109
973
|
|
|
1110
974
|
const sendPrivateRelay = async (jid, content, targets = [], options = {}) => {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
if (!Array.isArray(targets) || !targets.length) {
|
|
1118
|
-
throw new Boom('Target kosong', {
|
|
1119
|
-
statusCode: 400
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
const userJid = authState.creds.me.id;
|
|
1124
|
-
|
|
1125
|
-
const fullMsg = await generateWAMessage(jid, content, {
|
|
1126
|
-
logger,
|
|
1127
|
-
userJid,
|
|
1128
|
-
upload: waUploadToServer,
|
|
1129
|
-
mediaCache: config.mediaCache,
|
|
1130
|
-
options: config.options,
|
|
1131
|
-
...options,
|
|
1132
|
-
messageId: generateMessageIDV2(userJid)
|
|
1133
|
-
});
|
|
1134
|
-
|
|
1135
|
-
const uniqueTargets = [
|
|
1136
|
-
...new Set(
|
|
1137
|
-
targets
|
|
1138
|
-
.filter(Boolean)
|
|
1139
|
-
.map(j => jidNormalizedUser(j))
|
|
1140
|
-
)
|
|
1141
|
-
];
|
|
975
|
+
if (!isJidGroup(jid)) {
|
|
976
|
+
throw new Boom('Private relay hanya bisa digunakan untuk group', {
|
|
977
|
+
statusCode: 400
|
|
978
|
+
});
|
|
979
|
+
}
|
|
1142
980
|
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
981
|
+
if (!Array.isArray(targets) || !targets.length) {
|
|
982
|
+
throw new Boom('Target kosong', {
|
|
983
|
+
statusCode: 400
|
|
984
|
+
});
|
|
985
|
+
}
|
|
1146
986
|
|
|
1147
|
-
|
|
1148
|
-
jid: target,
|
|
1149
|
-
count: 0
|
|
1150
|
-
},
|
|
987
|
+
const userJid = authState.creds.me.id;
|
|
1151
988
|
|
|
1152
|
-
|
|
989
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
990
|
+
logger,
|
|
991
|
+
userJid,
|
|
992
|
+
upload: waUploadToServer,
|
|
993
|
+
mediaCache: config.mediaCache,
|
|
994
|
+
options: config.options,
|
|
995
|
+
...options,
|
|
996
|
+
messageId: generateMessageIDV2(userJid)
|
|
997
|
+
});
|
|
1153
998
|
|
|
1154
|
-
|
|
1155
|
-
|
|
999
|
+
const uniqueTargets = [
|
|
1000
|
+
...new Set(
|
|
1001
|
+
targets
|
|
1002
|
+
.filter(Boolean)
|
|
1003
|
+
.map(j => jidNormalizedUser(j))
|
|
1004
|
+
)
|
|
1005
|
+
];
|
|
1156
1006
|
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1007
|
+
for (const target of uniqueTargets) {
|
|
1008
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1009
|
+
messageId: fullMsg.key.id,
|
|
1010
|
+
participant: {
|
|
1011
|
+
jid: target,
|
|
1012
|
+
count: 0
|
|
1013
|
+
},
|
|
1014
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1015
|
+
additionalAttributes: options.additionalAttributes,
|
|
1016
|
+
additionalNodes: options.additionalNodes,
|
|
1017
|
+
ptcp: false
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1160
1020
|
|
|
1161
|
-
|
|
1162
|
-
};
|
|
1021
|
+
return fullMsg;
|
|
1022
|
+
};
|
|
1163
1023
|
|
|
1164
1024
|
const getMessageType = (message) => {
|
|
1165
1025
|
if (!message)
|
|
@@ -1183,6 +1043,7 @@ for (const { user, jid } of devices) {
|
|
|
1183
1043
|
}
|
|
1184
1044
|
return 'text';
|
|
1185
1045
|
};
|
|
1046
|
+
|
|
1186
1047
|
const getMediaType = (message) => {
|
|
1187
1048
|
if (message.imageMessage) {
|
|
1188
1049
|
return 'image';
|
|
@@ -1238,7 +1099,6 @@ for (const { user, jid } of devices) {
|
|
|
1238
1099
|
else if (message.extendedTextMessage?.matchedText || message.groupInviteMessage) {
|
|
1239
1100
|
return 'url';
|
|
1240
1101
|
}
|
|
1241
|
-
// Lia@Note 02-02-26 --- Add more message type here
|
|
1242
1102
|
else if ((message.extendedTextMessage?.text || message.conversation || '').includes('://wa.me/c/')) {
|
|
1243
1103
|
return 'cataloglink';
|
|
1244
1104
|
}
|
|
@@ -1247,6 +1107,7 @@ for (const { user, jid } of devices) {
|
|
|
1247
1107
|
}
|
|
1248
1108
|
return '';
|
|
1249
1109
|
};
|
|
1110
|
+
|
|
1250
1111
|
const issuePrivacyTokens = async (jids, timestamp) => {
|
|
1251
1112
|
const t = (timestamp ?? unixTimestampSeconds()).toString();
|
|
1252
1113
|
const result = await query({
|
|
@@ -1273,8 +1134,10 @@ for (const { user, jid } of devices) {
|
|
|
1273
1134
|
});
|
|
1274
1135
|
return result;
|
|
1275
1136
|
};
|
|
1137
|
+
|
|
1276
1138
|
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
1277
1139
|
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
1140
|
+
|
|
1278
1141
|
registerSocketEndHandler(() => {
|
|
1279
1142
|
if (!config.userDevicesCache && userDevicesCache.close) {
|
|
1280
1143
|
userDevicesCache.close();
|
|
@@ -1284,6 +1147,7 @@ for (const { user, jid } of devices) {
|
|
|
1284
1147
|
messageRetryManager.clear();
|
|
1285
1148
|
}
|
|
1286
1149
|
});
|
|
1150
|
+
|
|
1287
1151
|
return {
|
|
1288
1152
|
...sock,
|
|
1289
1153
|
userDevicesCache,
|
|
@@ -1346,15 +1210,12 @@ for (const { user, jid } of devices) {
|
|
|
1346
1210
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1347
1211
|
return message;
|
|
1348
1212
|
},
|
|
1349
|
-
|
|
1350
1213
|
sendHtmlApp: async (jid, html, options = {}) => {
|
|
1351
1214
|
const { text, ...rest } = options;
|
|
1352
1215
|
return sendHtmlAppBuilder({ ...sock, relayMessage }, jid, html, text !== undefined ? { label: text, ...rest } : rest);
|
|
1353
1216
|
},
|
|
1354
|
-
// Lia@Changes 30-01-26 --- Add support for modifying additionalNodes and additionalAttributes using "options" in sendMessage()
|
|
1355
1217
|
sendMessage: async (jid, content, options = {}) => {
|
|
1356
1218
|
const userJid = authState.creds.me.id;
|
|
1357
|
-
// Lia@Changes 13-03-26 --- Add status mentions!
|
|
1358
1219
|
if (Array.isArray(jid)) {
|
|
1359
1220
|
const { delayMs = 1500 } = options;
|
|
1360
1221
|
const allUsers = new Set();
|
|
@@ -1471,7 +1332,6 @@ for (const { user, jid } of devices) {
|
|
|
1471
1332
|
logger,
|
|
1472
1333
|
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1473
1334
|
}),
|
|
1474
|
-
//TODO: CACHE
|
|
1475
1335
|
getProfilePicUrl: sock.profilePictureUrl,
|
|
1476
1336
|
getCallLink: sock.createCallLink,
|
|
1477
1337
|
upload: waUploadToServer,
|
|
@@ -1492,9 +1352,7 @@ for (const { user, jid } of devices) {
|
|
|
1492
1352
|
const isNeedBizAttrs = 'secureMetaServiceLabel' in content && !!content.secureMetaServiceLabel;
|
|
1493
1353
|
const additionalAttributes = options.additionalAttributes || {};
|
|
1494
1354
|
const additionalNodes = options.additionalNodes || [];
|
|
1495
|
-
// required for delete
|
|
1496
1355
|
if (isDeleteMsg || isKeepMsg) {
|
|
1497
|
-
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1498
1356
|
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1499
1357
|
additionalAttributes.edit = '8';
|
|
1500
1358
|
}
|
|
@@ -1515,7 +1373,6 @@ for (const { user, jid } of devices) {
|
|
|
1515
1373
|
additionalNodes.push({
|
|
1516
1374
|
tag: 'meta',
|
|
1517
1375
|
attrs: {
|
|
1518
|
-
// Lia@Note 08-02-26 --- Still a hypothesis regarding PollResult ༎ຶ‿༎ຶ
|
|
1519
1376
|
polltype: isQuizMsg ? 'quiz_creation' : 'creation',
|
|
1520
1377
|
contenttype: isPollMsg && isNewsletter ? 'text' : undefined
|
|
1521
1378
|
},
|
|
@@ -1531,7 +1388,6 @@ for (const { user, jid } of devices) {
|
|
|
1531
1388
|
content: undefined
|
|
1532
1389
|
});
|
|
1533
1390
|
}
|
|
1534
|
-
// Lia@Changes 30-01-26 --- Add support for AI label in message when "ai" is true, but works only in private chat
|
|
1535
1391
|
else if (isAiMsg) {
|
|
1536
1392
|
if (!(isPnUser(jid) || isLidUser(jid))) {
|
|
1537
1393
|
throw new Boom('AI icon on message are only allowed in private chat', { statusCode: 400 });
|
|
@@ -1539,7 +1395,6 @@ for (const { user, jid } of devices) {
|
|
|
1539
1395
|
if ('messageContextInfo' in fullMsg.message && !!fullMsg.message.messageContextInfo) {
|
|
1540
1396
|
fullMsg.message.messageContextInfo.supportPayload = BIZ_BOT_SUPPORT_PAYLOAD;
|
|
1541
1397
|
}
|
|
1542
|
-
;
|
|
1543
1398
|
additionalNodes.push({
|
|
1544
1399
|
tag: 'bot',
|
|
1545
1400
|
attrs: {
|
|
@@ -1563,8 +1418,6 @@ for (const { user, jid } of devices) {
|
|
|
1563
1418
|
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1564
1419
|
});
|
|
1565
1420
|
}
|
|
1566
|
-
// Lia@Changes 31-01-26 --- Add support for album messages
|
|
1567
|
-
// Lia@Note 06-02-26 --- Refactored to reduce high RSS usage (╥﹏╥)
|
|
1568
1421
|
if ('album' in content) {
|
|
1569
1422
|
const { delayMs = 1500 } = options;
|
|
1570
1423
|
for (const albumMedia of content.album) {
|
|
@@ -1593,7 +1446,6 @@ for (const { user, jid } of devices) {
|
|
|
1593
1446
|
additionalAttributes,
|
|
1594
1447
|
additionalNodes,
|
|
1595
1448
|
ptcp: options.ptcp ?? true
|
|
1596
|
-
|
|
1597
1449
|
});
|
|
1598
1450
|
if (config.emitOwnEvents) {
|
|
1599
1451
|
process.nextTick(async () => {
|
|
@@ -18,6 +18,7 @@ export const Browsers = {
|
|
|
18
18
|
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
19
19
|
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
20
20
|
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
21
|
+
android: browser => [browser, 'Android', ''],
|
|
21
22
|
/** The appropriate browser based on your OS & release */
|
|
22
23
|
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
23
24
|
};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -1181,16 +1181,6 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1181
1181
|
};
|
|
1182
1182
|
}
|
|
1183
1183
|
}
|
|
1184
|
-
if (hasOptionalProperty(message, "edit")) {
|
|
1185
|
-
m = {
|
|
1186
|
-
protocolMessage: {
|
|
1187
|
-
key: message.edit,
|
|
1188
|
-
editedMessage: m,
|
|
1189
|
-
timestampMs: Date.now(),
|
|
1190
|
-
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
1191
|
-
},
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
1184
|
if (hasOptionalProperty(message, "contextInfo") && !!message.contextInfo) {
|
|
1195
1185
|
const messageType = Object.keys(m)[0];
|
|
1196
1186
|
const key = m[messageType];
|
|
@@ -1206,6 +1196,16 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1206
1196
|
m.messageContextInfo.messageSecret = randomBytes(32);
|
|
1207
1197
|
}
|
|
1208
1198
|
}
|
|
1199
|
+
if (hasOptionalProperty(message, "edit")) {
|
|
1200
|
+
m = {
|
|
1201
|
+
protocolMessage: {
|
|
1202
|
+
key: message.edit,
|
|
1203
|
+
editedMessage: m,
|
|
1204
|
+
timestampMs: Date.now(),
|
|
1205
|
+
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
1206
|
+
},
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
1209
|
return WAProto.Message.create(m);
|
|
1210
1210
|
};
|
|
1211
1211
|
const applyContextInfoDeep = (message, contextInfo) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fvckerss/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.19",
|
|
5
5
|
"description": "Baileys mod by Swiper",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@hapi/boom": "^9.1.3",
|
|
45
45
|
"async-mutex": "^0.5.0",
|
|
46
46
|
"libphonenumber-js": "^1.10.20",
|
|
47
|
-
"libsignal": "git+https://github.com/whiskeysockets/libsignal-node",
|
|
47
|
+
"libsignal": "git+https://github.com/whiskeysockets/libsignal-node.git",
|
|
48
48
|
"lru-cache": "^11.1.0",
|
|
49
49
|
"music-metadata": "^11.12.3",
|
|
50
50
|
"p-queue": "^9.0.0",
|