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