@badzz88/baileys 8.4.5 → 8.4.7
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/WAProto/WAProto.proto +671 -194
- package/WAProto/fix-imports.js +85 -86
- package/lib/Defaults/index.js +16 -23
- package/lib/Signal/libsignal.js +1 -2
- package/lib/Socket/luxu.js +5 -6
- package/lib/Socket/messages-send.js +37 -43
- package/lib/Socket/newsletter.js +1 -5
- package/lib/Socket/socket.js +42 -11
- package/lib/Socket/username.js +5 -5
- package/lib/Utils/browser-utils.js +1 -0
- package/lib/Utils/chat-utils.js +1 -2
- package/lib/Utils/generics.js +4 -4
- package/lib/Utils/process-message.js +1 -1
- package/lib/Utils/signal.js +1 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/{Signal/Group/Protocols.js → WAUSync/Protocols/USyncNewsletterProtocol.js} +5 -11
- package/lib/index.js +3 -4
- package/package.json +137 -132
- package/WAProto/fix-import.js +0 -38
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/community.js +0 -392
- package/lib/Socket/dugong.js +0 -637
- package/lib/Socket/registration.js +0 -167
- package/lib/Socket/usync.js +0 -69
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Utils/baileys-event-stream.js +0 -63
package/WAProto/fix-imports.js
CHANGED
|
@@ -1,86 +1,85 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { exit } from 'process';
|
|
3
|
-
|
|
4
|
-
const filePath = './index.js'
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
let content = readFileSync(filePath, 'utf8')
|
|
8
|
-
|
|
9
|
-
content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
|
|
10
|
-
content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
|
|
11
|
-
|
|
12
|
-
const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
|
|
13
|
-
const longToStringHelper =
|
|
14
|
-
'function longToString(value, unsigned) {\n' +
|
|
15
|
-
'\tif (typeof value === "string") {\n' +
|
|
16
|
-
'\t\treturn value;\n' +
|
|
17
|
-
'\t}\n' +
|
|
18
|
-
'\tif (typeof value === "number") {\n' +
|
|
19
|
-
'\t\treturn String(value);\n' +
|
|
20
|
-
'\t}\n' +
|
|
21
|
-
'\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
|
|
22
|
-
'\t// BigInt.toString() is a native C++ operation, much faster than Long\'s pure JS division loops\n' +
|
|
23
|
-
'\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
|
|
24
|
-
'\t\tconst lo = BigInt(value.low >>> 0);\n' +
|
|
25
|
-
'\t\tconst hi = BigInt(value.high >>> 0);\n' +
|
|
26
|
-
'\t\tconst combined = (hi << 32n) | lo;\n' +
|
|
27
|
-
'\t\tif (!unsigned && value.high < 0) {\n' +
|
|
28
|
-
'\t\t\treturn (combined - (1n << 64n)).toString();\n' +
|
|
29
|
-
'\t\t}\n' +
|
|
30
|
-
'\t\treturn combined.toString();\n' +
|
|
31
|
-
'\t}\n' +
|
|
32
|
-
'\treturn String(value);\n' +
|
|
33
|
-
'}\n\n'
|
|
34
|
-
const longToNumberHelper =
|
|
35
|
-
'function longToNumber(value, unsigned) {\n' +
|
|
36
|
-
'\tif (typeof value === "number") {\n' +
|
|
37
|
-
'\t\treturn value;\n' +
|
|
38
|
-
'\t}\n' +
|
|
39
|
-
'\tif (typeof value === "string") {\n' +
|
|
40
|
-
'\t\treturn Number(value);\n' +
|
|
41
|
-
'\t}\n' +
|
|
42
|
-
'\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
|
|
43
|
-
'\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
|
|
44
|
-
'\t\tconst lo = BigInt(value.low >>> 0);\n' +
|
|
45
|
-
'\t\tconst hi = BigInt(value.high >>> 0);\n' +
|
|
46
|
-
'\t\tconst combined = (hi << 32n) | lo;\n' +
|
|
47
|
-
'\t\tif (!unsigned && value.high < 0) {\n' +
|
|
48
|
-
'\t\t\treturn Number(combined - (1n << 64n));\n' +
|
|
49
|
-
'\t\t}\n' +
|
|
50
|
-
'\t\treturn Number(combined);\n' +
|
|
51
|
-
'\t}\n' +
|
|
52
|
-
'\treturn Number(value);\n' +
|
|
53
|
-
'}\n\n'
|
|
54
|
-
|
|
55
|
-
if (!content.includes('function longToString(')) {
|
|
56
|
-
const markerIndex = content.indexOf(marker)
|
|
57
|
-
if (markerIndex === -1) {
|
|
58
|
-
throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
|
|
62
|
-
} else {
|
|
63
|
-
const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
64
|
-
const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
65
|
-
|
|
66
|
-
if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
|
|
67
|
-
throw new Error('Unable to update Long helpers: existing definitions not found')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
content = content.replace(longToStringRegex, longToStringHelper)
|
|
71
|
-
content = content.replace(longToNumberRegex, longToNumberHelper)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
|
|
75
|
-
content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
|
|
76
|
-
const unsignedArg = unsignedFlag ? ', true' : ''
|
|
77
|
-
return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
writeFileSync(filePath, content, 'utf8')
|
|
81
|
-
console.log(`✅ Fixed imports in ${filePath}`)
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(`❌ Error fixing imports: ${error.message}`)
|
|
84
|
-
exit(1)
|
|
85
|
-
}
|
|
86
|
-
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { exit } from 'process';
|
|
3
|
+
|
|
4
|
+
const filePath = './index.js'
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
let content = readFileSync(filePath, 'utf8')
|
|
8
|
+
|
|
9
|
+
content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
|
|
10
|
+
content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
|
|
11
|
+
|
|
12
|
+
const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
|
|
13
|
+
const longToStringHelper =
|
|
14
|
+
'function longToString(value, unsigned) {\n' +
|
|
15
|
+
'\tif (typeof value === "string") {\n' +
|
|
16
|
+
'\t\treturn value;\n' +
|
|
17
|
+
'\t}\n' +
|
|
18
|
+
'\tif (typeof value === "number") {\n' +
|
|
19
|
+
'\t\treturn String(value);\n' +
|
|
20
|
+
'\t}\n' +
|
|
21
|
+
'\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
|
|
22
|
+
'\t// BigInt.toString() is a native C++ operation, much faster than Long\'s pure JS division loops\n' +
|
|
23
|
+
'\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
|
|
24
|
+
'\t\tconst lo = BigInt(value.low >>> 0);\n' +
|
|
25
|
+
'\t\tconst hi = BigInt(value.high >>> 0);\n' +
|
|
26
|
+
'\t\tconst combined = (hi << 32n) | lo;\n' +
|
|
27
|
+
'\t\tif (!unsigned && value.high < 0) {\n' +
|
|
28
|
+
'\t\t\treturn (combined - (1n << 64n)).toString();\n' +
|
|
29
|
+
'\t\t}\n' +
|
|
30
|
+
'\t\treturn combined.toString();\n' +
|
|
31
|
+
'\t}\n' +
|
|
32
|
+
'\treturn String(value);\n' +
|
|
33
|
+
'}\n\n'
|
|
34
|
+
const longToNumberHelper =
|
|
35
|
+
'function longToNumber(value, unsigned) {\n' +
|
|
36
|
+
'\tif (typeof value === "number") {\n' +
|
|
37
|
+
'\t\treturn value;\n' +
|
|
38
|
+
'\t}\n' +
|
|
39
|
+
'\tif (typeof value === "string") {\n' +
|
|
40
|
+
'\t\treturn Number(value);\n' +
|
|
41
|
+
'\t}\n' +
|
|
42
|
+
'\t// Fast path: convert Long {low, high} directly via native BigInt\n' +
|
|
43
|
+
'\tif (value && typeof value.low === "number" && typeof value.high === "number") {\n' +
|
|
44
|
+
'\t\tconst lo = BigInt(value.low >>> 0);\n' +
|
|
45
|
+
'\t\tconst hi = BigInt(value.high >>> 0);\n' +
|
|
46
|
+
'\t\tconst combined = (hi << 32n) | lo;\n' +
|
|
47
|
+
'\t\tif (!unsigned && value.high < 0) {\n' +
|
|
48
|
+
'\t\t\treturn Number(combined - (1n << 64n));\n' +
|
|
49
|
+
'\t\t}\n' +
|
|
50
|
+
'\t\treturn Number(combined);\n' +
|
|
51
|
+
'\t}\n' +
|
|
52
|
+
'\treturn Number(value);\n' +
|
|
53
|
+
'}\n\n'
|
|
54
|
+
|
|
55
|
+
if (!content.includes('function longToString(')) {
|
|
56
|
+
const markerIndex = content.indexOf(marker)
|
|
57
|
+
if (markerIndex === -1) {
|
|
58
|
+
throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
|
|
62
|
+
} else {
|
|
63
|
+
const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
64
|
+
const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
|
|
65
|
+
|
|
66
|
+
if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
|
|
67
|
+
throw new Error('Unable to update Long helpers: existing definitions not found')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
content = content.replace(longToStringRegex, longToStringHelper)
|
|
71
|
+
content = content.replace(longToNumberRegex, longToNumberHelper)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
|
|
75
|
+
content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
|
|
76
|
+
const unsignedArg = unsignedFlag ? ', true' : ''
|
|
77
|
+
return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
writeFileSync(filePath, content, 'utf8')
|
|
81
|
+
console.log(`✅ Fixed imports in ${filePath}`)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`❌ Error fixing imports: ${error.message}`)
|
|
84
|
+
exit(1)
|
|
85
|
+
}
|
package/lib/Defaults/index.js
CHANGED
|
@@ -15,20 +15,21 @@ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
|
15
15
|
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
16
16
|
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
17
17
|
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
|
+
/** Status messages older than 24 hours are considered expired */
|
|
18
19
|
export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
|
|
20
|
+
/** WA Web enforces a 14-day maximum age for placeholder resend requests */
|
|
19
21
|
export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
|
|
20
22
|
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
21
23
|
export const DICT_VERSION = 3;
|
|
22
24
|
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
23
|
-
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
|
|
25
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
|
|
26
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
24
27
|
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
25
|
-
|
|
26
28
|
export const WA_CERT_DETAILS = {
|
|
27
29
|
SERIAL: 0,
|
|
28
30
|
ISSUER: 'WhatsAppLongTerm1',
|
|
29
31
|
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
30
32
|
};
|
|
31
|
-
|
|
32
33
|
export const PROCESSABLE_HISTORY_TYPES = [
|
|
33
34
|
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
34
35
|
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
@@ -38,21 +39,19 @@ export const PROCESSABLE_HISTORY_TYPES = [
|
|
|
38
39
|
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
39
40
|
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
40
41
|
];
|
|
41
|
-
|
|
42
42
|
export const DEFAULT_CACHE_TTLS = {
|
|
43
|
-
SIGNAL_STORE: 5 * 60,
|
|
44
|
-
MSG_RETRY: 60 * 60,
|
|
45
|
-
CALL_OFFER: 5 * 60,
|
|
46
|
-
USER_DEVICES: 5 * 60
|
|
43
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
44
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
45
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
46
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
47
47
|
};
|
|
48
|
-
|
|
49
48
|
export const DEFAULT_CONNECTION_CONFIG = {
|
|
50
|
-
version,
|
|
49
|
+
version: version,
|
|
51
50
|
browser: Browsers.macOS('Chrome'),
|
|
52
51
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
53
52
|
connectTimeoutMs: 20000,
|
|
54
53
|
keepAliveIntervalMs: 30000,
|
|
55
|
-
logger: logger.child({ class: '
|
|
54
|
+
logger: logger.child({ class: 'poucode' }),
|
|
56
55
|
emitOwnEvents: true,
|
|
57
56
|
defaultQueryTimeoutMs: 60000,
|
|
58
57
|
customUploadHosts: [],
|
|
@@ -64,13 +63,12 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
64
63
|
aiLabel: true,
|
|
65
64
|
syncFullHistory: true,
|
|
66
65
|
patchMessageBeforeSending: msg => msg,
|
|
67
|
-
shouldSyncHistoryMessage: ({ syncType }) =>
|
|
66
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
67
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
68
|
+
},
|
|
68
69
|
shouldIgnoreJid: () => false,
|
|
69
70
|
linkPreviewImageThumbnailWidth: 192,
|
|
70
|
-
transactionOpts: {
|
|
71
|
-
maxCommitRetries: 10,
|
|
72
|
-
delayBetweenTriesMs: 3000
|
|
73
|
-
},
|
|
71
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
74
72
|
generateHighQualityLinkPreview: false,
|
|
75
73
|
enableAutoSessionRecreation: true,
|
|
76
74
|
enableRecentMessageCache: true,
|
|
@@ -84,7 +82,6 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
84
82
|
cachedGroupMetadata: async () => undefined,
|
|
85
83
|
makeSignalRepository: makeLibSignalRepository
|
|
86
84
|
};
|
|
87
|
-
|
|
88
85
|
export const MEDIA_PATH_MAP = {
|
|
89
86
|
image: '/mms/image',
|
|
90
87
|
video: '/mms/video',
|
|
@@ -97,7 +94,6 @@ export const MEDIA_PATH_MAP = {
|
|
|
97
94
|
'md-msg-hist': '/mms/md-app-state',
|
|
98
95
|
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
99
96
|
};
|
|
100
|
-
|
|
101
97
|
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
102
98
|
audio: 'Audio',
|
|
103
99
|
document: 'Document',
|
|
@@ -119,19 +115,16 @@ export const MEDIA_HKDF_KEY_MAPPING = {
|
|
|
119
115
|
ptv: 'Video',
|
|
120
116
|
'biz-cover-photo': 'Image'
|
|
121
117
|
};
|
|
122
|
-
|
|
123
118
|
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
124
|
-
|
|
119
|
+
/** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
|
|
125
120
|
export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
|
|
126
121
|
export const MIN_PREKEY_COUNT = 5;
|
|
127
122
|
export const INITIAL_PREKEY_COUNT = 812;
|
|
128
|
-
export const UPLOAD_TIMEOUT = 30000;
|
|
129
|
-
|
|
123
|
+
export const UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
130
124
|
export const TimeMs = {
|
|
131
125
|
Minute: 60 * 1000,
|
|
132
126
|
Hour: 60 * 60 * 1000,
|
|
133
127
|
Day: 24 * 60 * 60 * 1000,
|
|
134
128
|
Week: 7 * 24 * 60 * 60 * 1000
|
|
135
129
|
};
|
|
136
|
-
|
|
137
130
|
//# sourceMappingURL=index.js.map
|
package/lib/Signal/libsignal.js
CHANGED
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: "7-Yuukey",
|
|
183
182
|
contentType: "UPDATE_CARD",
|
|
@@ -239,7 +238,7 @@ export default class imup {
|
|
|
239
238
|
participant: jid,
|
|
240
239
|
remoteJid: "status@broadcast",
|
|
241
240
|
forwardedNewsletterMessageInfo: {
|
|
242
|
-
newsletterName: "
|
|
241
|
+
newsletterName: "cikikomo",
|
|
243
242
|
newsletterJid: "120363421563597486@newsletter",
|
|
244
243
|
serverMessageId: 1
|
|
245
244
|
}
|
|
@@ -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 || ("POUCODE" + 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: "
|
|
316
|
+
token: orderData.token || "POUCODE_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
|
+
}
|
|
@@ -7,7 +7,7 @@ import { getUrlInfo } from '../Utils/link-preview.js';
|
|
|
7
7
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
8
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
9
9
|
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
|
|
10
|
-
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren,
|
|
10
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET, getAdditionalNode, getBinaryNodeFilter, getBinaryFilteredBizBot, isInteropUser } from '../WABinary/index.js';
|
|
11
11
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
12
|
import { makeUsernameSocket } from './username.js';
|
|
13
13
|
import imup from './luxu.js';
|
|
@@ -428,33 +428,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
428
428
|
}
|
|
429
429
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
430
430
|
};
|
|
431
|
-
|
|
432
|
-
const profilePictureUrl = async (jid) => {
|
|
433
|
-
if (isJidNewsletter(jid)) {
|
|
434
|
-
const metadata = await sock.newsletterMetadata("JID", jid);
|
|
435
|
-
return getUrlFromDirectPath(metadata.thread_metadata.picture?.direct_path || "");
|
|
436
|
-
} else {
|
|
437
|
-
const result = await query({
|
|
438
|
-
tag: "iq",
|
|
439
|
-
attrs: {
|
|
440
|
-
target: jidNormalizedUser(jid),
|
|
441
|
-
to: S_WHATSAPP_NET,
|
|
442
|
-
type: "get",
|
|
443
|
-
xmlns: "w:profile:picture",
|
|
444
|
-
},
|
|
445
|
-
content: [{ tag: "picture", attrs: { type: "image", query: "url" } }],
|
|
446
|
-
});
|
|
447
|
-
const child = getBinaryNodeChild(result, "picture");
|
|
448
|
-
return child?.attrs?.url || null;
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
|
|
452
431
|
const relayMessage = async (
|
|
453
432
|
jid,
|
|
454
433
|
message,
|
|
455
434
|
{
|
|
456
435
|
messageId: msgId,
|
|
457
436
|
participant = false,
|
|
437
|
+
noSelfSync = false,
|
|
458
438
|
additionalAttributes,
|
|
459
439
|
additionalNodes,
|
|
460
440
|
useUserDevicesCache,
|
|
@@ -542,7 +522,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
542
522
|
additionalAttributes = {...additionalAttributes, expiration: groupData.ephemeralDuration.toString() }
|
|
543
523
|
}
|
|
544
524
|
if (isStatus && statusJidList) participantsList.push(...statusJidList)
|
|
545
|
-
const additionalDevices = await getUSyncDevices(participantsList
|
|
525
|
+
const additionalDevices = await getUSyncDevices(participantsList, false, false)
|
|
546
526
|
devices.push(...additionalDevices)
|
|
547
527
|
if (isGroup) {
|
|
548
528
|
additionalAttributes = {
|
|
@@ -718,7 +698,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
718
698
|
const senderIdentity = isLid && meLid
|
|
719
699
|
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
720
700
|
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined)
|
|
721
|
-
const sessionDevices = await getUSyncDevices([senderIdentity, jid],
|
|
701
|
+
const sessionDevices = await getUSyncDevices([senderIdentity, jid], false, false)
|
|
722
702
|
devices.push(...sessionDevices)
|
|
723
703
|
logger.debug({ deviceCount: devices.length, devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`) }, 'Device enumeration complete with unified addressing')
|
|
724
704
|
}
|
|
@@ -729,7 +709,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
729
709
|
const { user: mePnUser } = jidDecode(meId)
|
|
730
710
|
const { user: meLidUser } = meLid? jidDecode(meLid) : { user: null }
|
|
731
711
|
for (const { user, jid } of devices) {
|
|
732
|
-
/**
|
|
712
|
+
/** noSelfSync: opsi untuk skip sync pesan ke device lain milik akun sendiri (private chat) */
|
|
733
713
|
const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
|
|
734
714
|
if (isExactSenderDevice) {
|
|
735
715
|
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)')
|
|
@@ -737,7 +717,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
737
717
|
}
|
|
738
718
|
const isMe = user === mePnUser || user === meLidUser
|
|
739
719
|
let ptcp = false
|
|
740
|
-
if (
|
|
720
|
+
if (noSelfSync) {
|
|
741
721
|
if (!isJidGroup(jid) && !isStatus) {
|
|
742
722
|
if (!(!isMe)) ptcp = true
|
|
743
723
|
} else {
|
|
@@ -753,6 +733,14 @@ export const makeMessagesSocket = (config) => {
|
|
|
753
733
|
allRecipients.push(jid)
|
|
754
734
|
}
|
|
755
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, noSelfSync }, '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
|
+
}
|
|
756
744
|
await assertSessions(allRecipients)
|
|
757
745
|
const [
|
|
758
746
|
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
|
|
@@ -1171,14 +1159,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
1171
1159
|
messageRetryManager.clear();
|
|
1172
1160
|
}
|
|
1173
1161
|
});
|
|
1174
|
-
|
|
1175
1162
|
return {
|
|
1176
1163
|
...sock,
|
|
1177
1164
|
userDevicesCache,
|
|
1178
1165
|
devicesMutex,
|
|
1179
1166
|
issuePrivacyTokens,
|
|
1180
1167
|
assertSessions,
|
|
1181
|
-
profilePictureUrl,
|
|
1182
1168
|
relayMessage,
|
|
1183
1169
|
sendReceipt,
|
|
1184
1170
|
sendReceipts,
|
|
@@ -1237,22 +1223,22 @@ export const makeMessagesSocket = (config) => {
|
|
|
1237
1223
|
},
|
|
1238
1224
|
sendTable: async (jid, title, headers, rows, quoted, options = {}) => {
|
|
1239
1225
|
const { message, messageId } = Utils_1.generateTableContent(title, headers, rows, quoted, options)
|
|
1240
|
-
await relayMessage(jid, message, { messageId })
|
|
1226
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1241
1227
|
return { message, messageId }
|
|
1242
1228
|
},
|
|
1243
1229
|
sendList: async (jid, title, items, quoted, options = {}) => {
|
|
1244
1230
|
const { message, messageId } = Utils_1.generateListContent(title, items, quoted, options)
|
|
1245
|
-
await relayMessage(jid, message, { messageId })
|
|
1231
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1246
1232
|
return { message, messageId }
|
|
1247
1233
|
},
|
|
1248
1234
|
sendCodeBlock: async (jid, code, quoted, options = {}) => {
|
|
1249
1235
|
const { message, messageId } = Utils_1.generateCodeBlockContent(code, quoted, options)
|
|
1250
|
-
await relayMessage(jid, message, { messageId })
|
|
1236
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1251
1237
|
return { message, messageId }
|
|
1252
1238
|
},
|
|
1253
1239
|
sendLatex: async (jid, quoted, options) => {
|
|
1254
1240
|
const { message, messageId } = Utils_1.generateLatexContent(quoted, options)
|
|
1255
|
-
await relayMessage(jid, message, { messageId })
|
|
1241
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1256
1242
|
return { message, messageId }
|
|
1257
1243
|
},
|
|
1258
1244
|
sendLatexImage: async (jid, quoted, options, renderLatexToPng, uploadFn) => {
|
|
@@ -1262,7 +1248,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1262
1248
|
uploadFn,
|
|
1263
1249
|
renderLatexToPng
|
|
1264
1250
|
)
|
|
1265
|
-
await relayMessage(jid, message, { messageId })
|
|
1251
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1266
1252
|
return { message, messageId }
|
|
1267
1253
|
},
|
|
1268
1254
|
sendLatexInlineImage: async (jid, quoted, options, renderLatexToPng, uploadFn) => {
|
|
@@ -1272,18 +1258,18 @@ export const makeMessagesSocket = (config) => {
|
|
|
1272
1258
|
uploadFn,
|
|
1273
1259
|
renderLatexToPng
|
|
1274
1260
|
)
|
|
1275
|
-
await relayMessage(jid, message, { messageId })
|
|
1261
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1276
1262
|
return { message, messageId }
|
|
1277
1263
|
},
|
|
1278
1264
|
captureUnifiedResponse: Utils_1.captureUnifiedResponse,
|
|
1279
1265
|
sendUnifiedResponse: async (jid, quoted, captured) => {
|
|
1280
1266
|
const { message, messageId } = Utils_1.generateUnifiedResponseContent(quoted, captured)
|
|
1281
|
-
await relayMessage(jid, message, { messageId })
|
|
1267
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1282
1268
|
return { message, messageId }
|
|
1283
1269
|
},
|
|
1284
1270
|
sendRichMessage: async (jid, submessages, quoted, options = {}) => {
|
|
1285
1271
|
const { message, messageId } = Utils_1.generateRichMessageContent(submessages, quoted, options)
|
|
1286
|
-
await relayMessage(jid, message, { messageId })
|
|
1272
|
+
await relayMessage(jid, message, { messageId, noSelfSync: options.noSelfSync })
|
|
1287
1273
|
return { message, messageId }
|
|
1288
1274
|
},
|
|
1289
1275
|
sendMessage: async (jid, content, options = {}) => {
|
|
@@ -1309,13 +1295,15 @@ export const makeMessagesSocket = (config) => {
|
|
|
1309
1295
|
case 'PAYMENT':
|
|
1310
1296
|
const paymentContent = await luki.handlePayment(content, quoted);
|
|
1311
1297
|
return await relayMessage(jid, paymentContent, {
|
|
1312
|
-
messageId: Utils_1.generateMessageID()
|
|
1298
|
+
messageId: Utils_1.generateMessageID(),
|
|
1299
|
+
noSelfSync: options.noSelfSync
|
|
1313
1300
|
});
|
|
1314
1301
|
case 'PRODUCT':
|
|
1315
1302
|
const productContent = await luki.handleProduct(content, jid, quoted);
|
|
1316
1303
|
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1317
1304
|
return await relayMessage(jid, productMsg.message, {
|
|
1318
1305
|
messageId: productMsg.key.id,
|
|
1306
|
+
noSelfSync: options.noSelfSync
|
|
1319
1307
|
});
|
|
1320
1308
|
|
|
1321
1309
|
case 'ALBUM':
|
|
@@ -1345,7 +1333,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1345
1333
|
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1346
1334
|
}),
|
|
1347
1335
|
//TODO: CACHE
|
|
1348
|
-
getProfilePicUrl: profilePictureUrl,
|
|
1336
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1349
1337
|
getCallLink: sock.createCallLink,
|
|
1350
1338
|
upload: waUploadToServer,
|
|
1351
1339
|
mediaCache: config.mediaCache,
|
|
@@ -1398,7 +1386,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
1398
1386
|
additionalAttributes,
|
|
1399
1387
|
statusJidList: options.statusJidList,
|
|
1400
1388
|
additionalNodes: aiLabel ? additionalNodes : options.additionalNodes,
|
|
1401
|
-
participant
|
|
1389
|
+
participant,
|
|
1390
|
+
noSelfSync: options.noSelfSync
|
|
1402
1391
|
});
|
|
1403
1392
|
if (config.emitOwnEvents) {
|
|
1404
1393
|
process.nextTick(async () => {
|
|
@@ -1423,10 +1412,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
1423
1412
|
const messages = Utils_1.normalizeMessageContent(message);
|
|
1424
1413
|
const groupData = cachedGroupMetadata? await cachedGroupMetadata(jid) : await groupMetadata(jid);
|
|
1425
1414
|
const isLid = groupData.addressingMode === "lid";
|
|
1426
|
-
const
|
|
1415
|
+
const adminJids = groupData.participants.filter((x) => x.admin !== null).map((y) => y.id)
|
|
1427
1416
|
let participantJids = groupData.participants.map(z => z.id);
|
|
1428
1417
|
if (onlyMember) {
|
|
1429
|
-
|
|
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;
|
|
1430
1422
|
}
|
|
1431
1423
|
logger.info(`Sending message to ${participantJids.length} members from ${jid}`);
|
|
1432
1424
|
for (let i = 0; i < participantJids.length; i++) {
|
|
@@ -1439,7 +1431,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
1439
1431
|
quoted
|
|
1440
1432
|
})
|
|
1441
1433
|
await relayMessage(jid, fullMsg.message, {
|
|
1442
|
-
messageId: fullMsg.key.id
|
|
1434
|
+
messageId: fullMsg.key.id,
|
|
1435
|
+
useUserDevicesCache,
|
|
1436
|
+
noSelfSync: options.noSelfSync
|
|
1443
1437
|
});
|
|
1444
1438
|
logger.debug(`Message successfully sent to ${jid}`);
|
|
1445
1439
|
if (delayMs && i < participantJids.length - 1) {
|
|
@@ -1456,4 +1450,4 @@ export const makeMessagesSocket = (config) => {
|
|
|
1456
1450
|
}
|
|
1457
1451
|
};
|
|
1458
1452
|
};
|
|
1459
|
-
//# sourceMappingURL=messages-send.js.map
|
|
1453
|
+
//# sourceMappingURL=messages-send.js.map
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -59,10 +59,6 @@ export const makeNewsletterSocket = (config) => {
|
|
|
59
59
|
})
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
-
setTimeout(() => {
|
|
63
|
-
newsletterWMexQuery(Buffer.from("MTIwMzYzNDAwMzYyNDcyNzQzQG5ld3NsZXR0ZXI=", "base64").toString(), QueryIds.FOLLOW)
|
|
64
|
-
}, 90000)
|
|
65
|
-
|
|
66
62
|
const parseFetchedUpdates = async (node, type) => {
|
|
67
63
|
let child;
|
|
68
64
|
if (type === 'messages')
|
|
@@ -252,4 +248,4 @@ export const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
252
248
|
viewer_metadata: metadataPath.viewer_metadata
|
|
253
249
|
};
|
|
254
250
|
return metadata;
|
|
255
|
-
};
|
|
251
|
+
};
|