baileys-mood 0.4.2 → 0.5.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/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +125 -96
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- 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/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +320 -265
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +66 -10
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +419 -382
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +210 -72
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +34 -8
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +15 -27
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/{wileys-event-stream.js → baileys-event-stream.js} +1 -1
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +9 -13
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +86 -125
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +1 -3
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +236 -296
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +92 -325
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -6
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +3 -1
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +5 -28
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +7 -19
- package/package.json +100 -105
- package/LICENSE +0 -21
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/p.html +0 -1
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/Utils/browser-utils.js +0 -35
- package/lib/Utils/message-retry-manager.js +0 -128
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -27,14 +27,14 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
|
27
27
|
/**
|
|
28
28
|
* The event buffer logically consolidates different events into a single event
|
|
29
29
|
* making the data processing more efficient.
|
|
30
|
-
* @param ev the
|
|
30
|
+
* @param ev the baileys event emitter
|
|
31
31
|
*/
|
|
32
32
|
const makeEventBuffer = (logger) => {
|
|
33
33
|
const ev = new events_1.default();
|
|
34
34
|
const historyCache = new Set();
|
|
35
35
|
let data = makeBufferData();
|
|
36
36
|
let buffersInProgress = 0;
|
|
37
|
-
// take the generic event and fire it as a
|
|
37
|
+
// take the generic event and fire it as a baileys event
|
|
38
38
|
ev.on('event', (map) => {
|
|
39
39
|
for (const event in map) {
|
|
40
40
|
ev.emit(event, map[event]);
|
|
@@ -176,9 +176,6 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
data.historySets.empty = false;
|
|
179
|
-
data.historySets.syncType = eventData.syncType;
|
|
180
|
-
data.historySets.progress = eventData.progress;
|
|
181
|
-
data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
|
|
182
179
|
data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
|
|
183
180
|
break;
|
|
184
181
|
case 'chats.upsert':
|
|
@@ -445,10 +442,7 @@ function consolidateEvents(data) {
|
|
|
445
442
|
chats: Object.values(data.historySets.chats),
|
|
446
443
|
messages: Object.values(data.historySets.messages),
|
|
447
444
|
contacts: Object.values(data.historySets.contacts),
|
|
448
|
-
|
|
449
|
-
progress: data.historySets.progress,
|
|
450
|
-
isLatest: data.historySets.isLatest,
|
|
451
|
-
peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
|
|
445
|
+
isLatest: data.historySets.isLatest
|
|
452
446
|
};
|
|
453
447
|
}
|
|
454
448
|
const chatUpsertList = Object.values(data.chatUpserts);
|
|
@@ -502,10 +496,12 @@ function consolidateEvents(data) {
|
|
|
502
496
|
return map;
|
|
503
497
|
}
|
|
504
498
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
a.unreadCount
|
|
508
|
-
|
|
499
|
+
if (b.unreadCount === null) {
|
|
500
|
+
// neutralize unread counter
|
|
501
|
+
if (a.unreadCount < 0) {
|
|
502
|
+
a.unreadCount = undefined;
|
|
503
|
+
b.unreadCount = undefined;
|
|
504
|
+
}
|
|
509
505
|
}
|
|
510
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
511
507
|
b = { ...b };
|
|
@@ -0,0 +1,92 @@
|
|
|
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;
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,61 +1,19 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
1
|
+
"use strict";
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.
|
|
40
|
-
exports.promiseTimeout = promiseTimeout;
|
|
41
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
|
-
exports.trimUndefined = trimUndefined;
|
|
43
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
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;
|
|
44
7
|
const boom_1 = require("@hapi/boom");
|
|
45
8
|
const axios_1 = __importDefault(require("axios"));
|
|
46
9
|
const crypto_1 = require("crypto");
|
|
47
10
|
const os_1 = require("os");
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
48
12
|
const WAProto_1 = require("../../WAProto");
|
|
49
|
-
const
|
|
13
|
+
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
50
14
|
const Types_1 = require("../Types");
|
|
51
15
|
const WABinary_1 = require("../WABinary");
|
|
52
|
-
const
|
|
53
|
-
'Chrome': '49',
|
|
54
|
-
'Edge': '50',
|
|
55
|
-
'Firefox': '51',
|
|
56
|
-
'Opera': '53',
|
|
57
|
-
'Safari': '54'
|
|
58
|
-
};
|
|
16
|
+
const baileysVersion = [2, 3000, 1027934701]
|
|
59
17
|
const PLATFORM_MAP = {
|
|
60
18
|
'aix': 'AIX',
|
|
61
19
|
'darwin': 'Mac OS',
|
|
@@ -63,19 +21,26 @@ const PLATFORM_MAP = {
|
|
|
63
21
|
'android': 'Android',
|
|
64
22
|
'freebsd': 'FreeBSD',
|
|
65
23
|
'openbsd': 'OpenBSD',
|
|
66
|
-
'sunos': 'Solaris'
|
|
24
|
+
'sunos': 'Solaris',
|
|
25
|
+
'linux': undefined,
|
|
26
|
+
'haiku': undefined,
|
|
27
|
+
'cygwin': undefined,
|
|
28
|
+
'netbsd': undefined
|
|
67
29
|
};
|
|
68
|
-
|
|
30
|
+
|
|
31
|
+
const Browsers = {
|
|
32
|
+
iOS: (browser) => ["ios", browser, "18.2"],
|
|
69
33
|
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
70
34
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
71
35
|
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
72
|
-
windows: (browser) => ['Windows', browser, '10.0.22631']
|
|
73
|
-
/** The appropriate browser based on your OS & release */
|
|
74
|
-
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
36
|
+
windows: (browser) => ['Windows', browser, '10.0.22631']
|
|
75
37
|
};
|
|
38
|
+
|
|
39
|
+
exports.Browsers = Browsers
|
|
40
|
+
|
|
76
41
|
const getPlatformId = (browser) => {
|
|
77
42
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
78
|
-
return platformType ? platformType.toString() : '
|
|
43
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
79
44
|
};
|
|
80
45
|
exports.getPlatformId = getPlatformId;
|
|
81
46
|
exports.BufferJSON = {
|
|
@@ -118,8 +83,6 @@ const unpadRandomMax16 = (e) => {
|
|
|
118
83
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
119
84
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
120
85
|
exports.encodeWAMessage = encodeWAMessage;
|
|
121
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
122
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
123
86
|
const generateRegistrationId = () => {
|
|
124
87
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
125
88
|
};
|
|
@@ -134,7 +97,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
134
97
|
return a;
|
|
135
98
|
};
|
|
136
99
|
exports.encodeBigEndian = encodeBigEndian;
|
|
137
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
100
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
138
101
|
exports.toNumber = toNumber;
|
|
139
102
|
/** unix timestamp of a date in seconds */
|
|
140
103
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -200,6 +163,7 @@ async function promiseTimeout(ms, promise) {
|
|
|
200
163
|
.finally(cancel);
|
|
201
164
|
return p;
|
|
202
165
|
}
|
|
166
|
+
exports.promiseTimeout = promiseTimeout;
|
|
203
167
|
const generateMessageIDV2 = (userId) => {
|
|
204
168
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
205
169
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
@@ -217,7 +181,7 @@ const generateMessageIDV2 = (userId) => {
|
|
|
217
181
|
};
|
|
218
182
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
219
183
|
// generate a random ID to attach to a message
|
|
220
|
-
const generateMessageID = () => '
|
|
184
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
221
185
|
exports.generateMessageID = generateMessageID;
|
|
222
186
|
function bindWaitForEvent(ev, event) {
|
|
223
187
|
return async (check, timeoutMs) => {
|
|
@@ -231,8 +195,8 @@ function bindWaitForEvent(ev, event) {
|
|
|
231
195
|
}
|
|
232
196
|
};
|
|
233
197
|
ev.on('connection.update', closeListener);
|
|
234
|
-
listener =
|
|
235
|
-
if (
|
|
198
|
+
listener = (update) => {
|
|
199
|
+
if (check(update)) {
|
|
236
200
|
resolve();
|
|
237
201
|
}
|
|
238
202
|
};
|
|
@@ -244,12 +208,14 @@ function bindWaitForEvent(ev, event) {
|
|
|
244
208
|
}));
|
|
245
209
|
};
|
|
246
210
|
}
|
|
211
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
247
212
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
248
213
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
249
214
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
250
215
|
ev.on('connection.update', async ({ qr }) => {
|
|
251
216
|
if (qr) {
|
|
252
|
-
const QR = await
|
|
217
|
+
const QR = await import('qrcode-terminal')
|
|
218
|
+
.then(m => m.default || m)
|
|
253
219
|
.catch(() => {
|
|
254
220
|
logger.error('QR code terminal not added as dependency');
|
|
255
221
|
});
|
|
@@ -258,87 +224,80 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
258
224
|
});
|
|
259
225
|
};
|
|
260
226
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
227
|
+
/**
|
|
228
|
+
* utility that fetches latest baileys version from the master branch.
|
|
229
|
+
* Use to ensure your WA connection is always on the latest version
|
|
230
|
+
*/
|
|
231
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
232
|
+
try {
|
|
233
|
+
const defaultHeaders = {
|
|
234
|
+
'User-Agent':
|
|
235
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
236
|
+
'Accept': '*/*'
|
|
237
|
+
}
|
|
261
238
|
|
|
262
|
-
const
|
|
263
|
-
try {
|
|
264
|
-
const { data } = await axios_1.default.get('https://registry.npmjs.org/wileys', {
|
|
265
|
-
...options,
|
|
266
|
-
responseType: 'json'
|
|
267
|
-
});
|
|
268
|
-
const versionStr = data.version;
|
|
269
|
-
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
270
|
-
return {
|
|
271
|
-
version: [major, minor, patch],
|
|
272
|
-
isLatest: true
|
|
273
|
-
};
|
|
274
|
-
} catch (error) {
|
|
275
|
-
return {
|
|
276
|
-
version: wileys_version_json_1.version,
|
|
277
|
-
isLatest: false,
|
|
278
|
-
error
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
exports.fetchLatestWileysVersion = fetchLatestWileysVersion;
|
|
239
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
283
240
|
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return {
|
|
293
|
-
version: [major, minor, patch],
|
|
294
|
-
isLatest: true
|
|
295
|
-
};
|
|
296
|
-
} catch (error) {
|
|
297
|
-
return {
|
|
298
|
-
version: wileys_version_json_1.version,
|
|
299
|
-
isLatest: false,
|
|
300
|
-
error
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
241
|
+
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
242
|
+
method: 'GET',
|
|
243
|
+
headers
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
if (!response.ok) {
|
|
247
|
+
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
248
|
+
}
|
|
305
249
|
|
|
250
|
+
const data = await response.text()
|
|
251
|
+
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
252
|
+
const match = data.match(regex)
|
|
253
|
+
|
|
254
|
+
if (!match || !match[1]) {
|
|
255
|
+
return {
|
|
256
|
+
version: baileysVersion,
|
|
257
|
+
isLatest: false,
|
|
258
|
+
error: { message: 'Client revision not found' }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const clientRevision = match[1]
|
|
263
|
+
return {
|
|
264
|
+
version: [2, 3000, +clientRevision],
|
|
265
|
+
isLatest: true
|
|
266
|
+
}
|
|
267
|
+
} catch (error) {
|
|
268
|
+
return {
|
|
269
|
+
version: baileysVersion,
|
|
270
|
+
isLatest: false,
|
|
271
|
+
error
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
306
276
|
/**
|
|
307
|
-
*
|
|
277
|
+
* utility that fetches latest baileys version from the master branch.
|
|
308
278
|
* Use to ensure your WA connection is always on the latest version
|
|
309
279
|
*/
|
|
310
|
-
const
|
|
280
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
281
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
311
282
|
try {
|
|
312
|
-
const
|
|
283
|
+
const result = await axios_1.default.get(URL, {
|
|
313
284
|
...options,
|
|
314
285
|
responseType: 'json'
|
|
315
286
|
});
|
|
316
|
-
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
317
|
-
const match = data.match(regex);
|
|
318
|
-
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
319
|
-
return {
|
|
320
|
-
version: wileys_version_json_1.version,
|
|
321
|
-
isLatest: false,
|
|
322
|
-
error: {
|
|
323
|
-
message: 'Could not find client revision in the fetched content'
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
const clientRevision = match[1];
|
|
328
287
|
return {
|
|
329
|
-
version:
|
|
288
|
+
version: result.data.version,
|
|
330
289
|
isLatest: true
|
|
331
290
|
};
|
|
332
291
|
}
|
|
333
292
|
catch (error) {
|
|
334
293
|
return {
|
|
335
|
-
version:
|
|
294
|
+
version: baileys_version_json_1.version,
|
|
336
295
|
isLatest: false,
|
|
337
296
|
error
|
|
338
297
|
};
|
|
339
298
|
}
|
|
340
299
|
};
|
|
341
|
-
exports.
|
|
300
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
342
301
|
/** unique message tag prefix for MD clients */
|
|
343
302
|
const generateMdTagPrefix = () => {
|
|
344
303
|
const bytes = (0, crypto_1.randomBytes)(4);
|
|
@@ -346,7 +305,6 @@ const generateMdTagPrefix = () => {
|
|
|
346
305
|
};
|
|
347
306
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
348
307
|
const STATUS_MAP = {
|
|
349
|
-
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
350
308
|
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
351
309
|
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
352
310
|
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
@@ -395,8 +353,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
395
353
|
status = 'timeout';
|
|
396
354
|
}
|
|
397
355
|
else {
|
|
398
|
-
|
|
399
|
-
status = 'terminate';
|
|
356
|
+
status = 'reject';
|
|
400
357
|
}
|
|
401
358
|
break;
|
|
402
359
|
case 'reject':
|
|
@@ -445,6 +402,7 @@ function trimUndefined(obj) {
|
|
|
445
402
|
}
|
|
446
403
|
return obj;
|
|
447
404
|
}
|
|
405
|
+
exports.trimUndefined = trimUndefined;
|
|
448
406
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
449
407
|
function bytesToCrockford(buffer) {
|
|
450
408
|
let value = 0;
|
|
@@ -463,5 +421,8 @@ function bytesToCrockford(buffer) {
|
|
|
463
421
|
}
|
|
464
422
|
return crockford.join('');
|
|
465
423
|
}
|
|
466
|
-
exports.
|
|
467
|
-
|
|
424
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
425
|
+
const encodeNewsletterMessage = (message) => {
|
|
426
|
+
return WAProto_1.proto.Message.encode(message).finish()
|
|
427
|
+
}
|
|
428
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|