@vinzsocket/baileys 2.8.30 → 3.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.
- package/WAProto/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
package/lib/Utils/generics.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.bindWaitForConnectionUpdate = exports.BufferJSON = exports.Browsers = void 0;
|
|
5
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
6
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
7
|
+
exports.encodeBigEndian = exports.delayCancellable = exports.delay = exports.debouncedTimeout = void 0;
|
|
8
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
9
|
+
exports.isWABusinessPlatform = exports.getStatusFromReceiptType = exports.getPlatformId = exports.getKeyAuthor = exports.getErrorCodeFromStreamError = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.generateRegistrationId = exports.generateMessageIDV2 = exports.generateMessageID = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.encodeWAMessage = void 0;
|
|
10
|
+
exports.promiseTimeout = promiseTimeout;
|
|
11
|
+
exports.toNumber = void 0;
|
|
12
|
+
exports.trimUndefined = trimUndefined;
|
|
13
|
+
exports.writeRandomPadMax16 = exports.unpadRandomMax16 = exports.unixTimestampSeconds = void 0;
|
|
14
|
+
var _boom = require("@hapi/boom");
|
|
15
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
16
|
+
var _crypto = require("crypto");
|
|
17
|
+
var _os = require("os");
|
|
18
|
+
var _index = require("../../WAProto/index.js");
|
|
19
|
+
var _index2 = require("../Types/index.js");
|
|
20
|
+
var _index3 = require("../WABinary/index.js");
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
22
|
const baileysVersion = [2, 3000, 1023223821];
|
|
7
|
-
import { DisconnectReason } from '../Types/index.js';
|
|
8
|
-
import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
|
|
9
23
|
const PLATFORM_MAP = {
|
|
10
24
|
aix: 'AIX',
|
|
11
25
|
darwin: 'Mac OS',
|
|
@@ -19,19 +33,20 @@ const PLATFORM_MAP = {
|
|
|
19
33
|
cygwin: undefined,
|
|
20
34
|
netbsd: undefined
|
|
21
35
|
};
|
|
22
|
-
|
|
36
|
+
const Browsers = exports.Browsers = {
|
|
23
37
|
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
24
38
|
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
25
39
|
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
26
40
|
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
27
41
|
/** The appropriate browser based on your OS & release */
|
|
28
|
-
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
42
|
+
appropriate: browser => [PLATFORM_MAP[(0, _os.platform)()] || 'Ubuntu', browser, (0, _os.release)()]
|
|
29
43
|
};
|
|
30
|
-
|
|
31
|
-
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
44
|
+
const getPlatformId = browser => {
|
|
45
|
+
const platformType = _index.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
32
46
|
return platformType ? platformType.toString() : '1'; //chrome
|
|
33
47
|
};
|
|
34
|
-
|
|
48
|
+
exports.getPlatformId = getPlatformId;
|
|
49
|
+
const BufferJSON = exports.BufferJSON = {
|
|
35
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
51
|
replacer: (k, value) => {
|
|
37
52
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
@@ -51,13 +66,15 @@ export const BufferJSON = {
|
|
|
51
66
|
return value;
|
|
52
67
|
}
|
|
53
68
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participant || key?.remoteJid) || '';
|
|
70
|
+
exports.getKeyAuthor = getKeyAuthor;
|
|
71
|
+
const writeRandomPadMax16 = msg => {
|
|
72
|
+
const pad = (0, _crypto.randomBytes)(1);
|
|
57
73
|
const padLength = (pad[0] & 0x0f) + 1;
|
|
58
74
|
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
59
75
|
};
|
|
60
|
-
|
|
76
|
+
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
77
|
+
const unpadRandomMax16 = e => {
|
|
61
78
|
const t = new Uint8Array(e);
|
|
62
79
|
if (0 === t.length) {
|
|
63
80
|
throw new Error('unpadPkcs7 given empty bytes');
|
|
@@ -68,11 +85,14 @@ export const unpadRandomMax16 = e => {
|
|
|
68
85
|
}
|
|
69
86
|
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
70
87
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
89
|
+
const encodeWAMessage = message => writeRandomPadMax16(_index.proto.Message.encode(message).finish());
|
|
90
|
+
exports.encodeWAMessage = encodeWAMessage;
|
|
91
|
+
const generateRegistrationId = () => {
|
|
92
|
+
return Uint16Array.from((0, _crypto.randomBytes)(2))[0] & 16383;
|
|
74
93
|
};
|
|
75
|
-
|
|
94
|
+
exports.generateRegistrationId = generateRegistrationId;
|
|
95
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
76
96
|
let r = e;
|
|
77
97
|
const a = new Uint8Array(t);
|
|
78
98
|
for (let i = t - 1; i >= 0; i--) {
|
|
@@ -81,10 +101,13 @@ export const encodeBigEndian = (e, t = 4) => {
|
|
|
81
101
|
}
|
|
82
102
|
return a;
|
|
83
103
|
};
|
|
84
|
-
|
|
104
|
+
exports.encodeBigEndian = encodeBigEndian;
|
|
105
|
+
const toNumber = t => typeof t === 'object' && t ? 'toNumber' in t ? t.toNumber() : t.low : t || 0;
|
|
85
106
|
/** unix timestamp of a date in seconds */
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
exports.toNumber = toNumber;
|
|
108
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
109
|
+
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
110
|
+
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
88
111
|
let timeout;
|
|
89
112
|
return {
|
|
90
113
|
start: (newIntervalMs, newTask) => {
|
|
@@ -101,8 +124,10 @@ export const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
|
101
124
|
setInterval: newInterval => intervalMs = newInterval
|
|
102
125
|
};
|
|
103
126
|
};
|
|
104
|
-
|
|
105
|
-
|
|
127
|
+
exports.debouncedTimeout = debouncedTimeout;
|
|
128
|
+
const delay = ms => delayCancellable(ms).delay;
|
|
129
|
+
exports.delay = delay;
|
|
130
|
+
const delayCancellable = ms => {
|
|
106
131
|
const stack = new Error().stack;
|
|
107
132
|
let timeout;
|
|
108
133
|
let reject;
|
|
@@ -112,7 +137,7 @@ export const delayCancellable = ms => {
|
|
|
112
137
|
});
|
|
113
138
|
const cancel = () => {
|
|
114
139
|
clearTimeout(timeout);
|
|
115
|
-
reject(new Boom('Cancelled', {
|
|
140
|
+
reject(new _boom.Boom('Cancelled', {
|
|
116
141
|
statusCode: 500,
|
|
117
142
|
data: {
|
|
118
143
|
stack
|
|
@@ -124,7 +149,8 @@ export const delayCancellable = ms => {
|
|
|
124
149
|
cancel
|
|
125
150
|
};
|
|
126
151
|
};
|
|
127
|
-
|
|
152
|
+
exports.delayCancellable = delayCancellable;
|
|
153
|
+
async function promiseTimeout(ms, promise) {
|
|
128
154
|
if (!ms) {
|
|
129
155
|
return new Promise(promise);
|
|
130
156
|
}
|
|
@@ -135,8 +161,8 @@ export async function promiseTimeout(ms, promise) {
|
|
|
135
161
|
cancel
|
|
136
162
|
} = delayCancellable(ms);
|
|
137
163
|
const p = new Promise((resolve, reject) => {
|
|
138
|
-
delay.then(() => reject(new Boom('Timed Out', {
|
|
139
|
-
statusCode: DisconnectReason.timedOut,
|
|
164
|
+
delay.then(() => reject(new _boom.Boom('Timed Out', {
|
|
165
|
+
statusCode: _index2.DisconnectReason.timedOut,
|
|
140
166
|
data: {
|
|
141
167
|
stack
|
|
142
168
|
}
|
|
@@ -147,24 +173,26 @@ export async function promiseTimeout(ms, promise) {
|
|
|
147
173
|
}
|
|
148
174
|
// inspired from whatsmeow code
|
|
149
175
|
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
150
|
-
|
|
176
|
+
const generateMessageIDV2 = userId => {
|
|
151
177
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
152
178
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
153
179
|
if (userId) {
|
|
154
|
-
const id = jidDecode(userId);
|
|
180
|
+
const id = (0, _index3.jidDecode)(userId);
|
|
155
181
|
if (id?.user) {
|
|
156
182
|
data.write(id.user, 8);
|
|
157
183
|
data.write('@c.us', 8 + id.user.length);
|
|
158
184
|
}
|
|
159
185
|
}
|
|
160
|
-
const random = randomBytes(16);
|
|
186
|
+
const random = (0, _crypto.randomBytes)(16);
|
|
161
187
|
random.copy(data, 28);
|
|
162
|
-
const hash = createHash('sha256').update(data).digest();
|
|
188
|
+
const hash = (0, _crypto.createHash)('sha256').update(data).digest();
|
|
163
189
|
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
164
190
|
};
|
|
165
191
|
// generate a random ID to attach to a message
|
|
166
|
-
|
|
167
|
-
|
|
192
|
+
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
193
|
+
const generateMessageID = () => '3EB0' + (0, _crypto.randomBytes)(18).toString('hex').toUpperCase();
|
|
194
|
+
exports.generateMessageID = generateMessageID;
|
|
195
|
+
function bindWaitForEvent(ev, event) {
|
|
168
196
|
return async (check, timeoutMs) => {
|
|
169
197
|
let listener;
|
|
170
198
|
let closeListener;
|
|
@@ -174,8 +202,8 @@ export function bindWaitForEvent(ev, event) {
|
|
|
174
202
|
lastDisconnect
|
|
175
203
|
}) => {
|
|
176
204
|
if (connection === 'close') {
|
|
177
|
-
reject(lastDisconnect?.error || new Boom('Connection Closed', {
|
|
178
|
-
statusCode: DisconnectReason.connectionClosed
|
|
205
|
+
reject(lastDisconnect?.error || new _boom.Boom('Connection Closed', {
|
|
206
|
+
statusCode: _index2.DisconnectReason.connectionClosed
|
|
179
207
|
}));
|
|
180
208
|
}
|
|
181
209
|
};
|
|
@@ -192,15 +220,16 @@ export function bindWaitForEvent(ev, event) {
|
|
|
192
220
|
});
|
|
193
221
|
};
|
|
194
222
|
}
|
|
195
|
-
|
|
223
|
+
const bindWaitForConnectionUpdate = ev => bindWaitForEvent(ev, 'connection.update');
|
|
196
224
|
/**
|
|
197
225
|
* utility that fetches latest baileys version from the master branch.
|
|
198
226
|
* Use to ensure your WA connection is always on the latest version
|
|
199
227
|
*/
|
|
200
|
-
|
|
228
|
+
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
229
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
201
230
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
|
|
202
231
|
try {
|
|
203
|
-
const result = await
|
|
232
|
+
const result = await _axios.default.get(URL, {
|
|
204
233
|
...options,
|
|
205
234
|
responseType: 'text'
|
|
206
235
|
});
|
|
@@ -229,11 +258,12 @@ export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
229
258
|
* A utility that fetches the latest web version of whatsapp.
|
|
230
259
|
* Use to ensure your WA connection is always on the latest version
|
|
231
260
|
*/
|
|
232
|
-
|
|
261
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
262
|
+
const fetchLatestWaWebVersion = async options => {
|
|
233
263
|
try {
|
|
234
264
|
const {
|
|
235
265
|
data
|
|
236
|
-
} = await
|
|
266
|
+
} = await _axios.default.get('https://web.whatsapp.com/sw.js', {
|
|
237
267
|
...options,
|
|
238
268
|
responseType: 'json'
|
|
239
269
|
});
|
|
@@ -262,39 +292,42 @@ export const fetchLatestWaWebVersion = async options => {
|
|
|
262
292
|
}
|
|
263
293
|
};
|
|
264
294
|
/** unique message tag prefix for MD clients */
|
|
265
|
-
|
|
266
|
-
|
|
295
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
296
|
+
const generateMdTagPrefix = () => {
|
|
297
|
+
const bytes = (0, _crypto.randomBytes)(4);
|
|
267
298
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
268
299
|
};
|
|
300
|
+
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
269
301
|
const STATUS_MAP = {
|
|
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
|
|
302
|
+
sender: _index.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
303
|
+
played: _index.proto.WebMessageInfo.Status.PLAYED,
|
|
304
|
+
read: _index.proto.WebMessageInfo.Status.READ,
|
|
305
|
+
'read-self': _index.proto.WebMessageInfo.Status.READ
|
|
274
306
|
};
|
|
275
307
|
/**
|
|
276
308
|
* Given a type of receipt, returns what the new status of the message should be
|
|
277
309
|
* @param type type from receipt
|
|
278
310
|
*/
|
|
279
|
-
|
|
311
|
+
const getStatusFromReceiptType = type => {
|
|
280
312
|
const status = STATUS_MAP[type];
|
|
281
313
|
if (typeof type === 'undefined') {
|
|
282
|
-
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
314
|
+
return _index.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
283
315
|
}
|
|
284
316
|
return status;
|
|
285
317
|
};
|
|
318
|
+
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
286
319
|
const CODE_MAP = {
|
|
287
|
-
conflict: DisconnectReason.connectionReplaced
|
|
320
|
+
conflict: _index2.DisconnectReason.connectionReplaced
|
|
288
321
|
};
|
|
289
322
|
/**
|
|
290
323
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
291
324
|
* @param reason the string reason given, eg. "conflict"
|
|
292
325
|
*/
|
|
293
|
-
|
|
294
|
-
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
326
|
+
const getErrorCodeFromStreamError = node => {
|
|
327
|
+
const [reasonNode] = (0, _index3.getAllBinaryNodeChildren)(node);
|
|
295
328
|
let reason = reasonNode?.tag || 'unknown';
|
|
296
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
297
|
-
if (statusCode === DisconnectReason.restartRequired) {
|
|
329
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || _index2.DisconnectReason.badSession);
|
|
330
|
+
if (statusCode === _index2.DisconnectReason.restartRequired) {
|
|
298
331
|
reason = 'restart required';
|
|
299
332
|
}
|
|
300
333
|
return {
|
|
@@ -302,7 +335,8 @@ export const getErrorCodeFromStreamError = node => {
|
|
|
302
335
|
statusCode
|
|
303
336
|
};
|
|
304
337
|
};
|
|
305
|
-
|
|
338
|
+
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
339
|
+
const getCallStatusFromNode = ({
|
|
306
340
|
tag,
|
|
307
341
|
attrs
|
|
308
342
|
}) => {
|
|
@@ -332,8 +366,9 @@ export const getCallStatusFromNode = ({
|
|
|
332
366
|
}
|
|
333
367
|
return status;
|
|
334
368
|
};
|
|
369
|
+
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
335
370
|
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
336
|
-
|
|
371
|
+
const getCodeFromWSError = error => {
|
|
337
372
|
let statusCode = 500;
|
|
338
373
|
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
339
374
|
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
@@ -352,11 +387,13 @@ export const getCodeFromWSError = error => {
|
|
|
352
387
|
* Is the given platform WA business
|
|
353
388
|
* @param platform AuthenticationCreds.platform
|
|
354
389
|
*/
|
|
355
|
-
|
|
390
|
+
exports.getCodeFromWSError = getCodeFromWSError;
|
|
391
|
+
const isWABusinessPlatform = platform => {
|
|
356
392
|
return platform === 'smbi' || platform === 'smba';
|
|
357
393
|
};
|
|
358
394
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
|
-
|
|
395
|
+
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
396
|
+
function trimUndefined(obj) {
|
|
360
397
|
for (const key in obj) {
|
|
361
398
|
if (typeof obj[key] === 'undefined') {
|
|
362
399
|
delete obj[key];
|
|
@@ -365,7 +402,7 @@ export function trimUndefined(obj) {
|
|
|
365
402
|
return obj;
|
|
366
403
|
}
|
|
367
404
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
368
|
-
|
|
405
|
+
function bytesToCrockford(buffer) {
|
|
369
406
|
let value = 0;
|
|
370
407
|
let bitCount = 0;
|
|
371
408
|
const crockford = [];
|
|
@@ -382,7 +419,6 @@ export function bytesToCrockford(buffer) {
|
|
|
382
419
|
}
|
|
383
420
|
return crockford.join('');
|
|
384
421
|
}
|
|
385
|
-
|
|
386
|
-
return proto.Message.encode(message).finish();
|
|
387
|
-
}
|
|
388
|
-
//# sourceMappingURL=generics.js.map
|
|
422
|
+
function encodeNewsletterMessage(message) {
|
|
423
|
+
return _index.proto.Message.encode(message).finish();
|
|
424
|
+
}
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.processHistoryMessage = exports.getHistoryMsg = exports.downloadHistory = exports.downloadAndProcessHistorySyncNotification = void 0;
|
|
5
|
+
var _util = require("util");
|
|
6
|
+
var _zlib = require("zlib");
|
|
7
|
+
var _index = require("../../WAProto/index.js");
|
|
8
|
+
var _index2 = require("../Types/index.js");
|
|
9
|
+
var _generics = require("./generics.js");
|
|
10
|
+
var _messages = require("./messages.js");
|
|
11
|
+
var _messagesMedia = require("./messages-media.js");
|
|
12
|
+
const inflatePromise = (0, _util.promisify)(_zlib.inflate);
|
|
13
|
+
const downloadHistory = async (msg, options) => {
|
|
14
|
+
const stream = await (0, _messagesMedia.downloadContentFromMessage)(msg, 'md-msg-hist', {
|
|
11
15
|
options
|
|
12
16
|
});
|
|
13
17
|
const bufferArray = [];
|
|
@@ -17,18 +21,19 @@ export const downloadHistory = async (msg, options) => {
|
|
|
17
21
|
let buffer = Buffer.concat(bufferArray);
|
|
18
22
|
// decompress buffer
|
|
19
23
|
buffer = await inflatePromise(buffer);
|
|
20
|
-
const syncData = proto.HistorySync.decode(buffer);
|
|
24
|
+
const syncData = _index.proto.HistorySync.decode(buffer);
|
|
21
25
|
return syncData;
|
|
22
26
|
};
|
|
23
|
-
|
|
27
|
+
exports.downloadHistory = downloadHistory;
|
|
28
|
+
const processHistoryMessage = item => {
|
|
24
29
|
const messages = [];
|
|
25
30
|
const contacts = [];
|
|
26
31
|
const chats = [];
|
|
27
32
|
switch (item.syncType) {
|
|
28
|
-
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
29
|
-
case proto.HistorySync.HistorySyncType.RECENT:
|
|
30
|
-
case proto.HistorySync.HistorySyncType.FULL:
|
|
31
|
-
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
33
|
+
case _index.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
34
|
+
case _index.proto.HistorySync.HistorySyncType.RECENT:
|
|
35
|
+
case _index.proto.HistorySync.HistorySyncType.FULL:
|
|
36
|
+
case _index.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
32
37
|
for (const chat of item.conversations) {
|
|
33
38
|
contacts.push({
|
|
34
39
|
id: chat.id,
|
|
@@ -48,9 +53,9 @@ export const processHistoryMessage = item => {
|
|
|
48
53
|
}];
|
|
49
54
|
}
|
|
50
55
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
51
|
-
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
56
|
+
chat.lastMessageRecvTimestamp = (0, _generics.toNumber)(message.messageTimestamp);
|
|
52
57
|
}
|
|
53
|
-
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP || message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) && message.messageStubParameters?.[0]) {
|
|
58
|
+
if ((message.messageStubType === _index2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP || message.messageStubType === _index2.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) && message.messageStubParameters?.[0]) {
|
|
54
59
|
contacts.push({
|
|
55
60
|
id: message.key.participant || message.key.remoteJid,
|
|
56
61
|
verifiedName: message.messageStubParameters?.[0]
|
|
@@ -62,7 +67,7 @@ export const processHistoryMessage = item => {
|
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
break;
|
|
65
|
-
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
70
|
+
case _index.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
66
71
|
for (const c of item.pushnames) {
|
|
67
72
|
contacts.push({
|
|
68
73
|
id: c.id,
|
|
@@ -79,13 +84,15 @@ export const processHistoryMessage = item => {
|
|
|
79
84
|
progress: item.progress
|
|
80
85
|
};
|
|
81
86
|
};
|
|
82
|
-
|
|
87
|
+
exports.processHistoryMessage = processHistoryMessage;
|
|
88
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
83
89
|
const historyMsg = await downloadHistory(msg, options);
|
|
84
90
|
return processHistoryMessage(historyMsg);
|
|
85
91
|
};
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
93
|
+
const getHistoryMsg = message => {
|
|
94
|
+
const normalizedContent = !!message ? (0, _messages.normalizeMessageContent)(message) : undefined;
|
|
88
95
|
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
89
96
|
return anyHistoryMsg;
|
|
90
97
|
};
|
|
91
|
-
|
|
98
|
+
exports.getHistoryMsg = getHistoryMsg;
|