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