@vinzsocket/baileys 2.8.10 → 2.8.30

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 (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -2
@@ -1,5 +1,5 @@
1
1
  import { Boom } from '@hapi/boom';
2
- import axios, {} from 'axios';
2
+ import axios from 'axios';
3
3
  import { createHash, randomBytes } from 'crypto';
4
4
  import { platform, release } from 'os';
5
5
  import { proto } from '../../WAProto/index.js';
@@ -7,371 +7,382 @@ const baileysVersion = [2, 3000, 1023223821];
7
7
  import { DisconnectReason } from '../Types/index.js';
8
8
  import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
9
9
  const PLATFORM_MAP = {
10
- aix: 'AIX',
11
- darwin: 'Mac OS',
12
- win32: 'Windows',
13
- android: 'Android',
14
- freebsd: 'FreeBSD',
15
- openbsd: 'OpenBSD',
16
- sunos: 'Solaris',
17
- linux: undefined,
18
- haiku: undefined,
19
- cygwin: undefined,
20
- netbsd: undefined
10
+ aix: 'AIX',
11
+ darwin: 'Mac OS',
12
+ win32: 'Windows',
13
+ android: 'Android',
14
+ freebsd: 'FreeBSD',
15
+ openbsd: 'OpenBSD',
16
+ sunos: 'Solaris',
17
+ linux: undefined,
18
+ haiku: undefined,
19
+ cygwin: undefined,
20
+ netbsd: undefined
21
21
  };
22
22
  export const Browsers = {
23
- ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
24
- macOS: browser => ['Mac OS', browser, '14.4.1'],
25
- baileys: browser => ['Baileys', browser, '6.5.0'],
26
- windows: browser => ['Windows', browser, '10.0.22631'],
27
- /** The appropriate browser based on your OS & release */
28
- appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
23
+ ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
24
+ macOS: browser => ['Mac OS', browser, '14.4.1'],
25
+ baileys: browser => ['Baileys', browser, '6.5.0'],
26
+ windows: browser => ['Windows', browser, '10.0.22631'],
27
+ /** The appropriate browser based on your OS & release */
28
+ appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
29
29
  };
30
- export const getPlatformId = (browser) => {
31
- const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
32
- return platformType ? platformType.toString() : '1'; //chrome
30
+ export const getPlatformId = browser => {
31
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
32
+ return platformType ? platformType.toString() : '1'; //chrome
33
33
  };
34
34
  export const BufferJSON = {
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- replacer: (k, value) => {
37
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
38
- return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
39
- }
40
- return value;
41
- },
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- reviver: (_, value) => {
44
- if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
45
- const val = value.data || value.value;
46
- return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
47
- }
48
- return value;
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ replacer: (k, value) => {
37
+ if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
38
+ return {
39
+ type: 'Buffer',
40
+ data: Buffer.from(value?.data || value).toString('base64')
41
+ };
49
42
  }
43
+ return value;
44
+ },
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ reviver: (_, value) => {
47
+ if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
48
+ const val = value.data || value.value;
49
+ return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
50
+ }
51
+ return value;
52
+ }
50
53
  };
51
54
  export const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participant || key?.remoteJid) || '';
52
- export const writeRandomPadMax16 = (msg) => {
53
- const pad = randomBytes(1);
54
- const padLength = (pad[0] & 0x0f) + 1;
55
- return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
55
+ export const writeRandomPadMax16 = msg => {
56
+ const pad = randomBytes(1);
57
+ const padLength = (pad[0] & 0x0f) + 1;
58
+ return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
56
59
  };
57
- export const unpadRandomMax16 = (e) => {
58
- const t = new Uint8Array(e);
59
- if (0 === t.length) {
60
- throw new Error('unpadPkcs7 given empty bytes');
61
- }
62
- var r = t[t.length - 1];
63
- if (r > t.length) {
64
- throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
65
- }
66
- return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
60
+ export const unpadRandomMax16 = e => {
61
+ const t = new Uint8Array(e);
62
+ if (0 === t.length) {
63
+ throw new Error('unpadPkcs7 given empty bytes');
64
+ }
65
+ var r = t[t.length - 1];
66
+ if (r > t.length) {
67
+ throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
68
+ }
69
+ return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
67
70
  };
68
- export const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
71
+ export const encodeWAMessage = message => writeRandomPadMax16(proto.Message.encode(message).finish());
69
72
  export const generateRegistrationId = () => {
70
- return Uint16Array.from(randomBytes(2))[0] & 16383;
73
+ return Uint16Array.from(randomBytes(2))[0] & 16383;
71
74
  };
72
75
  export const encodeBigEndian = (e, t = 4) => {
73
- let r = e;
74
- const a = new Uint8Array(t);
75
- for (let i = t - 1; i >= 0; i--) {
76
- a[i] = 255 & r;
77
- r >>>= 8;
78
- }
79
- return a;
76
+ let r = e;
77
+ const a = new Uint8Array(t);
78
+ for (let i = t - 1; i >= 0; i--) {
79
+ a[i] = 255 & r;
80
+ r >>>= 8;
81
+ }
82
+ return a;
80
83
  };
81
- export const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
84
+ export const toNumber = t => typeof t === 'object' && t ? 'toNumber' in t ? t.toNumber() : t.low : t || 0;
82
85
  /** unix timestamp of a date in seconds */
83
86
  export const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
84
87
  export const debouncedTimeout = (intervalMs = 1000, task) => {
85
- let timeout;
86
- return {
87
- start: (newIntervalMs, newTask) => {
88
- task = newTask || task;
89
- intervalMs = newIntervalMs || intervalMs;
90
- timeout && clearTimeout(timeout);
91
- timeout = setTimeout(() => task?.(), intervalMs);
92
- },
93
- cancel: () => {
94
- timeout && clearTimeout(timeout);
95
- timeout = undefined;
96
- },
97
- setTask: (newTask) => (task = newTask),
98
- setInterval: (newInterval) => (intervalMs = newInterval)
99
- };
88
+ let timeout;
89
+ return {
90
+ start: (newIntervalMs, newTask) => {
91
+ task = newTask || task;
92
+ intervalMs = newIntervalMs || intervalMs;
93
+ timeout && clearTimeout(timeout);
94
+ timeout = setTimeout(() => task?.(), intervalMs);
95
+ },
96
+ cancel: () => {
97
+ timeout && clearTimeout(timeout);
98
+ timeout = undefined;
99
+ },
100
+ setTask: newTask => task = newTask,
101
+ setInterval: newInterval => intervalMs = newInterval
102
+ };
100
103
  };
101
- export const delay = (ms) => delayCancellable(ms).delay;
102
- export const delayCancellable = (ms) => {
103
- const stack = new Error().stack;
104
- let timeout;
105
- let reject;
106
- const delay = new Promise((resolve, _reject) => {
107
- timeout = setTimeout(resolve, ms);
108
- reject = _reject;
109
- });
110
- const cancel = () => {
111
- clearTimeout(timeout);
112
- reject(new Boom('Cancelled', {
113
- statusCode: 500,
114
- data: {
115
- stack
116
- }
117
- }));
118
- };
119
- return { delay, cancel };
104
+ export const delay = ms => delayCancellable(ms).delay;
105
+ export const delayCancellable = ms => {
106
+ const stack = new Error().stack;
107
+ let timeout;
108
+ let reject;
109
+ const delay = new Promise((resolve, _reject) => {
110
+ timeout = setTimeout(resolve, ms);
111
+ reject = _reject;
112
+ });
113
+ const cancel = () => {
114
+ clearTimeout(timeout);
115
+ reject(new Boom('Cancelled', {
116
+ statusCode: 500,
117
+ data: {
118
+ stack
119
+ }
120
+ }));
121
+ };
122
+ return {
123
+ delay,
124
+ cancel
125
+ };
120
126
  };
121
127
  export async function promiseTimeout(ms, promise) {
122
- if (!ms) {
123
- return new Promise(promise);
124
- }
125
- const stack = new Error().stack;
126
- // Create a promise that rejects in <ms> milliseconds
127
- const { delay, cancel } = delayCancellable(ms);
128
- const p = new Promise((resolve, reject) => {
129
- delay
130
- .then(() => reject(new Boom('Timed Out', {
131
- statusCode: DisconnectReason.timedOut,
132
- data: {
133
- stack
134
- }
135
- })))
136
- .catch(err => reject(err));
137
- promise(resolve, reject);
138
- }).finally(cancel);
139
- return p;
128
+ if (!ms) {
129
+ return new Promise(promise);
130
+ }
131
+ const stack = new Error().stack;
132
+ // Create a promise that rejects in <ms> milliseconds
133
+ const {
134
+ delay,
135
+ cancel
136
+ } = delayCancellable(ms);
137
+ const p = new Promise((resolve, reject) => {
138
+ delay.then(() => reject(new Boom('Timed Out', {
139
+ statusCode: DisconnectReason.timedOut,
140
+ data: {
141
+ stack
142
+ }
143
+ }))).catch(err => reject(err));
144
+ promise(resolve, reject);
145
+ }).finally(cancel);
146
+ return p;
140
147
  }
141
148
  // inspired from whatsmeow code
142
149
  // https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
143
- export const generateMessageIDV2 = (userId) => {
144
- const data = Buffer.alloc(8 + 20 + 16);
145
- data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
146
- if (userId) {
147
- const id = jidDecode(userId);
148
- if (id?.user) {
149
- data.write(id.user, 8);
150
- data.write('@c.us', 8 + id.user.length);
151
- }
150
+ export const generateMessageIDV2 = userId => {
151
+ const data = Buffer.alloc(8 + 20 + 16);
152
+ data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
153
+ if (userId) {
154
+ const id = jidDecode(userId);
155
+ if (id?.user) {
156
+ data.write(id.user, 8);
157
+ data.write('@c.us', 8 + id.user.length);
152
158
  }
153
- const random = randomBytes(16);
154
- random.copy(data, 28);
155
- const hash = createHash('sha256').update(data).digest();
156
- return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
159
+ }
160
+ const random = randomBytes(16);
161
+ random.copy(data, 28);
162
+ const hash = createHash('sha256').update(data).digest();
163
+ return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
157
164
  };
158
165
  // generate a random ID to attach to a message
159
166
  export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').toUpperCase();
160
167
  export function bindWaitForEvent(ev, event) {
161
- return async (check, timeoutMs) => {
162
- let listener;
163
- let closeListener;
164
- await promiseTimeout(timeoutMs, (resolve, reject) => {
165
- closeListener = ({ connection, lastDisconnect }) => {
166
- if (connection === 'close') {
167
- reject(lastDisconnect?.error || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }));
168
- }
169
- };
170
- ev.on('connection.update', closeListener);
171
- listener = async (update) => {
172
- if (await check(update)) {
173
- resolve();
174
- }
175
- };
176
- ev.on(event, listener);
177
- }).finally(() => {
178
- ev.off(event, listener);
179
- ev.off('connection.update', closeListener);
180
- });
181
- };
168
+ return async (check, timeoutMs) => {
169
+ let listener;
170
+ let closeListener;
171
+ await promiseTimeout(timeoutMs, (resolve, reject) => {
172
+ closeListener = ({
173
+ connection,
174
+ lastDisconnect
175
+ }) => {
176
+ if (connection === 'close') {
177
+ reject(lastDisconnect?.error || new Boom('Connection Closed', {
178
+ statusCode: DisconnectReason.connectionClosed
179
+ }));
180
+ }
181
+ };
182
+ ev.on('connection.update', closeListener);
183
+ listener = async update => {
184
+ if (await check(update)) {
185
+ resolve();
186
+ }
187
+ };
188
+ ev.on(event, listener);
189
+ }).finally(() => {
190
+ ev.off(event, listener);
191
+ ev.off('connection.update', closeListener);
192
+ });
193
+ };
182
194
  }
183
- export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
195
+ export const bindWaitForConnectionUpdate = ev => bindWaitForEvent(ev, 'connection.update');
184
196
  /**
185
197
  * utility that fetches latest baileys version from the master branch.
186
198
  * Use to ensure your WA connection is always on the latest version
187
199
  */
188
200
  export const fetchLatestBaileysVersion = async (options = {}) => {
189
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
190
- try {
191
- const result = await axios.get(URL, {
192
- ...options,
193
- responseType: 'text'
194
- });
195
- // Extract version from line 7 (const version = [...])
196
- const lines = result.data.split('\n');
197
- const versionLine = lines[6]; // Line 7 (0-indexed)
198
- const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
199
- if (versionMatch) {
200
- const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
201
- return {
202
- version,
203
- isLatest: true
204
- };
205
- }
206
- else {
207
- throw new Error('Could not parse version from Defaults/index.ts');
208
- }
209
- }
210
- catch (error) {
211
- return {
212
- version: baileysVersion,
213
- isLatest: false,
214
- error
215
- };
201
+ const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
202
+ try {
203
+ const result = await axios.get(URL, {
204
+ ...options,
205
+ responseType: 'text'
206
+ });
207
+ // Extract version from line 7 (const version = [...])
208
+ const lines = result.data.split('\n');
209
+ const versionLine = lines[6]; // Line 7 (0-indexed)
210
+ const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
211
+ if (versionMatch) {
212
+ const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
213
+ return {
214
+ version,
215
+ isLatest: true
216
+ };
217
+ } else {
218
+ throw new Error('Could not parse version from Defaults/index.ts');
216
219
  }
220
+ } catch (error) {
221
+ return {
222
+ version: baileysVersion,
223
+ isLatest: false,
224
+ error
225
+ };
226
+ }
217
227
  };
218
228
  /**
219
229
  * A utility that fetches the latest web version of whatsapp.
220
230
  * Use to ensure your WA connection is always on the latest version
221
231
  */
222
- export const fetchLatestWaWebVersion = async (options) => {
223
- try {
224
- const { data } = await axios.get('https://web.whatsapp.com/sw.js', {
225
- ...options,
226
- responseType: 'json'
227
- });
228
- const regex = /\\?"client_revision\\?":\s*(\d+)/;
229
- const match = data.match(regex);
230
- if (!match?.[1]) {
231
- return {
232
- version: baileysVersion,
233
- isLatest: false,
234
- error: {
235
- message: 'Could not find client revision in the fetched content'
236
- }
237
- };
232
+ export const fetchLatestWaWebVersion = async options => {
233
+ try {
234
+ const {
235
+ data
236
+ } = await axios.get('https://web.whatsapp.com/sw.js', {
237
+ ...options,
238
+ responseType: 'json'
239
+ });
240
+ const regex = /\\?"client_revision\\?":\s*(\d+)/;
241
+ const match = data.match(regex);
242
+ if (!match?.[1]) {
243
+ return {
244
+ version: baileysVersion,
245
+ isLatest: false,
246
+ error: {
247
+ message: 'Could not find client revision in the fetched content'
238
248
  }
239
- const clientRevision = match[1];
240
- return {
241
- version: [2, 3000, +clientRevision],
242
- isLatest: true
243
- };
244
- }
245
- catch (error) {
246
- return {
247
- version: baileysVersion,
248
- isLatest: false,
249
- error
250
- };
249
+ };
251
250
  }
251
+ const clientRevision = match[1];
252
+ return {
253
+ version: [2, 3000, +clientRevision],
254
+ isLatest: true
255
+ };
256
+ } catch (error) {
257
+ return {
258
+ version: baileysVersion,
259
+ isLatest: false,
260
+ error
261
+ };
262
+ }
252
263
  };
253
264
  /** unique message tag prefix for MD clients */
254
265
  export const generateMdTagPrefix = () => {
255
- const bytes = randomBytes(4);
256
- return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
266
+ const bytes = randomBytes(4);
267
+ return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
257
268
  };
258
269
  const STATUS_MAP = {
259
- sender: proto.WebMessageInfo.Status.SERVER_ACK,
260
- played: proto.WebMessageInfo.Status.PLAYED,
261
- read: proto.WebMessageInfo.Status.READ,
262
- 'read-self': proto.WebMessageInfo.Status.READ
270
+ sender: proto.WebMessageInfo.Status.SERVER_ACK,
271
+ played: proto.WebMessageInfo.Status.PLAYED,
272
+ read: proto.WebMessageInfo.Status.READ,
273
+ 'read-self': proto.WebMessageInfo.Status.READ
263
274
  };
264
275
  /**
265
276
  * Given a type of receipt, returns what the new status of the message should be
266
277
  * @param type type from receipt
267
278
  */
268
- export const getStatusFromReceiptType = (type) => {
269
- const status = STATUS_MAP[type];
270
- if (typeof type === 'undefined') {
271
- return proto.WebMessageInfo.Status.DELIVERY_ACK;
272
- }
273
- return status;
279
+ export const getStatusFromReceiptType = type => {
280
+ const status = STATUS_MAP[type];
281
+ if (typeof type === 'undefined') {
282
+ return proto.WebMessageInfo.Status.DELIVERY_ACK;
283
+ }
284
+ return status;
274
285
  };
275
286
  const CODE_MAP = {
276
- conflict: DisconnectReason.connectionReplaced
287
+ conflict: DisconnectReason.connectionReplaced
277
288
  };
278
289
  /**
279
290
  * Stream errors generally provide a reason, map that to a baileys DisconnectReason
280
291
  * @param reason the string reason given, eg. "conflict"
281
292
  */
282
- export const getErrorCodeFromStreamError = (node) => {
283
- const [reasonNode] = getAllBinaryNodeChildren(node);
284
- let reason = reasonNode?.tag || 'unknown';
285
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
286
- if (statusCode === DisconnectReason.restartRequired) {
287
- reason = 'restart required';
288
- }
289
- return {
290
- reason,
291
- statusCode
292
- };
293
+ export const getErrorCodeFromStreamError = node => {
294
+ const [reasonNode] = getAllBinaryNodeChildren(node);
295
+ let reason = reasonNode?.tag || 'unknown';
296
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
297
+ if (statusCode === DisconnectReason.restartRequired) {
298
+ reason = 'restart required';
299
+ }
300
+ return {
301
+ reason,
302
+ statusCode
303
+ };
293
304
  };
294
- export const getCallStatusFromNode = ({ tag, attrs }) => {
295
- let status;
296
- switch (tag) {
297
- case 'offer':
298
- case 'offer_notice':
299
- status = 'offer';
300
- break;
301
- case 'terminate':
302
- if (attrs.reason === 'timeout') {
303
- status = 'timeout';
304
- }
305
- else {
306
- //fired when accepted/rejected/timeout/caller hangs up
307
- status = 'terminate';
308
- }
309
- break;
310
- case 'reject':
311
- status = 'reject';
312
- break;
313
- case 'accept':
314
- status = 'accept';
315
- break;
316
- default:
317
- status = 'ringing';
318
- break;
319
- }
320
- return status;
305
+ export const getCallStatusFromNode = ({
306
+ tag,
307
+ attrs
308
+ }) => {
309
+ let status;
310
+ switch (tag) {
311
+ case 'offer':
312
+ case 'offer_notice':
313
+ status = 'offer';
314
+ break;
315
+ case 'terminate':
316
+ if (attrs.reason === 'timeout') {
317
+ status = 'timeout';
318
+ } else {
319
+ //fired when accepted/rejected/timeout/caller hangs up
320
+ status = 'terminate';
321
+ }
322
+ break;
323
+ case 'reject':
324
+ status = 'reject';
325
+ break;
326
+ case 'accept':
327
+ status = 'accept';
328
+ break;
329
+ default:
330
+ status = 'ringing';
331
+ break;
332
+ }
333
+ return status;
321
334
  };
322
335
  const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
323
- export const getCodeFromWSError = (error) => {
324
- let statusCode = 500;
325
- if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
326
- const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
327
- if (!Number.isNaN(code) && code >= 400) {
328
- statusCode = code;
329
- }
330
- }
331
- else if (
332
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
333
- error?.code?.startsWith('E') ||
334
- error?.message?.includes('timed out')) {
335
- // handle ETIMEOUT, ENOTFOUND etc
336
- statusCode = 408;
336
+ export const getCodeFromWSError = error => {
337
+ let statusCode = 500;
338
+ if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
339
+ const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
340
+ if (!Number.isNaN(code) && code >= 400) {
341
+ statusCode = code;
337
342
  }
338
- return statusCode;
343
+ } else if (
344
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
345
+ error?.code?.startsWith('E') || error?.message?.includes('timed out')) {
346
+ // handle ETIMEOUT, ENOTFOUND etc
347
+ statusCode = 408;
348
+ }
349
+ return statusCode;
339
350
  };
340
351
  /**
341
352
  * Is the given platform WA business
342
353
  * @param platform AuthenticationCreds.platform
343
354
  */
344
- export const isWABusinessPlatform = (platform) => {
345
- return platform === 'smbi' || platform === 'smba';
355
+ export const isWABusinessPlatform = platform => {
356
+ return platform === 'smbi' || platform === 'smba';
346
357
  };
347
358
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
359
  export function trimUndefined(obj) {
349
- for (const key in obj) {
350
- if (typeof obj[key] === 'undefined') {
351
- delete obj[key];
352
- }
360
+ for (const key in obj) {
361
+ if (typeof obj[key] === 'undefined') {
362
+ delete obj[key];
353
363
  }
354
- return obj;
364
+ }
365
+ return obj;
355
366
  }
356
367
  const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
357
368
  export function bytesToCrockford(buffer) {
358
- let value = 0;
359
- let bitCount = 0;
360
- const crockford = [];
361
- for (const element of buffer) {
362
- value = (value << 8) | (element & 0xff);
363
- bitCount += 8;
364
- while (bitCount >= 5) {
365
- crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
366
- bitCount -= 5;
367
- }
368
- }
369
- if (bitCount > 0) {
370
- crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
369
+ let value = 0;
370
+ let bitCount = 0;
371
+ const crockford = [];
372
+ for (const element of buffer) {
373
+ value = value << 8 | element & 0xff;
374
+ bitCount += 8;
375
+ while (bitCount >= 5) {
376
+ crockford.push(CROCKFORD_CHARACTERS.charAt(value >>> bitCount - 5 & 31));
377
+ bitCount -= 5;
371
378
  }
372
- return crockford.join('');
379
+ }
380
+ if (bitCount > 0) {
381
+ crockford.push(CROCKFORD_CHARACTERS.charAt(value << 5 - bitCount & 31));
382
+ }
383
+ return crockford.join('');
373
384
  }
374
385
  export function encodeNewsletterMessage(message) {
375
- return proto.Message.encode(message).finish();
386
+ return proto.Message.encode(message).finish();
376
387
  }
377
388
  //# sourceMappingURL=generics.js.map