@ryuu-reinzz/baileys 3.0.0-beta.9 → 3.0.1

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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -15
  3. package/WAProto/fix-imports.js +70 -18
  4. package/WAProto/index.js +197 -160
  5. package/lib/Defaults/index.js +17 -4
  6. package/lib/Signal/libsignal.js +64 -2
  7. package/lib/Signal/lid-mapping.js +170 -70
  8. package/lib/Socket/Client/websocket.js +5 -1
  9. package/lib/Socket/business.js +11 -8
  10. package/lib/Socket/chats.js +55 -28
  11. package/lib/Socket/index.js +0 -6
  12. package/lib/Socket/messages-recv.js +152 -75
  13. package/lib/Socket/messages-send.js +229 -144
  14. package/lib/Socket/socket.js +69 -15
  15. package/lib/Utils/auth-utils.js +53 -20
  16. package/lib/Utils/chat-utils.js +100 -51
  17. package/lib/Utils/crypto.js +2 -26
  18. package/lib/Utils/event-buffer.js +33 -7
  19. package/lib/Utils/generics.js +6 -3
  20. package/lib/Utils/history.js +46 -5
  21. package/lib/Utils/identity-change-handler.js +49 -0
  22. package/lib/Utils/index.js +2 -1
  23. package/lib/Utils/lt-hash.js +2 -42
  24. package/lib/Utils/make-mutex.js +20 -27
  25. package/lib/Utils/message-retry-manager.js +58 -5
  26. package/lib/Utils/messages-media.js +151 -40
  27. package/lib/Utils/messages.js +43 -23
  28. package/lib/Utils/noise-handler.js +139 -85
  29. package/lib/Utils/process-message.js +57 -14
  30. package/lib/Utils/reporting-utils.js +258 -0
  31. package/lib/Utils/sync-action-utils.js +48 -0
  32. package/lib/Utils/tc-token-utils.js +18 -0
  33. package/lib/Utils/use-sqlite-auth-state.js +13 -7
  34. package/lib/WABinary/decode.js +24 -0
  35. package/lib/WABinary/encode.js +5 -1
  36. package/lib/WABinary/generic-utils.js +19 -8
  37. package/lib/index.cjs +196 -0
  38. package/package.json +96 -87
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Rajeh Taher/WhiskeySockets
3
+ Copyright (c) 2026 RyuuReinzz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -15,6 +15,12 @@ This is a temporary README.md, the new guide is in development and will this fil
15
15
 
16
16
  New guide link: https://baileys.wiki
17
17
 
18
+ # Get Support
19
+
20
+ If you'd like business to enterprise-level support from Rajeh, the current maintainer of Baileys, you can book a video chat. Book a 1 hour time slot by contacting him on Discord or pre-ordering [here](https://purpshell.dev/book). The earlier you pre-order the better, as his time slots usually fill up very quickly. He offers immense value per hour and will answer all your questions before the time runs out.
21
+
22
+ If you are a business, we encourage you to contribute back to the high development costs of the project and to feed the maintainers who dump tens of hours a week on this. You can do so by booking meetings or sponsoring below. All support, even in bona fide / contribution hours, is welcome by businesses of all sizes. This is not condoning or endorsing businesses to use the library. See the Disclaimer below.
23
+
18
24
  # Sponsor
19
25
  If you'd like to financially support this project, you can do so by supporting the current maintainer [here](https://purpshell.dev/sponsor).
20
26
 
@@ -50,17 +56,12 @@ To run the example script, download or clone the repo and then type the followin
50
56
 
51
57
  Use the stable version:
52
58
  ```
53
- yarn add @whiskeysockets/baileys
54
- ```
55
-
56
- Use the edge version (no guarantee of stability, but latest fixes + features)
57
- ```
58
- yarn add github:WhiskeySockets/Baileys
59
+ yarn add @ryuu-reinzz/baileys
59
60
  ```
60
61
 
61
62
  Then import your code using:
62
63
  ```ts
63
- import makeWASocket from '@whiskeysockets/baileys'
64
+ import makeWASocket from '@ryuu-reinzz/baileys'
64
65
  ```
65
66
 
66
67
  # Links
@@ -189,7 +190,7 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
189
190
  > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
190
191
 
191
192
  ```ts
192
- import makeWASocket from '@whiskeysockets/baileys'
193
+ import makeWASocket from '@ryuu-reinzz/baileys'
193
194
 
194
195
  const sock = makeWASocket({
195
196
  // can provide additional config here
@@ -209,7 +210,7 @@ If the connection is successful, you will see a QR code printed on your terminal
209
210
  The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
210
211
 
211
212
  ```ts
212
- import makeWASocket from '@whiskeysockets/baileys'
213
+ import makeWASocket from '@ryuu-reinzz/baileys'
213
214
 
214
215
  const sock = makeWASocket({
215
216
  // can provide additional config here
@@ -282,7 +283,7 @@ You obviously don't want to keep scanning the QR code every time you want to con
282
283
 
283
284
  So, you can load the credentials to log back in:
284
285
  ```ts
285
- import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'
286
+ import makeWASocket, { useMultiFileAuthState } from '@ryuu-reinzz/baileys'
286
287
 
287
288
  const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
288
289
 
@@ -325,7 +326,7 @@ sock.ev.on('messages.upsert', ({ messages }) => {
325
326
  > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
326
327
 
327
328
  ```ts
328
- import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@whiskeysockets/baileys'
329
+ import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@ryuu-reinzz/baileys'
329
330
  import { Boom } from '@hapi/boom'
330
331
 
331
332
  async function connectToWhatsApp () {
@@ -407,7 +408,7 @@ sock.ev.on('messages.update', event => {
407
408
  It can be used as follows:
408
409
 
409
410
  ```ts
410
- import makeWASocket, { makeInMemoryStore } from '@whiskeysockets/baileys'
411
+ import makeWASocket, { makeInMemoryStore } from '@ryuu-reinzz/baileys'
411
412
  // the store maintains the data of the WA connection in memory
412
413
  // can be written out to a file & read from it
413
414
  const store = makeInMemoryStore({ })
@@ -593,7 +594,7 @@ await sock.sendMessage(
593
594
  await sock.sendMessage(
594
595
  jid,
595
596
  {
596
- text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
597
+ text: 'Hi, this was sent using https://github.com/ryuu-reinzz/baileys'
597
598
  }
598
599
  )
599
600
  ```
@@ -723,7 +724,7 @@ await sock.sendMessage(jid, {
723
724
  If you want to save the media you received
724
725
  ```ts
725
726
  import { createWriteStream } from 'fs'
726
- import { downloadMediaMessage, getContentType } from '@whiskeysockets/baileys'
727
+ import { downloadMediaMessage, getContentType } from '@ryuu-reinzz/baileys'
727
728
 
728
729
  sock.ev.on('messages.upsert', async ({ [m] }) => {
729
730
  if (!m.message) return // if there is no text or media message
@@ -1282,7 +1283,7 @@ sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1282
1283
  ```
1283
1284
 
1284
1285
  # License
1285
- Copyright (c) 2025 Rajeh Taher/WhiskeySockets
1286
+ Copyright (c) 2025 RyuuReinzz
1286
1287
 
1287
1288
  Licensed under the MIT License:
1288
1289
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,29 +1,81 @@
1
1
  import { readFileSync, writeFileSync } from 'fs';
2
2
  import { exit } from 'process';
3
3
 
4
- const filePath = './index.js';
4
+ const filePath = './index.js'
5
5
 
6
6
  try {
7
- // Read the file
8
- let content = readFileSync(filePath, 'utf8');
7
+ let content = readFileSync(filePath, 'utf8')
9
8
 
10
- // Fix the import statement
11
- content = content.replace(
12
- /import \* as (\$protobuf) from/g,
13
- 'import $1 from'
14
- );
9
+ content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
10
+ content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
15
11
 
16
- // add missing extension to the import
17
- content = content.replace(
18
- /(['"])protobufjs\/minimal(['"])/g,
19
- '$1protobufjs/minimal.js$2'
20
- );
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
+ '\tif (!$util.Long) {\n' +
22
+ '\t\treturn String(value);\n' +
23
+ '\t}\n' +
24
+ '\tconst normalized = $util.Long.fromValue(value);\n' +
25
+ '\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
26
+ '\t\t? normalized.toUnsigned()\n' +
27
+ '\t\t: normalized;\n' +
28
+ '\treturn prepared.toString();\n' +
29
+ '}\n\n'
30
+ const longToNumberHelper =
31
+ 'function longToNumber(value, unsigned) {\n' +
32
+ '\tif (typeof value === "number") {\n' +
33
+ '\t\treturn value;\n' +
34
+ '\t}\n' +
35
+ '\tif (typeof value === "string") {\n' +
36
+ '\t\tconst numeric = Number(value);\n' +
37
+ '\t\treturn numeric;\n' +
38
+ '\t}\n' +
39
+ '\tif (!$util.Long) {\n' +
40
+ '\t\treturn Number(value);\n' +
41
+ '\t}\n' +
42
+ '\tconst normalized = $util.Long.fromValue(value);\n' +
43
+ '\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
44
+ '\t\t? normalized.toUnsigned()\n' +
45
+ '\t\t: typeof normalized.toSigned === "function"\n' +
46
+ '\t\t\t? normalized.toSigned()\n' +
47
+ '\t\t\t: normalized;\n' +
48
+ '\treturn prepared.toNumber();\n' +
49
+ '}\n\n'
21
50
 
22
- // Write back
23
- writeFileSync(filePath, content, 'utf8');
51
+ if (!content.includes('function longToString(')) {
52
+ const markerIndex = content.indexOf(marker)
53
+ if (markerIndex === -1) {
54
+ throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
55
+ }
24
56
 
25
- console.log(`✅ Fixed imports in ${filePath}`);
57
+ content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
58
+ } else {
59
+ const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
60
+ const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
61
+
62
+ if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
63
+ throw new Error('Unable to update Long helpers: existing definitions not found')
64
+ }
65
+
66
+ content = content.replace(longToStringRegex, longToStringHelper)
67
+ content = content.replace(longToNumberRegex, longToNumberHelper)
68
+ }
69
+
70
+ 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
71
+ content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
72
+ const unsignedArg = unsignedFlag ? ', true' : ''
73
+ return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
74
+ })
75
+
76
+ writeFileSync(filePath, content, 'utf8')
77
+ console.log(`✅ Fixed imports in ${filePath}`)
26
78
  } catch (error) {
27
- console.error(`❌ Error fixing imports: ${error.message}`);
28
- exit(1);
79
+ console.error(`❌ Error fixing imports: ${error.message}`)
80
+ exit(1)
29
81
  }