@dyyxyzz/baileys-mod 6.0.37 → 6.0.40
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/lib/Socket/messages-send.js +165 -198
- package/lib/Utils/messages.js +3 -3
- package/package.json +1 -1
|
@@ -8,7 +8,6 @@ const boom_1 = require("@hapi/boom");
|
|
|
8
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
9
|
const WAProto_1 = require("../../WAProto");
|
|
10
10
|
const Defaults_1 = require("../Defaults");
|
|
11
|
-
const axios_1 = require("axios")
|
|
12
11
|
const Types_1 = require("../Types")
|
|
13
12
|
const Utils_1 = require("../Utils");
|
|
14
13
|
const link_preview_1 = require("../Utils/link-preview");
|
|
@@ -16,7 +15,9 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
15
|
const newsletter_1 = require("./newsletter");
|
|
17
16
|
const WAUSync_1 = require("../WAUSync")
|
|
18
17
|
const kikyy = require('./dugong');
|
|
18
|
+
|
|
19
19
|
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
20
|
+
|
|
20
21
|
const makeMessagesSocket = (config) => {
|
|
21
22
|
const {
|
|
22
23
|
logger,
|
|
@@ -25,6 +26,7 @@ const makeMessagesSocket = (config) => {
|
|
|
25
26
|
options: axiosOptions,
|
|
26
27
|
patchMessageBeforeSending
|
|
27
28
|
} = config;
|
|
29
|
+
|
|
28
30
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
29
31
|
const {
|
|
30
32
|
ev,
|
|
@@ -40,11 +42,14 @@ const makeMessagesSocket = (config) => {
|
|
|
40
42
|
groupToggleEphemeral,
|
|
41
43
|
executeUSyncQuery
|
|
42
44
|
} = sock;
|
|
45
|
+
|
|
43
46
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
44
47
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
45
48
|
useClones: false
|
|
46
49
|
});
|
|
50
|
+
|
|
47
51
|
let mediaConn;
|
|
52
|
+
|
|
48
53
|
const refreshMediaConn = async (forceGet = false) => {
|
|
49
54
|
const media = await mediaConn;
|
|
50
55
|
if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
|
@@ -74,10 +79,7 @@ const makeMessagesSocket = (config) => {
|
|
|
74
79
|
}
|
|
75
80
|
return mediaConn;
|
|
76
81
|
};
|
|
77
|
-
|
|
78
|
-
* generic send receipt function
|
|
79
|
-
* used for receipts of phone call, read, delivery etc.
|
|
80
|
-
* */
|
|
82
|
+
|
|
81
83
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
82
84
|
const node = {
|
|
83
85
|
tag: 'receipt',
|
|
@@ -118,86 +120,69 @@ const makeMessagesSocket = (config) => {
|
|
|
118
120
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
119
121
|
await sendNode(node);
|
|
120
122
|
};
|
|
121
|
-
|
|
123
|
+
|
|
122
124
|
const sendReceipts = async (keys, type) => {
|
|
123
125
|
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
124
126
|
for (const { jid, participant, messageIds } of recps) {
|
|
125
127
|
await sendReceipt(jid, participant, messageIds, type);
|
|
126
128
|
}
|
|
127
129
|
};
|
|
128
|
-
|
|
130
|
+
|
|
129
131
|
const readMessages = async (keys) => {
|
|
130
132
|
const privacySettings = await fetchPrivacySettings();
|
|
131
|
-
// based on privacy settings, we have to change the read type
|
|
132
133
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
133
134
|
await sendReceipts(keys, readType);
|
|
134
135
|
};
|
|
135
|
-
|
|
136
|
+
|
|
136
137
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
137
138
|
const deviceResults = []
|
|
138
|
-
|
|
139
139
|
if (!useCache) {
|
|
140
140
|
logger.debug('not using cache for devices')
|
|
141
141
|
}
|
|
142
|
-
|
|
143
142
|
const toFetch = []
|
|
144
|
-
|
|
145
143
|
jids = Array.from(new Set(jids))
|
|
146
|
-
|
|
147
144
|
for (let jid of jids) {
|
|
148
145
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
149
|
-
|
|
150
146
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
-
|
|
152
147
|
if (useCache) {
|
|
153
148
|
const devices = userDevicesCache.get(user)
|
|
154
|
-
|
|
155
149
|
if (devices) {
|
|
156
150
|
deviceResults.push(...devices)
|
|
157
151
|
logger.trace({ user }, 'using cache for devices')
|
|
158
152
|
}
|
|
159
|
-
|
|
160
153
|
else {
|
|
161
154
|
toFetch.push(jid)
|
|
162
155
|
}
|
|
163
156
|
}
|
|
164
|
-
|
|
165
157
|
else {
|
|
166
158
|
toFetch.push(jid)
|
|
167
159
|
}
|
|
168
160
|
}
|
|
169
|
-
|
|
170
161
|
if (!toFetch.length) {
|
|
171
162
|
return deviceResults
|
|
172
163
|
}
|
|
173
|
-
|
|
174
164
|
const query = new WAUSync_1.USyncQuery()
|
|
175
165
|
.withContext('message')
|
|
176
166
|
.withDeviceProtocol()
|
|
177
|
-
|
|
178
167
|
for (const jid of toFetch) {
|
|
179
168
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
180
169
|
}
|
|
181
|
-
|
|
182
170
|
const result = await executeUSyncQuery(query)
|
|
183
|
-
|
|
184
171
|
if (result) {
|
|
185
172
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
186
173
|
const deviceMap = {}
|
|
187
|
-
|
|
188
174
|
for (const item of extracted) {
|
|
189
175
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
176
|
deviceMap[item.user].push(item)
|
|
191
177
|
deviceResults.push(item)
|
|
192
178
|
}
|
|
193
|
-
|
|
194
179
|
for (const key in deviceMap) {
|
|
195
180
|
userDevicesCache.set(key, deviceMap[key])
|
|
196
181
|
}
|
|
197
182
|
}
|
|
198
|
-
|
|
199
183
|
return deviceResults
|
|
200
184
|
}
|
|
185
|
+
|
|
201
186
|
const assertSessions = async (jids, force) => {
|
|
202
187
|
let didFetchNewSession = false;
|
|
203
188
|
let jidsRequiringFetch = [];
|
|
@@ -205,12 +190,10 @@ const makeMessagesSocket = (config) => {
|
|
|
205
190
|
jidsRequiringFetch = jids;
|
|
206
191
|
}
|
|
207
192
|
else {
|
|
208
|
-
const addrs = jids.map(jid => (signalRepository
|
|
209
|
-
.jidToSignalProtocolAddress(jid)));
|
|
193
|
+
const addrs = jids.map(jid => (signalRepository.jidToSignalProtocolAddress(jid)));
|
|
210
194
|
const sessions = await authState.keys.get('session', addrs);
|
|
211
195
|
for (const jid of jids) {
|
|
212
|
-
const signalId = signalRepository
|
|
213
|
-
.jidToSignalProtocolAddress(jid);
|
|
196
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
214
197
|
if (!sessions[signalId]) {
|
|
215
198
|
jidsRequiringFetch.push(jid);
|
|
216
199
|
}
|
|
@@ -241,13 +224,11 @@ const makeMessagesSocket = (config) => {
|
|
|
241
224
|
}
|
|
242
225
|
return didFetchNewSession;
|
|
243
226
|
};
|
|
244
|
-
|
|
245
|
-
|
|
227
|
+
|
|
246
228
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
247
229
|
if (!authState.creds.me?.id) {
|
|
248
230
|
throw new boom_1.Boom('Not authenticated')
|
|
249
231
|
}
|
|
250
|
-
|
|
251
232
|
const protocolMessage = {
|
|
252
233
|
protocolMessage: {
|
|
253
234
|
peerDataOperationRequestMessage: pdoMessage,
|
|
@@ -258,19 +239,18 @@ const makeMessagesSocket = (config) => {
|
|
|
258
239
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
259
240
|
additionalAttributes: {
|
|
260
241
|
category: 'peer',
|
|
261
|
-
// eslint-disable-next-line camelcase
|
|
262
242
|
push_priority: 'high_force',
|
|
263
243
|
},
|
|
264
244
|
});
|
|
265
245
|
return msgId;
|
|
266
246
|
};
|
|
247
|
+
|
|
267
248
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
268
249
|
const patched = await patchMessageBeforeSending(message, jids);
|
|
269
250
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
|
270
251
|
let shouldIncludeDeviceIdentity = false;
|
|
271
252
|
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
272
|
-
const { type, ciphertext } = await signalRepository
|
|
273
|
-
.encryptMessage({ jid, data: bytes });
|
|
253
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
|
|
274
254
|
if (type === 'pkmsg') {
|
|
275
255
|
shouldIncludeDeviceIdentity = true;
|
|
276
256
|
}
|
|
@@ -278,19 +258,20 @@ const makeMessagesSocket = (config) => {
|
|
|
278
258
|
tag: 'to',
|
|
279
259
|
attrs: { jid },
|
|
280
260
|
content: [{
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
261
|
+
tag: 'enc',
|
|
262
|
+
attrs: {
|
|
263
|
+
v: '2',
|
|
264
|
+
type,
|
|
265
|
+
...extraAttrs || {}
|
|
266
|
+
},
|
|
267
|
+
content: ciphertext
|
|
268
|
+
}]
|
|
289
269
|
};
|
|
290
270
|
return node;
|
|
291
271
|
}));
|
|
292
272
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
|
-
};
|
|
273
|
+
};
|
|
274
|
+
|
|
294
275
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
295
276
|
const meId = authState.creds.me.id;
|
|
296
277
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -318,16 +299,15 @@ const makeMessagesSocket = (config) => {
|
|
|
318
299
|
const extraAttrs = {}
|
|
319
300
|
const messages = Utils_1.normalizeMessageContent(message)
|
|
320
301
|
const buttonType = getButtonType(messages);
|
|
302
|
+
|
|
321
303
|
if (participant) {
|
|
322
|
-
// when the retry request is not for a group
|
|
323
|
-
// only send to the specific device that asked for a retry
|
|
324
|
-
// otherwise the message is sent out to every device that should be a recipient
|
|
325
304
|
if (!isGroup && !isStatus) {
|
|
326
305
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
327
306
|
}
|
|
328
307
|
const { user, device } = WABinary_1.jidDecode(participant.jid);
|
|
329
308
|
devices.push({ user, device });
|
|
330
309
|
}
|
|
310
|
+
|
|
331
311
|
await authState.keys.transaction(async () => {
|
|
332
312
|
const mediaType = getMediaType(messages);
|
|
333
313
|
|
|
@@ -350,11 +330,9 @@ const makeMessagesSocket = (config) => {
|
|
|
350
330
|
if (groupData) {
|
|
351
331
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
352
332
|
}
|
|
353
|
-
|
|
354
333
|
else if (!isStatus) {
|
|
355
334
|
groupData = await groupMetadata(jid)
|
|
356
335
|
}
|
|
357
|
-
|
|
358
336
|
return groupData;
|
|
359
337
|
})(),
|
|
360
338
|
(async () => {
|
|
@@ -362,27 +340,15 @@ const makeMessagesSocket = (config) => {
|
|
|
362
340
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
341
|
return result[jid] || {}
|
|
364
342
|
}
|
|
365
|
-
|
|
366
343
|
return {}
|
|
367
|
-
|
|
368
344
|
})()
|
|
369
345
|
]);
|
|
346
|
+
|
|
370
347
|
if (!participant) {
|
|
371
348
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
-
|
|
373
349
|
if (isStatus && statusJidList) {
|
|
374
350
|
participantsList.push(...statusJidList)
|
|
375
351
|
}
|
|
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
352
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
387
353
|
devices.push(...additionalDevices)
|
|
388
354
|
}
|
|
@@ -395,18 +361,16 @@ const makeMessagesSocket = (config) => {
|
|
|
395
361
|
data: bytes,
|
|
396
362
|
meId,
|
|
397
363
|
});
|
|
398
|
-
const senderKeyJids = [];
|
|
399
364
|
|
|
365
|
+
const senderKeyJids = [];
|
|
400
366
|
for (const { user, device } of devices) {
|
|
401
367
|
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
402
368
|
if (!senderKeyMap[jid] || !!participant) {
|
|
403
369
|
senderKeyJids.push(jid);
|
|
404
|
-
// store that this person has had the sender keys sent to them
|
|
405
370
|
senderKeyMap[jid] = true;
|
|
406
371
|
}
|
|
407
372
|
}
|
|
408
|
-
|
|
409
|
-
// if there are, we re-send the senderkey
|
|
373
|
+
|
|
410
374
|
if (senderKeyJids.length) {
|
|
411
375
|
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
412
376
|
const senderKeyMsg = {
|
|
@@ -420,6 +384,7 @@ const makeMessagesSocket = (config) => {
|
|
|
420
384
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
421
385
|
participants.push(...result.nodes);
|
|
422
386
|
}
|
|
387
|
+
|
|
423
388
|
binaryNodeContent.push({
|
|
424
389
|
tag: 'enc',
|
|
425
390
|
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
@@ -428,21 +393,16 @@ const makeMessagesSocket = (config) => {
|
|
|
428
393
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
394
|
}
|
|
430
395
|
else if (isNewsletter) {
|
|
431
|
-
// Message edit
|
|
432
396
|
if (message.protocolMessage?.editedMessage) {
|
|
433
397
|
msgId = message.protocolMessage.key?.id
|
|
434
398
|
message = message.protocolMessage.editedMessage
|
|
435
399
|
}
|
|
436
|
-
|
|
437
|
-
// Message delete
|
|
438
400
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
439
401
|
msgId = message.protocolMessage.key?.id
|
|
440
402
|
message = {}
|
|
441
403
|
}
|
|
442
|
-
|
|
443
404
|
const patched = await patchMessageBeforeSending(message, [])
|
|
444
405
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
-
|
|
446
406
|
binaryNodeContent.push({
|
|
447
407
|
tag: 'plaintext',
|
|
448
408
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -456,30 +416,27 @@ const makeMessagesSocket = (config) => {
|
|
|
456
416
|
if (user !== meUser) {
|
|
457
417
|
devices.push({ user: meUser })
|
|
458
418
|
}
|
|
459
|
-
|
|
460
419
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
461
420
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
-
|
|
463
421
|
devices.push(...additionalDevices)
|
|
464
422
|
}
|
|
465
423
|
}
|
|
424
|
+
|
|
466
425
|
const allJids = [];
|
|
467
426
|
const meJids = [];
|
|
468
427
|
const otherJids = [];
|
|
469
428
|
for (const { user, device } of devices) {
|
|
470
429
|
const isMe = user === meUser
|
|
471
430
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
472
|
-
|
|
473
431
|
if (isMe) {
|
|
474
432
|
meJids.push(jid)
|
|
475
433
|
}
|
|
476
|
-
|
|
477
434
|
else {
|
|
478
435
|
otherJids.push(jid)
|
|
479
436
|
}
|
|
480
|
-
|
|
481
437
|
allJids.push(jid)
|
|
482
438
|
}
|
|
439
|
+
|
|
483
440
|
await assertSessions(allJids, false);
|
|
484
441
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
485
442
|
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
@@ -489,15 +446,14 @@ const makeMessagesSocket = (config) => {
|
|
|
489
446
|
participants.push(...otherNodes);
|
|
490
447
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
491
448
|
}
|
|
449
|
+
|
|
492
450
|
if (participants.length) {
|
|
493
451
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
494
452
|
const peerNode = participants[0]?.content?.[0]
|
|
495
|
-
|
|
496
453
|
if (peerNode) {
|
|
497
|
-
binaryNodeContent.push(peerNode)
|
|
454
|
+
binaryNodeContent.push(peerNode)
|
|
498
455
|
}
|
|
499
456
|
}
|
|
500
|
-
|
|
501
457
|
else {
|
|
502
458
|
binaryNodeContent.push({
|
|
503
459
|
tag: 'participants',
|
|
@@ -516,9 +472,7 @@ const makeMessagesSocket = (config) => {
|
|
|
516
472
|
},
|
|
517
473
|
content: binaryNodeContent
|
|
518
474
|
}
|
|
519
|
-
|
|
520
|
-
// ensure the message is only sent to that person
|
|
521
|
-
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
475
|
+
|
|
522
476
|
if (participant) {
|
|
523
477
|
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
524
478
|
stanza.attrs.to = destinationJid;
|
|
@@ -535,6 +489,7 @@ const makeMessagesSocket = (config) => {
|
|
|
535
489
|
else {
|
|
536
490
|
stanza.attrs.to = destinationJid;
|
|
537
491
|
}
|
|
492
|
+
|
|
538
493
|
if (shouldIncludeDeviceIdentity) {
|
|
539
494
|
stanza.content.push({
|
|
540
495
|
tag: 'device-identity',
|
|
@@ -551,31 +506,37 @@ const makeMessagesSocket = (config) => {
|
|
|
551
506
|
biz_bot: '1'
|
|
552
507
|
}
|
|
553
508
|
}
|
|
554
|
-
|
|
555
509
|
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
-
|
|
557
510
|
if (filteredBizBot) {
|
|
558
511
|
stanza.content.push(...additionalNodes)
|
|
559
512
|
didPushAdditional = true
|
|
560
513
|
}
|
|
561
|
-
|
|
562
514
|
else {
|
|
563
515
|
stanza.content.push(botNode)
|
|
564
516
|
}
|
|
565
517
|
}
|
|
566
518
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
519
|
+
// 🔥 FIX UTAMA: Support button params untuk SEMUA tipe (termasuk channel/newsletter)
|
|
520
|
+
if (!isStatus) {
|
|
521
|
+
// Deteksi apakah ada button params dalam message
|
|
522
|
+
const hasButtonParams = buttonType ||
|
|
523
|
+
messages.interactiveMessage?.nativeFlowMessage ||
|
|
524
|
+
messages.buttonsMessage ||
|
|
525
|
+
messages.listMessage;
|
|
526
|
+
|
|
527
|
+
if (hasButtonParams) {
|
|
528
|
+
const content = WABinary_1.getAdditionalNode(buttonType || 'interactive')
|
|
529
|
+
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
530
|
+
|
|
531
|
+
if (filteredNode) {
|
|
532
|
+
didPushAdditional = true
|
|
533
|
+
stanza.content.push(...additionalNodes)
|
|
534
|
+
}
|
|
535
|
+
else if (content && content.length > 0) {
|
|
536
|
+
stanza.content.push(...content)
|
|
537
|
+
}
|
|
538
|
+
logger.debug({ jid, buttonType, isNewsletter }, 'adding business node for buttons')
|
|
577
539
|
}
|
|
578
|
-
logger.debug({ jid }, 'adding business node')
|
|
579
540
|
}
|
|
580
541
|
|
|
581
542
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
@@ -602,10 +563,10 @@ const makeMessagesSocket = (config) => {
|
|
|
602
563
|
}
|
|
603
564
|
|
|
604
565
|
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
-
// return msgId;
|
|
606
566
|
};
|
|
567
|
+
|
|
607
568
|
const getTypeMessage = (msg) => {
|
|
608
|
-
|
|
569
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
609
570
|
if (message.reactionMessage) {
|
|
610
571
|
return 'reaction'
|
|
611
572
|
}
|
|
@@ -690,13 +651,14 @@ const makeMessagesSocket = (config) => {
|
|
|
690
651
|
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
691
652
|
return 'payment_method'
|
|
692
653
|
}
|
|
693
|
-
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
694
|
-
return 'interactive'
|
|
695
|
-
}
|
|
696
654
|
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
697
655
|
return 'native_flow'
|
|
698
656
|
}
|
|
657
|
+
else if (message.interactiveMessage) {
|
|
658
|
+
return 'interactive'
|
|
659
|
+
}
|
|
699
660
|
}
|
|
661
|
+
|
|
700
662
|
const getPrivacyTokens = async (jids) => {
|
|
701
663
|
const t = Utils_1.unixTimestampSeconds().toString();
|
|
702
664
|
const result = await query({
|
|
@@ -723,9 +685,11 @@ const makeMessagesSocket = (config) => {
|
|
|
723
685
|
});
|
|
724
686
|
return result;
|
|
725
687
|
}
|
|
688
|
+
|
|
726
689
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
690
|
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
728
691
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
692
|
+
|
|
729
693
|
return {
|
|
730
694
|
...sock,
|
|
731
695
|
getPrivacyTokens,
|
|
@@ -793,117 +757,120 @@ const makeMessagesSocket = (config) => {
|
|
|
793
757
|
const { filter = false, quoted } = options;
|
|
794
758
|
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
795
759
|
const messageType = rahmi.detectType(content);
|
|
760
|
+
|
|
796
761
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
797
762
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
798
763
|
const { disappearingMessagesInChat } = content
|
|
799
|
-
|
|
800
764
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
801
765
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
802
766
|
disappearingMessagesInChat
|
|
803
|
-
|
|
804
767
|
await groupToggleEphemeral(jid, value)
|
|
805
768
|
}
|
|
806
|
-
|
|
807
769
|
else {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
770
|
+
if (messageType) {
|
|
771
|
+
switch(messageType) {
|
|
772
|
+
case 'PAYMENT':
|
|
773
|
+
const paymentContent = await rahmi.handlePayment(content, quoted);
|
|
774
|
+
return await relayMessage(jid, paymentContent, {
|
|
775
|
+
messageId: Utils_1.generateMessageID(),
|
|
776
|
+
...getParticipantAttr()
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
case 'PRODUCT':
|
|
780
|
+
const productContent = await rahmi.handleProduct(content, jid, quoted);
|
|
781
|
+
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
782
|
+
return await relayMessage(jid, productMsg.message, {
|
|
783
|
+
messageId: productMsg.key.id,
|
|
784
|
+
...getParticipantAttr()
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
case 'INTERACTIVE':
|
|
788
|
+
const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
|
|
789
|
+
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
790
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
791
|
+
messageId: interactiveMsg.key.id,
|
|
792
|
+
...getParticipantAttr()
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
case 'ALBUM':
|
|
796
|
+
return await rahmi.handleAlbum(content, jid, quoted)
|
|
797
|
+
|
|
798
|
+
case 'EVENT':
|
|
799
|
+
return await rahmi.handleEvent(content, jid, quoted)
|
|
800
|
+
|
|
801
|
+
case 'POLL_RESULT':
|
|
802
|
+
return await rahmi.handlePollResult(content, jid, quoted)
|
|
803
|
+
|
|
804
|
+
case 'GROUP_STORY':
|
|
805
|
+
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
806
|
+
}
|
|
807
|
+
}
|
|
827
808
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
809
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
810
|
+
logger,
|
|
811
|
+
userJid,
|
|
812
|
+
quoted,
|
|
813
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
814
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
815
|
+
fetchOpts: {
|
|
816
|
+
timeout: 3000,
|
|
817
|
+
...axiosOptions || {}
|
|
818
|
+
},
|
|
819
|
+
logger,
|
|
820
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
821
|
+
}),
|
|
822
|
+
upload: async (readStream, opts) => {
|
|
823
|
+
const up = await waUploadToServer(readStream, {
|
|
824
|
+
...opts,
|
|
825
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
834
826
|
});
|
|
835
|
-
|
|
836
|
-
return await rahmi.handleAlbum(content, jid, quoted)
|
|
837
|
-
case 'EVENT':
|
|
838
|
-
return await rahmi.handleEvent(content, jid, quoted)
|
|
839
|
-
case 'POLL_RESULT':
|
|
840
|
-
return await rahmi.handlePollResult(content, jid, quoted)
|
|
841
|
-
case 'GROUP_STORY':
|
|
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 || {}
|
|
827
|
+
return up;
|
|
854
828
|
},
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
upload: async (readStream, opts) => {
|
|
859
|
-
const up = await waUploadToServer(readStream, {
|
|
860
|
-
...opts,
|
|
861
|
-
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
862
|
-
});
|
|
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({
|
|
885
|
-
attrs: {
|
|
886
|
-
biz_bot: '1'
|
|
887
|
-
}, tag: "bot"
|
|
829
|
+
mediaCache: config.mediaCache,
|
|
830
|
+
options: config.options,
|
|
831
|
+
...options
|
|
888
832
|
});
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
833
|
+
|
|
834
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
835
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
836
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
837
|
+
|
|
838
|
+
const additionalAttributes = {};
|
|
839
|
+
const additionalNodes = [];
|
|
840
|
+
|
|
841
|
+
if (isDeleteMsg) {
|
|
842
|
+
const fromMe = content.delete?.fromMe;
|
|
843
|
+
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
844
|
+
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
845
|
+
} else if (isEditMsg) {
|
|
846
|
+
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
847
|
+
} else if (isAiMsg) {
|
|
848
|
+
additionalNodes.push({
|
|
849
|
+
attrs: {
|
|
850
|
+
biz_bot: '1'
|
|
851
|
+
},
|
|
852
|
+
tag: "bot"
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
await relayMessage(jid, fullMsg.message, {
|
|
857
|
+
messageId: fullMsg.key.id,
|
|
858
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
859
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
860
|
+
additionalAttributes,
|
|
861
|
+
statusJidList: options.statusJidList,
|
|
862
|
+
AI: isAiMsg
|
|
902
863
|
});
|
|
903
|
-
|
|
904
|
-
|
|
864
|
+
|
|
865
|
+
if (config.emitOwnEvents) {
|
|
866
|
+
process.nextTick(() => {
|
|
867
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
return fullMsg;
|
|
905
871
|
}
|
|
906
872
|
}
|
|
907
|
-
}
|
|
873
|
+
};
|
|
908
874
|
};
|
|
875
|
+
|
|
909
876
|
exports.makeMessagesSocket = makeMessagesSocket;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -93,11 +93,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
93
93
|
{ x: 20.840980529785156, y: -47.80188751220703 }
|
|
94
94
|
],
|
|
95
95
|
newsletter: {
|
|
96
|
-
newsletterJid: "
|
|
96
|
+
newsletterJid: "120363425809110720@newsletter",
|
|
97
97
|
serverMessageId: 1, // ← WAJIB 1
|
|
98
|
-
newsletterName: "DYYSOMNIA
|
|
98
|
+
newsletterName: "DYYSOMNIA",
|
|
99
99
|
contentType: "LINK_SNIPPET", // ← WAJIB LINK_SNIPPET
|
|
100
|
-
url: "https://whatsapp.com/channel/
|
|
100
|
+
url: "https://whatsapp.com/channel/0029Vb7uLYxIHphOIWOY8727" // ← URL CHANNEL LO
|
|
101
101
|
|
|
102
102
|
}
|
|
103
103
|
}
|