@hbmodsofc/baileys 1.7.7 → 2.0.0

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 (155) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +157084 -24729
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.d.ts +8 -12
  5. package/lib/Defaults/index.js +124 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  8. package/lib/Signal/Group/group_cipher.js +39 -28
  9. package/lib/Signal/Group/queue-job.d.ts +1 -0
  10. package/lib/Signal/Group/queue-job.js +57 -0
  11. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  12. package/lib/Signal/Group/sender-chain-key.js +2 -9
  13. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-message.js +3 -3
  15. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  16. package/lib/Signal/Group/sender-key-state.js +16 -47
  17. package/lib/Signal/libsignal.d.ts +3 -7
  18. package/lib/Signal/libsignal.js +39 -224
  19. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  20. package/lib/Socket/Client/index.d.ts +3 -2
  21. package/lib/Socket/Client/index.js +3 -2
  22. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  24. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  25. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  26. package/lib/Socket/business.d.ts +78 -94
  27. package/lib/Socket/business.js +11 -130
  28. package/lib/Socket/chats.d.ts +233 -63
  29. package/lib/Socket/chats.js +184 -234
  30. package/lib/Socket/groups.d.ts +41 -62
  31. package/lib/Socket/groups.js +64 -76
  32. package/lib/Socket/hbmods.d.ts +253 -0
  33. package/lib/Socket/hbmods.js +1 -0
  34. package/lib/Socket/index.d.ts +83 -129
  35. package/lib/Socket/index.js +6 -13
  36. package/lib/Socket/messages-recv.d.ts +48 -59
  37. package/lib/Socket/messages-recv.js +371 -516
  38. package/lib/Socket/messages-send.d.ts +67 -86
  39. package/lib/Socket/messages-send.js +1 -1091
  40. package/lib/Socket/newsletter.d.ts +64 -76
  41. package/lib/Socket/newsletter.js +1 -184
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +166 -0
  44. package/lib/Socket/socket.d.ts +13 -19
  45. package/lib/Socket/socket.js +1 -805
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Socket/usync.js +70 -0
  48. package/lib/Types/Auth.d.ts +10 -4
  49. package/lib/Types/Call.d.ts +1 -1
  50. package/lib/Types/Chat.d.ts +9 -29
  51. package/lib/Types/Chat.js +1 -7
  52. package/lib/Types/Contact.d.ts +1 -5
  53. package/lib/Types/Events.d.ts +14 -55
  54. package/lib/Types/GroupMetadata.d.ts +5 -15
  55. package/lib/Types/Label.d.ts +0 -11
  56. package/lib/Types/Label.js +1 -1
  57. package/lib/Types/LabelAssociation.js +1 -1
  58. package/lib/Types/Message.d.ts +49 -75
  59. package/lib/Types/Message.js +7 -10
  60. package/lib/Types/Newsletter.d.ts +98 -129
  61. package/lib/Types/Newsletter.js +38 -33
  62. package/lib/Types/Product.d.ts +1 -1
  63. package/lib/Types/Signal.d.ts +1 -29
  64. package/lib/Types/Socket.d.ts +22 -48
  65. package/lib/Types/State.d.ts +2 -13
  66. package/lib/Types/State.js +0 -12
  67. package/lib/Types/USync.d.ts +1 -1
  68. package/lib/Types/index.d.ts +3 -10
  69. package/lib/Types/index.js +2 -2
  70. package/lib/Utils/auth-utils.d.ts +3 -3
  71. package/lib/Utils/auth-utils.js +102 -378
  72. package/lib/Utils/baileys-event-stream.js +1 -1
  73. package/lib/Utils/business.d.ts +2 -2
  74. package/lib/Utils/business.js +13 -19
  75. package/lib/Utils/chat-utils.d.ts +22 -21
  76. package/lib/Utils/chat-utils.js +154 -201
  77. package/lib/Utils/crypto.d.ts +19 -18
  78. package/lib/Utils/crypto.js +37 -78
  79. package/lib/Utils/decode-wa-message.d.ts +7 -34
  80. package/lib/Utils/decode-wa-message.js +66 -138
  81. package/lib/Utils/event-buffer.d.ts +8 -6
  82. package/lib/Utils/event-buffer.js +43 -81
  83. package/lib/Utils/generics.d.ts +27 -27
  84. package/lib/Utils/generics.js +133 -128
  85. package/lib/Utils/history.d.ts +5 -9
  86. package/lib/Utils/history.js +23 -17
  87. package/lib/Utils/index.d.ts +0 -2
  88. package/lib/Utils/index.js +0 -2
  89. package/lib/Utils/link-preview.d.ts +4 -4
  90. package/lib/Utils/link-preview.js +12 -40
  91. package/lib/Utils/logger.d.ts +3 -11
  92. package/lib/Utils/lt-hash.d.ts +8 -8
  93. package/lib/Utils/lt-hash.js +24 -23
  94. package/lib/Utils/make-mutex.d.ts +2 -2
  95. package/lib/Utils/make-mutex.js +2 -3
  96. package/lib/Utils/messages-media.d.ts +41 -37
  97. package/lib/Utils/messages-media.js +368 -252
  98. package/lib/Utils/messages.d.ts +15 -13
  99. package/lib/Utils/messages.js +261 -274
  100. package/lib/Utils/noise-handler.d.ts +15 -13
  101. package/lib/Utils/noise-handler.js +26 -20
  102. package/lib/Utils/process-message.d.ts +8 -9
  103. package/lib/Utils/process-message.js +93 -157
  104. package/lib/Utils/signal.d.ts +5 -6
  105. package/lib/Utils/signal.js +29 -37
  106. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  107. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  108. package/lib/Utils/validate-connection.d.ts +6 -5
  109. package/lib/Utils/validate-connection.js +97 -39
  110. package/lib/WABinary/constants.d.ts +27 -24
  111. package/lib/WABinary/constants.js +13 -1276
  112. package/lib/WABinary/decode.d.ts +4 -3
  113. package/lib/WABinary/decode.js +14 -28
  114. package/lib/WABinary/encode.d.ts +2 -1
  115. package/lib/WABinary/encode.js +147 -134
  116. package/lib/WABinary/generic-utils.d.ts +7 -4
  117. package/lib/WABinary/generic-utils.js +125 -40
  118. package/lib/WABinary/jid-utils.d.ts +8 -13
  119. package/lib/WABinary/jid-utils.js +16 -27
  120. package/lib/WAM/BinaryInfo.d.ts +11 -2
  121. package/lib/WAM/constants.d.ts +2 -3
  122. package/lib/WAM/constants.js +2359 -2252
  123. package/lib/WAM/encode.d.ts +2 -1
  124. package/lib/WAM/encode.js +11 -8
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  137. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  138. package/lib/WAUSync/USyncQuery.js +15 -19
  139. package/lib/WAUSync/USyncUser.d.ts +5 -5
  140. package/lib/WAUSync/index.d.ts +1 -1
  141. package/lib/WAUSync/index.js +1 -1
  142. package/package.json +102 -102
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,58 +1,50 @@
1
- "use strict";
1
+ "use strict";
2
2
  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.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.generateParticipantHashV2 = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
7
- exports.promiseTimeout = promiseTimeout;
8
- exports.bindWaitForEvent = bindWaitForEvent;
9
- exports.trimUndefined = trimUndefined;
10
- exports.bytesToCrockford = bytesToCrockford;
11
- exports.encodeNewsletterMessage = encodeNewsletterMessage;
6
+ exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
12
7
  const boom_1 = require("@hapi/boom");
13
8
  const axios_1 = __importDefault(require("axios"));
14
9
  const crypto_1 = require("crypto");
15
10
  const os_1 = require("os");
16
- const index_js_1 = require("../../WAProto/index.js");
17
- const baileysVersion = [2, 3000, 1023223821];
11
+ const fetch_1 = require("node-fetch")
12
+ const WAProto_1 = require("../../WAProto");
13
+ const baileys_version_json_1 = require("../Defaults/baileys-version.json");
18
14
  const Types_1 = require("../Types");
19
15
  const WABinary_1 = require("../WABinary");
20
- const crypto_2 = require("./crypto");
16
+ const baileysVersion = [2, 3000, 1027934701]
21
17
  const PLATFORM_MAP = {
22
- aix: 'AIX',
23
- darwin: 'Mac OS',
24
- win32: 'Windows',
25
- android: 'Android',
26
- freebsd: 'FreeBSD',
27
- openbsd: 'OpenBSD',
28
- sunos: 'Solaris',
29
- linux: undefined,
30
- haiku: undefined,
31
- cygwin: undefined,
32
- netbsd: undefined
18
+ 'aix': 'AIX',
19
+ 'darwin': 'Mac OS',
20
+ 'win32': 'Windows',
21
+ 'android': 'Android',
22
+ 'freebsd': 'FreeBSD',
23
+ 'openbsd': 'OpenBSD',
24
+ 'sunos': 'Solaris',
25
+ 'linux': undefined,
26
+ 'haiku': undefined,
27
+ 'cygwin': undefined,
28
+ 'netbsd': undefined
33
29
  };
34
- exports.Browsers = {
35
- ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
36
- macOS: browser => ['Mac OS', browser, '14.4.1'],
37
- baileys: browser => ['Baileys', browser, '6.5.0'],
38
- windows: browser => ['Windows', browser, '10.0.22631'],
39
- /** The appropriate browser based on your OS & release */
40
- appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
30
+ exports.Browsers = (browser) => {
31
+ const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
32
+ const osRelease = os_1.release();
33
+ return [osName, browser, osRelease];
41
34
  };
35
+
42
36
  const getPlatformId = (browser) => {
43
- const platformType = index_js_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
37
+ const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
44
38
  return platformType ? platformType.toString() : '1'; //chrome
45
39
  };
46
40
  exports.getPlatformId = getPlatformId;
47
41
  exports.BufferJSON = {
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
42
  replacer: (k, value) => {
50
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
51
- return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
43
+ if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
44
+ return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
52
45
  }
53
46
  return value;
54
47
  },
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
48
  reviver: (_, value) => {
57
49
  if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
58
50
  const val = value.data || value.value;
@@ -61,12 +53,15 @@ exports.BufferJSON = {
61
53
  return value;
62
54
  }
63
55
  };
64
- const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participant || key?.remoteJid) || '';
56
+ const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
65
57
  exports.getKeyAuthor = getKeyAuthor;
66
58
  const writeRandomPadMax16 = (msg) => {
67
59
  const pad = (0, crypto_1.randomBytes)(1);
68
- const padLength = (pad[0] & 0x0f) + 1;
69
- return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
60
+ pad[0] &= 0xf;
61
+ if (!pad[0]) {
62
+ pad[0] = 0xf;
63
+ }
64
+ return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
70
65
  };
71
66
  exports.writeRandomPadMax16 = writeRandomPadMax16;
72
67
  const unpadRandomMax16 = (e) => {
@@ -81,14 +76,7 @@ const unpadRandomMax16 = (e) => {
81
76
  return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
82
77
  };
83
78
  exports.unpadRandomMax16 = unpadRandomMax16;
84
- // code is inspired by whatsmeow
85
- const generateParticipantHashV2 = (participants) => {
86
- participants.sort();
87
- const sha256Hash = (0, crypto_2.sha256)(Buffer.from(participants.join(''))).toString('base64');
88
- return '2:' + sha256Hash.slice(0, 6);
89
- };
90
- exports.generateParticipantHashV2 = generateParticipantHashV2;
91
- const encodeWAMessage = (message) => (0, exports.writeRandomPadMax16)(index_js_1.proto.Message.encode(message).finish());
79
+ const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
92
80
  exports.encodeWAMessage = encodeWAMessage;
93
81
  const generateRegistrationId = () => {
94
82
  return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
@@ -104,7 +92,7 @@ const encodeBigEndian = (e, t = 4) => {
104
92
  return a;
105
93
  };
106
94
  exports.encodeBigEndian = encodeBigEndian;
107
- const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
95
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
108
96
  exports.toNumber = toNumber;
109
97
  /** unix timestamp of a date in seconds */
110
98
  const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
@@ -116,14 +104,14 @@ const debouncedTimeout = (intervalMs = 1000, task) => {
116
104
  task = newTask || task;
117
105
  intervalMs = newIntervalMs || intervalMs;
118
106
  timeout && clearTimeout(timeout);
119
- timeout = setTimeout(() => task?.(), intervalMs);
107
+ timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
120
108
  },
121
109
  cancel: () => {
122
110
  timeout && clearTimeout(timeout);
123
111
  timeout = undefined;
124
112
  },
125
- setTask: (newTask) => (task = newTask),
126
- setInterval: (newInterval) => (intervalMs = newInterval)
113
+ setTask: (newTask) => task = newTask,
114
+ setInterval: (newInterval) => intervalMs = newInterval
127
115
  };
128
116
  };
129
117
  exports.debouncedTimeout = debouncedTimeout;
@@ -166,17 +154,17 @@ async function promiseTimeout(ms, promise) {
166
154
  })))
167
155
  .catch(err => reject(err));
168
156
  promise(resolve, reject);
169
- }).finally(cancel);
157
+ })
158
+ .finally(cancel);
170
159
  return p;
171
160
  }
172
- // inspired from whatsmeow code
173
- // https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
161
+ exports.promiseTimeout = promiseTimeout;
174
162
  const generateMessageIDV2 = (userId) => {
175
163
  const data = Buffer.alloc(8 + 20 + 16);
176
164
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
177
165
  if (userId) {
178
166
  const id = (0, WABinary_1.jidDecode)(userId);
179
- if (id?.user) {
167
+ if (id === null || id === void 0 ? void 0 : id.user) {
180
168
  data.write(id.user, 8);
181
169
  data.write('@c.us', 8 + id.user.length);
182
170
  }
@@ -188,104 +176,123 @@ const generateMessageIDV2 = (userId) => {
188
176
  };
189
177
  exports.generateMessageIDV2 = generateMessageIDV2;
190
178
  // generate a random ID to attach to a message
191
- const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
179
+ const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
192
180
  exports.generateMessageID = generateMessageID;
193
181
  function bindWaitForEvent(ev, event) {
194
182
  return async (check, timeoutMs) => {
195
183
  let listener;
196
184
  let closeListener;
197
- await promiseTimeout(timeoutMs, (resolve, reject) => {
185
+ await (promiseTimeout(timeoutMs, (resolve, reject) => {
198
186
  closeListener = ({ connection, lastDisconnect }) => {
199
187
  if (connection === 'close') {
200
- reject(lastDisconnect?.error || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
188
+ reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
189
+ || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
201
190
  }
202
191
  };
203
192
  ev.on('connection.update', closeListener);
204
- listener = async (update) => {
205
- if (await check(update)) {
193
+ listener = (update) => {
194
+ if (check(update)) {
206
195
  resolve();
207
196
  }
208
197
  };
209
198
  ev.on(event, listener);
210
- }).finally(() => {
199
+ })
200
+ .finally(() => {
211
201
  ev.off(event, listener);
212
202
  ev.off('connection.update', closeListener);
213
- });
203
+ }));
214
204
  };
215
205
  }
206
+ exports.bindWaitForEvent = bindWaitForEvent;
216
207
  const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
217
208
  exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
209
+ const printQRIfNecessaryListener = (ev, logger) => {
210
+ ev.on('connection.update', async ({ qr }) => {
211
+ if (qr) {
212
+ const QR = await import('qrcode-terminal')
213
+ .then(m => m.default || m)
214
+ .catch(() => {
215
+ logger.error('QR code terminal not added as dependency');
216
+ });
217
+ QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
218
+ }
219
+ });
220
+ };
221
+ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
218
222
  /**
219
223
  * utility that fetches latest baileys version from the master branch.
220
224
  * Use to ensure your WA connection is always on the latest version
221
225
  */
222
- const fetchLatestBaileysVersion = async (options = {}) => {
223
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
224
- try {
225
- const result = await axios_1.default.get(URL, {
226
- ...options,
227
- responseType: 'text'
228
- });
229
- // Extract version from line 7 (const version = [...])
230
- const lines = result.data.split('\n');
231
- const versionLine = lines[6]; // Line 7 (0-indexed)
232
- const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
233
- if (versionMatch) {
234
- const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
235
- return {
236
- version,
237
- isLatest: true
238
- };
239
- }
240
- else {
241
- throw new Error('Could not parse version from Defaults/index.ts');
242
- }
243
- }
244
- catch (error) {
245
- return {
246
- version: baileysVersion,
247
- isLatest: false,
248
- error
249
- };
250
- }
251
- };
252
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
226
+ const fetchLatestWaWebVersion = async (options = {}) => {
227
+ try {
228
+ const defaultHeaders = {
229
+ 'User-Agent':
230
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
231
+ 'Accept': '*/*'
232
+ }
233
+
234
+ const headers = { ...defaultHeaders, ...options.headers }
235
+
236
+ const response = await fetch_1('https://web.whatsapp.com/sw.js', {
237
+ method: 'GET',
238
+ headers
239
+ })
240
+
241
+ if (!response.ok) {
242
+ throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
243
+ }
244
+
245
+ const data = await response.text()
246
+ const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
247
+ const match = data.match(regex)
248
+
249
+ if (!match || !match[1]) {
250
+ return {
251
+ version: baileysVersion,
252
+ isLatest: false,
253
+ error: { message: 'Client revision not found' }
254
+ }
255
+ }
256
+
257
+ const clientRevision = match[1]
258
+ return {
259
+ version: [2, 3000, +clientRevision],
260
+ isLatest: true
261
+ }
262
+ } catch (error) {
263
+ return {
264
+ version: baileysVersion,
265
+ isLatest: false,
266
+ error
267
+ }
268
+ }
269
+ }
270
+ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
253
271
  /**
254
- * A utility that fetches the latest web version of whatsapp.
272
+ * utility that fetches latest baileys version from the master branch.
255
273
  * Use to ensure your WA connection is always on the latest version
256
274
  */
257
- const fetchLatestWaWebVersion = async (options) => {
275
+ const fetchLatestBaileysVersion = async (options = {}) => {
276
+ const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
258
277
  try {
259
- const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
278
+ const result = await axios_1.default.get(URL, {
260
279
  ...options,
261
280
  responseType: 'json'
262
281
  });
263
- const regex = /\\?"client_revision\\?":\s*(\d+)/;
264
- const match = data.match(regex);
265
- if (!match?.[1]) {
266
- return {
267
- version: baileysVersion,
268
- isLatest: false,
269
- error: {
270
- message: 'Could not find client revision in the fetched content'
271
- }
272
- };
273
- }
274
- const clientRevision = match[1];
275
282
  return {
276
- version: [2, 3000, +clientRevision],
283
+ version: result.data.version,
277
284
  isLatest: true
278
285
  };
279
286
  }
280
287
  catch (error) {
281
288
  return {
282
- version: baileysVersion,
289
+ version: baileys_version_json_1.version,
283
290
  isLatest: false,
284
291
  error
285
292
  };
286
293
  }
287
294
  };
288
- exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
295
+ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
289
296
  /** unique message tag prefix for MD clients */
290
297
  const generateMdTagPrefix = () => {
291
298
  const bytes = (0, crypto_1.randomBytes)(4);
@@ -293,10 +300,9 @@ const generateMdTagPrefix = () => {
293
300
  };
294
301
  exports.generateMdTagPrefix = generateMdTagPrefix;
295
302
  const STATUS_MAP = {
296
- sender: index_js_1.proto.WebMessageInfo.Status.SERVER_ACK,
297
- played: index_js_1.proto.WebMessageInfo.Status.PLAYED,
298
- read: index_js_1.proto.WebMessageInfo.Status.READ,
299
- 'read-self': index_js_1.proto.WebMessageInfo.Status.READ
303
+ 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
304
+ 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
305
+ 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
300
306
  };
301
307
  /**
302
308
  * Given a type of receipt, returns what the new status of the message should be
@@ -305,7 +311,7 @@ const STATUS_MAP = {
305
311
  const getStatusFromReceiptType = (type) => {
306
312
  const status = STATUS_MAP[type];
307
313
  if (typeof type === 'undefined') {
308
- return index_js_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
314
+ return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
309
315
  }
310
316
  return status;
311
317
  };
@@ -319,7 +325,7 @@ const CODE_MAP = {
319
325
  */
320
326
  const getErrorCodeFromStreamError = (node) => {
321
327
  const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
322
- let reason = reasonNode?.tag || 'unknown';
328
+ let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
323
329
  const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
324
330
  if (statusCode === Types_1.DisconnectReason.restartRequired) {
325
331
  reason = 'restart required';
@@ -342,8 +348,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
342
348
  status = 'timeout';
343
349
  }
344
350
  else {
345
- //fired when accepted/rejected/timeout/caller hangs up
346
- status = 'terminate';
351
+ status = 'reject';
347
352
  }
348
353
  break;
349
354
  case 'reject':
@@ -361,18 +366,16 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
361
366
  exports.getCallStatusFromNode = getCallStatusFromNode;
362
367
  const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
363
368
  const getCodeFromWSError = (error) => {
369
+ var _a, _b, _c;
364
370
  let statusCode = 500;
365
- if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
366
- const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
371
+ if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
372
+ const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
367
373
  if (!Number.isNaN(code) && code >= 400) {
368
374
  statusCode = code;
369
375
  }
370
376
  }
371
- else if (
372
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
373
- error?.code?.startsWith('E') ||
374
- error?.message?.includes('timed out')) {
375
- // handle ETIMEOUT, ENOTFOUND etc
377
+ else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
378
+ || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
376
379
  statusCode = 408;
377
380
  }
378
381
  return statusCode;
@@ -386,7 +389,6 @@ const isWABusinessPlatform = (platform) => {
386
389
  return platform === 'smbi' || platform === 'smba';
387
390
  };
388
391
  exports.isWABusinessPlatform = isWABusinessPlatform;
389
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
390
392
  function trimUndefined(obj) {
391
393
  for (const key in obj) {
392
394
  if (typeof obj[key] === 'undefined') {
@@ -395,13 +397,14 @@ function trimUndefined(obj) {
395
397
  }
396
398
  return obj;
397
399
  }
400
+ exports.trimUndefined = trimUndefined;
398
401
  const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
399
402
  function bytesToCrockford(buffer) {
400
403
  let value = 0;
401
404
  let bitCount = 0;
402
405
  const crockford = [];
403
- for (const element of buffer) {
404
- value = (value << 8) | (element & 0xff);
406
+ for (let i = 0; i < buffer.length; i++) {
407
+ value = (value << 8) | (buffer[i] & 0xff);
405
408
  bitCount += 8;
406
409
  while (bitCount >= 5) {
407
410
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -413,6 +416,8 @@ function bytesToCrockford(buffer) {
413
416
  }
414
417
  return crockford.join('');
415
418
  }
416
- function encodeNewsletterMessage(message) {
417
- return index_js_1.proto.Message.encode(message).finish();
419
+ exports.bytesToCrockford = bytesToCrockford;
420
+ const encodeNewsletterMessage = (message) => {
421
+ return WAProto_1.proto.Message.encode(message).finish()
418
422
  }
423
+ exports.encodeNewsletterMessage = encodeNewsletterMessage;
@@ -1,19 +1,15 @@
1
- import type { AxiosRequestConfig } from 'axios';
2
- import { proto } from '../../WAProto/index.js';
3
- import type { Chat, Contact } from '../Types';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { proto } from '../../WAProto';
3
+ import { Chat, Contact } from '../Types';
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
5
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
6
  chats: Chat[];
7
7
  contacts: Contact[];
8
8
  messages: proto.IWebMessageInfo[];
9
- syncType: proto.HistorySync.HistorySyncType;
10
- progress: number | null | undefined;
11
9
  };
12
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
10
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
13
11
  chats: Chat[];
14
12
  contacts: Contact[];
15
13
  messages: proto.IWebMessageInfo[];
16
- syncType: proto.HistorySync.HistorySyncType;
17
- progress: number | null | undefined;
18
14
  }>;
19
15
  export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
4
4
  const util_1 = require("util");
5
5
  const zlib_1 = require("zlib");
6
- const index_js_1 = require("../../WAProto/index.js");
6
+ const WAProto_1 = require("../../WAProto");
7
7
  const Types_1 = require("../Types");
8
+ const WABinary_1 = require("../WABinary");
8
9
  const generics_1 = require("./generics");
9
10
  const messages_1 = require("./messages");
10
11
  const messages_media_1 = require("./messages-media");
@@ -18,51 +19,57 @@ const downloadHistory = async (msg, options) => {
18
19
  let buffer = Buffer.concat(bufferArray);
19
20
  // decompress buffer
20
21
  buffer = await inflatePromise(buffer);
21
- const syncData = index_js_1.proto.HistorySync.decode(buffer);
22
+ const syncData = WAProto_1.proto.HistorySync.decode(buffer);
22
23
  return syncData;
23
24
  };
24
25
  exports.downloadHistory = downloadHistory;
25
26
  const processHistoryMessage = (item) => {
27
+ var _a, _b, _c;
26
28
  const messages = [];
27
29
  const contacts = [];
28
30
  const chats = [];
29
31
  switch (item.syncType) {
30
- case index_js_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
31
- case index_js_1.proto.HistorySync.HistorySyncType.RECENT:
32
- case index_js_1.proto.HistorySync.HistorySyncType.FULL:
33
- case index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
32
+ case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
33
+ case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
34
+ case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
34
35
  for (const chat of item.conversations) {
35
- contacts.push({
36
+ contacts.push({
36
37
  id: chat.id,
37
38
  name: chat.name || undefined,
38
39
  lid: chat.lidJid || undefined,
39
- phoneNumber: chat.pnJid || undefined
40
+ jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
40
41
  });
41
42
  const msgs = chat.messages || [];
42
43
  delete chat.messages;
44
+ delete chat.archived;
45
+ delete chat.muteEndTime;
46
+ delete chat.pinned;
43
47
  for (const item of msgs) {
44
48
  const message = item.message;
45
49
  messages.push(message);
46
- if (!chat.messages?.length) {
50
+ if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
47
51
  // keep only the most recent message in the chat array
48
52
  chat.messages = [{ message }];
49
53
  }
50
54
  if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
51
55
  chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
52
56
  }
53
- if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
54
- message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
55
- message.messageStubParameters?.[0]) {
57
+ if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
58
+ || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
59
+ && ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
56
60
  contacts.push({
57
61
  id: message.key.participant || message.key.remoteJid,
58
- verifiedName: message.messageStubParameters?.[0]
62
+ verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
59
63
  });
60
64
  }
61
65
  }
66
+ if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
67
+ delete chat.readOnly;
68
+ }
62
69
  chats.push({ ...chat });
63
70
  }
64
71
  break;
65
- case index_js_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
72
+ case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
66
73
  for (const c of item.pushnames) {
67
74
  contacts.push({ id: c.id, notify: c.pushname });
68
75
  }
@@ -72,8 +79,6 @@ const processHistoryMessage = (item) => {
72
79
  chats,
73
80
  contacts,
74
81
  messages,
75
- syncType: item.syncType,
76
- progress: item.progress
77
82
  };
78
83
  };
79
84
  exports.processHistoryMessage = processHistoryMessage;
@@ -83,8 +88,9 @@ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
83
88
  };
84
89
  exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
85
90
  const getHistoryMsg = (message) => {
91
+ var _a;
86
92
  const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
87
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
93
+ const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
88
94
  return anyHistoryMsg;
89
95
  };
90
96
  exports.getHistoryMsg = getHistoryMsg;
@@ -15,5 +15,3 @@ export * from './use-multi-file-auth-state';
15
15
  export * from './link-preview';
16
16
  export * from './event-buffer';
17
17
  export * from './process-message';
18
- export * from './message-retry-manager';
19
- export * from './lidToJid-test';
@@ -31,5 +31,3 @@ __exportStar(require("./use-multi-file-auth-state"), exports);
31
31
  __exportStar(require("./link-preview"), exports);
32
32
  __exportStar(require("./event-buffer"), exports);
33
33
  __exportStar(require("./process-message"), exports);
34
- __exportStar(require("./message-retry-manager"), exports);
35
- __exportStar(require("./lidToJid-test"), exports);
@@ -1,6 +1,6 @@
1
- import type { AxiosRequestConfig } from 'axios';
2
- import type { WAMediaUploadFunction, WAUrlInfo } from '../Types';
3
- import type { ILogger } from './logger';
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { Logger } from 'pino';
3
+ import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
4
4
  export type URLGenerationOptions = {
5
5
  thumbnailWidth: number;
6
6
  fetchOpts: {
@@ -10,7 +10,7 @@ export type URLGenerationOptions = {
10
10
  headers?: AxiosRequestConfig<{}>['headers'];
11
11
  };
12
12
  uploadImage?: WAMediaUploadFunction;
13
- logger?: ILogger;
13
+ logger?: Logger;
14
14
  };
15
15
  /**
16
16
  * Given a piece of text, checks for any URL present, generates link preview for the same and returns it