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