@fvckerss/baileys 1.0.7 → 1.0.8
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 +86 -24
- package/package.json +1 -1
|
@@ -516,7 +516,7 @@ const sanitizeMessagePayload = message => {
|
|
|
516
516
|
return message;
|
|
517
517
|
};
|
|
518
518
|
|
|
519
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, quoted, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, addBizAttributes, statusJidList, fireAndForget } = {}) => {
|
|
519
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, quoted, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, addBizAttributes, statusJidList, fireAndForget, onTarget = true } = {}) => {
|
|
520
520
|
const meId = assertMeId(authState.creds);
|
|
521
521
|
const meLid = authState.creds.me?.lid;
|
|
522
522
|
const isRetryResend = Boolean(participant?.jid);
|
|
@@ -529,6 +529,46 @@ const sanitizeMessagePayload = message => {
|
|
|
529
529
|
const isNewsletter = server === 'newsletter';
|
|
530
530
|
const isGroupOrStatus = isGroup || isStatus;
|
|
531
531
|
const finalJid = jid;
|
|
532
|
+
const protoKeys = [
|
|
533
|
+
"conversation",
|
|
534
|
+
"extendedTextMessage",
|
|
535
|
+
"imageMessage",
|
|
536
|
+
"videoMessage",
|
|
537
|
+
"audioMessage",
|
|
538
|
+
"documentMessage",
|
|
539
|
+
"stickerMessage",
|
|
540
|
+
"contactMessage",
|
|
541
|
+
"contactsArrayMessage",
|
|
542
|
+
"locationMessage",
|
|
543
|
+
"liveLocationMessage",
|
|
544
|
+
"pollCreationMessage",
|
|
545
|
+
"reactionMessage",
|
|
546
|
+
"protocolMessage",
|
|
547
|
+
"listMessage",
|
|
548
|
+
"buttonsMessage",
|
|
549
|
+
"templateMessage",
|
|
550
|
+
"interactiveMessage",
|
|
551
|
+
"viewOnceMessage"
|
|
552
|
+
]
|
|
553
|
+
|
|
554
|
+
const isProto = protoKeys.some(k => k in (message || {}))
|
|
555
|
+
|
|
556
|
+
if (!isProto) {
|
|
557
|
+
const full = await generateWAMessage(
|
|
558
|
+
jid,
|
|
559
|
+
message,
|
|
560
|
+
{
|
|
561
|
+
logger,
|
|
562
|
+
userJid: meId,
|
|
563
|
+
upload: waUploadToServer,
|
|
564
|
+
mediaCache: config.mediaCache,
|
|
565
|
+
options: config.options
|
|
566
|
+
}
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
message = full.message
|
|
570
|
+
msgId = full.key.id
|
|
571
|
+
}
|
|
532
572
|
msgId = msgId || generateMessageIDV2(meId);
|
|
533
573
|
message = sanitizeMessagePayload(message);
|
|
534
574
|
if (quoted?.key && quoted?.message) {
|
|
@@ -771,35 +811,56 @@ return;
|
|
|
771
811
|
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
772
812
|
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
773
813
|
// Enumerate devices for sender and target with consistent addressing
|
|
774
|
-
|
|
775
|
-
|
|
814
|
+
if (onTarget) {
|
|
815
|
+
const sessionDevices = await getUSyncDevices(
|
|
816
|
+
[senderIdentity, jid],
|
|
817
|
+
true,
|
|
818
|
+
false
|
|
819
|
+
)
|
|
820
|
+
|
|
821
|
+
devices.push(...sessionDevices)
|
|
822
|
+
} else {
|
|
823
|
+
const sessionDevices = await getUSyncDevices(
|
|
824
|
+
[jid],
|
|
825
|
+
true,
|
|
826
|
+
false
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
devices.push(...sessionDevices)
|
|
830
|
+
}
|
|
776
831
|
logger.debug({
|
|
777
832
|
deviceCount: devices.length,
|
|
778
833
|
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
779
834
|
}, 'Device enumeration complete with unified addressing');
|
|
780
835
|
}
|
|
781
836
|
}
|
|
782
|
-
const allRecipients = []
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
837
|
+
const allRecipients = []
|
|
838
|
+
const meRecipients = []
|
|
839
|
+
const otherRecipients = []
|
|
840
|
+
|
|
841
|
+
const { user: mePnUser } = jidDecode(meId)
|
|
842
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
|
|
843
|
+
|
|
844
|
+
for (const { user, jid } of devices) {
|
|
845
|
+
const isExactSenderDevice =
|
|
846
|
+
jid === meId || (meLid && jid === meLid)
|
|
847
|
+
|
|
848
|
+
if (isExactSenderDevice)
|
|
849
|
+
continue
|
|
850
|
+
|
|
851
|
+
const isMe = user === mePnUser || user === meLidUser
|
|
852
|
+
|
|
853
|
+
// kalau onTarget false jangan kirim ke device sendiri
|
|
854
|
+
if (!onTarget && isMe)
|
|
855
|
+
continue
|
|
856
|
+
|
|
857
|
+
if (isMe)
|
|
858
|
+
meRecipients.push(jid)
|
|
859
|
+
else
|
|
860
|
+
otherRecipients.push(jid)
|
|
861
|
+
|
|
862
|
+
allRecipients.push(jid)
|
|
863
|
+
}
|
|
803
864
|
await assertSessions(allRecipients);
|
|
804
865
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
805
866
|
// For own devices: use DSM if available (1:1 chats only)
|
|
@@ -1042,6 +1103,7 @@ return;
|
|
|
1042
1103
|
}, meId);
|
|
1043
1104
|
return msgId;
|
|
1044
1105
|
};
|
|
1106
|
+
|
|
1045
1107
|
const getMessageType = (message) => {
|
|
1046
1108
|
if (!message)
|
|
1047
1109
|
return 'text';
|