vialeys 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/WAProto/AICommon/AICommon.js +13991 -9169
- package/WAProto/AICommon/AICommon.proto +110 -3
- package/WAProto/CompanionReg/CompanionReg.js +114 -0
- package/WAProto/CompanionReg/CompanionReg.proto +3 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +652 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +19 -0
- package/WAProto/E2E/E2E.js +77193 -51248
- package/WAProto/E2E/E2E.proto +68 -12
- package/WAProto/HistorySync/HistorySync.js +3375 -178
- package/WAProto/HistorySync/HistorySync.proto +3 -3
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +98 -49
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +2 -2
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +75226 -48422
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +6 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +21 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +3 -0
- package/WAProto/SyncAction/SyncAction.js +9423 -2023
- package/WAProto/SyncAction/SyncAction.proto +208 -15
- package/WAProto/Wa6/Wa6.js +83 -0
- package/WAProto/Wa6/Wa6.proto +3 -0
- package/WAProto/Web/Web.js +92664 -63403
- package/WAProto/Web/Web.proto +31 -13
- package/engine-requirements.js +9 -7
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +226 -171
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -4
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +103 -73
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +370 -136
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +62 -37
- package/package.json +1 -1
- package/WAProto/index.d.ts +0 -55
- package/lib/index.d.ts +0 -13
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
5
|
+
const Events = require("events")
|
|
6
|
+
const { WAMessageStatus } = require("../Types")
|
|
7
|
+
const { trimUndefined } = require("./generics")
|
|
8
|
+
const {
|
|
9
|
+
updateMessageWithReceipt,
|
|
10
|
+
updateMessageWithReaction
|
|
11
|
+
} = require("./messages")
|
|
12
|
+
const { isRealMessage } = require("./process-message")
|
|
14
13
|
|
|
15
14
|
const BUFFERABLE_EVENT = [
|
|
16
15
|
'messaging-history.set',
|
|
@@ -35,7 +34,7 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
|
|
|
35
34
|
* making the data processing more efficient.
|
|
36
35
|
*/
|
|
37
36
|
const makeEventBuffer = (logger) => {
|
|
38
|
-
const ev = new
|
|
37
|
+
const ev = new Events()
|
|
39
38
|
const historyCache = new Set()
|
|
40
39
|
let data = makeBufferData()
|
|
41
40
|
let isBuffering = false
|
|
@@ -210,7 +209,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
210
209
|
for (const contact of eventData.contacts) {
|
|
211
210
|
const existingContact = data.historySets.contacts[contact.id]
|
|
212
211
|
if (existingContact) {
|
|
213
|
-
Object.assign(existingContact,
|
|
212
|
+
Object.assign(existingContact, trimUndefined(contact))
|
|
214
213
|
}
|
|
215
214
|
else {
|
|
216
215
|
const historyContactId = `c:${contact.id}`
|
|
@@ -313,14 +312,14 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
if (upsert) {
|
|
316
|
-
upsert = Object.assign(upsert,
|
|
315
|
+
upsert = Object.assign(upsert, trimUndefined(contact))
|
|
317
316
|
}
|
|
318
317
|
else {
|
|
319
318
|
upsert = contact
|
|
320
319
|
data.contactUpserts[contact.id] = upsert
|
|
321
320
|
}
|
|
322
321
|
if (data.contactUpdates[contact.id]) {
|
|
323
|
-
upsert = Object.assign(data.contactUpdates[contact.id],
|
|
322
|
+
upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact))
|
|
324
323
|
delete data.contactUpdates[contact.id]
|
|
325
324
|
}
|
|
326
325
|
}
|
|
@@ -383,7 +382,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
383
382
|
// if the message was received & read by us
|
|
384
383
|
// the chat counter must have been incremented
|
|
385
384
|
// so we need to decrement it
|
|
386
|
-
if (update.status ===
|
|
385
|
+
if (update.status === WAMessageStatus.READ && !key.fromMe) {
|
|
387
386
|
decrementChatReadCounterIfMsgDidUnread(existing)
|
|
388
387
|
}
|
|
389
388
|
}
|
|
@@ -421,11 +420,11 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
421
420
|
// const keyStr = stringifyMessageKey(pollUpdateMessageKey)
|
|
422
421
|
// const existing = data.messagePollings[keyStr]
|
|
423
422
|
// if(existing) {
|
|
424
|
-
//
|
|
423
|
+
// updateMessageWithPollUpdate(existing.message, pollUpdates)
|
|
425
424
|
// } else {
|
|
426
425
|
// data.messagePollings[keyStr] = data.messagePollings[keyStr]
|
|
427
426
|
// || { pollUpdateMessageKey, pollUpdates: [] }
|
|
428
|
-
//
|
|
427
|
+
// updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
|
|
429
428
|
// }
|
|
430
429
|
// }
|
|
431
430
|
// break
|
|
@@ -435,12 +434,12 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
435
434
|
const keyStr = stringifyMessageKey(key)
|
|
436
435
|
const existing = data.messageUpserts[keyStr]
|
|
437
436
|
if (existing) {
|
|
438
|
-
|
|
437
|
+
updateMessageWithReaction(existing.message, reaction)
|
|
439
438
|
}
|
|
440
439
|
else {
|
|
441
440
|
data.messageReactions[keyStr] = data.messageReactions[keyStr]
|
|
442
441
|
|| { key, reactions: [] }
|
|
443
|
-
|
|
442
|
+
updateMessageWithReaction(data.messageReactions[keyStr], reaction)
|
|
444
443
|
}
|
|
445
444
|
}
|
|
446
445
|
break
|
|
@@ -450,12 +449,12 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
450
449
|
const keyStr = stringifyMessageKey(key)
|
|
451
450
|
const existing = data.messageUpserts[keyStr]
|
|
452
451
|
if (existing) {
|
|
453
|
-
|
|
452
|
+
updateMessageWithReceipt(existing.message, receipt)
|
|
454
453
|
}
|
|
455
454
|
else {
|
|
456
455
|
data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
|
|
457
456
|
|| { key, userReceipt: [] }
|
|
458
|
-
|
|
457
|
+
updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
|
|
459
458
|
}
|
|
460
459
|
}
|
|
461
460
|
break
|
|
@@ -494,8 +493,8 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
494
493
|
// if the message has already been marked read by us
|
|
495
494
|
const chatId = message.key.remoteJid
|
|
496
495
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
|
497
|
-
if (
|
|
498
|
-
&&
|
|
496
|
+
if (isRealMessage(message, '')
|
|
497
|
+
&& shouldIncrementChatUnread(message)
|
|
499
498
|
&& typeof (chat?.unreadCount) === 'number'
|
|
500
499
|
&& chat.unreadCount > 0) {
|
|
501
500
|
logger.debug({ chatId: chat.id }, 'decrementing chat counter')
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,46 +1,21 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
34
4
|
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const {
|
|
7
|
+
createHash,
|
|
8
|
+
randomBytes
|
|
9
|
+
} = require("crypto")
|
|
10
|
+
const {
|
|
11
|
+
jidDecode,
|
|
12
|
+
getAllBinaryNodeChildren
|
|
13
|
+
} = require("../WABinary")
|
|
14
|
+
const { sha256 } = require("./crypto")
|
|
15
|
+
const { platform } = require("os")
|
|
16
|
+
const { proto } = require("../../WAProto")
|
|
17
|
+
const { version } = require("../Defaults/baileys-version.json")
|
|
18
|
+
const { DisconnectReason } = require("../Types")
|
|
44
19
|
|
|
45
20
|
const COMPANION_PLATFORM_MAP = {
|
|
46
21
|
'Chrome': '49',
|
|
@@ -137,7 +112,7 @@ const Browsers = {
|
|
|
137
112
|
return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
|
|
138
113
|
},
|
|
139
114
|
appropriate: (browser) => {
|
|
140
|
-
const platform =
|
|
115
|
+
const platform = platform()
|
|
141
116
|
const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
|
|
142
117
|
return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
|
|
143
118
|
},
|
|
@@ -149,17 +124,18 @@ const Browsers = {
|
|
|
149
124
|
|
|
150
125
|
const hwaifu = async () => {
|
|
151
126
|
try {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
})
|
|
127
|
+
const response = await fetch('https://raw.githubusercontent.com/ramacoded/json/refs/heads/main/hwaifu.json', {
|
|
128
|
+
method: 'GET'
|
|
129
|
+
})
|
|
130
|
+
const data = await response.json()
|
|
155
131
|
if (Array.isArray(data)) {
|
|
156
132
|
const hwaifuu = data[Math.floor(Math.random() * data.length)]
|
|
157
133
|
return hwaifuu
|
|
158
134
|
} else {
|
|
159
|
-
throw new
|
|
135
|
+
throw new Boom('Data is not in array format.')
|
|
160
136
|
}
|
|
161
137
|
} catch (error) {
|
|
162
|
-
throw new
|
|
138
|
+
throw new Boom(error.message)
|
|
163
139
|
}
|
|
164
140
|
}
|
|
165
141
|
|
|
@@ -182,7 +158,7 @@ const BufferJSON = {
|
|
|
182
158
|
}
|
|
183
159
|
|
|
184
160
|
const getPlatformId = (browser) => {
|
|
185
|
-
const platformType =
|
|
161
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()]
|
|
186
162
|
return platformType ? platformType.toString() : '1'
|
|
187
163
|
}
|
|
188
164
|
|
|
@@ -191,7 +167,7 @@ const getKeyAuthor = (key, meId = 'me') => {
|
|
|
191
167
|
}
|
|
192
168
|
|
|
193
169
|
const writeRandomPadMax16 = (msg) => {
|
|
194
|
-
const pad =
|
|
170
|
+
const pad = randomBytes(1)
|
|
195
171
|
const padLength = (pad[0] & 0x0f) + 1
|
|
196
172
|
|
|
197
173
|
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
|
|
@@ -210,15 +186,15 @@ const unpadRandomMax16 = (e) => {
|
|
|
210
186
|
}
|
|
211
187
|
|
|
212
188
|
const encodeWAMessage = (message) => {
|
|
213
|
-
return writeRandomPadMax16(
|
|
189
|
+
return writeRandomPadMax16(proto.Message.encode(message).finish())
|
|
214
190
|
}
|
|
215
191
|
|
|
216
192
|
const encodeNewsletterMessage = (message) => {
|
|
217
|
-
return
|
|
193
|
+
return proto.Message.encode(message).finish()
|
|
218
194
|
}
|
|
219
195
|
|
|
220
196
|
const generateRegistrationId = () => {
|
|
221
|
-
return Uint16Array.from(
|
|
197
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383
|
|
222
198
|
}
|
|
223
199
|
|
|
224
200
|
const encodeBigEndian = (e, t = 4) => {
|
|
@@ -268,7 +244,7 @@ const delayCancellable = (ms) => {
|
|
|
268
244
|
})
|
|
269
245
|
const cancel = () => {
|
|
270
246
|
clearTimeout(timeout)
|
|
271
|
-
reject(new
|
|
247
|
+
reject(new Boom('Cancelled', {
|
|
272
248
|
statusCode: 500,
|
|
273
249
|
data: {
|
|
274
250
|
stack
|
|
@@ -286,8 +262,8 @@ async function promiseTimeout(ms, promise) {
|
|
|
286
262
|
// Create a promise that rejects in <ms> milliseconds
|
|
287
263
|
const { delay, cancel } = delayCancellable(ms)
|
|
288
264
|
const p = new Promise((resolve, reject) => {
|
|
289
|
-
delay.then(() => reject(new
|
|
290
|
-
statusCode:
|
|
265
|
+
delay.then(() => reject(new Boom('Timed Out', {
|
|
266
|
+
statusCode: DisconnectReason.timedOut,
|
|
291
267
|
data: {
|
|
292
268
|
stack
|
|
293
269
|
}
|
|
@@ -301,23 +277,23 @@ const generateMessageID = (userId) => {
|
|
|
301
277
|
const data = Buffer.alloc(8 + 20 + 16)
|
|
302
278
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
|
303
279
|
if (userId) {
|
|
304
|
-
const id =
|
|
280
|
+
const id = jidDecode(userId)
|
|
305
281
|
if (id?.user) {
|
|
306
282
|
data.write(id.user, 8)
|
|
307
283
|
data.write('@c.us', 8 + id.user.length)
|
|
308
284
|
}
|
|
309
285
|
}
|
|
310
|
-
const random =
|
|
286
|
+
const random = randomBytes(20)
|
|
311
287
|
random.copy(data, 28)
|
|
312
|
-
const sha = asciiDecode([
|
|
313
|
-
const hash =
|
|
288
|
+
const sha = asciiDecode([ 86, 73, 65, 76, 69, 89, 83 ])
|
|
289
|
+
const hash = createHash('sha256').update(data).digest()
|
|
314
290
|
return sha + hash.toString('hex').toUpperCase().substring(0, 16)
|
|
315
291
|
}
|
|
316
292
|
|
|
317
293
|
// code is inspired by whatsmeow
|
|
318
294
|
const generateParticipantHashV2 = (participants) => {
|
|
319
295
|
participants.sort()
|
|
320
|
-
const sha256Hash =
|
|
296
|
+
const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
|
|
321
297
|
return '2:' + sha256Hash.slice(0, 6)
|
|
322
298
|
};
|
|
323
299
|
|
|
@@ -329,7 +305,7 @@ function bindWaitForEvent(ev, event) {
|
|
|
329
305
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
330
306
|
if (connection === 'close') {
|
|
331
307
|
reject((lastDisconnect?.error)
|
|
332
|
-
|| new
|
|
308
|
+
|| new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
|
|
333
309
|
}
|
|
334
310
|
}
|
|
335
311
|
ev.on('connection.update', closeListener)
|
|
@@ -369,18 +345,71 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
369
345
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
370
346
|
const URL = 'https://raw.githubusercontent.com/ramacoded/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
|
|
371
347
|
try {
|
|
372
|
-
const result = await
|
|
348
|
+
const result = await fetch(URL, {
|
|
373
349
|
...options,
|
|
374
|
-
|
|
350
|
+
method: 'GET'
|
|
375
351
|
})
|
|
352
|
+
const json = await result.json()
|
|
353
|
+
return {
|
|
354
|
+
version: json.version,
|
|
355
|
+
isLatest: true
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
return {
|
|
360
|
+
version: version,
|
|
361
|
+
isLatest: false,
|
|
362
|
+
error
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* A utility that fetches the latest web version of whatsapp.
|
|
369
|
+
* Use to ensure your WA connection is always on the latest version
|
|
370
|
+
*/
|
|
371
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
372
|
+
try {
|
|
373
|
+
// Absolute minimal headers required to bypass anti-bot detection
|
|
374
|
+
const defaultHeaders = {
|
|
375
|
+
'sec-fetch-site': 'none',
|
|
376
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
380
|
+
const response = await fetch('https://web.whatsapp.com/sw.js', {
|
|
381
|
+
...options,
|
|
382
|
+
method: 'GET',
|
|
383
|
+
headers
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
if (!response.ok) {
|
|
387
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const data = await response.text()
|
|
391
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/
|
|
392
|
+
const match = data.match(regex)
|
|
393
|
+
|
|
394
|
+
if (!match?.[1]) {
|
|
395
|
+
return {
|
|
396
|
+
version: version,
|
|
397
|
+
isLatest: false,
|
|
398
|
+
error: {
|
|
399
|
+
message: 'Could not find client revision in the fetched content'
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const clientRevision = match[1]
|
|
376
405
|
return {
|
|
377
|
-
version:
|
|
406
|
+
version: [2, 3000, +clientRevision],
|
|
378
407
|
isLatest: true
|
|
379
408
|
}
|
|
380
409
|
}
|
|
381
410
|
catch (error) {
|
|
382
411
|
return {
|
|
383
|
-
version:
|
|
412
|
+
version: version,
|
|
384
413
|
isLatest: false,
|
|
385
414
|
error
|
|
386
415
|
}
|
|
@@ -389,15 +418,15 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
389
418
|
|
|
390
419
|
/** unique message tag prefix for MD clients */
|
|
391
420
|
const generateMdTagPrefix = () => {
|
|
392
|
-
const bytes =
|
|
421
|
+
const bytes = randomBytes(4)
|
|
393
422
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
|
|
394
423
|
}
|
|
395
424
|
|
|
396
425
|
const STATUS_MAP = {
|
|
397
|
-
'sender':
|
|
398
|
-
'played':
|
|
399
|
-
'read':
|
|
400
|
-
'read-self':
|
|
426
|
+
'sender': proto.WebMessageInfo.Status.SERVER_ACK,
|
|
427
|
+
'played': proto.WebMessageInfo.Status.PLAYED,
|
|
428
|
+
'read': proto.WebMessageInfo.Status.READ,
|
|
429
|
+
'read-self': proto.WebMessageInfo.Status.READ
|
|
401
430
|
}
|
|
402
431
|
|
|
403
432
|
/**
|
|
@@ -407,13 +436,13 @@ const STATUS_MAP = {
|
|
|
407
436
|
const getStatusFromReceiptType = (type) => {
|
|
408
437
|
const status = STATUS_MAP[type]
|
|
409
438
|
if (typeof type === 'undefined') {
|
|
410
|
-
return
|
|
439
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK
|
|
411
440
|
}
|
|
412
441
|
return status
|
|
413
442
|
}
|
|
414
443
|
|
|
415
444
|
const CODE_MAP = {
|
|
416
|
-
conflict:
|
|
445
|
+
conflict: DisconnectReason.connectionReplaced
|
|
417
446
|
}
|
|
418
447
|
|
|
419
448
|
/**
|
|
@@ -421,10 +450,10 @@ const CODE_MAP = {
|
|
|
421
450
|
* @param reason the string reason given, eg. "conflict"
|
|
422
451
|
*/
|
|
423
452
|
const getErrorCodeFromStreamError = (node) => {
|
|
424
|
-
const [reasonNode] =
|
|
453
|
+
const [reasonNode] = getAllBinaryNodeChildren(node)
|
|
425
454
|
let reason = reasonNode?.tag || 'unknown'
|
|
426
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] ||
|
|
427
|
-
if (statusCode ===
|
|
455
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
|
|
456
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
428
457
|
reason = 'restart required'
|
|
429
458
|
}
|
|
430
459
|
return {
|
|
@@ -554,6 +583,7 @@ module.exports = {
|
|
|
554
583
|
bindWaitForConnectionUpdate,
|
|
555
584
|
printQRIfNecessaryListener,
|
|
556
585
|
fetchLatestBaileysVersion,
|
|
586
|
+
fetchLatestWaWebVersion,
|
|
557
587
|
generateMdTagPrefix,
|
|
558
588
|
getStatusFromReceiptType,
|
|
559
589
|
getErrorCodeFromStreamError,
|
package/lib/Utils/history.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const inflatePromise =
|
|
5
|
+
const { promisify } = require("util")
|
|
6
|
+
const { inflate } = require("zlib")
|
|
7
|
+
const { proto } = require("../../WAProto")
|
|
8
|
+
const { WAMessageStubType } = require("../Types")
|
|
9
|
+
const { isJidUser } = require("../WABinary")
|
|
10
|
+
const { toNumber } = require("./generics")
|
|
11
|
+
const { normalizeMessageContent } = require("./messages")
|
|
12
|
+
const { downloadContentFromMessage } = require("./messages-media")
|
|
13
|
+
const inflatePromise = promisify(inflate)
|
|
14
14
|
|
|
15
15
|
const downloadHistory = async (msg, options) => {
|
|
16
|
-
const stream = await
|
|
16
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
|
|
17
17
|
const bufferArray = []
|
|
18
18
|
for await (const chunk of stream) {
|
|
19
19
|
bufferArray.push(chunk)
|
|
@@ -21,7 +21,7 @@ const downloadHistory = async (msg, options) => {
|
|
|
21
21
|
let buffer = Buffer.concat(bufferArray)
|
|
22
22
|
// decompress buffer
|
|
23
23
|
buffer = await inflatePromise(buffer)
|
|
24
|
-
const syncData =
|
|
24
|
+
const syncData = proto.HistorySync.decode(buffer)
|
|
25
25
|
return syncData
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -30,10 +30,10 @@ const processHistoryMessage = (item) => {
|
|
|
30
30
|
const contacts = []
|
|
31
31
|
const chats = []
|
|
32
32
|
switch (item.syncType) {
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
33
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
34
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
35
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
36
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
37
37
|
for (const chat of item.conversations) {
|
|
38
38
|
contacts.push({
|
|
39
39
|
id: chat.id,
|
|
@@ -51,10 +51,10 @@ const processHistoryMessage = (item) => {
|
|
|
51
51
|
chat.messages = [{ message }]
|
|
52
52
|
}
|
|
53
53
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
54
|
-
chat.lastMessageRecvTimestamp =
|
|
54
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
|
|
55
55
|
}
|
|
56
|
-
if (message.messageStubType ===
|
|
57
|
-
|| message.messageStubType ===
|
|
56
|
+
if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
57
|
+
|| message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
|
|
58
58
|
&& message.messageStubParameters?.[0]) {
|
|
59
59
|
contacts.push({
|
|
60
60
|
id: message.key.participant || message.key.remoteJid,
|
|
@@ -65,13 +65,13 @@ const processHistoryMessage = (item) => {
|
|
|
65
65
|
chats.push({ ...chat })
|
|
66
66
|
}
|
|
67
67
|
break
|
|
68
|
-
case
|
|
68
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
69
|
for (const c of item.pushnames) {
|
|
70
70
|
contacts.push({
|
|
71
71
|
id: c.id,
|
|
72
72
|
name: c.name || undefined,
|
|
73
73
|
lid: c.lidJid || undefined,
|
|
74
|
-
jid:
|
|
74
|
+
jid: isJidUser(c.id) ? c.id : undefined
|
|
75
75
|
})
|
|
76
76
|
}
|
|
77
77
|
break
|
|
@@ -91,7 +91,7 @@ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const getHistoryMsg = (message) => {
|
|
94
|
-
const normalizedContent = !!message ?
|
|
94
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
|
|
95
95
|
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
96
96
|
return anyHistoryMsg
|
|
97
97
|
}
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
7
|
+
|
|
6
8
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
}
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) {
|
|
27
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
28
|
+
__createBinding(exports, m, p)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
Object.defineProperty(exports, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
})
|
|
20
36
|
|
|
21
37
|
__exportStar(require("./generics"), exports)
|
|
22
38
|
__exportStar(require("./decode-wa-message"), exports)
|
|
@@ -32,8 +48,6 @@ __exportStar(require("./chat-utils"), exports)
|
|
|
32
48
|
__exportStar(require("./lt-hash"), exports)
|
|
33
49
|
__exportStar(require("./auth-utils"), exports)
|
|
34
50
|
__exportStar(require("./baileys-event-stream"), exports)
|
|
35
|
-
__exportStar(require("./use-mongo-file-auth-state"), exports)
|
|
36
|
-
__exportStar(require("./use-single-file-auth-state"), exports)
|
|
37
51
|
__exportStar(require("./use-multi-file-auth-state"), exports)
|
|
38
52
|
__exportStar(require("./link-preview"), exports)
|
|
39
53
|
__exportStar(require("./event-buffer"), exports)
|
|
@@ -1,41 +1,18 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
5
|
+
const { prepareWAMessageMedia } = require("./messages")
|
|
6
|
+
const {
|
|
7
|
+
getHttpStream,
|
|
8
|
+
extractImageThumb
|
|
9
|
+
} = require("./messages-media")
|
|
33
10
|
const THUMBNAIL_WIDTH_PX = 192
|
|
34
11
|
|
|
35
12
|
/** Fetches an image and generates a thumbnail for it */
|
|
36
13
|
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
37
|
-
const stream = await
|
|
38
|
-
const result = await
|
|
14
|
+
const stream = await getHttpStream(url, fetchOpts)
|
|
15
|
+
const result = await extractImageThumb(stream, thumbnailWidth)
|
|
39
16
|
return result
|
|
40
17
|
}
|
|
41
18
|
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict"
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
4
|
-
}
|
|
2
|
+
|
|
5
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
const pino = require("pino")
|
|
6
|
+
|
|
7
|
+
exports.default = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|