lordceaser-baileys 2.0.11 → 2.0.13

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