@queenanya/baileys 7.4.7 → 7.4.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.
- package/README.md +26 -26
- package/WAProto/index.js +97194 -67957
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +231 -1
- package/lib/Defaults/index.js +23 -11
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +22 -29
- package/lib/Socket/chats.d.ts +3 -14
- package/lib/Socket/chats.js +48 -76
- package/lib/Socket/groups.d.ts +4 -21
- package/lib/Socket/groups.js +1 -12
- package/lib/Socket/index.d.ts +32 -37
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +22 -28
- package/lib/Socket/messages-recv.js +180 -291
- package/lib/Socket/messages-send.d.ts +13 -23
- package/lib/Socket/messages-send.js +76 -110
- package/lib/Socket/newsletter.d.ts +7 -17
- package/lib/Socket/newsletter.js +54 -67
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +1 -3
- package/lib/Socket/socket.js +17 -15
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +6 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Contact.d.ts +1 -1
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +1 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +30 -37
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +15 -1
- package/lib/Types/Socket.d.ts +3 -10
- package/lib/Types/index.d.ts +0 -8
- package/lib/Utils/auth-utils.js +7 -1
- package/lib/Utils/chat-utils.d.ts +4 -5
- package/lib/Utils/chat-utils.js +20 -41
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +2 -4
- package/lib/Utils/decode-wa-message.d.ts +0 -1
- package/lib/Utils/decode-wa-message.js +14 -34
- package/lib/Utils/event-buffer.js +8 -14
- package/lib/Utils/generics.d.ts +13 -37
- package/lib/Utils/generics.js +18 -102
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +0 -3
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +32 -17
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +72 -67
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +12 -7
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +21 -55
- package/lib/Utils/signal.js +16 -23
- package/lib/Utils/use-multi-file-auth-state.js +3 -17
- package/lib/Utils/validate-connection.d.ts +1 -0
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +2 -3
- package/lib/WABinary/decode.js +4 -6
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +6 -8
- package/lib/WABinary/generic-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +5 -5
- package/lib/WAM/BinaryInfo.d.ts +2 -3
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +0 -1
- package/lib/WAM/encode.js +2 -2
- package/package.json +37 -39
- /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { AxiosRequestConfig } from 'axios';
|
|
4
3
|
import { Logger } from 'pino';
|
|
5
4
|
import { proto } from '../../WAProto';
|
|
6
|
-
import { BaileysEventEmitter, BaileysEventMap,
|
|
5
|
+
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
7
6
|
import { BinaryNode } from '../WABinary';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
*/
|
|
17
|
-
export declare const Browsers: BrowsersMap;
|
|
18
|
-
/** Other Browser Support for Paircode */
|
|
19
|
-
export declare const getPlatformId: (browser: string) => any;
|
|
7
|
+
export declare const Browsers: {
|
|
8
|
+
ubuntu: (browser: any) => [string, string, string];
|
|
9
|
+
macOS: (browser: any) => [string, string, string];
|
|
10
|
+
baileys: (browser: any) => [string, string, string];
|
|
11
|
+
windows: (browser: any) => [string, string, string];
|
|
12
|
+
/** The appropriate browser based on your OS & release */
|
|
13
|
+
appropriate: (browser: any) => [string, string, string];
|
|
14
|
+
};
|
|
20
15
|
export declare const BufferJSON: {
|
|
21
16
|
replacer: (k: any, value: any) => any;
|
|
22
17
|
reviver: (_: any, value: any) => any;
|
|
@@ -25,7 +20,6 @@ export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, m
|
|
|
25
20
|
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
26
21
|
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
27
22
|
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
28
|
-
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
|
|
29
23
|
export declare const generateRegistrationId: () => number;
|
|
30
24
|
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
31
25
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
@@ -45,29 +39,15 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
45
39
|
};
|
|
46
40
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
47
41
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
48
|
-
export declare const generateMessageIDV3: (userId?: string) => string;
|
|
49
42
|
export declare const generateMessageID: () => string;
|
|
50
43
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
51
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
44
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
52
45
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
53
|
-
/**
|
|
54
|
-
* utility that fetches latest baileys version from the main branch.
|
|
55
|
-
* Use to ensure your WA connection is always on the latest version
|
|
56
|
-
*/
|
|
57
|
-
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
58
|
-
version: number[];
|
|
59
|
-
isLatest: boolean;
|
|
60
|
-
error?: undefined;
|
|
61
|
-
} | {
|
|
62
|
-
version: WAVersion;
|
|
63
|
-
isLatest: boolean;
|
|
64
|
-
error: any;
|
|
65
|
-
}>;
|
|
66
46
|
/**
|
|
67
47
|
* utility that fetches latest baileys version from the master branch.
|
|
68
48
|
* Use to ensure your WA connection is always on the latest version
|
|
69
49
|
*/
|
|
70
|
-
export declare const
|
|
50
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
71
51
|
version: WAVersion;
|
|
72
52
|
isLatest: boolean;
|
|
73
53
|
error?: undefined;
|
|
@@ -80,7 +60,7 @@ export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<a
|
|
|
80
60
|
* A utility that fetches the latest web version of whatsapp.
|
|
81
61
|
* Use to ensure your WA connection is always on the latest version
|
|
82
62
|
*/
|
|
83
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<
|
|
63
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
84
64
|
version: WAVersion;
|
|
85
65
|
isLatest: boolean;
|
|
86
66
|
error?: undefined;
|
|
@@ -111,9 +91,5 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
111
91
|
* @param platform AuthenticationCreds.platform
|
|
112
92
|
*/
|
|
113
93
|
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
114
|
-
export declare function trimUndefined(obj:
|
|
115
|
-
[_: string]: any;
|
|
116
|
-
}): {
|
|
117
|
-
[_: string]: any;
|
|
118
|
-
};
|
|
94
|
+
export declare function trimUndefined(obj: any): any;
|
|
119
95
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
|
30
7
|
const boom_1 = require("@hapi/boom");
|
|
31
8
|
const axios_1 = __importDefault(require("axios"));
|
|
32
9
|
const crypto_1 = require("crypto");
|
|
@@ -35,48 +12,27 @@ const WAProto_1 = require("../../WAProto");
|
|
|
35
12
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
36
13
|
const Types_1 = require("../Types");
|
|
37
14
|
const WABinary_1 = require("../WABinary");
|
|
38
|
-
/** Added Extra Browsers or Platforms*/
|
|
39
15
|
const PLATFORM_MAP = {
|
|
40
16
|
'aix': 'AIX',
|
|
41
17
|
'darwin': 'Mac OS',
|
|
42
18
|
'win32': 'Windows',
|
|
43
|
-
'android': 'Android'
|
|
44
|
-
'freebsd': 'FreeBSD',
|
|
45
|
-
'openbsd': 'OpenBSD',
|
|
46
|
-
'sunos': 'Solaris'
|
|
19
|
+
'android': 'Android'
|
|
47
20
|
};
|
|
48
|
-
/**
|
|
49
|
-
const COMPANION_PLATFORM_MAP = {
|
|
50
|
-
'Chrome': '49',
|
|
51
|
-
'Edge': '50',
|
|
52
|
-
'Firefox': '51',
|
|
53
|
-
'Opera': '53',
|
|
54
|
-
'Safari': '54'
|
|
55
|
-
}
|
|
56
|
-
*/
|
|
57
21
|
exports.Browsers = {
|
|
58
|
-
ubuntu:
|
|
59
|
-
macOS:
|
|
60
|
-
baileys:
|
|
61
|
-
windows:
|
|
22
|
+
ubuntu: browser => ['Ubuntu', browser, '20.0.04'],
|
|
23
|
+
macOS: browser => ['Mac OS', browser, '10.15.7'],
|
|
24
|
+
baileys: browser => ['Baileys', browser, '4.0.0'],
|
|
25
|
+
windows: browser => ['Windows', browser, '10.0.22621'],
|
|
62
26
|
/** The appropriate browser based on your OS & release */
|
|
63
|
-
appropriate:
|
|
27
|
+
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
64
28
|
};
|
|
65
|
-
/** Other Browser Support for Paircode */
|
|
66
|
-
const getPlatformId = (browser) => {
|
|
67
|
-
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
68
|
-
return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
|
|
69
|
-
};
|
|
70
|
-
exports.getPlatformId = getPlatformId;
|
|
71
29
|
exports.BufferJSON = {
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
30
|
replacer: (k, value) => {
|
|
74
31
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
75
32
|
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
76
33
|
}
|
|
77
34
|
return value;
|
|
78
35
|
},
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
36
|
reviver: (_, value) => {
|
|
81
37
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
82
38
|
const val = value.data || value.value;
|
|
@@ -110,8 +66,6 @@ const unpadRandomMax16 = (e) => {
|
|
|
110
66
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
111
67
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
112
68
|
exports.encodeWAMessage = encodeWAMessage;
|
|
113
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
114
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
115
69
|
const generateRegistrationId = () => {
|
|
116
70
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
117
71
|
};
|
|
@@ -126,7 +80,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
126
80
|
return a;
|
|
127
81
|
};
|
|
128
82
|
exports.encodeBigEndian = encodeBigEndian;
|
|
129
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
83
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
130
84
|
exports.toNumber = toNumber;
|
|
131
85
|
/** unix timestamp of a date in seconds */
|
|
132
86
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -193,7 +147,6 @@ async function promiseTimeout(ms, promise) {
|
|
|
193
147
|
return p;
|
|
194
148
|
}
|
|
195
149
|
exports.promiseTimeout = promiseTimeout;
|
|
196
|
-
//Useless but still keep this to avoid unexpected errors and bugs
|
|
197
150
|
const generateMessageIDV2 = (userId) => {
|
|
198
151
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
199
152
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -207,19 +160,11 @@ const generateMessageIDV2 = (userId) => {
|
|
|
207
160
|
const random = (0, crypto_1.randomBytes)(16);
|
|
208
161
|
random.copy(data, 28);
|
|
209
162
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
210
|
-
return '
|
|
163
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
211
164
|
};
|
|
212
165
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
213
|
-
//Message ID function for Anya_Baileyz
|
|
214
|
-
//This V3 is RollBack Update Of Old Message ID
|
|
215
|
-
const generateMessageIDV3 = (userId) => {
|
|
216
|
-
let swebfix = 'ANYAWEB';
|
|
217
|
-
let swebRandom = (0, crypto_1.randomBytes)(5).toString('hex').toUpperCase().substring(0, 10);
|
|
218
|
-
return swebfix + swebRandom;
|
|
219
|
-
};
|
|
220
|
-
exports.generateMessageIDV3 = generateMessageIDV3;
|
|
221
166
|
// generate a random ID to attach to a message
|
|
222
|
-
const generateMessageID = () => '
|
|
167
|
+
const generateMessageID = () => 'FELZ' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
223
168
|
exports.generateMessageID = generateMessageID;
|
|
224
169
|
function bindWaitForEvent(ev, event) {
|
|
225
170
|
return async (check, timeoutMs) => {
|
|
@@ -252,7 +197,8 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
|
252
197
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
253
198
|
ev.on('connection.update', async ({ qr }) => {
|
|
254
199
|
if (qr) {
|
|
255
|
-
const QR = await
|
|
200
|
+
const QR = await import('qrcode-terminal')
|
|
201
|
+
.then(m => m.default || m)
|
|
256
202
|
.catch(() => {
|
|
257
203
|
logger.error('QR code terminal not added as dependency');
|
|
258
204
|
});
|
|
@@ -261,37 +207,11 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
261
207
|
});
|
|
262
208
|
};
|
|
263
209
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
264
|
-
/**
|
|
265
|
-
* utility that fetches latest baileys version from the main branch.
|
|
266
|
-
* Use to ensure your WA connection is always on the latest version
|
|
267
|
-
*/
|
|
268
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
269
|
-
try {
|
|
270
|
-
const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
|
|
271
|
-
...options,
|
|
272
|
-
responseType: 'json'
|
|
273
|
-
});
|
|
274
|
-
const version = result.data.currentVersion.split('.');
|
|
275
|
-
const version2 = version[2].replace('-alpha', '');
|
|
276
|
-
return {
|
|
277
|
-
version: [+version[0], +version[1], +version2],
|
|
278
|
-
isLatest: true
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
return {
|
|
283
|
-
version: baileys_version_json_1.version,
|
|
284
|
-
isLatest: false,
|
|
285
|
-
error
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
290
210
|
/**
|
|
291
211
|
* utility that fetches latest baileys version from the master branch.
|
|
292
212
|
* Use to ensure your WA connection is always on the latest version
|
|
293
213
|
*/
|
|
294
|
-
const
|
|
214
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
295
215
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
|
296
216
|
try {
|
|
297
217
|
const result = await axios_1.default.get(URL, {
|
|
@@ -311,7 +231,7 @@ const fetchLatestBaileysVersion2 = async (options = {}) => {
|
|
|
311
231
|
};
|
|
312
232
|
}
|
|
313
233
|
};
|
|
314
|
-
exports.
|
|
234
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
315
235
|
/**
|
|
316
236
|
* A utility that fetches the latest web version of whatsapp.
|
|
317
237
|
* Use to ensure your WA connection is always on the latest version
|
|
@@ -392,8 +312,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
392
312
|
status = 'timeout';
|
|
393
313
|
}
|
|
394
314
|
else {
|
|
395
|
-
|
|
396
|
-
status = 'terminate';
|
|
315
|
+
status = 'reject';
|
|
397
316
|
}
|
|
398
317
|
break;
|
|
399
318
|
case 'reject':
|
|
@@ -419,9 +338,7 @@ const getCodeFromWSError = (error) => {
|
|
|
419
338
|
statusCode = code;
|
|
420
339
|
}
|
|
421
340
|
}
|
|
422
|
-
else if (
|
|
423
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
424
|
-
((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
341
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
425
342
|
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
426
343
|
statusCode = 408;
|
|
427
344
|
}
|
|
@@ -436,7 +353,6 @@ const isWABusinessPlatform = (platform) => {
|
|
|
436
353
|
return platform === 'smbi' || platform === 'smba';
|
|
437
354
|
};
|
|
438
355
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
439
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
440
356
|
function trimUndefined(obj) {
|
|
441
357
|
for (const key in obj) {
|
|
442
358
|
if (typeof obj[key] === 'undefined') {
|
|
@@ -451,8 +367,8 @@ function bytesToCrockford(buffer) {
|
|
|
451
367
|
let value = 0;
|
|
452
368
|
let bitCount = 0;
|
|
453
369
|
const crockford = [];
|
|
454
|
-
for (
|
|
455
|
-
value = (value << 8) | (
|
|
370
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
371
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
456
372
|
bitCount += 8;
|
|
457
373
|
while (bitCount >= 5) {
|
|
458
374
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
8
8
|
messages: proto.IWebMessageInfo[];
|
|
9
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
-
progress: number | null | undefined;
|
|
11
9
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
11
|
chats: Chat[];
|
|
14
12
|
contacts: Contact[];
|
|
15
13
|
messages: proto.IWebMessageInfo[];
|
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
-
progress: number | null | undefined;
|
|
18
14
|
}>;
|
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -32,7 +32,6 @@ const processHistoryMessage = (item) => {
|
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
35
|
for (const chat of item.conversations) {
|
|
37
36
|
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
38
37
|
const msgs = chat.messages || [];
|
|
@@ -75,8 +74,6 @@ const processHistoryMessage = (item) => {
|
|
|
75
74
|
chats,
|
|
76
75
|
contacts,
|
|
77
76
|
messages,
|
|
78
|
-
syncType: item.syncType,
|
|
79
|
-
progress: item.progress
|
|
80
77
|
};
|
|
81
78
|
};
|
|
82
79
|
exports.processHistoryMessage = processHistoryMessage;
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from './chat-utils';
|
|
|
11
11
|
export * from './lt-hash';
|
|
12
12
|
export * from './auth-utils';
|
|
13
13
|
export * from './baileys-event-stream';
|
|
14
|
-
export * from './use-single-file-auth-state';
|
|
15
14
|
export * from './use-multi-file-auth-state';
|
|
16
15
|
export * from './link-preview';
|
|
17
16
|
export * from './event-buffer';
|
package/lib/Utils/index.js
CHANGED
|
@@ -27,7 +27,6 @@ __exportStar(require("./chat-utils"), exports);
|
|
|
27
27
|
__exportStar(require("./lt-hash"), exports);
|
|
28
28
|
__exportStar(require("./auth-utils"), exports);
|
|
29
29
|
__exportStar(require("./baileys-event-stream"), exports);
|
|
30
|
-
__exportStar(require("./use-single-file-auth-state"), exports);
|
|
31
30
|
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
32
31
|
__exportStar(require("./link-preview"), exports);
|
|
33
32
|
__exportStar(require("./event-buffer"), exports);
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getUrlInfo = void 0;
|
|
27
4
|
const messages_1 = require("./messages");
|
|
@@ -48,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
48
25
|
// retries
|
|
49
26
|
const retries = 0;
|
|
50
27
|
const maxRetry = 5;
|
|
51
|
-
const { getLinkPreview } = await
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
52
29
|
let previewLink = text;
|
|
53
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
54
31
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/logger.d.ts
CHANGED
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
4
|
const makeMutex = () => {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
5
|
let task = Promise.resolve();
|
|
7
6
|
let taskTimeout;
|
|
8
7
|
return {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
4
|
import { Boom } from '@hapi/boom';
|
|
6
5
|
import { AxiosRequestConfig } from 'axios';
|
|
7
6
|
import type { Logger } from 'pino';
|
|
@@ -100,7 +99,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
|
|
|
100
99
|
export type MediaDownloadOptions = {
|
|
101
100
|
startByte?: number;
|
|
102
101
|
endByte?: number;
|
|
103
|
-
options?: AxiosRequestConfig<
|
|
102
|
+
options?: AxiosRequestConfig<any>;
|
|
104
103
|
};
|
|
105
104
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
|
106
105
|
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
|
@@ -116,7 +115,7 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
|
116
115
|
*/
|
|
117
116
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
|
|
118
117
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
|
119
|
-
key:
|
|
118
|
+
key: proto.IMessageKey;
|
|
120
119
|
media?: {
|
|
121
120
|
ciphertext: Uint8Array;
|
|
122
121
|
iv: Uint8Array;
|
|
@@ -22,13 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.changeprofileFull = exports.generatePP = exports.generateProfilePictureFP = exports.generateProfilePictureFull = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
|
|
30
27
|
const boom_1 = require("@hapi/boom");
|
|
31
|
-
const axios_1 = __importDefault(require("axios"));
|
|
32
28
|
const child_process_1 = require("child_process");
|
|
33
29
|
const Crypto = __importStar(require("crypto"));
|
|
34
30
|
const events_1 = require("events");
|
|
@@ -45,11 +41,13 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
|
45
41
|
const getImageProcessingLibrary = async () => {
|
|
46
42
|
const [_jimp, sharp] = await Promise.all([
|
|
47
43
|
(async () => {
|
|
48
|
-
const jimp = await (
|
|
44
|
+
const jimp = await (import('jimp')
|
|
45
|
+
.catch(() => { }));
|
|
49
46
|
return jimp;
|
|
50
47
|
})(),
|
|
51
48
|
(async () => {
|
|
52
|
-
const sharp = await (
|
|
49
|
+
const sharp = await (import('sharp')
|
|
50
|
+
.catch(() => { }));
|
|
53
51
|
return sharp;
|
|
54
52
|
})()
|
|
55
53
|
]);
|
|
@@ -260,7 +258,7 @@ const mediaMessageSHA256B64 = (message) => {
|
|
|
260
258
|
};
|
|
261
259
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
262
260
|
async function getAudioDuration(buffer) {
|
|
263
|
-
const musicMetadata = await
|
|
261
|
+
const musicMetadata = await import('music-metadata');
|
|
264
262
|
let metadata;
|
|
265
263
|
if (Buffer.isBuffer(buffer)) {
|
|
266
264
|
metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
|
|
@@ -285,7 +283,7 @@ exports.getAudioDuration = getAudioDuration;
|
|
|
285
283
|
*/
|
|
286
284
|
async function getAudioWaveform(buffer, logger) {
|
|
287
285
|
try {
|
|
288
|
-
const audioDecode = (buffer) =>
|
|
286
|
+
const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
|
|
289
287
|
let audioData;
|
|
290
288
|
if (Buffer.isBuffer(buffer)) {
|
|
291
289
|
audioData = buffer;
|
|
@@ -385,7 +383,8 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
385
383
|
}
|
|
386
384
|
exports.generateThumbnail = generateThumbnail;
|
|
387
385
|
const getHttpStream = async (url, options = {}) => {
|
|
388
|
-
const
|
|
386
|
+
const { default: axios } = await import('axios');
|
|
387
|
+
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
|
389
388
|
return fetched.data;
|
|
390
389
|
};
|
|
391
390
|
exports.getHttpStream = getHttpStream;
|
|
@@ -443,7 +442,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
443
442
|
let writeStream;
|
|
444
443
|
let didSaveToTmpPath = false;
|
|
445
444
|
if (type === 'file') {
|
|
446
|
-
bodyPath = media.url
|
|
445
|
+
bodyPath = media.url;
|
|
447
446
|
}
|
|
448
447
|
else if (saveOriginalFileIfRequired) {
|
|
449
448
|
bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
|
|
@@ -466,8 +465,10 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
466
465
|
});
|
|
467
466
|
}
|
|
468
467
|
sha256Plain = sha256Plain.update(data);
|
|
469
|
-
if (writeStream
|
|
470
|
-
|
|
468
|
+
if (writeStream) {
|
|
469
|
+
if (!writeStream.write(data)) {
|
|
470
|
+
await (0, events_1.once)(writeStream, 'drain');
|
|
471
|
+
}
|
|
471
472
|
}
|
|
472
473
|
onChunk(aes.update(data));
|
|
473
474
|
}
|
|
@@ -638,23 +639,33 @@ exports.extensionForMediaMessage = extensionForMediaMessage;
|
|
|
638
639
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
639
640
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
640
641
|
var _a, _b;
|
|
642
|
+
const { default: axios } = await import('axios');
|
|
641
643
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
642
644
|
let uploadInfo = await refreshMediaConn(false);
|
|
643
645
|
let urls;
|
|
644
646
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
647
|
+
const chunks = [];
|
|
648
|
+
if (!Buffer.isBuffer(stream)) {
|
|
649
|
+
for await (const chunk of stream) {
|
|
650
|
+
chunks.push(chunk);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
645
654
|
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
646
655
|
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
|
647
656
|
if (newsletter) {
|
|
648
657
|
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
|
649
658
|
}
|
|
650
|
-
for (const { hostname } of hosts) {
|
|
659
|
+
for (const { hostname, maxContentLengthBytes } of hosts) {
|
|
651
660
|
logger.debug(`uploading to "${hostname}"`);
|
|
652
661
|
const auth = encodeURIComponent(uploadInfo.auth); // the auth token
|
|
653
|
-
const url = `https://${hostname}${
|
|
654
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
662
|
+
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
655
663
|
let result;
|
|
656
664
|
try {
|
|
657
|
-
|
|
665
|
+
if (maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
|
666
|
+
throw new boom_1.Boom(`Body too large for "${hostname}"`, { statusCode: 413 });
|
|
667
|
+
}
|
|
668
|
+
const body = await axios.post(url, reqBody, {
|
|
658
669
|
...options,
|
|
659
670
|
headers: {
|
|
660
671
|
...options.headers || {},
|
|
@@ -682,7 +693,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
682
693
|
}
|
|
683
694
|
}
|
|
684
695
|
catch (error) {
|
|
685
|
-
if (
|
|
696
|
+
if (axios.isAxiosError(error)) {
|
|
686
697
|
result = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
687
698
|
}
|
|
688
699
|
const isLast = hostname === ((_b = hosts[uploadInfo.hosts.length - 1]) === null || _b === void 0 ? void 0 : _b.hostname);
|
|
@@ -784,3 +795,7 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
784
795
|
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
785
796
|
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
|
786
797
|
};
|
|
798
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
799
|
+
function __importStar(arg0) {
|
|
800
|
+
throw new Error('Function not implemented.');
|
|
801
|
+
}
|