@hbmodsofc/baileys 2.4.0 → 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/LICENSE +1 -1
- package/README.MD +220 -1198
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +5619 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +97 -122
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +455 -288
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/hbmods.js +374 -406
- package/lib/Socket/index.js +43 -11
- package/lib/Socket/messages-recv.js +24 -69
- package/lib/Socket/messages-send.js +391 -419
- package/lib/Socket/newsletter.js +104 -190
- package/lib/Socket/socket.js +40 -54
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +27 -15
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/index.js +2 -2
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.js +13 -9
- package/lib/Utils/generics.js +88 -84
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +340 -246
- package/lib/Utils/messages.js +329 -192
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -0
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +53 -7
- package/package.json +112 -104
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/hbmods.d.ts +0 -254
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'pino';
|
|
2
|
-
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
3
|
-
/**
|
|
4
|
-
* A map that contains a list of all events that have been triggered
|
|
5
|
-
*
|
|
6
|
-
* Note, this can contain different type of events
|
|
7
|
-
* this can make processing events extremely efficient -- since everything
|
|
8
|
-
* can be done in a single transaction
|
|
9
|
-
*/
|
|
10
|
-
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
-
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
|
-
/** Use to process events in a batch */
|
|
13
|
-
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
|
-
/**
|
|
15
|
-
* starts buffering events, call flush() to release them
|
|
16
|
-
* */
|
|
17
|
-
buffer(): void;
|
|
18
|
-
/** buffers all events till the promise completes */
|
|
19
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
20
|
-
/**
|
|
21
|
-
* flushes all buffered events
|
|
22
|
-
* @param force if true, will flush all data regardless of any pending buffers
|
|
23
|
-
* @returns returns true if the flush actually happened, otherwise false
|
|
24
|
-
*/
|
|
25
|
-
flush(force?: boolean): boolean;
|
|
26
|
-
/** is there an ongoing buffer */
|
|
27
|
-
isBuffering(): boolean;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* The event buffer logically consolidates different events into a single event
|
|
31
|
-
* making the data processing more efficient.
|
|
32
|
-
* @param ev the baileys event emitter
|
|
33
|
-
*/
|
|
34
|
-
export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
|
|
35
|
-
export {};
|
package/lib/Utils/generics.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { AxiosRequestConfig } from 'axios';
|
|
3
|
-
import { Logger } from 'pino';
|
|
4
|
-
import { proto } from '../../WAProto';
|
|
5
|
-
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
|
6
|
-
import { BinaryNode } from '../WABinary';
|
|
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
|
-
};
|
|
15
|
-
export declare const getPlatformId: (browser: string) => any;
|
|
16
|
-
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
17
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
|
18
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
|
19
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
|
20
|
-
export declare const generateRegistrationId: () => number;
|
|
21
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
22
|
-
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
23
|
-
/** unix timestamp of a date in seconds */
|
|
24
|
-
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
25
|
-
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
|
|
26
|
-
export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
|
|
27
|
-
start: (newIntervalMs?: number, newTask?: () => void) => void;
|
|
28
|
-
cancel: () => void;
|
|
29
|
-
setTask: (newTask: () => void) => () => void;
|
|
30
|
-
setInterval: (newInterval: number) => number;
|
|
31
|
-
};
|
|
32
|
-
export declare const delay: (ms: number) => Promise<void>;
|
|
33
|
-
export declare const delayCancellable: (ms: number) => {
|
|
34
|
-
delay: Promise<void>;
|
|
35
|
-
cancel: () => void;
|
|
36
|
-
};
|
|
37
|
-
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
38
|
-
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
39
|
-
export declare const generateMessageID: () => string;
|
|
40
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
41
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
42
|
-
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
43
|
-
/**
|
|
44
|
-
* utility that fetches latest baileys version from the master branch.
|
|
45
|
-
* Use to ensure your WA connection is always on the latest version
|
|
46
|
-
*/
|
|
47
|
-
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
48
|
-
version: WAVersion;
|
|
49
|
-
isLatest: boolean;
|
|
50
|
-
error?: undefined;
|
|
51
|
-
} | {
|
|
52
|
-
version: WAVersion;
|
|
53
|
-
isLatest: boolean;
|
|
54
|
-
error: any;
|
|
55
|
-
}>;
|
|
56
|
-
/**
|
|
57
|
-
* A utility that fetches the latest web version of whatsapp.
|
|
58
|
-
* Use to ensure your WA connection is always on the latest version
|
|
59
|
-
*/
|
|
60
|
-
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
61
|
-
version: WAVersion;
|
|
62
|
-
isLatest: boolean;
|
|
63
|
-
error?: undefined;
|
|
64
|
-
} | {
|
|
65
|
-
version: WAVersion;
|
|
66
|
-
isLatest: boolean;
|
|
67
|
-
error: any;
|
|
68
|
-
}>;
|
|
69
|
-
/** unique message tag prefix for MD clients */
|
|
70
|
-
export declare const generateMdTagPrefix: () => string;
|
|
71
|
-
/**
|
|
72
|
-
* Given a type of receipt, returns what the new status of the message should be
|
|
73
|
-
* @param type type from receipt
|
|
74
|
-
*/
|
|
75
|
-
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
76
|
-
/**
|
|
77
|
-
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
78
|
-
* @param reason the string reason given, eg. "conflict"
|
|
79
|
-
*/
|
|
80
|
-
export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
|
|
81
|
-
reason: string;
|
|
82
|
-
statusCode: number;
|
|
83
|
-
};
|
|
84
|
-
export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
|
|
85
|
-
export declare const getCodeFromWSError: (error: Error) => number;
|
|
86
|
-
/**
|
|
87
|
-
* Is the given platform WA business
|
|
88
|
-
* @param platform AuthenticationCreds.platform
|
|
89
|
-
*/
|
|
90
|
-
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
91
|
-
export declare function trimUndefined(obj: any): any;
|
|
92
|
-
export declare function bytesToCrockford(buffer: Buffer): string;
|
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
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;
|
|
7
|
-
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const crypto_1 = require("crypto");
|
|
10
|
-
const os_1 = require("os");
|
|
11
|
-
const fetch_1 = require("node-fetch")
|
|
12
|
-
const WAProto_1 = require("../../WAProto");
|
|
13
|
-
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
14
|
-
const Types_1 = require("../Types");
|
|
15
|
-
const WABinary_1 = require("../WABinary");
|
|
16
|
-
const baileysVersion = [2, 3000, 1027934701]
|
|
17
|
-
const PLATFORM_MAP = {
|
|
18
|
-
'aix': 'AIX',
|
|
19
|
-
'darwin': 'Mac OS',
|
|
20
|
-
'win32': 'Windows',
|
|
21
|
-
'android': 'Android',
|
|
22
|
-
'freebsd': 'FreeBSD',
|
|
23
|
-
'openbsd': 'OpenBSD',
|
|
24
|
-
'sunos': 'Solaris',
|
|
25
|
-
'linux': undefined,
|
|
26
|
-
'haiku': undefined,
|
|
27
|
-
'cygwin': undefined,
|
|
28
|
-
'netbsd': undefined
|
|
29
|
-
};
|
|
30
|
-
exports.Browsers = (browser) => {
|
|
31
|
-
const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
|
|
32
|
-
const osRelease = os_1.release();
|
|
33
|
-
return [osName, browser, osRelease];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const Browsers = {
|
|
37
|
-
iOS: (browser) => ["ios", browser, "18.2"],
|
|
38
|
-
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
39
|
-
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
40
|
-
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
41
|
-
windows: (browser) => ['Windows', browser, '10.0.22631']
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exports.Browsers = Browsers
|
|
45
|
-
|
|
46
|
-
const getPlatformId = (browser) => {
|
|
47
|
-
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
48
|
-
return platformType ? platformType.toString() : '1'; //chrome
|
|
49
|
-
};
|
|
50
|
-
exports.getPlatformId = getPlatformId;
|
|
51
|
-
exports.BufferJSON = {
|
|
52
|
-
replacer: (k, value) => {
|
|
53
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
54
|
-
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
55
|
-
}
|
|
56
|
-
return value;
|
|
57
|
-
},
|
|
58
|
-
reviver: (_, value) => {
|
|
59
|
-
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
60
|
-
const val = value.data || value.value;
|
|
61
|
-
return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
|
|
67
|
-
exports.getKeyAuthor = getKeyAuthor;
|
|
68
|
-
const writeRandomPadMax16 = (msg) => {
|
|
69
|
-
const pad = (0, crypto_1.randomBytes)(1);
|
|
70
|
-
pad[0] &= 0xf;
|
|
71
|
-
if (!pad[0]) {
|
|
72
|
-
pad[0] = 0xf;
|
|
73
|
-
}
|
|
74
|
-
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
75
|
-
};
|
|
76
|
-
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
77
|
-
const unpadRandomMax16 = (e) => {
|
|
78
|
-
const t = new Uint8Array(e);
|
|
79
|
-
if (0 === t.length) {
|
|
80
|
-
throw new Error('unpadPkcs7 given empty bytes');
|
|
81
|
-
}
|
|
82
|
-
var r = t[t.length - 1];
|
|
83
|
-
if (r > t.length) {
|
|
84
|
-
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
85
|
-
}
|
|
86
|
-
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
87
|
-
};
|
|
88
|
-
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
89
|
-
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
90
|
-
exports.encodeWAMessage = encodeWAMessage;
|
|
91
|
-
const generateRegistrationId = () => {
|
|
92
|
-
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
93
|
-
};
|
|
94
|
-
exports.generateRegistrationId = generateRegistrationId;
|
|
95
|
-
const encodeBigEndian = (e, t = 4) => {
|
|
96
|
-
let r = e;
|
|
97
|
-
const a = new Uint8Array(t);
|
|
98
|
-
for (let i = t - 1; i >= 0; i--) {
|
|
99
|
-
a[i] = 255 & r;
|
|
100
|
-
r >>>= 8;
|
|
101
|
-
}
|
|
102
|
-
return a;
|
|
103
|
-
};
|
|
104
|
-
exports.encodeBigEndian = encodeBigEndian;
|
|
105
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
106
|
-
exports.toNumber = toNumber;
|
|
107
|
-
/** unix timestamp of a date in seconds */
|
|
108
|
-
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
109
|
-
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
110
|
-
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
111
|
-
let timeout;
|
|
112
|
-
return {
|
|
113
|
-
start: (newIntervalMs, newTask) => {
|
|
114
|
-
task = newTask || task;
|
|
115
|
-
intervalMs = newIntervalMs || intervalMs;
|
|
116
|
-
timeout && clearTimeout(timeout);
|
|
117
|
-
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
118
|
-
},
|
|
119
|
-
cancel: () => {
|
|
120
|
-
timeout && clearTimeout(timeout);
|
|
121
|
-
timeout = undefined;
|
|
122
|
-
},
|
|
123
|
-
setTask: (newTask) => task = newTask,
|
|
124
|
-
setInterval: (newInterval) => intervalMs = newInterval
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
exports.debouncedTimeout = debouncedTimeout;
|
|
128
|
-
const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
|
|
129
|
-
exports.delay = delay;
|
|
130
|
-
const delayCancellable = (ms) => {
|
|
131
|
-
const stack = new Error().stack;
|
|
132
|
-
let timeout;
|
|
133
|
-
let reject;
|
|
134
|
-
const delay = new Promise((resolve, _reject) => {
|
|
135
|
-
timeout = setTimeout(resolve, ms);
|
|
136
|
-
reject = _reject;
|
|
137
|
-
});
|
|
138
|
-
const cancel = () => {
|
|
139
|
-
clearTimeout(timeout);
|
|
140
|
-
reject(new boom_1.Boom('Cancelled', {
|
|
141
|
-
statusCode: 500,
|
|
142
|
-
data: {
|
|
143
|
-
stack
|
|
144
|
-
}
|
|
145
|
-
}));
|
|
146
|
-
};
|
|
147
|
-
return { delay, cancel };
|
|
148
|
-
};
|
|
149
|
-
exports.delayCancellable = delayCancellable;
|
|
150
|
-
async function promiseTimeout(ms, promise) {
|
|
151
|
-
if (!ms) {
|
|
152
|
-
return new Promise(promise);
|
|
153
|
-
}
|
|
154
|
-
const stack = new Error().stack;
|
|
155
|
-
// Create a promise that rejects in <ms> milliseconds
|
|
156
|
-
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
157
|
-
const p = new Promise((resolve, reject) => {
|
|
158
|
-
delay
|
|
159
|
-
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
160
|
-
statusCode: Types_1.DisconnectReason.timedOut,
|
|
161
|
-
data: {
|
|
162
|
-
stack
|
|
163
|
-
}
|
|
164
|
-
})))
|
|
165
|
-
.catch(err => reject(err));
|
|
166
|
-
promise(resolve, reject);
|
|
167
|
-
})
|
|
168
|
-
.finally(cancel);
|
|
169
|
-
return p;
|
|
170
|
-
}
|
|
171
|
-
exports.promiseTimeout = promiseTimeout;
|
|
172
|
-
const generateMessageIDV2 = (userId) => {
|
|
173
|
-
const data = Buffer.alloc(8 + 20 + 16);
|
|
174
|
-
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
175
|
-
if (userId) {
|
|
176
|
-
const id = (0, WABinary_1.jidDecode)(userId);
|
|
177
|
-
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
178
|
-
data.write(id.user, 8);
|
|
179
|
-
data.write('@c.us', 8 + id.user.length);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const random = (0, crypto_1.randomBytes)(16);
|
|
183
|
-
random.copy(data, 28);
|
|
184
|
-
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
185
|
-
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
186
|
-
};
|
|
187
|
-
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
188
|
-
// generate a random ID to attach to a message
|
|
189
|
-
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
190
|
-
exports.generateMessageID = generateMessageID;
|
|
191
|
-
function bindWaitForEvent(ev, event) {
|
|
192
|
-
return async (check, timeoutMs) => {
|
|
193
|
-
let listener;
|
|
194
|
-
let closeListener;
|
|
195
|
-
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
196
|
-
closeListener = ({ connection, lastDisconnect }) => {
|
|
197
|
-
if (connection === 'close') {
|
|
198
|
-
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
199
|
-
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
ev.on('connection.update', closeListener);
|
|
203
|
-
listener = (update) => {
|
|
204
|
-
if (check(update)) {
|
|
205
|
-
resolve();
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
ev.on(event, listener);
|
|
209
|
-
})
|
|
210
|
-
.finally(() => {
|
|
211
|
-
ev.off(event, listener);
|
|
212
|
-
ev.off('connection.update', closeListener);
|
|
213
|
-
}));
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
217
|
-
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
218
|
-
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
219
|
-
const printQRIfNecessaryListener = (ev, logger) => {
|
|
220
|
-
ev.on('connection.update', async ({ qr }) => {
|
|
221
|
-
if (qr) {
|
|
222
|
-
const QR = await import('qrcode-terminal')
|
|
223
|
-
.then(m => m.default || m)
|
|
224
|
-
.catch(() => {
|
|
225
|
-
logger.error('QR code terminal not added as dependency');
|
|
226
|
-
});
|
|
227
|
-
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
232
|
-
/**
|
|
233
|
-
* utility that fetches latest baileys version from the master branch.
|
|
234
|
-
* Use to ensure your WA connection is always on the latest version
|
|
235
|
-
*/
|
|
236
|
-
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
237
|
-
try {
|
|
238
|
-
const defaultHeaders = {
|
|
239
|
-
'User-Agent':
|
|
240
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
241
|
-
'Accept': '*/*'
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const headers = { ...defaultHeaders, ...options.headers }
|
|
245
|
-
|
|
246
|
-
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
247
|
-
method: 'GET',
|
|
248
|
-
headers
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
if (!response.ok) {
|
|
252
|
-
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const data = await response.text()
|
|
256
|
-
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
257
|
-
const match = data.match(regex)
|
|
258
|
-
|
|
259
|
-
if (!match || !match[1]) {
|
|
260
|
-
return {
|
|
261
|
-
version: baileysVersion,
|
|
262
|
-
isLatest: false,
|
|
263
|
-
error: { message: 'Client revision not found' }
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const clientRevision = match[1]
|
|
268
|
-
return {
|
|
269
|
-
version: [2, 3000, +clientRevision],
|
|
270
|
-
isLatest: true
|
|
271
|
-
}
|
|
272
|
-
} catch (error) {
|
|
273
|
-
return {
|
|
274
|
-
version: baileysVersion,
|
|
275
|
-
isLatest: false,
|
|
276
|
-
error
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
281
|
-
/**
|
|
282
|
-
* utility that fetches latest baileys version from the master branch.
|
|
283
|
-
* Use to ensure your WA connection is always on the latest version
|
|
284
|
-
*/
|
|
285
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
286
|
-
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
287
|
-
try {
|
|
288
|
-
const result = await axios_1.default.get(URL, {
|
|
289
|
-
...options,
|
|
290
|
-
responseType: 'json'
|
|
291
|
-
});
|
|
292
|
-
return {
|
|
293
|
-
version: result.data.version,
|
|
294
|
-
isLatest: true
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
return {
|
|
299
|
-
version: baileys_version_json_1.version,
|
|
300
|
-
isLatest: false,
|
|
301
|
-
error
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
306
|
-
/** unique message tag prefix for MD clients */
|
|
307
|
-
const generateMdTagPrefix = () => {
|
|
308
|
-
const bytes = (0, crypto_1.randomBytes)(4);
|
|
309
|
-
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
310
|
-
};
|
|
311
|
-
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
312
|
-
const STATUS_MAP = {
|
|
313
|
-
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
314
|
-
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
315
|
-
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
316
|
-
};
|
|
317
|
-
/**
|
|
318
|
-
* Given a type of receipt, returns what the new status of the message should be
|
|
319
|
-
* @param type type from receipt
|
|
320
|
-
*/
|
|
321
|
-
const getStatusFromReceiptType = (type) => {
|
|
322
|
-
const status = STATUS_MAP[type];
|
|
323
|
-
if (typeof type === 'undefined') {
|
|
324
|
-
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
325
|
-
}
|
|
326
|
-
return status;
|
|
327
|
-
};
|
|
328
|
-
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
329
|
-
const CODE_MAP = {
|
|
330
|
-
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
331
|
-
};
|
|
332
|
-
/**
|
|
333
|
-
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
334
|
-
* @param reason the string reason given, eg. "conflict"
|
|
335
|
-
*/
|
|
336
|
-
const getErrorCodeFromStreamError = (node) => {
|
|
337
|
-
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
338
|
-
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
339
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
340
|
-
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
341
|
-
reason = 'restart required';
|
|
342
|
-
}
|
|
343
|
-
return {
|
|
344
|
-
reason,
|
|
345
|
-
statusCode
|
|
346
|
-
};
|
|
347
|
-
};
|
|
348
|
-
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
349
|
-
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
350
|
-
let status;
|
|
351
|
-
switch (tag) {
|
|
352
|
-
case 'offer':
|
|
353
|
-
case 'offer_notice':
|
|
354
|
-
status = 'offer';
|
|
355
|
-
break;
|
|
356
|
-
case 'terminate':
|
|
357
|
-
if (attrs.reason === 'timeout') {
|
|
358
|
-
status = 'timeout';
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
status = 'reject';
|
|
362
|
-
}
|
|
363
|
-
break;
|
|
364
|
-
case 'reject':
|
|
365
|
-
status = 'reject';
|
|
366
|
-
break;
|
|
367
|
-
case 'accept':
|
|
368
|
-
status = 'accept';
|
|
369
|
-
break;
|
|
370
|
-
default:
|
|
371
|
-
status = 'ringing';
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
return status;
|
|
375
|
-
};
|
|
376
|
-
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
377
|
-
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
378
|
-
const getCodeFromWSError = (error) => {
|
|
379
|
-
var _a, _b, _c;
|
|
380
|
-
let statusCode = 500;
|
|
381
|
-
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
382
|
-
const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
|
|
383
|
-
if (!Number.isNaN(code) && code >= 400) {
|
|
384
|
-
statusCode = code;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
388
|
-
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
389
|
-
statusCode = 408;
|
|
390
|
-
}
|
|
391
|
-
return statusCode;
|
|
392
|
-
};
|
|
393
|
-
exports.getCodeFromWSError = getCodeFromWSError;
|
|
394
|
-
/**
|
|
395
|
-
* Is the given platform WA business
|
|
396
|
-
* @param platform AuthenticationCreds.platform
|
|
397
|
-
*/
|
|
398
|
-
const isWABusinessPlatform = (platform) => {
|
|
399
|
-
return platform === 'smbi' || platform === 'smba';
|
|
400
|
-
};
|
|
401
|
-
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
402
|
-
function trimUndefined(obj) {
|
|
403
|
-
for (const key in obj) {
|
|
404
|
-
if (typeof obj[key] === 'undefined') {
|
|
405
|
-
delete obj[key];
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return obj;
|
|
409
|
-
}
|
|
410
|
-
exports.trimUndefined = trimUndefined;
|
|
411
|
-
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
412
|
-
function bytesToCrockford(buffer) {
|
|
413
|
-
let value = 0;
|
|
414
|
-
let bitCount = 0;
|
|
415
|
-
const crockford = [];
|
|
416
|
-
for (let i = 0; i < buffer.length; i++) {
|
|
417
|
-
value = (value << 8) | (buffer[i] & 0xff);
|
|
418
|
-
bitCount += 8;
|
|
419
|
-
while (bitCount >= 5) {
|
|
420
|
-
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
421
|
-
bitCount -= 5;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (bitCount > 0) {
|
|
425
|
-
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
426
|
-
}
|
|
427
|
-
return crockford.join('');
|
|
428
|
-
}
|
|
429
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
430
|
-
const encodeNewsletterMessage = (message) => {
|
|
431
|
-
return WAProto_1.proto.Message.encode(message).finish()
|
|
432
|
-
}
|
|
433
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
package/lib/Utils/history.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { proto } from '../../WAProto';
|
|
3
|
-
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
|
-
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
|
-
chats: Chat[];
|
|
7
|
-
contacts: Contact[];
|
|
8
|
-
messages: proto.IWebMessageInfo[];
|
|
9
|
-
};
|
|
10
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
11
|
-
chats: Chat[];
|
|
12
|
-
contacts: Contact[];
|
|
13
|
-
messages: proto.IWebMessageInfo[];
|
|
14
|
-
}>;
|
|
15
|
-
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './generics';
|
|
2
|
-
export * from './decode-wa-message';
|
|
3
|
-
export * from './messages';
|
|
4
|
-
export * from './messages-media';
|
|
5
|
-
export * from './validate-connection';
|
|
6
|
-
export * from './crypto';
|
|
7
|
-
export * from './signal';
|
|
8
|
-
export * from './noise-handler';
|
|
9
|
-
export * from './history';
|
|
10
|
-
export * from './chat-utils';
|
|
11
|
-
export * from './lt-hash';
|
|
12
|
-
export * from './auth-utils';
|
|
13
|
-
export * from './baileys-event-stream';
|
|
14
|
-
export * from './use-multi-file-auth-state';
|
|
15
|
-
export * from './link-preview';
|
|
16
|
-
export * from './event-buffer';
|
|
17
|
-
export * from './process-message';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { Logger } from 'pino';
|
|
3
|
-
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
-
export type URLGenerationOptions = {
|
|
5
|
-
thumbnailWidth: number;
|
|
6
|
-
fetchOpts: {
|
|
7
|
-
/** Timeout in ms */
|
|
8
|
-
timeout: number;
|
|
9
|
-
proxyUrl?: string;
|
|
10
|
-
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
|
-
};
|
|
12
|
-
uploadImage?: WAMediaUploadFunction;
|
|
13
|
-
logger?: Logger;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
17
|
-
* Return undefined if the fetch failed or no URL was found
|
|
18
|
-
* @param text first matched URL in text
|
|
19
|
-
* @returns the URL info required to generate link preview
|
|
20
|
-
*/
|
|
21
|
-
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
package/lib/Utils/logger.d.ts
DELETED
package/lib/Utils/lt-hash.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare class d {
|
|
2
|
-
salt: string;
|
|
3
|
-
constructor(e: string);
|
|
4
|
-
add(e: any, t: any): any;
|
|
5
|
-
subtract(e: any, t: any): any;
|
|
6
|
-
subtractThenAdd(e: any, t: any, r: any): any;
|
|
7
|
-
_addSingle(e: any, t: any): ArrayBuffer;
|
|
8
|
-
_subtractSingle(e: any, t: any): ArrayBuffer;
|
|
9
|
-
performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
|
|
10
|
-
}
|
|
11
|
-
export declare const LT_HASH_ANTI_TAMPERING: d;
|
|
12
|
-
export {};
|