@queenanya/baileys 7.5.11 → 8.1.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 (157) hide show
  1. package/package.json +13 -97
  2. package/LICENSE +0 -21
  3. package/README.md +0 -931
  4. package/WAProto/GenerateStatics.sh +0 -4
  5. package/WAProto/WAProto.proto +0 -3344
  6. package/WAProto/index.d.ts +0 -37016
  7. package/WAProto/index.js +0 -101044
  8. package/WASignalGroup/GroupProtocol.js +0 -1697
  9. package/WASignalGroup/ciphertext_message.js +0 -16
  10. package/WASignalGroup/group_cipher.js +0 -120
  11. package/WASignalGroup/group_session_builder.js +0 -46
  12. package/WASignalGroup/index.js +0 -5
  13. package/WASignalGroup/keyhelper.js +0 -21
  14. package/WASignalGroup/protobufs.js +0 -3
  15. package/WASignalGroup/queue_job.js +0 -69
  16. package/WASignalGroup/sender_chain_key.js +0 -50
  17. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  18. package/WASignalGroup/sender_key_message.js +0 -92
  19. package/WASignalGroup/sender_key_name.js +0 -70
  20. package/WASignalGroup/sender_key_record.js +0 -56
  21. package/WASignalGroup/sender_key_state.js +0 -129
  22. package/WASignalGroup/sender_message_key.js +0 -39
  23. package/lib/Defaults/baileys-version.json +0 -3
  24. package/lib/Defaults/index.d.ts +0 -53
  25. package/lib/Defaults/index.js +0 -107
  26. package/lib/Signal/libsignal.d.ts +0 -3
  27. package/lib/Signal/libsignal.js +0 -152
  28. package/lib/Socket/Client/index.d.ts +0 -2
  29. package/lib/Socket/Client/index.js +0 -18
  30. package/lib/Socket/Client/types.d.ts +0 -17
  31. package/lib/Socket/Client/types.js +0 -13
  32. package/lib/Socket/Client/websocket.d.ts +0 -12
  33. package/lib/Socket/Client/websocket.js +0 -62
  34. package/lib/Socket/business.d.ts +0 -177
  35. package/lib/Socket/business.js +0 -260
  36. package/lib/Socket/chats.d.ts +0 -91
  37. package/lib/Socket/chats.js +0 -949
  38. package/lib/Socket/groups.d.ts +0 -131
  39. package/lib/Socket/groups.js +0 -314
  40. package/lib/Socket/index.d.ts +0 -177
  41. package/lib/Socket/index.js +0 -10
  42. package/lib/Socket/messages-recv.d.ts +0 -164
  43. package/lib/Socket/messages-recv.js +0 -918
  44. package/lib/Socket/messages-send.d.ts +0 -157
  45. package/lib/Socket/messages-send.js +0 -794
  46. package/lib/Socket/newsletter.d.ts +0 -143
  47. package/lib/Socket/newsletter.js +0 -249
  48. package/lib/Socket/socket.d.ts +0 -45
  49. package/lib/Socket/socket.js +0 -616
  50. package/lib/Store/index.d.ts +0 -3
  51. package/lib/Store/index.js +0 -10
  52. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  53. package/lib/Store/make-cache-manager-store.js +0 -83
  54. package/lib/Store/make-in-memory-store.d.ts +0 -118
  55. package/lib/Store/make-in-memory-store.js +0 -420
  56. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  57. package/lib/Store/make-ordered-dictionary.js +0 -81
  58. package/lib/Store/object-repository.d.ts +0 -10
  59. package/lib/Store/object-repository.js +0 -27
  60. package/lib/Types/Auth.d.ts +0 -105
  61. package/lib/Types/Auth.js +0 -2
  62. package/lib/Types/Call.d.ts +0 -13
  63. package/lib/Types/Call.js +0 -2
  64. package/lib/Types/Chat.d.ts +0 -107
  65. package/lib/Types/Chat.js +0 -4
  66. package/lib/Types/Contact.d.ts +0 -19
  67. package/lib/Types/Contact.js +0 -2
  68. package/lib/Types/Events.d.ts +0 -199
  69. package/lib/Types/Events.js +0 -2
  70. package/lib/Types/GroupMetadata.d.ts +0 -56
  71. package/lib/Types/GroupMetadata.js +0 -2
  72. package/lib/Types/Label.d.ts +0 -46
  73. package/lib/Types/Label.js +0 -27
  74. package/lib/Types/LabelAssociation.d.ts +0 -29
  75. package/lib/Types/LabelAssociation.js +0 -9
  76. package/lib/Types/Message.d.ts +0 -280
  77. package/lib/Types/Message.js +0 -9
  78. package/lib/Types/Newsletter.d.ts +0 -79
  79. package/lib/Types/Newsletter.js +0 -18
  80. package/lib/Types/Product.d.ts +0 -78
  81. package/lib/Types/Product.js +0 -2
  82. package/lib/Types/Signal.d.ts +0 -57
  83. package/lib/Types/Signal.js +0 -2
  84. package/lib/Types/Socket.d.ts +0 -118
  85. package/lib/Types/Socket.js +0 -2
  86. package/lib/Types/State.d.ts +0 -27
  87. package/lib/Types/State.js +0 -2
  88. package/lib/Types/index.d.ts +0 -65
  89. package/lib/Types/index.js +0 -42
  90. package/lib/Utils/auth-utils.d.ts +0 -18
  91. package/lib/Utils/auth-utils.js +0 -200
  92. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  93. package/lib/Utils/baileys-event-stream.js +0 -63
  94. package/lib/Utils/business.d.ts +0 -22
  95. package/lib/Utils/business.js +0 -234
  96. package/lib/Utils/chat-utils.d.ts +0 -72
  97. package/lib/Utils/chat-utils.js +0 -745
  98. package/lib/Utils/crypto.d.ts +0 -42
  99. package/lib/Utils/crypto.js +0 -153
  100. package/lib/Utils/decode-wa-message.d.ts +0 -20
  101. package/lib/Utils/decode-wa-message.js +0 -218
  102. package/lib/Utils/event-buffer.d.ts +0 -35
  103. package/lib/Utils/event-buffer.js +0 -520
  104. package/lib/Utils/generics.d.ts +0 -119
  105. package/lib/Utils/generics.js +0 -467
  106. package/lib/Utils/history.d.ts +0 -19
  107. package/lib/Utils/history.js +0 -94
  108. package/lib/Utils/index.d.ts +0 -18
  109. package/lib/Utils/index.js +0 -34
  110. package/lib/Utils/link-preview.d.ts +0 -21
  111. package/lib/Utils/link-preview.js +0 -116
  112. package/lib/Utils/logger.d.ts +0 -2
  113. package/lib/Utils/logger.js +0 -7
  114. package/lib/Utils/lt-hash.d.ts +0 -12
  115. package/lib/Utils/lt-hash.js +0 -51
  116. package/lib/Utils/make-mutex.d.ts +0 -7
  117. package/lib/Utils/make-mutex.js +0 -44
  118. package/lib/Utils/messages-media.d.ts +0 -131
  119. package/lib/Utils/messages-media.js +0 -786
  120. package/lib/Utils/messages.d.ts +0 -78
  121. package/lib/Utils/messages.js +0 -767
  122. package/lib/Utils/noise-handler.d.ts +0 -21
  123. package/lib/Utils/noise-handler.js +0 -150
  124. package/lib/Utils/process-message.d.ts +0 -42
  125. package/lib/Utils/process-message.js +0 -355
  126. package/lib/Utils/signal.d.ts +0 -32
  127. package/lib/Utils/signal.js +0 -158
  128. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  129. package/lib/Utils/use-multi-file-auth-state.js +0 -94
  130. package/lib/Utils/use-single-file-auth-state.d.ts +0 -5
  131. package/lib/Utils/use-single-file-auth-state.js +0 -66
  132. package/lib/Utils/validate-connection.d.ts +0 -10
  133. package/lib/Utils/validate-connection.js +0 -171
  134. package/lib/WABinary/constants.d.ts +0 -27
  135. package/lib/WABinary/constants.js +0 -40
  136. package/lib/WABinary/decode.d.ts +0 -8
  137. package/lib/WABinary/decode.js +0 -254
  138. package/lib/WABinary/encode.d.ts +0 -2
  139. package/lib/WABinary/encode.js +0 -230
  140. package/lib/WABinary/generic-utils.d.ts +0 -16
  141. package/lib/WABinary/generic-utils.js +0 -110
  142. package/lib/WABinary/index.d.ts +0 -5
  143. package/lib/WABinary/index.js +0 -21
  144. package/lib/WABinary/jid-utils.d.ts +0 -31
  145. package/lib/WABinary/jid-utils.js +0 -62
  146. package/lib/WABinary/types.d.ts +0 -18
  147. package/lib/WABinary/types.js +0 -2
  148. package/lib/WAM/BinaryInfo.d.ts +0 -18
  149. package/lib/WAM/BinaryInfo.js +0 -13
  150. package/lib/WAM/constants.d.ts +0 -39
  151. package/lib/WAM/constants.js +0 -15350
  152. package/lib/WAM/encode.d.ts +0 -4
  153. package/lib/WAM/encode.js +0 -155
  154. package/lib/WAM/index.d.ts +0 -3
  155. package/lib/WAM/index.js +0 -19
  156. package/lib/index.d.ts +0 -11
  157. package/lib/index.js +0 -30
@@ -1,467 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion2 = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV3 = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
30
- const boom_1 = require("@hapi/boom");
31
- const axios_1 = __importDefault(require("axios"));
32
- const crypto_1 = require("crypto");
33
- const os_1 = require("os");
34
- const WAProto_1 = require("../../WAProto");
35
- const baileys_version_json_1 = require("../Defaults/baileys-version.json");
36
- const Types_1 = require("../Types");
37
- const WABinary_1 = require("../WABinary");
38
- /** Added Extra Browsers or Platforms*/
39
- const PLATFORM_MAP = {
40
- 'aix': 'AIX',
41
- 'darwin': 'Mac OS',
42
- 'win32': 'Windows',
43
- 'android': 'Android',
44
- 'freebsd': 'FreeBSD',
45
- 'openbsd': 'OpenBSD',
46
- 'sunos': 'Solaris'
47
- };
48
- /**
49
- const COMPANION_PLATFORM_MAP = {
50
- 'Chrome': '49',
51
- 'Edge': '50',
52
- 'Firefox': '51',
53
- 'Opera': '53',
54
- 'Safari': '54'
55
- }
56
- */
57
- exports.Browsers = {
58
- ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
59
- macOS: (browser) => ['Mac OS', browser, '14.4.1'],
60
- baileys: (browser) => ['Baileys', browser, '6.5.0'],
61
- windows: (browser) => ['Windows', browser, '10.0.22631'],
62
- /** The appropriate browser based on your OS & release */
63
- appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
64
- };
65
- /** Other Browser Support for Paircode */
66
- const getPlatformId = (browser) => {
67
- const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
68
- return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
69
- };
70
- exports.getPlatformId = getPlatformId;
71
- exports.BufferJSON = {
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- replacer: (k, value) => {
74
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
75
- return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
76
- }
77
- return value;
78
- },
79
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
- reviver: (_, value) => {
81
- if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
82
- const val = value.data || value.value;
83
- return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
84
- }
85
- return value;
86
- }
87
- };
88
- 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)) || '');
89
- exports.getKeyAuthor = getKeyAuthor;
90
- const writeRandomPadMax16 = (msg) => {
91
- const pad = (0, crypto_1.randomBytes)(1);
92
- pad[0] &= 0xf;
93
- if (!pad[0]) {
94
- pad[0] = 0xf;
95
- }
96
- return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
97
- };
98
- exports.writeRandomPadMax16 = writeRandomPadMax16;
99
- const unpadRandomMax16 = (e) => {
100
- const t = new Uint8Array(e);
101
- if (0 === t.length) {
102
- throw new Error('unpadPkcs7 given empty bytes');
103
- }
104
- var r = t[t.length - 1];
105
- if (r > t.length) {
106
- throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
107
- }
108
- return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
109
- };
110
- exports.unpadRandomMax16 = unpadRandomMax16;
111
- const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
112
- exports.encodeWAMessage = encodeWAMessage;
113
- const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
114
- exports.encodeNewsletterMessage = encodeNewsletterMessage;
115
- const generateRegistrationId = () => {
116
- return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
117
- };
118
- exports.generateRegistrationId = generateRegistrationId;
119
- const encodeBigEndian = (e, t = 4) => {
120
- let r = e;
121
- const a = new Uint8Array(t);
122
- for (let i = t - 1; i >= 0; i--) {
123
- a[i] = 255 & r;
124
- r >>>= 8;
125
- }
126
- return a;
127
- };
128
- exports.encodeBigEndian = encodeBigEndian;
129
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
130
- exports.toNumber = toNumber;
131
- /** unix timestamp of a date in seconds */
132
- const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
133
- exports.unixTimestampSeconds = unixTimestampSeconds;
134
- const debouncedTimeout = (intervalMs = 1000, task) => {
135
- let timeout;
136
- return {
137
- start: (newIntervalMs, newTask) => {
138
- task = newTask || task;
139
- intervalMs = newIntervalMs || intervalMs;
140
- timeout && clearTimeout(timeout);
141
- timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
142
- },
143
- cancel: () => {
144
- timeout && clearTimeout(timeout);
145
- timeout = undefined;
146
- },
147
- setTask: (newTask) => task = newTask,
148
- setInterval: (newInterval) => intervalMs = newInterval
149
- };
150
- };
151
- exports.debouncedTimeout = debouncedTimeout;
152
- const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
153
- exports.delay = delay;
154
- const delayCancellable = (ms) => {
155
- const stack = new Error().stack;
156
- let timeout;
157
- let reject;
158
- const delay = new Promise((resolve, _reject) => {
159
- timeout = setTimeout(resolve, ms);
160
- reject = _reject;
161
- });
162
- const cancel = () => {
163
- clearTimeout(timeout);
164
- reject(new boom_1.Boom('Cancelled', {
165
- statusCode: 500,
166
- data: {
167
- stack
168
- }
169
- }));
170
- };
171
- return { delay, cancel };
172
- };
173
- exports.delayCancellable = delayCancellable;
174
- async function promiseTimeout(ms, promise) {
175
- if (!ms) {
176
- return new Promise(promise);
177
- }
178
- const stack = new Error().stack;
179
- // Create a promise that rejects in <ms> milliseconds
180
- const { delay, cancel } = (0, exports.delayCancellable)(ms);
181
- const p = new Promise((resolve, reject) => {
182
- delay
183
- .then(() => reject(new boom_1.Boom('Timed Out', {
184
- statusCode: Types_1.DisconnectReason.timedOut,
185
- data: {
186
- stack
187
- }
188
- })))
189
- .catch(err => reject(err));
190
- promise(resolve, reject);
191
- })
192
- .finally(cancel);
193
- return p;
194
- }
195
- exports.promiseTimeout = promiseTimeout;
196
- //Useless but still keep this to avoid unexpected errors and bugs
197
- const generateMessageIDV2 = (userId) => {
198
- const data = Buffer.alloc(8 + 20 + 16);
199
- data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
200
- if (userId) {
201
- const id = (0, WABinary_1.jidDecode)(userId);
202
- if (id === null || id === void 0 ? void 0 : id.user) {
203
- data.write(id.user, 8);
204
- data.write('@c.us', 8 + id.user.length);
205
- }
206
- }
207
- const random = (0, crypto_1.randomBytes)(16);
208
- random.copy(data, 28);
209
- const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
210
- return 'ANYAWEB' + hash.toString('hex').toUpperCase().substring(0, 18);
211
- };
212
- exports.generateMessageIDV2 = generateMessageIDV2;
213
- //Message ID function for Anya_Baileyz
214
- //This V3 is RollBack Update Of Old Message ID
215
- const generateMessageIDV3 = (userId) => {
216
- let swebfix = 'ANYAWEB';
217
- let swebRandom = (0, crypto_1.randomBytes)(5).toString('hex').toUpperCase().substring(0, 10);
218
- return swebfix + swebRandom;
219
- };
220
- exports.generateMessageIDV3 = generateMessageIDV3;
221
- // generate a random ID to attach to a message
222
- const generateMessageID = () => 'ANYAWEB' + (0, crypto_1.randomBytes)(10).toString('hex').toUpperCase();
223
- exports.generateMessageID = generateMessageID;
224
- function bindWaitForEvent(ev, event) {
225
- return async (check, timeoutMs) => {
226
- let listener;
227
- let closeListener;
228
- await (promiseTimeout(timeoutMs, (resolve, reject) => {
229
- closeListener = ({ connection, lastDisconnect }) => {
230
- if (connection === 'close') {
231
- reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
232
- || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
233
- }
234
- };
235
- ev.on('connection.update', closeListener);
236
- listener = (update) => {
237
- if (check(update)) {
238
- resolve();
239
- }
240
- };
241
- ev.on(event, listener);
242
- })
243
- .finally(() => {
244
- ev.off(event, listener);
245
- ev.off('connection.update', closeListener);
246
- }));
247
- };
248
- }
249
- exports.bindWaitForEvent = bindWaitForEvent;
250
- const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
251
- exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
252
- const printQRIfNecessaryListener = (ev, logger) => {
253
- ev.on('connection.update', async ({ qr }) => {
254
- if (qr) {
255
- const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
256
- .catch(() => {
257
- logger.error('QR code terminal not added as dependency');
258
- });
259
- QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
260
- }
261
- });
262
- };
263
- exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
264
- /**
265
- * utility that fetches latest baileys version from the main branch.
266
- * Use to ensure your WA connection is always on the latest version
267
- */
268
- const fetchLatestBaileysVersion = async (options = {}) => {
269
- try {
270
- const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
271
- ...options,
272
- responseType: 'json'
273
- });
274
- const version = result.data.currentVersion.split('.');
275
- const version2 = version[2].replace('-alpha', '');
276
- return {
277
- version: [+version[0], +version[1], +version2],
278
- isLatest: true
279
- };
280
- }
281
- catch (error) {
282
- return {
283
- version: baileys_version_json_1.version,
284
- isLatest: false,
285
- error
286
- };
287
- }
288
- };
289
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
290
- /**
291
- * utility that fetches latest baileys version from the master branch.
292
- * Use to ensure your WA connection is always on the latest version
293
- */
294
- const fetchLatestBaileysVersion2 = async (options = {}) => {
295
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
296
- try {
297
- const result = await axios_1.default.get(URL, {
298
- ...options,
299
- responseType: 'json'
300
- });
301
- return {
302
- version: result.data.version,
303
- isLatest: true
304
- };
305
- }
306
- catch (error) {
307
- return {
308
- version: baileys_version_json_1.version,
309
- isLatest: false,
310
- error
311
- };
312
- }
313
- };
314
- exports.fetchLatestBaileysVersion2 = fetchLatestBaileysVersion2;
315
- /**
316
- * A utility that fetches the latest web version of whatsapp.
317
- * Use to ensure your WA connection is always on the latest version
318
- */
319
- const fetchLatestWaWebVersion = async (options) => {
320
- try {
321
- const result = await axios_1.default.get('https://web.whatsapp.com/check-update?version=1&platform=web', {
322
- ...options,
323
- responseType: 'json'
324
- });
325
- const version = result.data.currentVersion.split('.');
326
- return {
327
- version: [+version[0], +version[1], +version[2]],
328
- isLatest: true
329
- };
330
- }
331
- catch (error) {
332
- return {
333
- version: baileys_version_json_1.version,
334
- isLatest: false,
335
- error
336
- };
337
- }
338
- };
339
- exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
340
- /** unique message tag prefix for MD clients */
341
- const generateMdTagPrefix = () => {
342
- const bytes = (0, crypto_1.randomBytes)(4);
343
- return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
344
- };
345
- exports.generateMdTagPrefix = generateMdTagPrefix;
346
- const STATUS_MAP = {
347
- 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
348
- 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
349
- 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
350
- };
351
- /**
352
- * Given a type of receipt, returns what the new status of the message should be
353
- * @param type type from receipt
354
- */
355
- const getStatusFromReceiptType = (type) => {
356
- const status = STATUS_MAP[type];
357
- if (typeof type === 'undefined') {
358
- return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
359
- }
360
- return status;
361
- };
362
- exports.getStatusFromReceiptType = getStatusFromReceiptType;
363
- const CODE_MAP = {
364
- conflict: Types_1.DisconnectReason.connectionReplaced
365
- };
366
- /**
367
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
368
- * @param reason the string reason given, eg. "conflict"
369
- */
370
- const getErrorCodeFromStreamError = (node) => {
371
- const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
372
- let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
373
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
374
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
375
- reason = 'restart required';
376
- }
377
- return {
378
- reason,
379
- statusCode
380
- };
381
- };
382
- exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
383
- const getCallStatusFromNode = ({ tag, attrs }) => {
384
- let status;
385
- switch (tag) {
386
- case 'offer':
387
- case 'offer_notice':
388
- status = 'offer';
389
- break;
390
- case 'terminate':
391
- if (attrs.reason === 'timeout') {
392
- status = 'timeout';
393
- }
394
- else {
395
- //fired when accepted/rejected/timeout/caller hangs up
396
- status = 'terminate';
397
- }
398
- break;
399
- case 'reject':
400
- status = 'reject';
401
- break;
402
- case 'accept':
403
- status = 'accept';
404
- break;
405
- default:
406
- status = 'ringing';
407
- break;
408
- }
409
- return status;
410
- };
411
- exports.getCallStatusFromNode = getCallStatusFromNode;
412
- const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
413
- const getCodeFromWSError = (error) => {
414
- var _a, _b, _c;
415
- let statusCode = 500;
416
- if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
417
- const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
418
- if (!Number.isNaN(code) && code >= 400) {
419
- statusCode = code;
420
- }
421
- }
422
- else if (
423
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
424
- ((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
425
- || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
426
- statusCode = 408;
427
- }
428
- return statusCode;
429
- };
430
- exports.getCodeFromWSError = getCodeFromWSError;
431
- /**
432
- * Is the given platform WA business
433
- * @param platform AuthenticationCreds.platform
434
- */
435
- const isWABusinessPlatform = (platform) => {
436
- return platform === 'smbi' || platform === 'smba';
437
- };
438
- exports.isWABusinessPlatform = isWABusinessPlatform;
439
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
440
- function trimUndefined(obj) {
441
- for (const key in obj) {
442
- if (typeof obj[key] === 'undefined') {
443
- delete obj[key];
444
- }
445
- }
446
- return obj;
447
- }
448
- exports.trimUndefined = trimUndefined;
449
- const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
450
- function bytesToCrockford(buffer) {
451
- let value = 0;
452
- let bitCount = 0;
453
- const crockford = [];
454
- for (const element of buffer) {
455
- value = (value << 8) | (element & 0xff);
456
- bitCount += 8;
457
- while (bitCount >= 5) {
458
- crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
459
- bitCount -= 5;
460
- }
461
- }
462
- if (bitCount > 0) {
463
- crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
464
- }
465
- return crockford.join('');
466
- }
467
- exports.bytesToCrockford = bytesToCrockford;
@@ -1,19 +0,0 @@
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<{}>) => Promise<proto.HistorySync>;
5
- export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
- chats: Chat[];
7
- contacts: Contact[];
8
- messages: proto.IWebMessageInfo[];
9
- syncType: proto.HistorySync.HistorySyncType;
10
- progress: number | null | undefined;
11
- };
12
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
13
- chats: Chat[];
14
- contacts: Contact[];
15
- messages: proto.IWebMessageInfo[];
16
- syncType: proto.HistorySync.HistorySyncType;
17
- progress: number | null | undefined;
18
- }>;
19
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -1,94 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
4
- const util_1 = require("util");
5
- const zlib_1 = require("zlib");
6
- const WAProto_1 = require("../../WAProto");
7
- const Types_1 = require("../Types");
8
- const WABinary_1 = require("../WABinary");
9
- const generics_1 = require("./generics");
10
- const messages_1 = require("./messages");
11
- const messages_media_1 = require("./messages-media");
12
- const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
13
- const downloadHistory = async (msg, options) => {
14
- const stream = await (0, messages_media_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
15
- const bufferArray = [];
16
- for await (const chunk of stream) {
17
- bufferArray.push(chunk);
18
- }
19
- let buffer = Buffer.concat(bufferArray);
20
- // decompress buffer
21
- buffer = await inflatePromise(buffer);
22
- const syncData = WAProto_1.proto.HistorySync.decode(buffer);
23
- return syncData;
24
- };
25
- exports.downloadHistory = downloadHistory;
26
- const processHistoryMessage = (item) => {
27
- var _a, _b, _c;
28
- const messages = [];
29
- const contacts = [];
30
- const chats = [];
31
- switch (item.syncType) {
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:
35
- case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
36
- for (const chat of item.conversations) {
37
- contacts.push({ id: chat.id, name: chat.name || undefined });
38
- const msgs = chat.messages || [];
39
- delete chat.messages;
40
- delete chat.archived;
41
- delete chat.muteEndTime;
42
- delete chat.pinned;
43
- for (const item of msgs) {
44
- const message = item.message;
45
- messages.push(message);
46
- if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
47
- // keep only the most recent message in the chat array
48
- chat.messages = [{ message }];
49
- }
50
- if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
51
- chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
52
- }
53
- if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
54
- || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
55
- && ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
56
- contacts.push({
57
- id: message.key.participant || message.key.remoteJid,
58
- verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
59
- });
60
- }
61
- }
62
- if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
63
- delete chat.readOnly;
64
- }
65
- chats.push({ ...chat });
66
- }
67
- break;
68
- case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
69
- for (const c of item.pushnames) {
70
- contacts.push({ id: c.id, notify: c.pushname });
71
- }
72
- break;
73
- }
74
- return {
75
- chats,
76
- contacts,
77
- messages,
78
- syncType: item.syncType,
79
- progress: item.progress
80
- };
81
- };
82
- exports.processHistoryMessage = processHistoryMessage;
83
- const downloadAndProcessHistorySyncNotification = async (msg, options) => {
84
- const historyMsg = await (0, exports.downloadHistory)(msg, options);
85
- return (0, exports.processHistoryMessage)(historyMsg);
86
- };
87
- exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
88
- const getHistoryMsg = (message) => {
89
- var _a;
90
- const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
91
- const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
92
- return anyHistoryMsg;
93
- };
94
- exports.getHistoryMsg = getHistoryMsg;
@@ -1,18 +0,0 @@
1
- export * from './generics';
2
- export * from './decode-wa-message';
3
- export * from './messages';
4
- export * from './messages-media';
5
- export * from './validate-connection';
6
- export * from './crypto';
7
- export * from './signal';
8
- export * from './noise-handler';
9
- export * from './history';
10
- export * from './chat-utils';
11
- export * from './lt-hash';
12
- export * from './auth-utils';
13
- export * from './baileys-event-stream';
14
- export * from './use-single-file-auth-state';
15
- export * from './use-multi-file-auth-state';
16
- export * from './link-preview';
17
- export * from './event-buffer';
18
- export * from './process-message';
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./generics"), exports);
18
- __exportStar(require("./decode-wa-message"), exports);
19
- __exportStar(require("./messages"), exports);
20
- __exportStar(require("./messages-media"), exports);
21
- __exportStar(require("./validate-connection"), exports);
22
- __exportStar(require("./crypto"), exports);
23
- __exportStar(require("./signal"), exports);
24
- __exportStar(require("./noise-handler"), exports);
25
- __exportStar(require("./history"), exports);
26
- __exportStar(require("./chat-utils"), exports);
27
- __exportStar(require("./lt-hash"), exports);
28
- __exportStar(require("./auth-utils"), exports);
29
- __exportStar(require("./baileys-event-stream"), exports);
30
- __exportStar(require("./use-single-file-auth-state"), exports);
31
- __exportStar(require("./use-multi-file-auth-state"), exports);
32
- __exportStar(require("./link-preview"), exports);
33
- __exportStar(require("./event-buffer"), exports);
34
- __exportStar(require("./process-message"), exports);
@@ -1,21 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { Logger } from 'pino';
3
- import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
4
- export type URLGenerationOptions = {
5
- thumbnailWidth: number;
6
- fetchOpts: {
7
- /** Timeout in ms */
8
- timeout: number;
9
- proxyUrl?: string;
10
- headers?: AxiosRequestConfig<{}>['headers'];
11
- };
12
- uploadImage?: WAMediaUploadFunction;
13
- logger?: Logger;
14
- };
15
- /**
16
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
17
- * Return undefined if the fetch failed or no URL was found
18
- * @param text first matched URL in text
19
- * @returns the URL info required to generate link preview
20
- */
21
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;