@alannxd/baileys 6.2.7 → 6.2.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/README.md +440 -203
- package/lib/Defaults/index.js +2 -2
- package/lib/Socket/Client/websocket.js +35 -5
- package/lib/Socket/chats.js +0 -5
- package/lib/Socket/index.js +1 -9
- package/lib/Socket/luxu.js +4 -5
- package/lib/Socket/messages-recv.js +1 -1
- package/lib/Socket/messages-send.js +56 -114
- package/lib/Socket/mex.js +38 -51
- package/lib/Socket/newsletter.js +276 -745
- package/lib/Socket/socket.js +27 -161
- package/lib/Socket/username.js +204 -206
- package/lib/Store/make-in-memory-store.js +1 -47
- package/lib/Types/Mex.js +2 -76
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/generics.js +2 -2
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/messages-media.js +0 -82
- package/lib/Utils/messages.js +2 -136
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -52
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +52 -55
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -37
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -12
- package/lib/WAUSync/USyncQuery.js +96 -149
- package/lib/WAUSync/USyncUser.js +29 -54
- package/lib/WAUSync/index.js +4 -3
- package/lib/index.js +5 -2
- package/package.json +14 -13
- package/lib/Socket/graphql.js +0 -716
- package/lib/Socket/interop.js +0 -463
- package/lib/Socket/message-builder.js +0 -475
- package/lib/Socket/privacy.js +0 -318
- package/lib/Utils/sticker.js +0 -133
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -43
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -58
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -28
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
package/lib/Defaults/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { proto } from '../../WAProto/index.js';
|
|
|
2
2
|
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
3
|
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
4
|
import logger from '../Utils/logger.js';
|
|
5
|
-
const version = [2, 3000,
|
|
5
|
+
const version = [2, 3000, 1035194821];
|
|
6
6
|
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
7
|
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
8
8
|
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
@@ -51,7 +51,7 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
51
51
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
52
52
|
connectTimeoutMs: 20000,
|
|
53
53
|
keepAliveIntervalMs: 30000,
|
|
54
|
-
logger: logger.child({ class: '
|
|
54
|
+
logger: logger.child({ class: 'poucode' }),
|
|
55
55
|
emitOwnEvents: true,
|
|
56
56
|
defaultQueryTimeoutMs: 60000,
|
|
57
57
|
customUploadHosts: [],
|
|
@@ -22,14 +22,44 @@ export class WebSocketClient extends AbstractSocketClient {
|
|
|
22
22
|
if (this.socket) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
const headers = {
|
|
27
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
|
28
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
29
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
30
|
+
'Accept': '*/*',
|
|
31
|
+
'DNT': '1',
|
|
32
|
+
'Pragma': 'no-cache',
|
|
33
|
+
'Cache-Control': 'no-cache',
|
|
34
|
+
'Sec-Fetch-Dest': 'empty',
|
|
35
|
+
'Sec-Fetch-Mode': 'cors',
|
|
36
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
37
|
+
'Sec-GPC': '1',
|
|
38
|
+
...this.config.options?.headers
|
|
39
|
+
};
|
|
40
|
+
|
|
25
41
|
this.socket = new WebSocket(this.url, {
|
|
26
42
|
origin: DEFAULT_ORIGIN,
|
|
27
|
-
headers:
|
|
28
|
-
handshakeTimeout: this.config.connectTimeoutMs,
|
|
29
|
-
timeout: this.config.connectTimeoutMs,
|
|
30
|
-
agent: this.config.agent
|
|
43
|
+
headers: headers,
|
|
44
|
+
handshakeTimeout: this.config.connectTimeoutMs || 30000,
|
|
45
|
+
timeout: this.config.connectTimeoutMs || 30000,
|
|
46
|
+
agent: this.config.agent,
|
|
47
|
+
perMessageDeflate: false,
|
|
48
|
+
maxPayload: 100 * 1024 * 1024,
|
|
49
|
+
rejectUnauthorized: false,
|
|
50
|
+
keepalive: true,
|
|
51
|
+
keepaliveInterval: 25000
|
|
31
52
|
});
|
|
53
|
+
|
|
32
54
|
this.socket.setMaxListeners(0);
|
|
55
|
+
|
|
56
|
+
this.socket.on('error', (error) => {
|
|
57
|
+
const errorCode = error?.code;
|
|
58
|
+
if (errorCode === 'ECONNREFUSED' || errorCode === 'ENOTFOUND') {
|
|
59
|
+
console.warn('WebSocket connection refused, retrying...');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
33
63
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
34
64
|
for (const event of events) {
|
|
35
65
|
this.socket?.on(event, (...args) => this.emit(event, ...args));
|
|
@@ -51,4 +81,4 @@ export class WebSocketClient extends AbstractSocketClient {
|
|
|
51
81
|
return Boolean(this.socket);
|
|
52
82
|
}
|
|
53
83
|
}
|
|
54
|
-
//# sourceMappingURL=websocket.js.map
|
|
84
|
+
//# sourceMappingURL=websocket.js.map
|
package/lib/Socket/chats.js
CHANGED
|
@@ -397,11 +397,6 @@ export const makeChatsSocket = (config) => {
|
|
|
397
397
|
return {
|
|
398
398
|
onMutation(mutation) {
|
|
399
399
|
processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
400
|
-
const nctSalt = mutation?.syncAction?.value?.nctSaltSyncAction?.salt;
|
|
401
|
-
if (nctSalt?.length) {
|
|
402
|
-
authState.keys.set({ 'nct-salt': { default: Buffer.from(nctSalt) } })
|
|
403
|
-
.catch(err => logger?.debug({ err: err?.message }, 'failed to store nct salt'));
|
|
404
|
-
}
|
|
405
400
|
}
|
|
406
401
|
};
|
|
407
402
|
};
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
2
|
import { makeCommunitiesSocket } from './communities.js';
|
|
3
|
-
import { makeInteropSocket } from './interop.js'
|
|
4
|
-
import { makePrivacySocket } from './privacy.js'
|
|
5
|
-
import { makeGraphQLSocket } from './graphql.js'
|
|
6
|
-
import { makeMessageBuilderSocket } from './message-builder.js'
|
|
7
3
|
// export the last socket layer
|
|
8
4
|
const makeWASocket = (config) => {
|
|
9
5
|
const newConfig = {
|
|
10
6
|
...DEFAULT_CONNECTION_CONFIG,
|
|
11
7
|
...config
|
|
12
8
|
};
|
|
13
|
-
|
|
14
|
-
const dua = makeInteropSocket(satu);
|
|
15
|
-
const tiga = makePrivacySocket(dua);
|
|
16
|
-
const empat = makeGraphQLSocket(tiga);
|
|
17
|
-
return makeMessageBuilderSocket(empat);
|
|
9
|
+
return makeCommunitiesSocket(newConfig);
|
|
18
10
|
};
|
|
19
11
|
export default makeWASocket;
|
|
20
12
|
//# sourceMappingURL=index.js.map
|
package/lib/Socket/luxu.js
CHANGED
|
@@ -177,7 +177,6 @@ export default class imup {
|
|
|
177
177
|
newsletterJid: "0@newsletter",
|
|
178
178
|
serverMessageId: 1,
|
|
179
179
|
newsletterName: `WhatsApp`,
|
|
180
|
-
contentType: 1,
|
|
181
180
|
timestamp: new Date().toISOString(),
|
|
182
181
|
senderName: "AlannXD",
|
|
183
182
|
contentType: "UPDATE_CARD",
|
|
@@ -306,7 +305,7 @@ export default class imup {
|
|
|
306
305
|
|
|
307
306
|
const Haha = await this.utils.generateWAMessageFromContent(jid, {
|
|
308
307
|
orderMessage: {
|
|
309
|
-
orderId: "
|
|
308
|
+
orderId: orderData.orderId || ("ALANNXD" + Date.now()),
|
|
310
309
|
thumbnail: orderData.thumbnail || null,
|
|
311
310
|
itemCount: orderData.itemCount || 0,
|
|
312
311
|
status: "ACCEPTED",
|
|
@@ -314,7 +313,7 @@ export default class imup {
|
|
|
314
313
|
message: orderData.message,
|
|
315
314
|
orderTitle: orderData.orderTitle,
|
|
316
315
|
sellerJid: "0@whatsapp.net",
|
|
317
|
-
token: "ALANNXD_EXAMPLE_TOKEN",
|
|
316
|
+
token: orderData.token || "ALANNXD_EXAMPLE_TOKEN",
|
|
318
317
|
totalAmount1000: orderData.totalAmount1000 || 0,
|
|
319
318
|
totalCurrencyCode: orderData.totalCurrencyCode || "IDR",
|
|
320
319
|
messageVersion: 2
|
|
@@ -362,7 +361,7 @@ export default class imup {
|
|
|
362
361
|
throw new Error('group required!')
|
|
363
362
|
}
|
|
364
363
|
|
|
365
|
-
const msg = this.utils.generateWAMessageFromContent(jid, {
|
|
364
|
+
const msg = await this.utils.generateWAMessageFromContent(jid, {
|
|
366
365
|
protocolMessage: {
|
|
367
366
|
type: "GROUP_MEMBER_LABEL_CHANGE",
|
|
368
367
|
memberLabel: {
|
|
@@ -384,4 +383,4 @@ export default class imup {
|
|
|
384
383
|
]
|
|
385
384
|
})
|
|
386
385
|
}
|
|
387
|
-
}
|
|
386
|
+
}
|
|
@@ -1280,7 +1280,7 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1280
1280
|
msgRelayOpts.useUserDevicesCache = false;
|
|
1281
1281
|
}
|
|
1282
1282
|
else {
|
|
1283
|
-
msgRelayOpts.
|
|
1283
|
+
msgRelayOpts.participant = {
|
|
1284
1284
|
jid: participant,
|
|
1285
1285
|
count: +retryNode.attrs.count
|
|
1286
1286
|
};
|
|
@@ -12,7 +12,7 @@ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
|
12
12
|
import { makeUsernameSocket } from './username.js';
|
|
13
13
|
import imup from './luxu.js';
|
|
14
14
|
import * as Utils_1 from '../Utils/index.js';
|
|
15
|
-
import { randomBytes
|
|
15
|
+
import { randomBytes } from 'crypto';
|
|
16
16
|
export const makeMessagesSocket = (config) => {
|
|
17
17
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount, aiLabel } = config;
|
|
18
18
|
const sock = makeUsernameSocket(config);
|
|
@@ -433,22 +433,18 @@ export const makeMessagesSocket = (config) => {
|
|
|
433
433
|
message,
|
|
434
434
|
{
|
|
435
435
|
messageId: msgId,
|
|
436
|
-
participant,
|
|
437
|
-
|
|
438
|
-
isSecret,
|
|
439
|
-
protected: protectedSend,
|
|
436
|
+
participant = false,
|
|
437
|
+
Alanself = false,
|
|
440
438
|
additionalAttributes,
|
|
441
439
|
additionalNodes,
|
|
442
440
|
useUserDevicesCache,
|
|
443
441
|
useCachedGroupMetadata,
|
|
444
|
-
statusJidList
|
|
445
|
-
cstoken = true
|
|
442
|
+
statusJidList
|
|
446
443
|
}
|
|
447
444
|
) => {
|
|
448
445
|
const meId = authState.creds.me.id
|
|
449
446
|
const meLid = authState.creds.me?.lid
|
|
450
|
-
const isRetryResend = Boolean(
|
|
451
|
-
const isRecipientOnly = Boolean(participant?.jid)
|
|
447
|
+
const isRetryResend = Boolean(participant?.jid)
|
|
452
448
|
let shouldIncludeDeviceIdentity = isRetryResend
|
|
453
449
|
const statusJid = 'status@broadcast'
|
|
454
450
|
const { user, server } = jidDecode(jid)
|
|
@@ -473,16 +469,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
473
469
|
messageContextInfo: message.messageContextInfo
|
|
474
470
|
}
|
|
475
471
|
const extraAttrs = {}
|
|
476
|
-
if (isRetryResend) {
|
|
477
|
-
if (!isGroup &&!isStatus) {
|
|
478
|
-
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
|
|
479
|
-
}
|
|
480
|
-
const { user: retryUser, device: retryDevice } = jidDecode(retryParticipants.jid)
|
|
481
|
-
devices.push({ user: retryUser, device: retryDevice, jid: retryParticipants.jid })
|
|
482
|
-
}
|
|
483
|
-
if ((isRecipientOnly || isSecret || protectedSend) &&!isGroup &&!isStatus) {
|
|
484
|
-
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
|
|
485
|
-
}
|
|
486
472
|
const regexGroupOld = /^(\d{1,15})-(\d+)@g\.us$/
|
|
487
473
|
const messages = normalizeMessageContent(message)
|
|
488
474
|
const buttonType = getButtonType(messages)
|
|
@@ -524,7 +510,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
524
510
|
return groupData
|
|
525
511
|
})(),
|
|
526
512
|
(async () => {
|
|
527
|
-
if (!
|
|
513
|
+
if (!participant &&!isStatus) {
|
|
528
514
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
529
515
|
return result[jid] || {}
|
|
530
516
|
}
|
|
@@ -664,7 +650,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
664
650
|
for (const device of devices) {
|
|
665
651
|
const deviceJid = device.jid
|
|
666
652
|
const hasKey =!!senderKeyMap[deviceJid]
|
|
667
|
-
if (!hasKey ||!!
|
|
653
|
+
if (!hasKey ||!!participant &&!isHostedLidUser(deviceJid) &&!isHostedPnUser(deviceJid) && device.device!== 99) {
|
|
668
654
|
senderKeyRecipients.push(deviceJid)
|
|
669
655
|
senderKeyMap[deviceJid] = true
|
|
670
656
|
}
|
|
@@ -693,7 +679,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
693
679
|
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation')
|
|
694
680
|
}
|
|
695
681
|
const { user: ownUser } = jidDecode(ownId)
|
|
696
|
-
if (!
|
|
682
|
+
if (!participant) {
|
|
697
683
|
const patchedForReporting = await patchMessageBeforeSending(message, [jid])
|
|
698
684
|
reportingMessage = Array.isArray(patchedForReporting)
|
|
699
685
|
? patchedForReporting.find(item => item.recipientJid === jid) || patchedForReporting[0]
|
|
@@ -723,33 +709,38 @@ export const makeMessagesSocket = (config) => {
|
|
|
723
709
|
const { user: mePnUser } = jidDecode(meId)
|
|
724
710
|
const { user: meLidUser } = meLid? jidDecode(meLid) : { user: null }
|
|
725
711
|
for (const { user, jid } of devices) {
|
|
726
|
-
/**
|
|
712
|
+
/** Alanself: opsi untuk skip sync pesan ke device lain milik akun sendiri (private chat) */
|
|
727
713
|
const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
|
|
728
714
|
if (isExactSenderDevice) {
|
|
729
715
|
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)')
|
|
730
716
|
continue
|
|
731
717
|
}
|
|
732
718
|
const isMe = user === mePnUser || user === meLidUser
|
|
733
|
-
const hasDevice = jid.includes(':')
|
|
734
719
|
let ptcp = false
|
|
735
|
-
if (
|
|
720
|
+
if (Alanself) {
|
|
736
721
|
if (!isJidGroup(jid) && !isStatus) {
|
|
737
722
|
if (!(!isMe)) ptcp = true
|
|
738
723
|
} else {
|
|
739
724
|
ptcp = false
|
|
740
725
|
}
|
|
741
726
|
}
|
|
742
|
-
if (ptcp)
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
otherRecipients.push(jid)
|
|
727
|
+
if (!ptcp) {
|
|
728
|
+
if (isMe) {
|
|
729
|
+
meRecipients.push(jid)
|
|
730
|
+
} else {
|
|
731
|
+
otherRecipients.push(jid)
|
|
732
|
+
}
|
|
733
|
+
allRecipients.push(jid)
|
|
750
734
|
}
|
|
751
|
-
allRecipients.push(jid)
|
|
752
735
|
}
|
|
736
|
+
// Fix: detect silent delivery failure — if the destination is genuinely
|
|
737
|
+
// someone else (not our own number) and device resolution produced zero
|
|
738
|
+
// recipient devices for them, don't proceed as if the send succeeded.
|
|
739
|
+
const isSelfChatDestination = user === mePnUser || user === meLidUser
|
|
740
|
+
if (!isRetryResend && !isSelfChatDestination && otherRecipients.length === 0) {
|
|
741
|
+
logger.warn({ jid, deviceCount: devices.length, Alanself }, 'relayMessage: no recipient devices resolved for the other party; aborting to avoid a silent no-op send')
|
|
742
|
+
throw new Boom('No devices resolved for recipient — message was not delivered to the other party', { statusCode: 421, data: { jid } })
|
|
743
|
+
}
|
|
753
744
|
await assertSessions(allRecipients)
|
|
754
745
|
const [
|
|
755
746
|
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
|
|
@@ -765,38 +756,18 @@ export const makeMessagesSocket = (config) => {
|
|
|
765
756
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
|
|
766
757
|
}
|
|
767
758
|
if (isRetryResend) {
|
|
768
|
-
const isParticipantLid =
|
|
769
|
-
const isMe = areJidsSameUser(
|
|
770
|
-
let messageToSend = message
|
|
771
|
-
if (isGroupOrStatus) {
|
|
772
|
-
let groupSenderIdentity
|
|
773
|
-
try {
|
|
774
|
-
if (meLid && await signalRepository.hasSenderKey({ group: destinationJid, meId: meLid })) {
|
|
775
|
-
groupSenderIdentity = meLid
|
|
776
|
-
} else if (await signalRepository.hasSenderKey({ group: destinationJid, meId })) {
|
|
777
|
-
groupSenderIdentity = meId
|
|
778
|
-
}
|
|
779
|
-
if (groupSenderIdentity) {
|
|
780
|
-
const skdm = await signalRepository.getSenderKeyDistributionMessage({ group: destinationJid, meId: groupSenderIdentity })
|
|
781
|
-
messageToSend = {
|
|
782
|
-
...message,
|
|
783
|
-
senderKeyDistributionMessage: { groupId: destinationJid, axolotlSenderKeyDistributionMessage: skdm }
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
} catch (err) {
|
|
787
|
-
logger.warn({ err, jid: destinationJid }, 'failed to build SKDM for retry, sending without it')
|
|
788
|
-
}
|
|
789
|
-
}
|
|
759
|
+
const isParticipantLid = jidDecode(participant.jid).server === 'lid'
|
|
760
|
+
const isMe = areJidsSameUser(participant.jid, isParticipantLid? meLid : meId)
|
|
790
761
|
const encodedMessageToSend = isMe
|
|
791
|
-
? encodeWAMessage({ deviceSentMessage: { destinationJid, message
|
|
792
|
-
: encodeWAMessage(
|
|
762
|
+
? encodeWAMessage({ deviceSentMessage: { destinationJid, message } })
|
|
763
|
+
: encodeWAMessage(message)
|
|
793
764
|
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
794
765
|
data: encodedMessageToSend,
|
|
795
|
-
jid:
|
|
766
|
+
jid: participant.jid
|
|
796
767
|
})
|
|
797
768
|
binaryNodeContent.push({
|
|
798
769
|
tag: 'enc',
|
|
799
|
-
attrs: { v: '2', type, count: (
|
|
770
|
+
attrs: { v: '2', type, count: (participant.count?? 0).toString() },
|
|
800
771
|
content: encryptedContent
|
|
801
772
|
})
|
|
802
773
|
}
|
|
@@ -816,17 +787,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
816
787
|
tag: 'message',
|
|
817
788
|
attrs: { id: msgId, to: destinationJid, type: getMessageType(message),...(additionalAttributes || {}) },
|
|
818
789
|
content: binaryNodeContent
|
|
819
|
-
}
|
|
820
|
-
if (isRetryResend) {
|
|
821
|
-
if (isJidGroup(destinationJid)) {
|
|
822
|
-
stanza.attrs.to = destinationJid
|
|
823
|
-
stanza.attrs.participant = retryParticipants.jid
|
|
824
|
-
} else if (areJidsSameUser(retryParticipants.jid, meId)) {
|
|
825
|
-
stanza.attrs.to = retryParticipants.jid
|
|
826
|
-
stanza.attrs.recipient = destinationJid
|
|
827
|
-
} else {
|
|
828
|
-
stanza.attrs.to = retryParticipants.jid
|
|
829
|
-
}
|
|
830
790
|
}
|
|
831
791
|
if (shouldIncludeDeviceIdentity) {
|
|
832
792
|
stanza.content.push({ tag: 'device-identity', attrs: {}, content: encodeSignedDeviceIdentity(authState.creds.account, true) })
|
|
@@ -849,7 +809,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
849
809
|
if (!isNewsletter &&!isRetryResend && reportingMessage?.messageContextInfo?.messageSecret && shouldIncludeReportingToken(reportingMessage)) {
|
|
850
810
|
try {
|
|
851
811
|
const encoded = encodeWAMessage(reportingMessage)
|
|
852
|
-
const reportingKey = { id: msgId, fromMe: true, remoteJid: destinationJid, participant:
|
|
812
|
+
const reportingKey = { id: msgId, fromMe: true, remoteJid: destinationJid, participant: participant?.jid }
|
|
853
813
|
const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey)
|
|
854
814
|
if (reportingNode) {
|
|
855
815
|
stanza.content.push(reportingNode)
|
|
@@ -895,26 +855,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
895
855
|
}
|
|
896
856
|
if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
|
|
897
857
|
stanza.content.push({ tag: 'tctoken', attrs: {}, content: tcTokenBuffer })
|
|
898
|
-
}
|
|
899
|
-
if (cstoken && is1on1Send &&!tcTokenBuffer?.length) {
|
|
900
|
-
try {
|
|
901
|
-
const lidJid = await resolveTcTokenJid(destinationJid, getLIDForPN)
|
|
902
|
-
if (isLidUser(lidJid)) {
|
|
903
|
-
const saltRes = await authState.keys.get('nct-salt', ['default'])
|
|
904
|
-
const nctSalt = saltRes?.default
|
|
905
|
-
if (nctSalt?.length) {
|
|
906
|
-
const cs = createHmac('sha256', Buffer.from(nctSalt)).update(Buffer.from(lidJid, 'utf8')).digest()
|
|
907
|
-
stanza.content.push({ tag: 'cstoken', attrs: {}, content: cs })
|
|
908
|
-
logger.debug({ jid: destinationJid, lid: lidJid }, 'attached cstoken (nct fallback)')
|
|
909
|
-
} else {
|
|
910
|
-
logger.debug({ jid: destinationJid }, 'cstoken requested but no nct salt stored yet')
|
|
911
|
-
}
|
|
912
|
-
} else {
|
|
913
|
-
logger.debug({ jid: destinationJid }, 'cstoken requested but recipient has no LID')
|
|
914
|
-
}
|
|
915
|
-
} catch (err) {
|
|
916
|
-
logger.debug({ jid: destinationJid, err: err?.message }, 'cstoken attach failed')
|
|
917
|
-
}
|
|
918
858
|
}
|
|
919
859
|
if (additionalNodes && additionalNodes.length > 0 &&!didPushAdditional) {
|
|
920
860
|
stanza.content.push(...additionalNodes)
|
|
@@ -947,7 +887,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
947
887
|
.catch(err => logger.debug({ jid: destinationJid, err: err?.message }, 'fire-and-forget tctoken issuance failed'))
|
|
948
888
|
.finally(() => inFlightTcTokenIssuance.delete(tcTokenJid))
|
|
949
889
|
}
|
|
950
|
-
if (messageRetryManager &&!
|
|
890
|
+
if (messageRetryManager &&!participant) {
|
|
951
891
|
messageRetryManager.addRecentMessage(destinationJid, msgId, message)
|
|
952
892
|
}
|
|
953
893
|
if (isInterop &&!isRetryResend) {
|
|
@@ -1004,9 +944,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
1004
944
|
else if (message.stickerMessage) {
|
|
1005
945
|
return 'sticker';
|
|
1006
946
|
}
|
|
1007
|
-
else if (message.stickerPackMessage) {
|
|
1008
|
-
return 'sticker';
|
|
1009
|
-
}
|
|
1010
947
|
else if (message.listMessage) {
|
|
1011
948
|
return 'list';
|
|
1012
949
|
}
|
|
@@ -1286,22 +1223,22 @@ export const makeMessagesSocket = (config) => {
|
|
|
1286
1223
|
},
|
|
1287
1224
|
sendTable: async (jid, title, headers, rows, quoted, options = {}) => {
|
|
1288
1225
|
const { message, messageId } = Utils_1.generateTableContent(title, headers, rows, quoted, options)
|
|
1289
|
-
await relayMessage(jid, message, { messageId })
|
|
1226
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1290
1227
|
return { message, messageId }
|
|
1291
1228
|
},
|
|
1292
1229
|
sendList: async (jid, title, items, quoted, options = {}) => {
|
|
1293
1230
|
const { message, messageId } = Utils_1.generateListContent(title, items, quoted, options)
|
|
1294
|
-
await relayMessage(jid, message, { messageId })
|
|
1231
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1295
1232
|
return { message, messageId }
|
|
1296
1233
|
},
|
|
1297
1234
|
sendCodeBlock: async (jid, code, quoted, options = {}) => {
|
|
1298
1235
|
const { message, messageId } = Utils_1.generateCodeBlockContent(code, quoted, options)
|
|
1299
|
-
await relayMessage(jid, message, { messageId })
|
|
1236
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1300
1237
|
return { message, messageId }
|
|
1301
1238
|
},
|
|
1302
1239
|
sendLatex: async (jid, quoted, options) => {
|
|
1303
1240
|
const { message, messageId } = Utils_1.generateLatexContent(quoted, options)
|
|
1304
|
-
await relayMessage(jid, message, { messageId })
|
|
1241
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1305
1242
|
return { message, messageId }
|
|
1306
1243
|
},
|
|
1307
1244
|
sendLatexImage: async (jid, quoted, options, renderLatexToPng, uploadFn) => {
|
|
@@ -1311,7 +1248,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1311
1248
|
uploadFn,
|
|
1312
1249
|
renderLatexToPng
|
|
1313
1250
|
)
|
|
1314
|
-
await relayMessage(jid, message, { messageId })
|
|
1251
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1315
1252
|
return { message, messageId }
|
|
1316
1253
|
},
|
|
1317
1254
|
sendLatexInlineImage: async (jid, quoted, options, renderLatexToPng, uploadFn) => {
|
|
@@ -1321,24 +1258,24 @@ export const makeMessagesSocket = (config) => {
|
|
|
1321
1258
|
uploadFn,
|
|
1322
1259
|
renderLatexToPng
|
|
1323
1260
|
)
|
|
1324
|
-
await relayMessage(jid, message, { messageId })
|
|
1261
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1325
1262
|
return { message, messageId }
|
|
1326
1263
|
},
|
|
1327
1264
|
captureUnifiedResponse: Utils_1.captureUnifiedResponse,
|
|
1328
1265
|
sendUnifiedResponse: async (jid, quoted, captured) => {
|
|
1329
1266
|
const { message, messageId } = Utils_1.generateUnifiedResponseContent(quoted, captured)
|
|
1330
|
-
await relayMessage(jid, message, { messageId })
|
|
1267
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1331
1268
|
return { message, messageId }
|
|
1332
1269
|
},
|
|
1333
1270
|
sendRichMessage: async (jid, submessages, quoted, options = {}) => {
|
|
1334
1271
|
const { message, messageId } = Utils_1.generateRichMessageContent(submessages, quoted, options)
|
|
1335
|
-
await relayMessage(jid, message, { messageId })
|
|
1272
|
+
await relayMessage(jid, message, { messageId, Alanself: options.Alanself })
|
|
1336
1273
|
return { message, messageId }
|
|
1337
1274
|
},
|
|
1338
1275
|
sendMessage: async (jid, content, options = {}) => {
|
|
1339
1276
|
const userJid = authState.creds.me.id;
|
|
1340
1277
|
const luki = new imup(Utils_1, waUploadToServer, relayMessage)
|
|
1341
|
-
const { quoted, participant = false
|
|
1278
|
+
const { quoted, participant = false } = options;
|
|
1342
1279
|
const messageType = luki.detectType(content);
|
|
1343
1280
|
if (typeof content === 'object' &&
|
|
1344
1281
|
'disappearingMessagesInChat' in content &&
|
|
@@ -1358,13 +1295,15 @@ export const makeMessagesSocket = (config) => {
|
|
|
1358
1295
|
case 'PAYMENT':
|
|
1359
1296
|
const paymentContent = await luki.handlePayment(content, quoted);
|
|
1360
1297
|
return await relayMessage(jid, paymentContent, {
|
|
1361
|
-
messageId: Utils_1.generateMessageID()
|
|
1298
|
+
messageId: Utils_1.generateMessageID(),
|
|
1299
|
+
Alanself: options.Alanself
|
|
1362
1300
|
});
|
|
1363
1301
|
case 'PRODUCT':
|
|
1364
1302
|
const productContent = await luki.handleProduct(content, jid, quoted);
|
|
1365
1303
|
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1366
1304
|
return await relayMessage(jid, productMsg.message, {
|
|
1367
1305
|
messageId: productMsg.key.id,
|
|
1306
|
+
Alanself: options.Alanself
|
|
1368
1307
|
});
|
|
1369
1308
|
|
|
1370
1309
|
case 'ALBUM':
|
|
@@ -1447,10 +1386,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
1447
1386
|
additionalAttributes,
|
|
1448
1387
|
statusJidList: options.statusJidList,
|
|
1449
1388
|
additionalNodes: aiLabel ? additionalNodes : options.additionalNodes,
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
protected: protectedSend,
|
|
1453
|
-
...(cstoken !== undefined ? { cstoken } : {})
|
|
1389
|
+
participant,
|
|
1390
|
+
Alanself: options.Alanself
|
|
1454
1391
|
});
|
|
1455
1392
|
if (config.emitOwnEvents) {
|
|
1456
1393
|
process.nextTick(async () => {
|
|
@@ -1475,10 +1412,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
1475
1412
|
const messages = Utils_1.normalizeMessageContent(message);
|
|
1476
1413
|
const groupData = cachedGroupMetadata? await cachedGroupMetadata(jid) : await groupMetadata(jid);
|
|
1477
1414
|
const isLid = groupData.addressingMode === "lid";
|
|
1478
|
-
const
|
|
1415
|
+
const adminJids = groupData.participants.filter((x) => x.admin !== null).map((y) => y.id)
|
|
1479
1416
|
let participantJids = groupData.participants.map(z => z.id);
|
|
1480
1417
|
if (onlyMember) {
|
|
1481
|
-
|
|
1418
|
+
// Fix: array selalu truthy di JS meski kosong ([] ? true).
|
|
1419
|
+
// Cek .length supaya fallback ke semua member beneran jalan
|
|
1420
|
+
// kalau data admin kosong, bukan diam-diam kirim ke 0 orang.
|
|
1421
|
+
participantJids = adminJids.length ? adminJids : participantJids;
|
|
1482
1422
|
}
|
|
1483
1423
|
logger.info(`Sending message to ${participantJids.length} members from ${jid}`);
|
|
1484
1424
|
for (let i = 0; i < participantJids.length; i++) {
|
|
@@ -1491,7 +1431,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
1491
1431
|
quoted
|
|
1492
1432
|
})
|
|
1493
1433
|
await relayMessage(jid, fullMsg.message, {
|
|
1494
|
-
messageId: fullMsg.key.id
|
|
1434
|
+
messageId: fullMsg.key.id,
|
|
1435
|
+
useUserDevicesCache,
|
|
1436
|
+
Alanself: options.Alanself
|
|
1495
1437
|
});
|
|
1496
1438
|
logger.debug(`Message successfully sent to ${jid}`);
|
|
1497
1439
|
if (delayMs && i < participantJids.length - 1) {
|
|
@@ -1508,4 +1450,4 @@ export const makeMessagesSocket = (config) => {
|
|
|
1508
1450
|
}
|
|
1509
1451
|
};
|
|
1510
1452
|
};
|
|
1511
|
-
//# sourceMappingURL=messages-send.js.map
|
|
1453
|
+
//# sourceMappingURL=messages-send.js.map
|
package/lib/Socket/mex.js
CHANGED
|
@@ -1,54 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
1
|
+
import * as boom_1 from '@hapi/boom'
|
|
2
|
+
import * as WABinary_1 from '../WABinary/index.js'
|
|
3
|
+
export const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
})
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
45
|
-
if (typeof response !== 'undefined') {
|
|
46
|
-
return response
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
51
|
-
? dataPath.substring(5).replace(/_/g, '')
|
|
52
|
-
: dataPath?.replace(/_/g, '')
|
|
53
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
23
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString())
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ')
|
|
28
|
+
const firstError = data.errors[0]
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
30
|
+
throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ')
|
|
40
|
+
throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
54
41
|
}
|