sauruslord-baileys 2.1.0 → 3.0.2
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 +41 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +2 -4
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/baileys-version.json +3 -0
- package/lib/Signal/index.d.ts +53 -0
- package/lib/Signal/index.js +147 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +3 -22
- package/lib/Socket/dugong.js +9 -148
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/lordsaurus.d.ts +266 -0
- package/lib/Socket/lordsaurus.js +580 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1085 -1085
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +257 -391
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +53 -159
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +7 -23
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +0 -1
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +47 -135
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +24 -70
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +4 -180
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +40 -19
- package/package.json +9 -9
- package/LICENSE +0 -21
|
@@ -8,13 +8,15 @@ 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
|
|
11
|
+
const axios_1 = require("axios")
|
|
12
|
+
const Types_1 = require("../Types")
|
|
12
13
|
const Utils_1 = require("../Utils");
|
|
13
14
|
const link_preview_1 = require("../Utils/link-preview");
|
|
14
15
|
const WABinary_1 = require("../WABinary");
|
|
15
16
|
const newsletter_1 = require("./newsletter");
|
|
16
|
-
const WAUSync_1 = require("../WAUSync")
|
|
17
|
-
const
|
|
17
|
+
const WAUSync_1 = require("../WAUSync")
|
|
18
|
+
const lordsaurus = require('./lordsaurus');
|
|
19
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
18
20
|
const makeMessagesSocket = (config) => {
|
|
19
21
|
const {
|
|
20
22
|
logger,
|
|
@@ -32,6 +34,7 @@ const makeMessagesSocket = (config) => {
|
|
|
32
34
|
upsertMessage,
|
|
33
35
|
query,
|
|
34
36
|
fetchPrivacySettings,
|
|
37
|
+
generateMessageTag,
|
|
35
38
|
sendNode,
|
|
36
39
|
groupMetadata,
|
|
37
40
|
groupToggleEphemeral,
|
|
@@ -124,50 +127,67 @@ const makeMessagesSocket = (config) => {
|
|
|
124
127
|
};
|
|
125
128
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
126
129
|
const deviceResults = []
|
|
130
|
+
|
|
127
131
|
if (!useCache) {
|
|
128
132
|
logger.debug('not using cache for devices')
|
|
129
133
|
}
|
|
134
|
+
|
|
130
135
|
const toFetch = []
|
|
136
|
+
|
|
131
137
|
jids = Array.from(new Set(jids))
|
|
138
|
+
|
|
132
139
|
for (let jid of jids) {
|
|
133
140
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
141
|
+
|
|
134
142
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
143
|
+
|
|
135
144
|
if (useCache) {
|
|
136
145
|
const devices = userDevicesCache.get(user)
|
|
146
|
+
|
|
137
147
|
if (devices) {
|
|
138
148
|
deviceResults.push(...devices)
|
|
139
149
|
logger.trace({ user }, 'using cache for devices')
|
|
140
150
|
}
|
|
151
|
+
|
|
141
152
|
else {
|
|
142
153
|
toFetch.push(jid)
|
|
143
154
|
}
|
|
144
155
|
}
|
|
156
|
+
|
|
145
157
|
else {
|
|
146
158
|
toFetch.push(jid)
|
|
147
159
|
}
|
|
148
160
|
}
|
|
161
|
+
|
|
149
162
|
if (!toFetch.length) {
|
|
150
163
|
return deviceResults
|
|
151
164
|
}
|
|
165
|
+
|
|
152
166
|
const query = new WAUSync_1.USyncQuery()
|
|
153
167
|
.withContext('message')
|
|
154
168
|
.withDeviceProtocol()
|
|
169
|
+
|
|
155
170
|
for (const jid of toFetch) {
|
|
156
171
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
157
172
|
}
|
|
173
|
+
|
|
158
174
|
const result = await executeUSyncQuery(query)
|
|
175
|
+
|
|
159
176
|
if (result) {
|
|
160
177
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
161
178
|
const deviceMap = {}
|
|
179
|
+
|
|
162
180
|
for (const item of extracted) {
|
|
163
181
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
164
182
|
deviceMap[item.user].push(item)
|
|
165
183
|
deviceResults.push(item)
|
|
166
184
|
}
|
|
185
|
+
|
|
167
186
|
for (const key in deviceMap) {
|
|
168
187
|
userDevicesCache.set(key, deviceMap[key])
|
|
169
188
|
}
|
|
170
189
|
}
|
|
190
|
+
|
|
171
191
|
return deviceResults
|
|
172
192
|
}
|
|
173
193
|
const assertSessions = async (jids, force) => {
|
|
@@ -213,10 +233,13 @@ const makeMessagesSocket = (config) => {
|
|
|
213
233
|
}
|
|
214
234
|
return didFetchNewSession;
|
|
215
235
|
};
|
|
236
|
+
|
|
237
|
+
|
|
216
238
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
217
239
|
if (!authState.creds.me?.id) {
|
|
218
240
|
throw new boom_1.Boom('Not authenticated')
|
|
219
241
|
}
|
|
242
|
+
|
|
220
243
|
const protocolMessage = {
|
|
221
244
|
protocolMessage: {
|
|
222
245
|
peerDataOperationRequestMessage: pdoMessage,
|
|
@@ -258,7 +281,7 @@ const makeMessagesSocket = (config) => {
|
|
|
258
281
|
return node;
|
|
259
282
|
}));
|
|
260
283
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
261
|
-
};
|
|
284
|
+
};
|
|
262
285
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
263
286
|
const meId = authState.creds.me.id;
|
|
264
287
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -284,7 +307,7 @@ const makeMessagesSocket = (config) => {
|
|
|
284
307
|
}
|
|
285
308
|
};
|
|
286
309
|
const extraAttrs = {}
|
|
287
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
310
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
288
311
|
const buttonType = getButtonType(messages);
|
|
289
312
|
if (participant) {
|
|
290
313
|
if (!isGroup && !isStatus) {
|
|
@@ -295,15 +318,19 @@ const makeMessagesSocket = (config) => {
|
|
|
295
318
|
}
|
|
296
319
|
await authState.keys.transaction(async () => {
|
|
297
320
|
const mediaType = getMediaType(messages);
|
|
321
|
+
|
|
298
322
|
if (mediaType) {
|
|
299
323
|
extraAttrs['mediatype'] = mediaType
|
|
300
324
|
}
|
|
325
|
+
|
|
301
326
|
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
302
327
|
extraAttrs['decrypt-fail'] = 'hide'
|
|
303
|
-
}
|
|
328
|
+
}
|
|
329
|
+
|
|
304
330
|
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
305
331
|
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
306
332
|
}
|
|
333
|
+
|
|
307
334
|
if (isGroup || isStatus) {
|
|
308
335
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
309
336
|
(async () => {
|
|
@@ -311,9 +338,11 @@ const makeMessagesSocket = (config) => {
|
|
|
311
338
|
if (groupData) {
|
|
312
339
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
313
340
|
}
|
|
341
|
+
|
|
314
342
|
else if (!isStatus) {
|
|
315
343
|
groupData = await groupMetadata(jid)
|
|
316
344
|
}
|
|
345
|
+
|
|
317
346
|
return groupData;
|
|
318
347
|
})(),
|
|
319
348
|
(async () => {
|
|
@@ -321,25 +350,32 @@ const makeMessagesSocket = (config) => {
|
|
|
321
350
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
322
351
|
return result[jid] || {}
|
|
323
352
|
}
|
|
353
|
+
|
|
324
354
|
return {}
|
|
325
|
-
|
|
355
|
+
|
|
356
|
+
})()
|
|
326
357
|
]);
|
|
327
358
|
if (!participant) {
|
|
328
359
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
360
|
+
|
|
329
361
|
if (isStatus && statusJidList) {
|
|
330
362
|
participantsList.push(...statusJidList)
|
|
331
363
|
}
|
|
364
|
+
|
|
332
365
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
333
366
|
devices.push(...additionalDevices)
|
|
334
367
|
}
|
|
368
|
+
|
|
335
369
|
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
336
370
|
const bytes = Utils_1.encodeWAMessage(patched);
|
|
371
|
+
|
|
337
372
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
338
373
|
group: destinationJid,
|
|
339
374
|
data: bytes,
|
|
340
375
|
meId,
|
|
341
376
|
});
|
|
342
377
|
const senderKeyJids = [];
|
|
378
|
+
|
|
343
379
|
for (const { user, device } of devices) {
|
|
344
380
|
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
345
381
|
if (!senderKeyMap[jid] || !!participant) {
|
|
@@ -372,12 +408,15 @@ const makeMessagesSocket = (config) => {
|
|
|
372
408
|
msgId = message.protocolMessage.key?.id
|
|
373
409
|
message = message.protocolMessage.editedMessage
|
|
374
410
|
}
|
|
411
|
+
|
|
375
412
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
376
413
|
msgId = message.protocolMessage.key?.id
|
|
377
414
|
message = {}
|
|
378
415
|
}
|
|
416
|
+
|
|
379
417
|
const patched = await patchMessageBeforeSending(message, [])
|
|
380
418
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
419
|
+
|
|
381
420
|
binaryNodeContent.push({
|
|
382
421
|
tag: 'plaintext',
|
|
383
422
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -391,8 +430,10 @@ const makeMessagesSocket = (config) => {
|
|
|
391
430
|
if (user !== meUser) {
|
|
392
431
|
devices.push({ user: meUser })
|
|
393
432
|
}
|
|
433
|
+
|
|
394
434
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
395
435
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
436
|
+
|
|
396
437
|
devices.push(...additionalDevices)
|
|
397
438
|
}
|
|
398
439
|
}
|
|
@@ -402,12 +443,15 @@ const makeMessagesSocket = (config) => {
|
|
|
402
443
|
for (const { user, device } of devices) {
|
|
403
444
|
const isMe = user === meUser
|
|
404
445
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
446
|
+
|
|
405
447
|
if (isMe) {
|
|
406
448
|
meJids.push(jid)
|
|
407
449
|
}
|
|
450
|
+
|
|
408
451
|
else {
|
|
409
452
|
otherJids.push(jid)
|
|
410
453
|
}
|
|
454
|
+
|
|
411
455
|
allJids.push(jid)
|
|
412
456
|
}
|
|
413
457
|
await assertSessions(allJids, false);
|
|
@@ -422,10 +466,12 @@ const makeMessagesSocket = (config) => {
|
|
|
422
466
|
if (participants.length) {
|
|
423
467
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
424
468
|
const peerNode = participants[0]?.content?.[0]
|
|
469
|
+
|
|
425
470
|
if (peerNode) {
|
|
426
|
-
binaryNodeContent.push(peerNode)
|
|
471
|
+
binaryNodeContent.push(peerNode)
|
|
427
472
|
}
|
|
428
473
|
}
|
|
474
|
+
|
|
429
475
|
else {
|
|
430
476
|
binaryNodeContent.push({
|
|
431
477
|
tag: 'participants',
|
|
@@ -434,11 +480,12 @@ const makeMessagesSocket = (config) => {
|
|
|
434
480
|
})
|
|
435
481
|
}
|
|
436
482
|
}
|
|
483
|
+
|
|
437
484
|
const stanza = {
|
|
438
485
|
tag: 'message',
|
|
439
486
|
attrs: {
|
|
440
487
|
id: msgId,
|
|
441
|
-
type: getTypeMessage(messages),
|
|
488
|
+
type: getTypeMessage(messages),
|
|
442
489
|
...(additionalAttributes || {})
|
|
443
490
|
},
|
|
444
491
|
content: binaryNodeContent
|
|
@@ -467,46 +514,56 @@ const makeMessagesSocket = (config) => {
|
|
|
467
514
|
});
|
|
468
515
|
logger.debug({ jid }, 'adding device identity');
|
|
469
516
|
}
|
|
517
|
+
|
|
470
518
|
if (AI && isPrivate) {
|
|
471
519
|
const botNode = {
|
|
472
|
-
tag: 'bot',
|
|
520
|
+
tag: 'bot',
|
|
473
521
|
attrs: {
|
|
474
522
|
biz_bot: '1'
|
|
475
523
|
}
|
|
476
524
|
}
|
|
477
|
-
|
|
525
|
+
|
|
526
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
527
|
+
|
|
478
528
|
if (filteredBizBot) {
|
|
479
|
-
stanza.content.push(...additionalNodes)
|
|
529
|
+
stanza.content.push(...additionalNodes)
|
|
480
530
|
didPushAdditional = true
|
|
481
531
|
}
|
|
532
|
+
|
|
482
533
|
else {
|
|
483
|
-
stanza.content.push(botNode)
|
|
534
|
+
stanza.content.push(botNode)
|
|
484
535
|
}
|
|
485
536
|
}
|
|
486
|
-
|
|
537
|
+
|
|
538
|
+
if(!isNewsletter && buttonType && !isStatus) {
|
|
487
539
|
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
488
540
|
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
541
|
+
|
|
489
542
|
if (filteredNode) {
|
|
490
543
|
didPushAdditional = true
|
|
491
544
|
stanza.content.push(...additionalNodes)
|
|
492
|
-
}
|
|
545
|
+
}
|
|
493
546
|
else {
|
|
494
547
|
stanza.content.push(...content)
|
|
495
548
|
}
|
|
496
549
|
logger.debug({ jid }, 'adding business node')
|
|
497
|
-
}
|
|
550
|
+
}
|
|
551
|
+
|
|
498
552
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
499
553
|
stanza.content.push(...additionalNodes);
|
|
500
554
|
}
|
|
555
|
+
|
|
501
556
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
502
557
|
await sendNode(stanza);
|
|
503
558
|
});
|
|
559
|
+
|
|
504
560
|
message = Types_1.WAProto.Message.fromObject(message)
|
|
561
|
+
|
|
505
562
|
const messageJSON = {
|
|
506
563
|
key: {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
564
|
+
remoteJid: jid,
|
|
565
|
+
fromMe: true,
|
|
566
|
+
id: msgId
|
|
510
567
|
},
|
|
511
568
|
message: message,
|
|
512
569
|
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
@@ -514,63 +571,104 @@ const makeMessagesSocket = (config) => {
|
|
|
514
571
|
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
515
572
|
status: Types_1.WAMessageStatus.PENDING
|
|
516
573
|
}
|
|
517
|
-
|
|
574
|
+
|
|
575
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
518
576
|
};
|
|
519
577
|
const getTypeMessage = (msg) => {
|
|
520
|
-
|
|
578
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
521
579
|
if (message.reactionMessage) {
|
|
522
580
|
return 'reaction'
|
|
523
|
-
}
|
|
581
|
+
}
|
|
524
582
|
else if (getMediaType(message)) {
|
|
525
583
|
return 'media'
|
|
526
|
-
}
|
|
584
|
+
}
|
|
527
585
|
else {
|
|
528
586
|
return 'text'
|
|
529
587
|
}
|
|
530
588
|
}
|
|
531
|
-
|
|
532
|
-
imageMessage: 'image',
|
|
533
|
-
contactMessage: 'vcard',
|
|
534
|
-
documentMessage: 'document',
|
|
535
|
-
contactsArrayMessage: 'contact_array',
|
|
536
|
-
liveLocationMessage: 'livelocation',
|
|
537
|
-
stickerMessage: 'sticker',
|
|
538
|
-
listMessage: 'list',
|
|
539
|
-
listResponseMessage: 'list_response',
|
|
540
|
-
buttonsResponseMessage: 'buttons_response',
|
|
541
|
-
orderMessage: 'order',
|
|
542
|
-
productMessage: 'product',
|
|
543
|
-
interactiveResponseMessage: 'native_flow_response',
|
|
544
|
-
groupInviteMessage: 'url',
|
|
545
|
-
stickerPackMessage: 'sticker_pack',
|
|
546
|
-
}
|
|
589
|
+
|
|
547
590
|
const getMediaType = (message) => {
|
|
548
|
-
if (message.
|
|
591
|
+
if (message.imageMessage) {
|
|
592
|
+
return 'image'
|
|
593
|
+
}
|
|
594
|
+
else if (message.videoMessage) {
|
|
549
595
|
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
550
596
|
}
|
|
551
|
-
if (message.audioMessage) {
|
|
597
|
+
else if (message.audioMessage) {
|
|
552
598
|
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
553
599
|
}
|
|
554
|
-
|
|
555
|
-
|
|
600
|
+
else if (message.contactMessage) {
|
|
601
|
+
return 'vcard'
|
|
602
|
+
}
|
|
603
|
+
else if (message.documentMessage) {
|
|
604
|
+
return 'document'
|
|
605
|
+
}
|
|
606
|
+
else if (message.contactsArrayMessage) {
|
|
607
|
+
return 'contact_array'
|
|
556
608
|
}
|
|
557
|
-
if (
|
|
609
|
+
else if (message.liveLocationMessage) {
|
|
610
|
+
return 'livelocation'
|
|
611
|
+
}
|
|
612
|
+
else if (message.stickerMessage) {
|
|
613
|
+
return 'sticker'
|
|
614
|
+
}
|
|
615
|
+
else if (message.stickerPackMessage) {
|
|
616
|
+
return 'sticker_pack'
|
|
617
|
+
}
|
|
618
|
+
else if (message.listMessage) {
|
|
619
|
+
return 'list'
|
|
620
|
+
}
|
|
621
|
+
else if (message.listResponseMessage) {
|
|
622
|
+
return 'list_response'
|
|
623
|
+
}
|
|
624
|
+
else if (message.buttonsResponseMessage) {
|
|
625
|
+
return 'buttons_response'
|
|
626
|
+
}
|
|
627
|
+
else if (message.orderMessage) {
|
|
628
|
+
return 'order'
|
|
629
|
+
}
|
|
630
|
+
else if (message.productMessage) {
|
|
631
|
+
return 'product'
|
|
632
|
+
}
|
|
633
|
+
else if (message.interactiveResponseMessage) {
|
|
634
|
+
return 'native_flow_response'
|
|
635
|
+
}
|
|
636
|
+
else if (message.groupInviteMessage) {
|
|
637
|
+
return 'url'
|
|
638
|
+
}
|
|
639
|
+
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
558
640
|
return 'productlink'
|
|
559
641
|
}
|
|
560
642
|
}
|
|
561
|
-
|
|
562
|
-
review_and_pay: 'review_and_pay',
|
|
563
|
-
review_order: 'review_order',
|
|
564
|
-
payment_info: 'payment_info',
|
|
565
|
-
payment_status: 'payment_status',
|
|
566
|
-
payment_method: 'payment_method',
|
|
567
|
-
}
|
|
643
|
+
|
|
568
644
|
const getButtonType = (message) => {
|
|
569
|
-
if (message.listMessage)
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
if (
|
|
573
|
-
|
|
645
|
+
if (message.listMessage) {
|
|
646
|
+
return 'list'
|
|
647
|
+
}
|
|
648
|
+
else if (message.buttonsMessage) {
|
|
649
|
+
return 'buttons'
|
|
650
|
+
}
|
|
651
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
652
|
+
return 'review_and_pay'
|
|
653
|
+
}
|
|
654
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
655
|
+
return 'review_order'
|
|
656
|
+
}
|
|
657
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
658
|
+
return 'payment_info'
|
|
659
|
+
}
|
|
660
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
661
|
+
return 'payment_status'
|
|
662
|
+
}
|
|
663
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
664
|
+
return 'payment_method'
|
|
665
|
+
}
|
|
666
|
+
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
667
|
+
return 'interactive'
|
|
668
|
+
}
|
|
669
|
+
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
670
|
+
return 'native_flow'
|
|
671
|
+
}
|
|
574
672
|
}
|
|
575
673
|
const getPrivacyTokens = async (jids) => {
|
|
576
674
|
const t = Utils_1.unixTimestampSeconds().toString();
|
|
@@ -597,9 +695,9 @@ const makeMessagesSocket = (config) => {
|
|
|
597
695
|
]
|
|
598
696
|
});
|
|
599
697
|
return result;
|
|
600
|
-
}
|
|
698
|
+
}
|
|
601
699
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
602
|
-
const
|
|
700
|
+
const saurusgntg = new lordsaurus(Utils_1, waUploadToServer, relayMessage);
|
|
603
701
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
604
702
|
return {
|
|
605
703
|
...sock,
|
|
@@ -608,7 +706,7 @@ const makeMessagesSocket = (config) => {
|
|
|
608
706
|
relayMessage,
|
|
609
707
|
sendReceipt,
|
|
610
708
|
sendReceipts,
|
|
611
|
-
|
|
709
|
+
saurusgntg,
|
|
612
710
|
readMessages,
|
|
613
711
|
refreshMediaConn,
|
|
614
712
|
getUSyncDevices,
|
|
@@ -655,368 +753,136 @@ const makeMessagesSocket = (config) => {
|
|
|
655
753
|
ev.emit('messages.update', [
|
|
656
754
|
{
|
|
657
755
|
key: message.key,
|
|
658
|
-
update: {
|
|
756
|
+
update: {
|
|
659
757
|
message: message.message
|
|
660
758
|
}
|
|
661
759
|
}
|
|
662
760
|
]);
|
|
663
761
|
return message;
|
|
664
762
|
},
|
|
665
|
-
setLabelGroup: async (id, text) => {
|
|
666
|
-
await relayMessage(id, {
|
|
667
|
-
protocolMessage: {
|
|
668
|
-
type: 30,
|
|
669
|
-
memberLabel: {
|
|
670
|
-
label: text.slice(0, 30)
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}, {
|
|
674
|
-
additionalNodes: [
|
|
675
|
-
{
|
|
676
|
-
tag: "meta",
|
|
677
|
-
attrs: {
|
|
678
|
-
tag_reason: "user_update",
|
|
679
|
-
appdata: "member_tag"
|
|
680
|
-
},
|
|
681
|
-
content: undefined
|
|
682
|
-
}
|
|
683
|
-
]
|
|
684
|
-
})
|
|
685
|
-
},
|
|
686
|
-
sendStatusMention: async (content, jids = []) => {
|
|
687
|
-
return await ourin.sendStatusWhatsApp(content, jids);
|
|
688
|
-
},
|
|
689
763
|
sendMessage: async (jid, content, options = {}) => {
|
|
690
764
|
const userJid = authState.creds.me.id;
|
|
691
765
|
delete options.ephemeralExpiration
|
|
692
766
|
const { filter = false, quoted } = options;
|
|
693
767
|
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
694
|
-
const messageType =
|
|
768
|
+
const messageType = saurusgntg.detectType(content);
|
|
695
769
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
696
770
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
697
771
|
const { disappearingMessagesInChat } = content
|
|
772
|
+
|
|
698
773
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
699
774
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
700
775
|
disappearingMessagesInChat
|
|
776
|
+
|
|
701
777
|
await groupToggleEphemeral(jid, value)
|
|
702
778
|
}
|
|
779
|
+
|
|
703
780
|
else {
|
|
704
781
|
let mediaHandle
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
745
|
-
logger,
|
|
746
|
-
userJid,
|
|
747
|
-
quoted,
|
|
748
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
749
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
750
|
-
fetchOpts: {
|
|
751
|
-
timeout: 3000,
|
|
752
|
-
...axiosOptions || {}
|
|
753
|
-
},
|
|
754
|
-
logger,
|
|
755
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
756
|
-
}),
|
|
757
|
-
upload: async (readStream, opts) => {
|
|
758
|
-
const up = await waUploadToServer(readStream, {
|
|
759
|
-
...opts,
|
|
760
|
-
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
if (messageType) {
|
|
785
|
+
switch(messageType) {
|
|
786
|
+
case 'PAYMENT':
|
|
787
|
+
const paymentContent = await saurusgntg.handlePayment(content, quoted);
|
|
788
|
+
return await relayMessage(jid, paymentContent, {
|
|
789
|
+
messageId: Utils_1.generateMessageID(),
|
|
790
|
+
...getParticipantAttr()
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
case 'PRODUCT':
|
|
794
|
+
const productContent = await saurusgntg.handleProduct(content, jid, quoted);
|
|
795
|
+
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
796
|
+
return await relayMessage(jid, productMsg.message, {
|
|
797
|
+
messageId: productMsg.key.id,
|
|
798
|
+
...getParticipantAttr()
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
case 'INTERACTIVE':
|
|
802
|
+
const interactiveContent = await saurusgntg.handleInteractive(content, jid, quoted);
|
|
803
|
+
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
804
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
805
|
+
messageId: interactiveMsg.key.id,
|
|
806
|
+
...getParticipantAttr()
|
|
807
|
+
});
|
|
808
|
+
case 'ALBUM':
|
|
809
|
+
return await saurusgntg.handleAlbum(content, jid, quoted)
|
|
810
|
+
case 'EVENT':
|
|
811
|
+
return await saurusgntg.handleEvent(content, jid, quoted)
|
|
812
|
+
case 'POLL_RESULT':
|
|
813
|
+
return await saurusgntg.handlePollResult(content, jid, quoted)
|
|
814
|
+
case 'GROUP_STORY':
|
|
815
|
+
return await saurusgntg.handleGroupStory(content, jid, quoted)
|
|
816
|
+
case 'STICKER_PACK':
|
|
817
|
+
const packContent = await saurusgntg.handleStickerPack(content, jid, quoted);
|
|
818
|
+
return await relayMessage(jid, packContent, {
|
|
819
|
+
messageId: Utils_1.generateMessageID(),
|
|
820
|
+
...getParticipantAttr()
|
|
761
821
|
});
|
|
762
|
-
return up;
|
|
763
|
-
},
|
|
764
|
-
mediaCache: config.mediaCache,
|
|
765
|
-
options: config.options,
|
|
766
|
-
...options
|
|
767
|
-
});
|
|
768
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
769
|
-
const isEditMsg = 'edit' in content && !!content.edit;
|
|
770
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
771
|
-
const additionalAttributes = {};
|
|
772
|
-
const additionalNodes = [];
|
|
773
|
-
if (isDeleteMsg) {
|
|
774
|
-
const fromMe = content.delete?.fromMe;
|
|
775
|
-
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
776
|
-
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
777
|
-
} else if (isEditMsg) {
|
|
778
|
-
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
779
|
-
} else if (isAiMsg) {
|
|
780
|
-
additionalNodes.push({
|
|
781
|
-
attrs: {
|
|
782
|
-
biz_bot: '1'
|
|
783
|
-
}, tag: "bot"
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
await relayMessage(jid, fullMsg.message, {
|
|
787
|
-
messageId: fullMsg.key.id,
|
|
788
|
-
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
789
|
-
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
790
|
-
additionalAttributes,
|
|
791
|
-
statusJidList: options.statusJidList
|
|
792
|
-
});
|
|
793
|
-
if (config.emitOwnEvents) {
|
|
794
|
-
process.nextTick(() => {
|
|
795
|
-
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
return fullMsg;
|
|
799
|
-
}
|
|
800
|
-
},
|
|
801
|
-
react(m, emoji = '') {
|
|
802
|
-
const key = m?.quoted?.key || m?.key
|
|
803
|
-
if (!key) throw new Error('No message key to react')
|
|
804
|
-
|
|
805
|
-
return this.sendMessage(key.remoteJid, {
|
|
806
|
-
react: {
|
|
807
|
-
text: emoji,
|
|
808
|
-
key
|
|
809
|
-
}
|
|
810
|
-
})
|
|
811
|
-
},
|
|
812
|
-
unreact(m) {
|
|
813
|
-
const key = m?.quoted?.key || m?.key
|
|
814
|
-
if (!key) throw new Error('No message key to react')
|
|
815
|
-
|
|
816
|
-
return this.sendMessage(key.remoteJid, {
|
|
817
|
-
react: {
|
|
818
|
-
text: '',
|
|
819
|
-
key
|
|
820
822
|
}
|
|
821
|
-
})
|
|
822
|
-
},
|
|
823
|
-
async delay(s) {
|
|
824
|
-
if( s < 0 ) s = 0;
|
|
825
|
-
const ms = s * 1000;
|
|
826
|
-
return await new Promise(resolve => setTimeout(resolve, ms));
|
|
827
|
-
},
|
|
828
|
-
edit(m, newText) {
|
|
829
|
-
if (!m?.key) throw new Error('Invalid message')
|
|
830
|
-
return this.sendMessage(m.key.remoteJid, {
|
|
831
|
-
edit: m.key,
|
|
832
|
-
text: newText
|
|
833
|
-
})
|
|
834
|
-
},
|
|
835
|
-
del(m) {
|
|
836
|
-
if (!m?.key) throw new Error('Invalid message')
|
|
837
|
-
return this.sendMessage(m.key.remoteJid, {
|
|
838
|
-
delete: m.key
|
|
839
|
-
})
|
|
840
|
-
},
|
|
841
|
-
detect(m) {
|
|
842
|
-
if (!m?.message) return 'unknown'
|
|
843
|
-
|
|
844
|
-
const msg = Utils_1.normalizeMessageContent(m.message)
|
|
845
|
-
|
|
846
|
-
if (msg.reactionMessage) return 'reaction'
|
|
847
|
-
if (msg.protocolMessage?.type === 0) return 'revoke'
|
|
848
|
-
if (msg.protocolMessage?.editedMessage) return 'edited'
|
|
849
|
-
|
|
850
|
-
if (msg.viewOnceMessageV2 || msg.viewOnceMessage) return 'viewonce'
|
|
851
|
-
|
|
852
|
-
if (msg.imageMessage) return 'image'
|
|
853
|
-
if (msg.videoMessage) return msg.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
854
|
-
if (msg.audioMessage) return msg.audioMessage.ptt ? 'ptt' : 'audio'
|
|
855
|
-
if (msg.stickerMessage) return 'sticker'
|
|
856
|
-
if (msg.documentMessage) return 'document'
|
|
857
|
-
if (msg.contactMessage) return 'contact'
|
|
858
|
-
if (msg.locationMessage || msg.liveLocationMessage) return 'location'
|
|
859
|
-
if (msg.pollCreationMessage) return 'poll'
|
|
860
|
-
if (msg.interactiveMessage) return 'interactive'
|
|
861
|
-
if (msg.buttonsResponseMessage) return 'button_response'
|
|
862
|
-
if (msg.listResponseMessage) return 'list_response'
|
|
863
|
-
if (msg.extendedTextMessage || msg.conversation) return 'text'
|
|
864
|
-
|
|
865
|
-
return 'unknown'
|
|
866
|
-
},
|
|
867
|
-
async forward(jid, m, options = {}) {
|
|
868
|
-
if (!m?.message) throw new Error('Invalid message')
|
|
869
|
-
const {
|
|
870
|
-
force = false,
|
|
871
|
-
removeContext = false
|
|
872
|
-
} = options
|
|
873
|
-
const msg = Utils_1.normalizeMessageContent(m.message)
|
|
874
|
-
let content = JSON.parse(JSON.stringify(msg))
|
|
875
|
-
if (removeContext) {
|
|
876
|
-
const ctx =
|
|
877
|
-
content?.extendedTextMessage?.contextInfo ||
|
|
878
|
-
content?.imageMessage?.contextInfo ||
|
|
879
|
-
content?.videoMessage?.contextInfo ||
|
|
880
|
-
content?.documentMessage?.contextInfo
|
|
881
|
-
|
|
882
|
-
if (ctx) delete ctx.quotedMessage
|
|
883
|
-
if (ctx) delete ctx.participant
|
|
884
|
-
if (ctx) delete ctx.stanzaId
|
|
885
|
-
if (ctx) delete ctx.mentionedJid
|
|
886
|
-
}
|
|
887
|
-
const target =
|
|
888
|
-
content.extendedTextMessage ||
|
|
889
|
-
content.imageMessage ||
|
|
890
|
-
content.videoMessage ||
|
|
891
|
-
content.documentMessage
|
|
892
|
-
if (target) {
|
|
893
|
-
target.contextInfo = target.contextInfo || {}
|
|
894
|
-
target.contextInfo.forwardingScore = force ? 999 : 1
|
|
895
|
-
target.contextInfo.isForwarded = true
|
|
896
823
|
}
|
|
897
|
-
const fullMsg = await Utils_1.generateWAMessage(
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
824
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
825
|
+
logger,
|
|
826
|
+
userJid,
|
|
827
|
+
quoted,
|
|
828
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
829
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
830
|
+
fetchOpts: {
|
|
831
|
+
timeout: 3000,
|
|
832
|
+
...axiosOptions || {}
|
|
833
|
+
},
|
|
901
834
|
logger,
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
}) {
|
|
915
|
-
const sharp = (await import('sharp')).default;
|
|
916
|
-
return sharp(buf)
|
|
917
|
-
.resize(width, height, { fit: 'inside' })
|
|
918
|
-
.jpeg({ quality })
|
|
919
|
-
.toBuffer();
|
|
920
|
-
},
|
|
921
|
-
|
|
922
|
-
async convert(buf, { to }) {
|
|
923
|
-
const fmt = to.toLowerCase().replace('.', '');
|
|
924
|
-
const IMG = { jpeg: 'jpeg', jpg: 'jpeg', png: 'png', webp: 'webp' };
|
|
925
|
-
if (IMG[fmt]) {
|
|
926
|
-
const sharp = (await import('sharp')).default;
|
|
927
|
-
return sharp(buf).toFormat(IMG[fmt]).toBuffer();
|
|
928
|
-
}
|
|
929
|
-
const { spawn } = require('child_process');
|
|
930
|
-
const args = ['-i', 'pipe:0', '-y'];
|
|
931
|
-
if (fmt === 'mp4') args.push('-movflags', 'frag_keyframe+empty_moov', '-f', 'mp4');
|
|
932
|
-
else args.push('-f', fmt);
|
|
933
|
-
args.push('pipe:1');
|
|
934
|
-
return new Promise((resolve, reject) => {
|
|
935
|
-
const ff = spawn('ffmpeg', args, { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
936
|
-
const chunks = [];
|
|
937
|
-
let len = 0;
|
|
938
|
-
ff.stdout.on('data', c => { chunks.push(c); len += c.length; });
|
|
939
|
-
ff.on('close', code => code === 0
|
|
940
|
-
? resolve(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, len))
|
|
941
|
-
: reject(new Error(`Convert failed (${code})`))
|
|
942
|
-
);
|
|
943
|
-
ff.on('error', reject);
|
|
944
|
-
ff.stdin.end(buf);
|
|
945
|
-
});
|
|
946
|
-
},
|
|
947
|
-
|
|
948
|
-
async toSticker(buf, { quality = 80 } = {}) {
|
|
949
|
-
const sharp = (await import('sharp')).default;
|
|
950
|
-
return sharp(buf)
|
|
951
|
-
.resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
|
952
|
-
.webp({ quality })
|
|
953
|
-
.toBuffer();
|
|
954
|
-
},
|
|
955
|
-
|
|
956
|
-
async compress(buf, { quality = 50 } = {}) {
|
|
957
|
-
try {
|
|
958
|
-
const sharp = (await import('sharp')).default;
|
|
959
|
-
const { format } = await sharp(buf).metadata();
|
|
960
|
-
if (format) return sharp(buf).toFormat(format, { quality }).toBuffer();
|
|
961
|
-
} catch {}
|
|
962
|
-
const { spawn } = require('child_process');
|
|
963
|
-
const crf = String(Math.round(51 - (quality / 100 * 51)));
|
|
964
|
-
return new Promise((resolve, reject) => {
|
|
965
|
-
const ff = spawn('ffmpeg', [
|
|
966
|
-
'-i', 'pipe:0', '-y',
|
|
967
|
-
'-crf', crf, '-preset', 'ultrafast',
|
|
968
|
-
'-movflags', 'frag_keyframe+empty_moov', '-f', 'mp4', 'pipe:1'
|
|
969
|
-
], { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
970
|
-
const chunks = [];
|
|
971
|
-
let len = 0;
|
|
972
|
-
ff.stdout.on('data', c => { chunks.push(c); len += c.length; });
|
|
973
|
-
ff.on('close', code => code === 0
|
|
974
|
-
? resolve(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, len))
|
|
975
|
-
: reject(new Error('Compress failed'))
|
|
976
|
-
);
|
|
977
|
-
ff.on('error', reject);
|
|
978
|
-
ff.stdin.end(buf);
|
|
835
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
836
|
+
}),
|
|
837
|
+
upload: async (readStream, opts) => {
|
|
838
|
+
const up = await waUploadToServer(readStream, {
|
|
839
|
+
...opts,
|
|
840
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
841
|
+
});
|
|
842
|
+
return up;
|
|
843
|
+
},
|
|
844
|
+
mediaCache: config.mediaCache,
|
|
845
|
+
options: config.options,
|
|
846
|
+
...options
|
|
979
847
|
});
|
|
980
|
-
|
|
848
|
+
|
|
849
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
850
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
851
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
852
|
+
|
|
853
|
+
const additionalAttributes = {};
|
|
854
|
+
const additionalNodes = [];
|
|
981
855
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
return result;
|
|
994
|
-
}
|
|
995
|
-
} catch {}
|
|
996
|
-
const { spawn } = require('child_process');
|
|
997
|
-
return new Promise(resolve => {
|
|
998
|
-
const ff = spawn('ffprobe', [
|
|
999
|
-
'-v', 'quiet', '-print_format', 'json',
|
|
1000
|
-
'-show_format', '-show_streams', 'pipe:0'
|
|
1001
|
-
], { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
1002
|
-
const chunks = [];
|
|
1003
|
-
ff.stdout.on('data', c => chunks.push(c));
|
|
1004
|
-
ff.on('close', () => {
|
|
1005
|
-
try {
|
|
1006
|
-
const d = JSON.parse(Buffer.concat(chunks).toString());
|
|
1007
|
-
const vid = d.streams?.find(s => s.codec_type === 'video');
|
|
1008
|
-
const aud = d.streams?.find(s => s.codec_type === 'audio');
|
|
1009
|
-
if (vid) { result.width = vid.width; result.height = vid.height; }
|
|
1010
|
-
result.duration = parseFloat(d.format?.duration) || undefined;
|
|
1011
|
-
result.mimetype = vid ? 'video/mp4' : aud ? 'audio/mpeg' : undefined;
|
|
1012
|
-
} catch {}
|
|
1013
|
-
resolve(result);
|
|
856
|
+
if (isDeleteMsg) {
|
|
857
|
+
const fromMe = content.delete?.fromMe;
|
|
858
|
+
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
859
|
+
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
860
|
+
} else if (isEditMsg) {
|
|
861
|
+
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
862
|
+
} else if (isAiMsg) {
|
|
863
|
+
additionalNodes.push({
|
|
864
|
+
attrs: {
|
|
865
|
+
biz_bot: '1'
|
|
866
|
+
}, tag: "bot"
|
|
1014
867
|
});
|
|
1015
|
-
|
|
1016
|
-
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
await relayMessage(jid, fullMsg.message, {
|
|
871
|
+
messageId: fullMsg.key.id,
|
|
872
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
873
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
874
|
+
additionalAttributes,
|
|
875
|
+
statusJidList: options.statusJidList
|
|
1017
876
|
});
|
|
877
|
+
|
|
878
|
+
if (config.emitOwnEvents) {
|
|
879
|
+
process.nextTick(() => {
|
|
880
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
return fullMsg;
|
|
884
|
+
}
|
|
1018
885
|
}
|
|
1019
|
-
|
|
1020
886
|
}
|
|
1021
887
|
};
|
|
1022
888
|
exports.makeMessagesSocket = makeMessagesSocket;
|