@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.
- package/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
package/lib/Utils/generics.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
-
import 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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 =
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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 =
|
|
71
|
+
export const encodeWAMessage = message => writeRandomPadMax16(proto.Message.encode(message).finish());
|
|
69
72
|
export const generateRegistrationId = () => {
|
|
70
|
-
|
|
73
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383;
|
|
71
74
|
};
|
|
72
75
|
export const encodeBigEndian = (e, t = 4) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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 =
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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 =
|
|
102
|
-
export const delayCancellable =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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 =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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 =
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
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
|
-
|
|
256
|
-
|
|
266
|
+
const bytes = randomBytes(4);
|
|
267
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
257
268
|
};
|
|
258
269
|
const STATUS_MAP = {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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 =
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
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 =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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 = ({
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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 =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
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 =
|
|
345
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
360
|
+
for (const key in obj) {
|
|
361
|
+
if (typeof obj[key] === 'undefined') {
|
|
362
|
+
delete obj[key];
|
|
353
363
|
}
|
|
354
|
-
|
|
364
|
+
}
|
|
365
|
+
return obj;
|
|
355
366
|
}
|
|
356
367
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
357
368
|
export function bytesToCrockford(buffer) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
-
|
|
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
|
-
|
|
386
|
+
return proto.Message.encode(message).finish();
|
|
376
387
|
}
|
|
377
388
|
//# sourceMappingURL=generics.js.map
|