@ryuhan/baileys 1.0.0 → 1.0.3

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 (113) hide show
  1. package/LICENSE +1 -1
  2. package/README.MD +105 -0
  3. package/lib/Defaults/index.js +47 -35
  4. package/lib/Defaults/ryuhan-version.json +3 -0
  5. package/lib/Socket/chats.js +131 -87
  6. package/lib/Socket/messages-recv.js +1 -1
  7. package/lib/Socket/socket.js +1 -1
  8. package/lib/Store/make-in-memory-store.js +1 -1
  9. package/lib/Utils/browser-utils.js +35 -0
  10. package/lib/Utils/event-buffer.js +2 -2
  11. package/lib/Utils/generics.js +36 -10
  12. package/lib/Utils/index.js +3 -1
  13. package/lib/Utils/message-retry-manager.js +128 -0
  14. package/lib/Utils/{baileys-event-stream.js → ryuhan-event-stream.js} +1 -1
  15. package/lib/Utils/use-multi-file-auth-state.js +0 -2
  16. package/lib/Utils/validate-connection.js +77 -21
  17. package/lib/index.js +30 -2
  18. package/package.json +29 -16
  19. package/WAProto/index.d.ts +0 -55057
  20. package/WAProto/index.ts.ts +0 -53473
  21. package/WAProto/p.html +0 -1
  22. package/lib/Defaults/baileys-version.json +0 -3
  23. package/lib/Defaults/index.d.ts +0 -51
  24. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  25. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  26. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  27. package/lib/Signal/Group/index.d.ts +0 -11
  28. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  29. package/lib/Signal/Group/queue-job.d.ts +0 -1
  30. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  31. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  32. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  33. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  34. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  35. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  36. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  37. package/lib/Signal/libsignal.d.ts +0 -3
  38. package/lib/Socket/Client/index.d.ts +0 -2
  39. package/lib/Socket/Client/types.d.ts +0 -16
  40. package/lib/Socket/Client/websocket.d.ts +0 -13
  41. package/lib/Socket/business.d.ts +0 -172
  42. package/lib/Socket/chats.d.ts +0 -82
  43. package/lib/Socket/groups.d.ts +0 -124
  44. package/lib/Socket/index.d.ts +0 -172
  45. package/lib/Socket/messages-recv.d.ts +0 -161
  46. package/lib/Socket/messages-send.d.ts +0 -151
  47. package/lib/Socket/newsletter.d.ts +0 -136
  48. package/lib/Socket/socket.d.ts +0 -43
  49. package/lib/Socket/usync.d.ts +0 -36
  50. package/lib/Store/index.d.ts +0 -2
  51. package/lib/Store/make-in-memory-store.d.ts +0 -118
  52. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  53. package/lib/Store/object-repository.d.ts +0 -10
  54. package/lib/Types/Auth.d.ts +0 -103
  55. package/lib/Types/Call.d.ts +0 -13
  56. package/lib/Types/Chat.d.ts +0 -109
  57. package/lib/Types/Contact.d.ts +0 -23
  58. package/lib/Types/Events.d.ts +0 -199
  59. package/lib/Types/GroupMetadata.d.ts +0 -64
  60. package/lib/Types/Label.d.ts +0 -35
  61. package/lib/Types/LabelAssociation.d.ts +0 -29
  62. package/lib/Types/Message.d.ts +0 -400
  63. package/lib/Types/Newsletter.d.ts +0 -79
  64. package/lib/Types/Product.d.ts +0 -78
  65. package/lib/Types/Signal.d.ts +0 -57
  66. package/lib/Types/Socket.d.ts +0 -119
  67. package/lib/Types/State.d.ts +0 -27
  68. package/lib/Types/USync.d.ts +0 -25
  69. package/lib/Types/index.d.ts +0 -64
  70. package/lib/Utils/auth-utils.d.ts +0 -18
  71. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  72. package/lib/Utils/business.d.ts +0 -22
  73. package/lib/Utils/chat-utils.d.ts +0 -70
  74. package/lib/Utils/crypto.d.ts +0 -40
  75. package/lib/Utils/decode-wa-message.d.ts +0 -35
  76. package/lib/Utils/event-buffer.d.ts +0 -35
  77. package/lib/Utils/generics.d.ts +0 -89
  78. package/lib/Utils/history.d.ts +0 -19
  79. package/lib/Utils/index.d.ts +0 -17
  80. package/lib/Utils/link-preview.d.ts +0 -21
  81. package/lib/Utils/logger.d.ts +0 -11
  82. package/lib/Utils/lt-hash.d.ts +0 -12
  83. package/lib/Utils/make-mutex.d.ts +0 -7
  84. package/lib/Utils/messages-media.d.ts +0 -120
  85. package/lib/Utils/messages.d.ts +0 -80
  86. package/lib/Utils/noise-handler.d.ts +0 -19
  87. package/lib/Utils/process-message.d.ts +0 -42
  88. package/lib/Utils/signal.d.ts +0 -33
  89. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  90. package/lib/Utils/validate-connection.d.ts +0 -10
  91. package/lib/WABinary/constants.d.ts +0 -27
  92. package/lib/WABinary/decode.d.ts +0 -6
  93. package/lib/WABinary/encode.d.ts +0 -2
  94. package/lib/WABinary/generic-utils.d.ts +0 -14
  95. package/lib/WABinary/index.d.ts +0 -5
  96. package/lib/WABinary/jid-utils.d.ts +0 -37
  97. package/lib/WABinary/jid-utils.js.bak +0 -83
  98. package/lib/WABinary/types.d.ts +0 -18
  99. package/lib/WAM/BinaryInfo.d.ts +0 -8
  100. package/lib/WAM/constants.d.ts +0 -38
  101. package/lib/WAM/encode.d.ts +0 -2
  102. package/lib/WAM/index.d.ts +0 -3
  103. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  104. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  106. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  107. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  108. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  109. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  110. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  111. package/lib/WAUSync/USyncUser.d.ts +0 -12
  112. package/lib/WAUSync/index.d.ts +0 -3
  113. package/lib/index.d.ts +0 -16
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Ryuhan Minamoto
3
+ Copyright (c) 2025 ryuhan
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 ADDED
@@ -0,0 +1,105 @@
1
+ <p align="center">
2
+ <img src="https://files.catbox.moe/f8tj1b.png" alt="Rimuru Bot" width="150"/>
3
+ </p>
4
+
5
+ <h1 align="center">💧 Rimuru Baileys</h1>
6
+ <p align="center">TypeScript-based library for WhatsApp Web API integration, with built-in fixes for group identifiers like @lid and @jid.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/ryuhandev/rimuru-baileys/stargazers"><img src="https://img.shields.io/github/stars/ryuhandev/rimuru-baileys?style=flat-square&logo=github" alt="GitHub Stars"/></a>
11
+ <a href="https://github.com/ryuhandev/rimuru-baileys/issues"><img src="https://img.shields.io/github/issues/ryuhandev/rimuru-baileys?style=flat-square&logo=github" alt="GitHub Issues"/></a>
12
+ <img src="https://img.shields.io/badge/License-MIT-green?style=flat-square" alt="License"/>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## ✨ Features
18
+
19
+ - **💧 Intelligent `@lid` and `@jid` mapping**
20
+ - **💧 Multi-device support**
21
+ - **💧 End-to-End Encryption support**
22
+ - **💧 Handles all WhatsApp message types**
23
+ - **💧 Fast and modern TypeScript codebase**
24
+ - **💧 Multi-Device Support:** Works with latest WhatsApp multi-device protocol.
25
+ - **💧 Media Handling:** Send and receive images, videos, audio, stickers, and documents.
26
+ - **💧 Pairing Code Login:** Easy login using Pairing Code.
27
+ - **💧 Simple & Extendable:** Clean code structure for customization and adding new features.
28
+ - **💧 Support Botton Message:** You can add cool botton to your bot menu
29
+ - **💧 High Compatibility:** Built on Ryuhan's fork of Baileys for reliable WhatsApp API integration.
30
+
31
+ ---
32
+ ### 💧 Installation
33
+
34
+ ```bash
35
+ npm install @ryuhan/baileys
36
+ # or
37
+ yarn add @ryuhan/baileys
38
+ ```
39
+
40
+ ### 💧 Quick Example
41
+
42
+ ```ts
43
+ import makeWASocket from '@ryuhan/baileys'
44
+ import { getSenderLid, toJid } from '@ryuhan/baileys'
45
+
46
+ const sock = makeWASocket({ printQRInTerminal: true })
47
+
48
+ sock.ev.on('messages.upsert', ({ messages }) => {
49
+ const msg = messages[0]
50
+ const info = getSenderLid(msg) // logs the sender LID
51
+ const jid = toJid(info.lid)
52
+ console.log('normalized jid:', jid)
53
+ })
54
+ ```
55
+
56
+ ### 💧 Advanced Usage (Multi-file Auth)
57
+
58
+ ```ts
59
+ import makeWASocket, { useMultiFileAuthState } from "@ryuhan/baileys"
60
+
61
+ async function start() {
62
+ const { state, saveCreds } = await useMultiFileAuthState("auth_info")
63
+ const sock = makeWASocket({ auth: state, printQRInTerminal: true })
64
+
65
+ sock.ev.on("creds.update", saveCreds)
66
+ sock.ev.on("messages.upsert", ({ messages }) => {
67
+ for (const m of messages) {
68
+ console.log(m.key.remoteJid, m.message?.conversation)
69
+ }
70
+ })
71
+ }
72
+
73
+ start()
74
+ ```
75
+ ---
76
+
77
+ ### 💧 EXAMPLE PACKAGE FOR PAIRING CODE BOT:
78
+
79
+ ```
80
+ {
81
+ "name": "your-bot",
82
+ "version": "1.0.0",
83
+ "type": "module",
84
+ "scripts": {
85
+ "start": "node index.js"
86
+ },
87
+ "dependencies": {
88
+ "@whiskeysockets/baileys": "npm:@ryuhan/baileys",
89
+ "archiver": "^7.0.1",
90
+ "awesome-phonenumber": "^7.6.0",
91
+ "@hapi/boom": "^10.0.1",
92
+ "readline": "^1.3.0",
93
+ "pino": "^9.5.0",
94
+ "@napi-rs/canvas": "^0.1.84",
95
+ "chalk": "^5.3.0",
96
+ "fs-extra": "^11.2.0",
97
+ "node-cache": "^5.1.2",
98
+ "file-type": "^19.6.0",
99
+ "axios": "^1.7.9",
100
+ "node-fetch": "^3.3.2",
101
+ "jimp": "^0.16.13"
102
+ }
103
+ }
104
+ ```
105
+ ---
@@ -3,61 +3,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = void 0;
6
+ exports.DEFAULT_CACHE_TTLS = exports.MIN_UPLOAD_INTERVAL = exports.UPLOAD_TIMEOUT = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = exports.WA_ADV_DEVICE_SIG_PREFIX = exports.WA_ADV_ACCOUNT_SIG_PREFIX = exports.UNAUTHORIZED_CODES = exports.version = void 0;
7
7
  const WAProto_1 = require("../../WAProto");
8
8
  const libsignal_1 = require("../Signal/libsignal");
9
- const Utils_1 = require("../Utils");
9
+ const browser_utils_1 = require("../Utils/browser-utils");
10
10
  const logger_1 = __importDefault(require("../Utils/logger"));
11
- const baileys_version_json_1 = require("./baileys-version.json");
11
+ exports.version = [2, 3000, 1027934701];
12
12
  exports.UNAUTHORIZED_CODES = [401, 403, 419];
13
13
  exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
14
+ exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
15
+ exports.CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
14
16
  exports.DEF_CALLBACK_PREFIX = 'CB:';
15
17
  exports.DEF_TAG_PREFIX = 'TAG:';
16
18
  exports.PHONE_CONNECTION_CB = 'CB:Pong';
19
+ exports.WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
20
+ exports.WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
21
+ exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
22
+ exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
17
23
  exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
18
24
  exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
19
25
  exports.DICT_VERSION = 3;
20
26
  exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
21
- exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
22
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
27
+ exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
23
28
  exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
24
29
  exports.WA_CERT_DETAILS = {
25
- SERIAL: 0,
30
+ SERIAL: 0
26
31
  };
27
32
  exports.PROCESSABLE_HISTORY_TYPES = [
28
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
29
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
30
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
31
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
32
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
33
+ WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
34
+ WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME,
35
+ WAProto_1.proto.HistorySync.HistorySyncType.RECENT,
36
+ WAProto_1.proto.HistorySync.HistorySyncType.FULL,
37
+ WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND,
38
+ WAProto_1.proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
39
+ WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3,
33
40
  ];
34
41
  exports.DEFAULT_CONNECTION_CONFIG = {
35
- version: baileys_version_json_1.version,
36
- browser: Utils_1.Browsers.ubuntu('Chrome'),
42
+ version: exports.version,
43
+ browser: (0, browser_utils_1.Browsers)('Chrome'),
37
44
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
38
- connectTimeoutMs: 20000,
39
- keepAliveIntervalMs: 30000,
45
+ connectTimeoutMs: 20_000,
46
+ keepAliveIntervalMs: 30_000,
40
47
  logger: logger_1.default.child({ class: 'baileys' }),
41
- printQRInTerminal: false,
42
48
  emitOwnEvents: true,
43
- defaultQueryTimeoutMs: 60000,
49
+ defaultQueryTimeoutMs: 60_000,
44
50
  customUploadHosts: [],
45
51
  retryRequestDelayMs: 250,
46
52
  maxMsgRetryCount: 5,
47
53
  fireInitQueries: true,
48
54
  auth: undefined,
49
55
  markOnlineOnConnect: true,
50
- syncFullHistory: false,
56
+ syncFullHistory: true,
51
57
  patchMessageBeforeSending: msg => msg,
52
58
  shouldSyncHistoryMessage: () => true,
53
59
  shouldIgnoreJid: () => false,
54
60
  linkPreviewImageThumbnailWidth: 192,
55
61
  transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
56
62
  generateHighQualityLinkPreview: false,
63
+ enableAutoSessionRecreation: true,
64
+ enableRecentMessageCache: true,
57
65
  options: {},
58
66
  appStateMacVerification: {
59
67
  patch: false,
60
- snapshot: false,
68
+ snapshot: false
61
69
  },
62
70
  countryCode: 'US',
63
71
  getMessage: async () => undefined,
@@ -74,17 +82,18 @@ exports.MEDIA_PATH_MAP = {
74
82
  'product-catalog-image': '/product/image',
75
83
  'md-app-state': '',
76
84
  'md-msg-hist': '/mms/md-app-state',
85
+ 'biz-cover-photo': '/pps/biz-cover-photo'
77
86
  };
78
87
  exports.MEDIA_HKDF_KEY_MAPPING = {
79
- 'audio': 'Audio',
80
- 'document': 'Document',
81
- 'gif': 'Video',
82
- 'image': 'Image',
83
- 'ppic': '',
84
- 'product': 'Image',
85
- 'ptt': 'Audio',
86
- 'sticker': 'Image',
87
- 'video': 'Video',
88
+ audio: 'Audio',
89
+ document: 'Document',
90
+ gif: 'Video',
91
+ image: 'Image',
92
+ ppic: '',
93
+ product: 'Image',
94
+ ptt: 'Audio',
95
+ sticker: 'Image',
96
+ video: 'Video',
88
97
  'thumbnail-document': 'Document Thumbnail',
89
98
  'thumbnail-image': 'Image Thumbnail',
90
99
  'thumbnail-video': 'Video Thumbnail',
@@ -93,14 +102,17 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
93
102
  'md-app-state': 'App State',
94
103
  'product-catalog-image': '',
95
104
  'payment-bg-image': 'Payment Background',
96
- 'ptv': 'Video'
105
+ ptv: 'Video',
106
+ 'biz-cover-photo': 'Image'
97
107
  };
98
108
  exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
99
109
  exports.MIN_PREKEY_COUNT = 5;
100
- exports.INITIAL_PREKEY_COUNT = 30;
110
+ exports.INITIAL_PREKEY_COUNT = 812;
111
+ exports.UPLOAD_TIMEOUT = 30000;
112
+ exports.MIN_UPLOAD_INTERVAL = 5000;
101
113
  exports.DEFAULT_CACHE_TTLS = {
102
- SIGNAL_STORE: 5 * 60, // 5 minutes
103
- MSG_RETRY: 60 * 60, // 1 hour
104
- CALL_OFFER: 5 * 60, // 5 minutes
105
- USER_DEVICES: 5 * 60, // 5 minutes
106
- };
114
+ SIGNAL_STORE: 5 * 60,
115
+ MSG_RETRY: 60 * 60,
116
+ CALL_OFFER: 5 * 60,
117
+ USER_DEVICES: 5 * 60
118
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": [2, 3000, 1027934701]
3
+ }