@realvare/based 2.7.62 → 2.7.71
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 +1062 -282
- package/WAProto/WAProto.proto +1073 -244
- package/WAProto/index.d.ts +16282 -8183
- package/WAProto/index.js +76605 -50628
- package/engine-requirements.js +10 -10
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -2
- package/lib/Defaults/index.js +8 -6
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -1
- package/lib/Signal/Group/ciphertext-message.js +1 -1
- package/lib/Signal/Group/sender-message-key.d.ts +1 -1
- package/lib/Signal/Group/sender-message-key.js +1 -1
- package/lib/Signal/libsignal.d.ts +1 -1
- package/lib/Socket/business.d.ts +1 -1
- package/lib/Socket/business.js +1 -1
- package/lib/Socket/chats.d.ts +4 -1
- package/lib/Socket/chats.js +213 -36
- package/lib/Socket/groups.js +87 -15
- package/lib/Socket/index.js +9 -0
- package/lib/Socket/messages-interactive.js +259 -0
- package/lib/Socket/messages-recv.js +1473 -1228
- package/lib/Socket/messages-send.js +437 -469
- package/lib/Socket/socket.js +143 -26
- package/lib/Socket/usync.js +57 -4
- package/lib/Store/make-in-memory-store.js +28 -15
- package/lib/Types/Auth.d.ts +4 -0
- package/lib/Types/Message.d.ts +316 -6
- package/lib/Types/Message.js +1 -1
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Utils/cache-manager.d.ts +16 -0
- package/lib/Utils/cache-manager.js +22 -5
- package/lib/Utils/chat-utils.js +17 -13
- package/lib/Utils/decode-wa-message.js +1 -11
- package/lib/Utils/event-buffer.js +103 -2
- package/lib/Utils/generics.js +5 -6
- package/lib/Utils/index.d.ts +5 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/jid-validation.d.ts +2 -0
- package/lib/Utils/jid-validation.js +43 -10
- package/lib/Utils/link-preview.js +38 -28
- package/lib/Utils/messages-media.d.ts +1 -1
- package/lib/Utils/messages-media.js +22 -53
- package/lib/Utils/messages.js +653 -65
- package/lib/Utils/performance-config.d.ts +2 -0
- package/lib/Utils/performance-config.js +16 -7
- package/lib/Utils/process-message.js +124 -12
- package/lib/Utils/rate-limiter.js +15 -20
- package/lib/WABinary/generic-utils.js +5 -1
- package/lib/WABinary/jid-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.js +265 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +75 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -6
- package/lib/WAUSync/USyncQuery.js +64 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.js +5 -4
- package/package.json +10 -15
- package/WAProto/index.ts.ts +0 -53473
package/lib/Utils/messages.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
|
|
6
|
+
exports.clearCache = exports.getCacheStats = exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
|
|
7
7
|
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
8
8
|
const boom_1 = require("@hapi/boom");
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -56,6 +56,7 @@ const assertColor = async (color) => {
|
|
|
56
56
|
let assertedColor;
|
|
57
57
|
if (typeof color === 'number') {
|
|
58
58
|
assertedColor = color > 0 ? color : 0xffffffff + Number(color) + 1;
|
|
59
|
+
return assertedColor;
|
|
59
60
|
}
|
|
60
61
|
else {
|
|
61
62
|
let hex = color.trim().replace('#', '');
|
|
@@ -117,7 +118,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
117
118
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
118
119
|
opts: options.options
|
|
119
120
|
});
|
|
120
|
-
// url safe Base64 encode the SHA256 hash of the body
|
|
121
121
|
const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
|
|
122
122
|
const [{ mediaUrl, directPath, handle }] = await Promise.all([
|
|
123
123
|
(async () => {
|
|
@@ -246,41 +246,35 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
246
246
|
var _p, _q;
|
|
247
247
|
|
|
248
248
|
// Cross-platform externalAdReply thumbnail handling
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (
|
|
249
|
+
const fixupExternalAdReplyThumb = async (externalAdReply) => {
|
|
250
|
+
const thumbUrl = externalAdReply.originalImageUrl || externalAdReply.thumbnailUrl;
|
|
251
|
+
const currentThumb = externalAdReply.thumbnail;
|
|
252
|
+
const currentThumbLen = currentThumb && typeof currentThumb.length === 'number' ? currentThumb.length : 0;
|
|
253
|
+
if (thumbUrl && (!currentThumb || currentThumbLen < 2000)) {
|
|
254
254
|
try {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
responseType: 'arraybuffer',
|
|
258
|
-
timeout: 5000,
|
|
255
|
+
const stream = await (0, messages_media_1.getHttpStream)(thumbUrl, {
|
|
256
|
+
timeout: 8000,
|
|
259
257
|
headers: {
|
|
260
258
|
'User-Agent': 'WhatsApp/2.23.20.15 iOS/16.0 Device/iPhone'
|
|
261
259
|
}
|
|
262
260
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
options.logger?.debug('Successfully downloaded externalAdReply thumbnail for cross-platform compatibility');
|
|
269
|
-
}
|
|
270
|
-
} catch (error) {
|
|
271
|
-
// If thumbnail download fails, keep thumbnailUrl as fallback
|
|
272
|
-
options.logger?.warn('Failed to download externalAdReply thumbnail for cross-platform compatibility:', error.message);
|
|
261
|
+
const { buffer } = await (0, messages_media_1.extractImageThumb)(stream, 512, 80);
|
|
262
|
+
externalAdReply.thumbnail = buffer;
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
options.logger?.warn('Failed to generate externalAdReply thumbnail for cross-platform compatibility:', error.message);
|
|
273
266
|
}
|
|
274
267
|
}
|
|
275
|
-
|
|
276
|
-
// Ensure renderLargerThumbnail is set for better display across platforms
|
|
277
268
|
if (externalAdReply.renderLargerThumbnail === undefined) {
|
|
278
|
-
externalAdReply.renderLargerThumbnail =
|
|
279
|
-
options.logger?.debug('Set renderLargerThumbnail=false for improved cross-platform display');
|
|
269
|
+
externalAdReply.renderLargerThumbnail = true;
|
|
280
270
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
271
|
+
return externalAdReply;
|
|
272
|
+
};
|
|
273
|
+
if (message.contextInfo?.externalAdReply) {
|
|
274
|
+
message.contextInfo.externalAdReply = await fixupExternalAdReplyThumb(message.contextInfo.externalAdReply);
|
|
275
|
+
}
|
|
276
|
+
if (message.externalAdReply) {
|
|
277
|
+
message.externalAdReply = await fixupExternalAdReplyThumb(message.externalAdReply);
|
|
284
278
|
}
|
|
285
279
|
|
|
286
280
|
let m = {};
|
|
@@ -361,25 +355,85 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
361
355
|
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
362
356
|
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
363
357
|
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
364
|
-
|
|
365
|
-
//
|
|
358
|
+
|
|
359
|
+
// Get group metadata to obtain disappearing mode and other group info
|
|
360
|
+
if (options.groupMetadata) {
|
|
361
|
+
try {
|
|
362
|
+
const groupMetadata = await options.groupMetadata(message.groupInvite.jid);
|
|
363
|
+
if (groupMetadata) {
|
|
364
|
+
// Add disappearing mode info if available
|
|
365
|
+
if (groupMetadata.ephemeralDuration !== undefined) {
|
|
366
|
+
m.groupInviteMessage.ephemeralDuration = groupMetadata.ephemeralDuration;
|
|
367
|
+
}
|
|
368
|
+
// Add group subject from metadata if not provided in message
|
|
369
|
+
if (!m.groupInviteMessage.groupName && groupMetadata.subject) {
|
|
370
|
+
m.groupInviteMessage.groupName = groupMetadata.subject;
|
|
371
|
+
}
|
|
372
|
+
// Add group participant count
|
|
373
|
+
if (groupMetadata.participants) {
|
|
374
|
+
m.groupInviteMessage.groupSize = groupMetadata.participants.length;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
} catch (error) {
|
|
378
|
+
options.logger?.debug({ error, jid: message.groupInvite.jid }, 'Failed to fetch group metadata for invite');
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Handle profile picture with caching
|
|
366
383
|
if (options.getProfilePicUrl) {
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
384
|
+
const cacheKey = `group_pfp:${message.groupInvite.jid}`;
|
|
385
|
+
|
|
386
|
+
// Check cache first if available
|
|
387
|
+
if (options.cache && options.cache.get) {
|
|
388
|
+
const cachedPfp = options.cache.get(cacheKey);
|
|
389
|
+
if (cachedPfp) {
|
|
390
|
+
m.groupInviteMessage.jpegThumbnail = cachedPfp;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Fetch if not in cache
|
|
395
|
+
if (!m.groupInviteMessage.jpegThumbnail) {
|
|
396
|
+
try {
|
|
397
|
+
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
398
|
+
if (pfpUrl) {
|
|
399
|
+
const resp = await axios_1.default.get(pfpUrl, {
|
|
400
|
+
responseType: 'arraybuffer',
|
|
401
|
+
timeout: 5000,
|
|
402
|
+
headers: {
|
|
403
|
+
'User-Agent': 'WhatsApp/2.23.20.15 iOS/16.0 Device/iPhone'
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
if (resp.status === 200) {
|
|
407
|
+
m.groupInviteMessage.jpegThumbnail = resp.data;
|
|
408
|
+
|
|
409
|
+
// Cache the result if cache is available
|
|
410
|
+
if (options.cache && options.cache.set) {
|
|
411
|
+
options.cache.set(cacheKey, resp.data, 3600); // Cache for 1 hour
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} catch (error) {
|
|
416
|
+
options.logger?.debug({ error, jid: message.groupInvite.jid }, 'Failed to fetch group profile picture');
|
|
372
417
|
}
|
|
373
418
|
}
|
|
374
419
|
}
|
|
375
420
|
}
|
|
376
421
|
else if ('pin' in message) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
m.pinInChatMessage
|
|
381
|
-
|
|
382
|
-
|
|
422
|
+
const pinData = typeof message.pin === 'object' ? message.pin : { key: message.pin };
|
|
423
|
+
// Map type: 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL
|
|
424
|
+
const pinType = pinData.type !== undefined ? pinData.type : (message.type !== undefined ? message.type : WAProto_1.proto.Message.PinInChatMessage.Type.PIN_FOR_ALL);
|
|
425
|
+
m.pinInChatMessage = {
|
|
426
|
+
key: pinData.key,
|
|
427
|
+
type: pinType,
|
|
428
|
+
senderTimestampMs: Date.now()
|
|
429
|
+
};
|
|
430
|
+
// Add messageContextInfo only for PIN (type 1), not for UNPIN (type 2)
|
|
431
|
+
if (pinType === WAProto_1.proto.Message.PinInChatMessage.Type.PIN_FOR_ALL) {
|
|
432
|
+
m.messageContextInfo = {
|
|
433
|
+
messageAddOnDurationInSecs: pinData.time || message.time || 86400, // Default 24 hours
|
|
434
|
+
messageAddOnExpiryType: WAProto_1.proto.MessageContextInfo.MessageAddonExpiryType.STATIC
|
|
435
|
+
};
|
|
436
|
+
}
|
|
383
437
|
}
|
|
384
438
|
else if ('keep' in message) {
|
|
385
439
|
m.keepInChatMessage = {};
|
|
@@ -388,13 +442,28 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
388
442
|
m.keepInChatMessage.timestampMs = Date.now();
|
|
389
443
|
}
|
|
390
444
|
else if ('call' in message) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
445
|
+
const call = message.call;
|
|
446
|
+
if (call && typeof call === 'object' && (
|
|
447
|
+
'callKey' in call
|
|
448
|
+
|| 'conversionSource' in call
|
|
449
|
+
|| 'conversionData' in call
|
|
450
|
+
|| 'conversionDelaySeconds' in call
|
|
451
|
+
|| 'ctwaSignals' in call
|
|
452
|
+
|| 'ctwaPayload' in call
|
|
453
|
+
|| 'nativeFlowCallButtonPayload' in call
|
|
454
|
+
|| 'deeplinkPayload' in call
|
|
455
|
+
)) {
|
|
456
|
+
m.call = WAProto_1.proto.Message.Call.fromObject(call);
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
m = {
|
|
460
|
+
scheduledCallCreationMessage: {
|
|
461
|
+
scheduledTimestampMs: (_a = call === null || call === void 0 ? void 0 : call.time) !== null && _a !== void 0 ? _a : Date.now(),
|
|
462
|
+
callType: (_b = call === null || call === void 0 ? void 0 : call.type) !== null && _b !== void 0 ? _b : 1,
|
|
463
|
+
title: call === null || call === void 0 ? void 0 : call.title
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
398
467
|
}
|
|
399
468
|
else if ('paymentInvite' in message) {
|
|
400
469
|
m.paymentInviteMessage = {
|
|
@@ -409,6 +478,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
409
478
|
selectedDisplayText: message.buttonReply.displayText,
|
|
410
479
|
selectedId: message.buttonReply.id,
|
|
411
480
|
selectedIndex: message.buttonReply.index,
|
|
481
|
+
selectedCarouselCardIndex: message.buttonReply.carouselCardIndex
|
|
412
482
|
};
|
|
413
483
|
break;
|
|
414
484
|
case 'plain':
|
|
@@ -486,12 +556,262 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
486
556
|
}
|
|
487
557
|
}
|
|
488
558
|
}
|
|
559
|
+
else if ('pollResultSnapshotV3' in message && !!message.pollResultSnapshotV3) {
|
|
560
|
+
m.pollResultSnapshotMessageV3 = {
|
|
561
|
+
pollCreationMessageKey: message.pollResultSnapshotV3.pollCreationMessageKey,
|
|
562
|
+
pollResult: message.pollResultSnapshotV3.pollResult,
|
|
563
|
+
selectedOptions: message.pollResultSnapshotV3.selectedOptions,
|
|
564
|
+
contextInfo: message.pollResultSnapshotV3.contextInfo,
|
|
565
|
+
pollType: message.pollResultSnapshotV3.pollType
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
else if ('pollV4' in message) {
|
|
569
|
+
const pollCreationMessage = {
|
|
570
|
+
name: message.pollV4.name,
|
|
571
|
+
selectableOptionsCount: message.pollV4.selectableCount,
|
|
572
|
+
options: message.pollV4.values.map(optionName => ({ optionName })),
|
|
573
|
+
pollType: message.pollV4.pollType
|
|
574
|
+
};
|
|
575
|
+
m.pollCreationMessageV4 = pollCreationMessage;
|
|
576
|
+
}
|
|
577
|
+
else if ('pollV5' in message) {
|
|
578
|
+
const pollCreationMessage = {
|
|
579
|
+
name: message.pollV5.name,
|
|
580
|
+
selectableOptionsCount: message.pollV5.selectableCount,
|
|
581
|
+
options: message.pollV5.values.map(optionName => ({ optionName })),
|
|
582
|
+
pollType: message.pollV5.pollType
|
|
583
|
+
};
|
|
584
|
+
m.pollCreationMessageV5 = pollCreationMessage;
|
|
585
|
+
}
|
|
489
586
|
else if ('event' in message) {
|
|
490
587
|
m.messageContextInfo = {
|
|
491
588
|
messageSecret: message.event.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
492
589
|
};
|
|
493
590
|
m.eventMessage = { ...message.event };
|
|
494
591
|
}
|
|
592
|
+
else if ('comment' in message) {
|
|
593
|
+
m.commentMessage = {
|
|
594
|
+
message: message.comment.message,
|
|
595
|
+
targetMessageKey: message.comment.targetMessageKey
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
else if ('question' in message) {
|
|
599
|
+
m.questionMessage = {
|
|
600
|
+
text: message.question.text,
|
|
601
|
+
contextInfo: message.question.contextInfo
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
else if ('questionResponse' in message) {
|
|
605
|
+
m.questionResponseMessage = {
|
|
606
|
+
key: message.questionResponse.key,
|
|
607
|
+
text: message.questionResponse.text
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
else if ('statusQuestionAnswer' in message) {
|
|
611
|
+
m.statusQuestionAnswerMessage = {
|
|
612
|
+
key: message.statusQuestionAnswer.key,
|
|
613
|
+
text: message.statusQuestionAnswer.text
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
else if ('statusQuoted' in message) {
|
|
617
|
+
m.statusQuotedMessage = {
|
|
618
|
+
type: message.statusQuoted.type,
|
|
619
|
+
text: message.statusQuoted.text,
|
|
620
|
+
thumbnail: message.statusQuoted.thumbnail,
|
|
621
|
+
originalStatusId: message.statusQuoted.originalStatusId
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
else if ('statusStickerInteraction' in message) {
|
|
625
|
+
m.statusStickerInteractionMessage = {
|
|
626
|
+
key: message.statusStickerInteraction.key,
|
|
627
|
+
stickerKey: message.statusStickerInteraction.stickerKey,
|
|
628
|
+
type: message.statusStickerInteraction.type
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
else if ('richResponse' in message) {
|
|
632
|
+
m.richResponseMessage = WAProto_1.proto.AIRichResponseMessage.fromObject({
|
|
633
|
+
messageType: message.richResponse.messageType !== undefined ? message.richResponse.messageType : 1, // AI_RICH_RESPONSE_TYPE_STANDARD
|
|
634
|
+
submessages: message.richResponse.submessages || [],
|
|
635
|
+
unifiedResponse: message.richResponse.unifiedResponse,
|
|
636
|
+
contextInfo: message.richResponse.contextInfo
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
else if ('eventResponse' in message && !!message.eventResponse) {
|
|
640
|
+
m.eventResponseMessage = {
|
|
641
|
+
response: message.eventResponse.response, // GOING = 1, NOT_GOING = 2, MAYBE = 3
|
|
642
|
+
timestampMs: message.eventResponse.timestampMs || Date.now(),
|
|
643
|
+
extraGuestCount: message.eventResponse.extraGuestCount
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
else if ('statusMention' in message && !!message.statusMention) {
|
|
647
|
+
m.statusMentionMessage = {
|
|
648
|
+
quotedStatus: message.statusMention.quotedStatus
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
else if ('groupStatus' in message && !!message.groupStatus) {
|
|
652
|
+
m.groupStatusMessage = message.groupStatus.message;
|
|
653
|
+
}
|
|
654
|
+
else if ('botTask' in message && !!message.botTask) {
|
|
655
|
+
m.botTaskMessage = message.botTask.message;
|
|
656
|
+
}
|
|
657
|
+
else if ('limitSharing' in message && !!message.limitSharing) {
|
|
658
|
+
m.limitSharingMessage = message.limitSharing.message;
|
|
659
|
+
}
|
|
660
|
+
else if ('statusAddYours' in message && !!message.statusAddYours) {
|
|
661
|
+
m.statusAddYours = message.statusAddYours.message;
|
|
662
|
+
}
|
|
663
|
+
else if ('botForwarded' in message && !!message.botForwarded) {
|
|
664
|
+
m.botForwardedMessage = message.botForwarded.message;
|
|
665
|
+
}
|
|
666
|
+
else if ('eventCoverImage' in message && !!message.eventCoverImage) {
|
|
667
|
+
m.eventCoverImage = message.eventCoverImage.message;
|
|
668
|
+
}
|
|
669
|
+
else if ('stickerPack' in message && !!message.stickerPack) {
|
|
670
|
+
const pack = message.stickerPack;
|
|
671
|
+
const stickerPackMessage = {
|
|
672
|
+
name: pack.name,
|
|
673
|
+
publisher: pack.publisher,
|
|
674
|
+
packDescription: pack.description,
|
|
675
|
+
stickerPackId: pack.stickerPackId || (0, crypto_1.randomBytes)(16).toString('hex'),
|
|
676
|
+
stickerPackOrigin: pack.origin || 2 // USER_CREATED = 2
|
|
677
|
+
};
|
|
678
|
+
// Process cover if provided
|
|
679
|
+
if (pack.cover) {
|
|
680
|
+
const coverMedia = await (0, exports.prepareWAMessageMedia)({ image: pack.cover }, options);
|
|
681
|
+
stickerPackMessage.thumbnailDirectPath = coverMedia.imageMessage.directPath;
|
|
682
|
+
stickerPackMessage.thumbnailSha256 = coverMedia.imageMessage.thumbnailSha256;
|
|
683
|
+
stickerPackMessage.thumbnailEncSha256 = coverMedia.imageMessage.thumbnailEncSha256;
|
|
684
|
+
stickerPackMessage.thumbnailHeight = coverMedia.imageMessage.height;
|
|
685
|
+
stickerPackMessage.thumbnailWidth = coverMedia.imageMessage.width;
|
|
686
|
+
}
|
|
687
|
+
// Process stickers
|
|
688
|
+
if (pack.stickers && pack.stickers.length > 0) {
|
|
689
|
+
const processedStickers = await Promise.all(pack.stickers.map(async (sticker) => {
|
|
690
|
+
const stickerMedia = await (0, exports.prepareWAMessageMedia)({ sticker: sticker.sticker }, options);
|
|
691
|
+
return {
|
|
692
|
+
fileName: sticker.fileName || `sticker_${Date.now()}.webp`,
|
|
693
|
+
isAnimated: sticker.isAnimated || false,
|
|
694
|
+
emojis: sticker.emojis || [],
|
|
695
|
+
accessibilityLabel: sticker.accessibilityLabel,
|
|
696
|
+
isLottie: sticker.isLottie || false,
|
|
697
|
+
mimetype: sticker.mimetype || stickerMedia.stickerMessage.mimetype
|
|
698
|
+
};
|
|
699
|
+
}));
|
|
700
|
+
stickerPackMessage.stickers = processedStickers;
|
|
701
|
+
stickerPackMessage.stickerPackSize = processedStickers.length;
|
|
702
|
+
}
|
|
703
|
+
if (pack.caption) {
|
|
704
|
+
stickerPackMessage.caption = pack.caption;
|
|
705
|
+
}
|
|
706
|
+
m.stickerPackMessage = stickerPackMessage;
|
|
707
|
+
}
|
|
708
|
+
else if ('interactiveResponse' in message && !!message.interactiveResponse) {
|
|
709
|
+
const response = message.interactiveResponse;
|
|
710
|
+
const interactiveResponseMessage = {
|
|
711
|
+
body: {
|
|
712
|
+
text: response.body?.text || '',
|
|
713
|
+
format: response.body?.format || 0 // DEFAULT = 0
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
if (response.nativeFlowResponse) {
|
|
717
|
+
interactiveResponseMessage.nativeFlowResponseMessage = {
|
|
718
|
+
name: response.nativeFlowResponse.name,
|
|
719
|
+
paramsJson: response.nativeFlowResponse.paramsJson,
|
|
720
|
+
version: response.nativeFlowResponse.version || 1
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
if (response.contextInfo) {
|
|
724
|
+
interactiveResponseMessage.contextInfo = response.contextInfo;
|
|
725
|
+
}
|
|
726
|
+
m.interactiveResponseMessage = interactiveResponseMessage;
|
|
727
|
+
}
|
|
728
|
+
else if ('bCall' in message && !!message.bCall) {
|
|
729
|
+
m.bcallMessage = {
|
|
730
|
+
sessionId: message.bCall.sessionId,
|
|
731
|
+
mediaType: message.bCall.mediaType || 0, // UNKNOWN = 0, AUDIO = 1, VIDEO = 2
|
|
732
|
+
masterKey: message.bCall.masterKey,
|
|
733
|
+
caption: message.bCall.caption
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
else if ('callLog' in message && !!message.callLog) {
|
|
737
|
+
m.callLogMesssage = {
|
|
738
|
+
isVideo: message.callLog.isVideo || false,
|
|
739
|
+
callOutcome: message.callLog.callOutcome || 0, // CONNECTED = 0
|
|
740
|
+
durationSecs: message.callLog.durationSecs,
|
|
741
|
+
callType: message.callLog.callType || 0, // REGULAR = 0
|
|
742
|
+
participants: message.callLog.participants || []
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
else if ('encComment' in message && !!message.encComment) {
|
|
746
|
+
m.encCommentMessage = {
|
|
747
|
+
targetMessageKey: message.encComment.targetMessageKey,
|
|
748
|
+
encPayload: message.encComment.encPayload,
|
|
749
|
+
encIv: message.encComment.encIv
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
else if ('encEventResponse' in message && !!message.encEventResponse) {
|
|
753
|
+
m.encEventResponseMessage = {
|
|
754
|
+
eventCreationMessageKey: message.encEventResponse.eventCreationMessageKey,
|
|
755
|
+
encPayload: message.encEventResponse.encPayload,
|
|
756
|
+
encIv: message.encEventResponse.encIv
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
else if ('messageHistoryBundle' in message && !!message.messageHistoryBundle) {
|
|
760
|
+
const bundle = message.messageHistoryBundle;
|
|
761
|
+
const bundleMedia = bundle.media ? await (0, exports.prepareWAMessageMedia)({ document: bundle.media }, options) : null;
|
|
762
|
+
m.messageHistoryBundle = {
|
|
763
|
+
mimetype: bundle.mimetype || 'application/octet-stream',
|
|
764
|
+
fileSha256: bundleMedia?.documentMessage?.fileSha256,
|
|
765
|
+
mediaKey: bundleMedia?.documentMessage?.mediaKey,
|
|
766
|
+
fileEncSha256: bundleMedia?.documentMessage?.fileEncSha256,
|
|
767
|
+
directPath: bundleMedia?.documentMessage?.directPath,
|
|
768
|
+
mediaKeyTimestamp: bundleMedia?.documentMessage?.mediaKeyTimestamp,
|
|
769
|
+
contextInfo: bundle.contextInfo,
|
|
770
|
+
messageHistoryMetadata: bundle.messageHistoryMetadata
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
else if ('messageHistoryNotice' in message && !!message.messageHistoryNotice) {
|
|
774
|
+
m.messageHistoryNotice = {
|
|
775
|
+
contextInfo: message.messageHistoryNotice.contextInfo,
|
|
776
|
+
messageHistoryMetadata: message.messageHistoryNotice.messageHistoryMetadata
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
else if ('inviteFollower' in message && !!message.inviteFollower) {
|
|
780
|
+
m.newsletterFollowerInviteMessageV2 = {
|
|
781
|
+
newsletterJid: message.inviteFollower.newsletterJid,
|
|
782
|
+
newsletterName: message.inviteFollower.newsletterName,
|
|
783
|
+
jpegThumbnail: message.inviteFollower.thumbnail,
|
|
784
|
+
caption: message.inviteFollower.caption,
|
|
785
|
+
contextInfo: message.inviteFollower.contextInfo
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
else if ('placeholder' in message && !!message.placeholder) {
|
|
789
|
+
m.placeholderMessage = {
|
|
790
|
+
type: message.placeholder.type || 0 // MASK_LINKED_DEVICES = 0
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
else if ('secretEncrypted' in message && !!message.secretEncrypted) {
|
|
794
|
+
m.secretEncryptedMessage = {
|
|
795
|
+
targetMessageKey: message.secretEncrypted.targetMessageKey,
|
|
796
|
+
encPayload: message.secretEncrypted.encPayload,
|
|
797
|
+
encIv: message.secretEncrypted.encIv,
|
|
798
|
+
secretEncType: message.secretEncrypted.secretEncType || 0 // UNKNOWN = 0, EVENT_EDIT = 1, MESSAGE_EDIT = 2
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
else if ('statusNotification' in message && !!message.statusNotification) {
|
|
802
|
+
m.statusNotificationMessage = {
|
|
803
|
+
responseMessageKey: message.statusNotification.responseMessageKey,
|
|
804
|
+
originalMessageKey: message.statusNotification.originalMessageKey,
|
|
805
|
+
type: message.statusNotification.type || 0 // UNKNOWN = 0, STATUS_ADD_YOURS = 1, STATUS_RESHARE = 2, STATUS_QUESTION_ANSWER_RESHARE = 3
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
else if ('stickerSyncRMR' in message && !!message.stickerSyncRMR) {
|
|
809
|
+
m.stickerSyncRmrMessage = {
|
|
810
|
+
filehash: message.stickerSyncRMR.filehash || [],
|
|
811
|
+
rmrSource: message.stickerSyncRMR.rmrSource,
|
|
812
|
+
requestTimestamp: message.stickerSyncRMR.requestTimestamp || Date.now()
|
|
813
|
+
};
|
|
814
|
+
}
|
|
495
815
|
else if ('inviteAdmin' in message) {
|
|
496
816
|
m.newsletterAdminInviteMessage = {};
|
|
497
817
|
m.newsletterAdminInviteMessage.inviteExpiration = message.inviteAdmin.inviteExpiration;
|
|
@@ -503,7 +823,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
503
823
|
else if ('requestPayment' in message) {
|
|
504
824
|
const reqPayment = message.requestPayment;
|
|
505
825
|
const sticker = reqPayment.sticker ?
|
|
506
|
-
await (0, exports.prepareWAMessageMedia)({ sticker: reqPayment.sticker
|
|
826
|
+
await (0, exports.prepareWAMessageMedia)({ sticker: reqPayment.sticker }, options)
|
|
507
827
|
: null;
|
|
508
828
|
let notes = {};
|
|
509
829
|
if (reqPayment.sticker) {
|
|
@@ -553,9 +873,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
553
873
|
else if ('requestPhoneNumber' in message) {
|
|
554
874
|
m.requestPhoneNumberMessage = {};
|
|
555
875
|
}
|
|
556
|
-
else if ('call' in message) {
|
|
557
|
-
m.callMessage = Types_1.WAProto.Message.CallMessage.fromObject(message.call);
|
|
558
|
-
}
|
|
559
876
|
else if ('newsletterMessage' in message) {
|
|
560
877
|
m.newsletterMessage = Types_1.WAProto.Message.NewsletterMessage.fromObject(message.newsletterMessage);
|
|
561
878
|
}
|
|
@@ -578,6 +895,62 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
578
895
|
}
|
|
579
896
|
};
|
|
580
897
|
}
|
|
898
|
+
else if ('sendPayment' in message && !!message.sendPayment) {
|
|
899
|
+
const payment = message.sendPayment;
|
|
900
|
+
m.sendPaymentMessage = {
|
|
901
|
+
requestMessageKey: payment.requestMessageKey,
|
|
902
|
+
noteMessage: payment.noteMessage,
|
|
903
|
+
background: payment.background,
|
|
904
|
+
transactionData: payment.transactionData
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
else if ('declinePayment' in message && !!message.declinePayment) {
|
|
908
|
+
m.declinePaymentRequestMessage = {
|
|
909
|
+
key: message.declinePayment.key
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
else if ('cancelPayment' in message && !!message.cancelPayment) {
|
|
913
|
+
m.cancelPaymentRequestMessage = {
|
|
914
|
+
key: message.cancelPayment.key
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
else if ('scheduledCallEdit' in message && !!message.scheduledCallEdit) {
|
|
918
|
+
m.scheduledCallEditMessage = {
|
|
919
|
+
key: message.scheduledCallEdit.key,
|
|
920
|
+
editType: message.scheduledCallEdit.editType || 0 // UNKNOWN = 0, CANCEL = 1
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
else if ('pollResultSnapshot' in message && !!message.pollResultSnapshot) {
|
|
924
|
+
m.pollResultSnapshotMessage = {
|
|
925
|
+
name: message.pollResultSnapshot.name,
|
|
926
|
+
pollVotes: message.pollResultSnapshot.pollVotes || [],
|
|
927
|
+
contextInfo: message.pollResultSnapshot.contextInfo,
|
|
928
|
+
pollType: message.pollResultSnapshot.pollType || 0 // POLL = 0, QUIZ = 1
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
else if ('pollUpdate' in message && !!message.pollUpdate) {
|
|
932
|
+
m.pollUpdateMessage = {
|
|
933
|
+
pollCreationMessageKey: message.pollUpdate.pollCreationMessageKey,
|
|
934
|
+
vote: message.pollUpdate.vote,
|
|
935
|
+
metadata: message.pollUpdate.metadata,
|
|
936
|
+
senderTimestampMs: message.pollUpdate.senderTimestampMs || Date.now()
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
else if ('deviceSent' in message && !!message.deviceSent) {
|
|
940
|
+
const deviceSent = message.deviceSent;
|
|
941
|
+
const innerMessage = await (0, exports.generateWAMessageContent)(deviceSent.message, options);
|
|
942
|
+
m.deviceSentMessage = {
|
|
943
|
+
destinationJid: deviceSent.destinationJid,
|
|
944
|
+
message: innerMessage,
|
|
945
|
+
phash: deviceSent.phash
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
else if ('chat' in message && !!message.chat) {
|
|
949
|
+
m.chat = {
|
|
950
|
+
displayName: message.chat.displayName,
|
|
951
|
+
id: message.chat.id
|
|
952
|
+
};
|
|
953
|
+
}
|
|
581
954
|
else if ('payment' in message) {
|
|
582
955
|
// Handle sendPayment functionality
|
|
583
956
|
m.requestPaymentMessage = Types_1.WAProto.Message.RequestPaymentMessage.fromObject({
|
|
@@ -594,6 +967,46 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
594
967
|
background: message.payment.background
|
|
595
968
|
});
|
|
596
969
|
}
|
|
970
|
+
else if ('comment' in message) {
|
|
971
|
+
m.commentMessage = {
|
|
972
|
+
message: message.comment.message,
|
|
973
|
+
targetMessageKey: message.comment.targetMessageKey
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
else if ('question' in message) {
|
|
977
|
+
m.questionMessage = {
|
|
978
|
+
text: message.question.text,
|
|
979
|
+
contextInfo: message.question.contextInfo
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
else if ('questionResponse' in message) {
|
|
983
|
+
m.questionResponseMessage = {
|
|
984
|
+
key: message.questionResponse.key,
|
|
985
|
+
text: message.questionResponse.text
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
else if ('statusQuestionAnswer' in message) {
|
|
989
|
+
m.statusQuestionAnswerMessage = {
|
|
990
|
+
key: message.statusQuestionAnswer.key,
|
|
991
|
+
text: message.statusQuestionAnswer.text
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
else if ('statusQuoted' in message) {
|
|
995
|
+
m.statusQuotedMessage = {
|
|
996
|
+
type: message.statusQuoted.type,
|
|
997
|
+
text: message.statusQuoted.text,
|
|
998
|
+
thumbnail: message.statusQuoted.thumbnail,
|
|
999
|
+
jid: message.statusQuoted.jid,
|
|
1000
|
+
originalStatusId: message.statusQuoted.originalStatusId
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
else if ('statusStickerInteraction' in message) {
|
|
1004
|
+
m.statusStickerInteractionMessage = {
|
|
1005
|
+
key: message.statusStickerInteraction.key,
|
|
1006
|
+
stickerKey: message.statusStickerInteraction.stickerKey,
|
|
1007
|
+
type: message.statusStickerInteraction.type
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
597
1010
|
else if ('album' in message) {
|
|
598
1011
|
const imageMessages = message.album.filter(item => 'image' in item);
|
|
599
1012
|
const videoMessages = message.album.filter(item => 'video' in item);
|
|
@@ -675,6 +1088,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
675
1088
|
const interactiveMessage = {
|
|
676
1089
|
nativeFlowMessage: Types_1.WAProto.Message.InteractiveMessage.NativeFlowMessage.fromObject({
|
|
677
1090
|
buttons: message.interactiveButtons,
|
|
1091
|
+
messageVersion: 1,
|
|
678
1092
|
})
|
|
679
1093
|
};
|
|
680
1094
|
if ('text' in message) {
|
|
@@ -689,22 +1103,69 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
689
1103
|
interactiveMessage.header = {
|
|
690
1104
|
title: message.title,
|
|
691
1105
|
subtitle: message.subtitle,
|
|
692
|
-
hasMediaAttachment: (
|
|
1106
|
+
hasMediaAttachment: !!(message === null || message === void 0 ? void 0 : message.media),
|
|
693
1107
|
};
|
|
694
1108
|
Object.assign(interactiveMessage.header, m);
|
|
695
1109
|
}
|
|
696
1110
|
if ('footer' in message && !!message.footer) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
1111
|
+
if (typeof message.footer === 'string') {
|
|
1112
|
+
interactiveMessage.footer = {
|
|
1113
|
+
text: message.footer
|
|
1114
|
+
};
|
|
1115
|
+
} else if (typeof message.footer === 'object' && message.footer.text) {
|
|
1116
|
+
interactiveMessage.footer = {
|
|
1117
|
+
text: message.footer.text,
|
|
1118
|
+
hasMediaAttachment: !!message.footer.audio
|
|
1119
|
+
};
|
|
1120
|
+
if (message.footer.audio) {
|
|
1121
|
+
const audioMedia = await (0, exports.prepareWAMessageMedia)({ audio: message.footer.audio }, options);
|
|
1122
|
+
interactiveMessage.footer.audioMessage = audioMedia.audioMessage;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
700
1125
|
}
|
|
701
1126
|
if ('title' in message && !!message.title) {
|
|
702
|
-
|
|
1127
|
+
const headerData = {
|
|
703
1128
|
title: message.title,
|
|
704
1129
|
subtitle: message.subtitle,
|
|
705
|
-
hasMediaAttachment:
|
|
1130
|
+
hasMediaAttachment: !!message.media,
|
|
706
1131
|
};
|
|
707
|
-
|
|
1132
|
+
|
|
1133
|
+
// Process media attachments for interactive buttons
|
|
1134
|
+
if (message.media) {
|
|
1135
|
+
if (message.media.image) {
|
|
1136
|
+
const mediaMessage = await (0, exports.prepareWAMessageMedia)({ image: message.media.image }, options);
|
|
1137
|
+
if (mediaMessage.imageMessage) {
|
|
1138
|
+
headerData.imageMessage = mediaMessage.imageMessage;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
else if (message.media.video) {
|
|
1142
|
+
const mediaMessage = await (0, exports.prepareWAMessageMedia)({ video: message.media.video }, options);
|
|
1143
|
+
if (mediaMessage.videoMessage) {
|
|
1144
|
+
headerData.videoMessage = mediaMessage.videoMessage;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
else if (message.media.document) {
|
|
1148
|
+
const mediaMessage = await (0, exports.prepareWAMessageMedia)({ document: message.media.document }, options);
|
|
1149
|
+
if (mediaMessage.documentMessage) {
|
|
1150
|
+
headerData.documentMessage = mediaMessage.documentMessage;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
interactiveMessage.header = headerData;
|
|
1156
|
+
// Support for ProductMessage in header
|
|
1157
|
+
if (message.headerProduct) {
|
|
1158
|
+
const productMedia = await (0, exports.prepareWAMessageMedia)({ image: message.headerProduct.productImage }, options);
|
|
1159
|
+
interactiveMessage.header.productMessage = {
|
|
1160
|
+
product: {
|
|
1161
|
+
...message.headerProduct,
|
|
1162
|
+
productImage: productMedia.imageMessage
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
interactiveMessage.header.hasMediaAttachment = true;
|
|
1166
|
+
} else {
|
|
1167
|
+
Object.assign(interactiveMessage.header, m);
|
|
1168
|
+
}
|
|
708
1169
|
}
|
|
709
1170
|
if ('contextInfo' in message && !!message.contextInfo) {
|
|
710
1171
|
interactiveMessage.contextInfo = message.contextInfo;
|
|
@@ -733,7 +1194,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
733
1194
|
interactiveMessage.header = {
|
|
734
1195
|
title: message.title,
|
|
735
1196
|
subtitle: message.subtitle,
|
|
736
|
-
hasMediaAttachment: (
|
|
1197
|
+
hasMediaAttachment: !!(message === null || message === void 0 ? void 0 : message.media),
|
|
737
1198
|
};
|
|
738
1199
|
Object.assign(interactiveMessage.header, m);
|
|
739
1200
|
}
|
|
@@ -746,7 +1207,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
746
1207
|
interactiveMessage.header = {
|
|
747
1208
|
title: message.title,
|
|
748
1209
|
subtitle: message.subtitle,
|
|
749
|
-
hasMediaAttachment: (
|
|
1210
|
+
hasMediaAttachment: !!(message === null || message === void 0 ? void 0 : message.media),
|
|
750
1211
|
};
|
|
751
1212
|
Object.assign(interactiveMessage.header, m);
|
|
752
1213
|
}
|
|
@@ -758,7 +1219,68 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
758
1219
|
}
|
|
759
1220
|
m = { interactiveMessage };
|
|
760
1221
|
}
|
|
1222
|
+
else if ('collection' in message && !!message.collection) {
|
|
1223
|
+
const interactiveMessage = {
|
|
1224
|
+
collectionMessage: Types_1.WAProto.Message.InteractiveMessage.CollectionMessage.fromObject({
|
|
1225
|
+
bizJid: message.collection.bizJid,
|
|
1226
|
+
id: message.collection.id,
|
|
1227
|
+
messageVersion: message.collection.messageVersion || 1
|
|
1228
|
+
})
|
|
1229
|
+
};
|
|
1230
|
+
if ('text' in message) {
|
|
1231
|
+
interactiveMessage.body = {
|
|
1232
|
+
text: message.text
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
if ('footer' in message && !!message.footer) {
|
|
1236
|
+
interactiveMessage.footer = {
|
|
1237
|
+
text: message.footer
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
if ('title' in message && !!message.title) {
|
|
1241
|
+
interactiveMessage.header = {
|
|
1242
|
+
title: message.title,
|
|
1243
|
+
subtitle: message.subtitle,
|
|
1244
|
+
hasMediaAttachment: false
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
if ('contextInfo' in message && !!message.contextInfo) {
|
|
1248
|
+
interactiveMessage.contextInfo = message.contextInfo;
|
|
1249
|
+
}
|
|
1250
|
+
m = { interactiveMessage };
|
|
1251
|
+
}
|
|
1252
|
+
else if ('invoice' in message && !!message.invoice) {
|
|
1253
|
+
const invoiceData = message.invoice;
|
|
1254
|
+
const invoiceMessage = {
|
|
1255
|
+
note: invoiceData.note,
|
|
1256
|
+
token: invoiceData.token,
|
|
1257
|
+
attachmentType: invoiceData.attachmentType || 0 // IMAGE = 0, PDF = 1
|
|
1258
|
+
};
|
|
1259
|
+
if (invoiceData.attachment) {
|
|
1260
|
+
const attachmentMedia = await (0, exports.prepareWAMessageMedia)({
|
|
1261
|
+
[invoiceData.attachmentType === 1 ? 'document' : 'image']: invoiceData.attachment
|
|
1262
|
+
}, options);
|
|
1263
|
+
if (invoiceData.attachmentType === 1) {
|
|
1264
|
+
invoiceMessage.attachmentMimetype = attachmentMedia.documentMessage.mimetype;
|
|
1265
|
+
invoiceMessage.attachmentMediaKey = attachmentMedia.documentMessage.mediaKey;
|
|
1266
|
+
invoiceMessage.attachmentMediaKeyTimestamp = attachmentMedia.documentMessage.mediaKeyTimestamp;
|
|
1267
|
+
invoiceMessage.attachmentFileSha256 = attachmentMedia.documentMessage.fileSha256;
|
|
1268
|
+
invoiceMessage.attachmentFileEncSha256 = attachmentMedia.documentMessage.fileEncSha256;
|
|
1269
|
+
invoiceMessage.attachmentDirectPath = attachmentMedia.documentMessage.directPath;
|
|
1270
|
+
} else {
|
|
1271
|
+
invoiceMessage.attachmentMimetype = attachmentMedia.imageMessage.mimetype;
|
|
1272
|
+
invoiceMessage.attachmentMediaKey = attachmentMedia.imageMessage.mediaKey;
|
|
1273
|
+
invoiceMessage.attachmentMediaKeyTimestamp = attachmentMedia.imageMessage.mediaKeyTimestamp;
|
|
1274
|
+
invoiceMessage.attachmentFileSha256 = attachmentMedia.imageMessage.fileSha256;
|
|
1275
|
+
invoiceMessage.attachmentFileEncSha256 = attachmentMedia.imageMessage.fileEncSha256;
|
|
1276
|
+
invoiceMessage.attachmentDirectPath = attachmentMedia.imageMessage.directPath;
|
|
1277
|
+
invoiceMessage.attachmentJpegThumbnail = attachmentMedia.imageMessage.jpegThumbnail;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
m = { invoiceMessage };
|
|
1281
|
+
}
|
|
761
1282
|
if ('cards' in message && !!message.cards && message.cards.length > 0) {
|
|
1283
|
+
const carouselCardType = message.carouselCardType || 1; // HSCROLL_CARDS = 1, ALBUM_IMAGE = 2
|
|
762
1284
|
const carouselCards = await Promise.all(message.cards.map(async (card) => {
|
|
763
1285
|
const cardMessage = {
|
|
764
1286
|
header: {
|
|
@@ -792,7 +1314,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
792
1314
|
buttons: card.buttons.map(button => ({
|
|
793
1315
|
name: button.name,
|
|
794
1316
|
buttonParamsJson: button.buttonParamsJson
|
|
795
|
-
}))
|
|
1317
|
+
})),
|
|
1318
|
+
messageVersion: 1,
|
|
796
1319
|
};
|
|
797
1320
|
}
|
|
798
1321
|
// Add footer if present
|
|
@@ -806,7 +1329,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
806
1329
|
const interactiveMessage = {
|
|
807
1330
|
carouselMessage: Types_1.WAProto.Message.InteractiveMessage.CarouselMessage.fromObject({
|
|
808
1331
|
cards: carouselCards,
|
|
809
|
-
messageVersion: 1
|
|
1332
|
+
messageVersion: 1,
|
|
1333
|
+
carouselCardType: carouselCardType
|
|
810
1334
|
})
|
|
811
1335
|
};
|
|
812
1336
|
if ('text' in message) {
|
|
@@ -834,8 +1358,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
834
1358
|
}
|
|
835
1359
|
m = { interactiveMessage };
|
|
836
1360
|
}
|
|
837
|
-
|
|
838
|
-
|
|
1361
|
+
// Interactive messages are commonly sent wrapped in a view-once container on MD.
|
|
1362
|
+
// This improves client compatibility (avoids "update WhatsApp" / invisible messages on some clients).
|
|
1363
|
+
const shouldWrapInteractive = !!(m === null || m === void 0 ? void 0 : m.interactiveMessage);
|
|
1364
|
+
const hasViewOnceAlready = !!(m === null || m === void 0 ? void 0 : m.viewOnceMessage) || !!(m === null || m === void 0 ? void 0 : m.viewOnceMessageV2) || !!(m === null || m === void 0 ? void 0 : m.viewOnceMessageV2Extension);
|
|
1365
|
+
if ((('viewOnce' in message && !!message.viewOnce) || shouldWrapInteractive) && !hasViewOnceAlready) {
|
|
1366
|
+
m = { viewOnceMessageV2: { message: m } };
|
|
839
1367
|
}
|
|
840
1368
|
if ('mentions' in message && ((_o = message.mentions) === null || _o === void 0 ? void 0 : _o.length)) {
|
|
841
1369
|
const [messageType] = Object.keys(m);
|
|
@@ -1203,3 +1731,63 @@ const assertMediaContent = (content) => {
|
|
|
1203
1731
|
return mediaContent;
|
|
1204
1732
|
};
|
|
1205
1733
|
exports.assertMediaContent = assertMediaContent;
|
|
1734
|
+
const cache_manager_1 = require("./cache-manager");
|
|
1735
|
+
const performance_config_1 = require("./performance-config");
|
|
1736
|
+
/**
|
|
1737
|
+
* Get cache statistics for monitoring performance
|
|
1738
|
+
*/
|
|
1739
|
+
const getCacheStats = () => {
|
|
1740
|
+
try {
|
|
1741
|
+
const cacheManager = cache_manager_1.default;
|
|
1742
|
+
const config = performance_config_1.getPerformanceConfig();
|
|
1743
|
+
|
|
1744
|
+
if (!cacheManager || !cacheManager.caches) {
|
|
1745
|
+
return {
|
|
1746
|
+
lidCache: { size: 0, maxSize: 0, ttl: config.cache.lidCache.ttl },
|
|
1747
|
+
jidCache: { size: 0, maxSize: 0, ttl: config.cache.jidCache.ttl }
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
const lidStats = cacheManager.getStats('lidCache');
|
|
1752
|
+
const jidStats = cacheManager.getStats('jidCache');
|
|
1753
|
+
|
|
1754
|
+
return {
|
|
1755
|
+
lidCache: {
|
|
1756
|
+
size: lidStats?.keys || 0,
|
|
1757
|
+
maxSize: lidStats?.max || config.cache.lidCache.maxSize || 0,
|
|
1758
|
+
ttl: config.cache.lidCache.ttl
|
|
1759
|
+
},
|
|
1760
|
+
jidCache: {
|
|
1761
|
+
size: jidStats?.keys || 0,
|
|
1762
|
+
maxSize: jidStats?.max || config.cache.jidCache.maxSize || 0,
|
|
1763
|
+
ttl: config.cache.jidCache.ttl
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
const config = performance_config_1.getPerformanceConfig();
|
|
1768
|
+
return {
|
|
1769
|
+
lidCache: { size: 0, maxSize: 0, ttl: config.cache.lidCache.ttl },
|
|
1770
|
+
jidCache: { size: 0, maxSize: 0, ttl: config.cache.jidCache.ttl }
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
exports.getCacheStats = getCacheStats;
|
|
1775
|
+
/**
|
|
1776
|
+
* Clear all caches (useful for testing or memory management)
|
|
1777
|
+
*/
|
|
1778
|
+
const clearCache = () => {
|
|
1779
|
+
try {
|
|
1780
|
+
const cacheManager = cache_manager_1.default;
|
|
1781
|
+
if (cacheManager && cacheManager.caches) {
|
|
1782
|
+
Object.keys(cacheManager.caches).forEach(cacheName => {
|
|
1783
|
+
const cache = cacheManager.caches[cacheName];
|
|
1784
|
+
if (cache && typeof cache.flushAll === 'function') {
|
|
1785
|
+
cache.flushAll();
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
} catch (error) {
|
|
1790
|
+
// Silently fail if cache manager is not available
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
exports.clearCache = clearCache;
|