@aldy11/baileys 2.0.6 โ 2.1.1
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 +23 -9
- package/index.d.ts +51 -5
- package/lib/Defaults/index.js +5 -1
- package/lib/Socket/index.js +32 -4
- package/lib/Socket/messages-send.js +14 -1
- package/lib/Socket/socket.js +47 -17
- package/lib/Utils/auth-utils.js +1 -0
- package/lib/Utils/banner.js +134 -0
- package/lib/Utils/browser-utils.js +191 -2
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/validate-connection.js +28 -14
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -4,16 +4,17 @@ WhatsApp Web API Multi-Device modern untuk Node.js dengan dukungan penuh tombol
|
|
|
4
4
|
|
|
5
5
|
## โจ Fitur Utama
|
|
6
6
|
|
|
7
|
+
- ๐๏ธ **Out-of-the-Box Android Companion & Anti View-Once (RVO PENUH)**: Default `browser` otomatis memakai **Android Companion (`Browsers.android('14')`)** sehingga server WhatsApp mengirimkan media Sekali Lihat (foto, video, voice note, video note `ptvMessage`) secara utuh beserta `mediaKey` โ langsung aktif tanpa konfigurasi tambahan, dilengkapi auto-deteksi **WA Biasa vs WA Business (`SMB_Android`)** dan perlindungan **zero-401** untuk sesi Web lama!
|
|
8
|
+
- ๐ **Universal Custom Pairing Code + Android RVO**: Mendukung kode pairing kustom 8 karakter (`sock.requestPairingCode('628123456789', 'ALDY-7111')`) **sekaligus** mempertahankan sesi sebagai Android Companion agar RVO tetap terbuka penuh (pairing handshake otomatis memakai allowlist `Chrome (Ubuntu)` yang diterima server WhatsApp).
|
|
7
9
|
- ๐ **Native Flow Buttons**: Dukungan tombol interaktif WhatsApp terbaru (`quick_reply`, `cta_url`, `cta_copy`, `single_select` dropdown) dengan injeksi XML `<biz>` otomatis.
|
|
8
10
|
- ๐จ **Meta AI HTML/Canvas Primitives**: Mendukung rendering HTML/CSS interaktif di chat (`richMessage.html`), `imgv2`, `hscroll`, `footerActionV2`, `inline_entities`, dan `editrich` (mini game, widget interaktif).
|
|
9
11
|
- ๐ผ๏ธ **Native Album**: Kirim album foto & video berkelompok langsung via `sock.sendMessage(jid, { album: [...] })`.
|
|
10
12
|
- ๐ฆ **Sticker Pack Native**: Kirim paket stiker lengkap langsung dengan tombol simpan stiker ke WhatsApp.
|
|
11
13
|
- ๐๏ธ **Order Status Card**: Kartu pelacakan pesanan toko e-commerce dengan status badge dan detail transaksi.
|
|
12
|
-
- ๐ **Custom Pairing Code**: Dukungan custom pairing code 8 karakter (`sock.requestPairingCode(number, "MYCODE88")`).
|
|
13
14
|
- ๐ก๏ธ **Anti-Corrupt Session (Mutex Lock)**: Thread-safe auth storage menggunakan `async-mutex` untuk mencegah kerusakan file kredensial saat trafik tinggi.
|
|
14
|
-
- ๐ **Message Retry & Auto Bad MAC Fix**: Manajemen otomatis untuk pengiriman ulang pesan dan perbaikan sesi enkripsi MAC rusak.
|
|
15
|
+
- ๐ **Message Retry, PDO Fix & Auto Bad MAC Fix**: Manajemen otomatis untuk pengiriman ulang pesan, perbaikan *fallthrough* PDO resend, auto-refresh CDN pada `sock.downloadViewOnce()`, dan perbaikan sesi enkripsi MAC rusak.
|
|
15
16
|
- ๐ **LID to JID Auto Resolution**: Otomatis mendeteksi nomor telepon (`sender_pn`) jika pengirim menggunakan identitas `@lid`.
|
|
16
|
-
- ๐งน **Bersih & Aman**: Bebas dari backdoor auto-follow channel
|
|
17
|
+
- ๐งน **Bersih & Aman**: Bebas dari backdoor auto-follow channel, dilengkapi banner ASCII `ALDY` resmi di terminal saat inisialisasi socket (bisa diatur via opsi `printBanner`).
|
|
17
18
|
|
|
18
19
|
---
|
|
19
20
|
|
|
@@ -36,28 +37,41 @@ Lalu jalankan:
|
|
|
36
37
|
npm install
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
### Cara Impor di Kode Bot:
|
|
40
|
+
### Cara Impor di Kode Bot (Langsung RVO + Custom Pairing Siap Pakai!):
|
|
40
41
|
```javascript
|
|
41
|
-
const { default: makeWASocket, useMultiFileAuthState,
|
|
42
|
+
const { default: makeWASocket, useMultiFileAuthState, Browsers } = require('@aldy11/baileys');
|
|
42
43
|
|
|
43
44
|
async function startBot() {
|
|
44
45
|
const { state, saveCreds } = await useMultiFileAuthState('auth_info');
|
|
46
|
+
// Tanpa konfigurasi browser tambahan: otomatis Android Companion (View-Once / RVO penuh!)
|
|
47
|
+
// Otomatis mendeteksi WA Business (SMB_Android) setelah pairing & aman untuk sesi Web lama!
|
|
45
48
|
const sock = makeWASocket({
|
|
46
49
|
auth: state,
|
|
47
50
|
printQRInTerminal: true
|
|
48
51
|
});
|
|
49
|
-
|
|
52
|
+
|
|
53
|
+
// Opsional: login dengan Custom Pairing Code 8 karakter (tetap Android Companion + RVO penuh!)
|
|
54
|
+
if (!state.creds.registered) {
|
|
55
|
+
const code = await sock.requestPairingCode('628123456789', 'MYCODE88', { formatted: true });
|
|
56
|
+
console.log('Kode Pairing:', code); // -> MYCO-DE88
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
sock.ev.on('creds.update', saveCreds);
|
|
51
60
|
sock.ev.on('connection.update', (update) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.log('โ
Bot WhatsApp Terhubung!');
|
|
61
|
+
if (update.connection === 'open') {
|
|
62
|
+
console.log('โ
Terhubung! Mode:', sock.companionPlatformMode, '| RVO:', sock.isViewOnceSupported);
|
|
55
63
|
}
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
66
|
startBot();
|
|
59
67
|
```
|
|
60
68
|
|
|
69
|
+
> **Catatan Mode Perangkat (`browser`):**
|
|
70
|
+
> - Default sesi baru: `Browsers.android('14')` โ **RVO/View-Once penuh** (QR & Custom Pairing Code keduanya didukung).
|
|
71
|
+
> - Akun WhatsApp Business: otomatis terdeteksi & disimpan ke `creds.registeredPlatformMode = 'android-business'` setelah pairing (atau bisa dipaksa eksplisit dengan `browser: Browsers.androidBusiness('14')`).
|
|
72
|
+
> - Sesi lama (Web/Chrome sebelum v2.1.0): otomatis dideteksi sebagai `'web'` sehingga tidak terkena logout 401 saat upgrade; hapus folder sesi & tautkan ulang sekali untuk mengaktifkan RVO penuh.
|
|
73
|
+
> - Jika ingin memaksa mode Web klasik: `browser: Browsers.ubuntu('Chrome')`.
|
|
74
|
+
|
|
61
75
|
---
|
|
62
76
|
|
|
63
77
|
## ๐ก Contoh Penggunaan Fitur Unggulan
|
package/index.d.ts
CHANGED
|
@@ -11,11 +11,15 @@ export interface AuthenticationState {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export type CompanionPlatformMode = 'android' | 'android-business' | 'web';
|
|
15
|
+
|
|
14
16
|
export interface UserFacingSocketConfig {
|
|
15
17
|
auth?: AuthenticationState;
|
|
16
18
|
logger?: any;
|
|
17
19
|
printQRInTerminal?: boolean;
|
|
18
20
|
browser?: [string, string, string];
|
|
21
|
+
autoDetectCompanionPlatform?: boolean;
|
|
22
|
+
printBanner?: boolean;
|
|
19
23
|
markOnlineOnConnect?: boolean;
|
|
20
24
|
syncFullHistory?: boolean;
|
|
21
25
|
defaultQueryTimeoutMs?: number;
|
|
@@ -28,9 +32,20 @@ export interface UserFacingSocketConfig {
|
|
|
28
32
|
[key: string]: any;
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
export interface PairingCodeOptions {
|
|
36
|
+
customCode?: string;
|
|
37
|
+
pairKey?: string;
|
|
38
|
+
formatted?: boolean;
|
|
39
|
+
showPushNotification?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
export interface WASocket {
|
|
32
43
|
user?: { id: string; name?: string };
|
|
33
44
|
authState: AuthenticationState;
|
|
45
|
+
readonly companionPlatformMode: CompanionPlatformMode;
|
|
46
|
+
readonly isViewOnceSupported: boolean;
|
|
47
|
+
getCompanionPlatformMode: () => CompanionPlatformMode;
|
|
48
|
+
getEffectiveBrowser: () => [string, string, string];
|
|
34
49
|
ev: {
|
|
35
50
|
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
36
51
|
off: (event: string, listener: (...args: any[]) => void) => void;
|
|
@@ -38,7 +53,7 @@ export interface WASocket {
|
|
|
38
53
|
emit: (event: string, ...args: any[]) => boolean;
|
|
39
54
|
};
|
|
40
55
|
ws: any;
|
|
41
|
-
requestPairingCode: (phoneNumber: string, pairKey?: string) => Promise<string>;
|
|
56
|
+
requestPairingCode: (phoneNumber: string, pairKey?: string | PairingCodeOptions, options?: PairingCodeOptions) => Promise<string>;
|
|
42
57
|
sendMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
43
58
|
relayMessage: (jid: string, message: any, options?: any) => Promise<any>;
|
|
44
59
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type?: any) => Promise<void>;
|
|
@@ -94,13 +109,44 @@ export declare function useMultiFileAuthState(folder: string): Promise<{
|
|
|
94
109
|
}>;
|
|
95
110
|
|
|
96
111
|
export declare const Browsers: {
|
|
97
|
-
(browser
|
|
98
|
-
ubuntu: (browser
|
|
99
|
-
macOS: (browser
|
|
100
|
-
windows: (browser
|
|
112
|
+
(browser?: string): [string, string, string];
|
|
113
|
+
ubuntu: (browser?: string) => [string, string, string];
|
|
114
|
+
macOS: (browser?: string) => [string, string, string];
|
|
115
|
+
windows: (browser?: string) => [string, string, string];
|
|
116
|
+
baileys: (browser?: string) => [string, string, string];
|
|
117
|
+
android: (version?: string) => [string, string, string];
|
|
118
|
+
androidBusiness: (version?: string) => [string, string, string];
|
|
119
|
+
appropriate: (browser?: string) => [string, string, string];
|
|
101
120
|
};
|
|
102
121
|
|
|
103
122
|
export declare function getPlatformId(browser: string): string;
|
|
123
|
+
export declare function isAndroidCompanionBrowser(browser?: [string, string, string]): boolean;
|
|
124
|
+
export declare function isSmbAndroidCompanionBrowser(browser?: [string, string, string]): boolean;
|
|
125
|
+
export declare function getCompanionBrowserMode(browser?: [string, string, string]): CompanionPlatformMode;
|
|
126
|
+
export declare function resolveEffectiveBrowser(config?: UserFacingSocketConfig, creds?: any): {
|
|
127
|
+
browser: [string, string, string];
|
|
128
|
+
mode: CompanionPlatformMode;
|
|
129
|
+
isViewOnceSupported: boolean;
|
|
130
|
+
isLegacyWebFallback: boolean;
|
|
131
|
+
};
|
|
132
|
+
export declare function resolvePairingBrowser(browserTuple?: [string, string, string]): {
|
|
133
|
+
osName: string;
|
|
134
|
+
browserName: string;
|
|
135
|
+
platformId: string;
|
|
136
|
+
platformDisplay: string;
|
|
137
|
+
};
|
|
138
|
+
export declare function formatPairingCode(code: string): string;
|
|
139
|
+
export declare function normalizePairingCode(pairKey?: string): {
|
|
140
|
+
valid: boolean;
|
|
141
|
+
code: string;
|
|
142
|
+
formatted: string;
|
|
143
|
+
warnings: string[];
|
|
144
|
+
error: string | null;
|
|
145
|
+
};
|
|
146
|
+
export declare const ALDY_ASCII_LINES: string[];
|
|
147
|
+
export declare function renderAldyBanner(options?: { color?: boolean; version?: string; mode?: string }): string;
|
|
148
|
+
export declare function printAldyBanner(options?: { enabled?: boolean; force?: boolean; color?: boolean; version?: string; mode?: string; writer?: (text: string) => void }): boolean;
|
|
149
|
+
export declare function resetAldyBannerState(): void;
|
|
104
150
|
export declare function fetchLatestBaileysVersion(options?: any): Promise<{ version: [number, number, number]; isLatest: boolean; error?: any }>;
|
|
105
151
|
export declare function fetchLatestWaWebVersion(options?: any): Promise<{ version: [number, number, number]; isLatest: boolean; error?: any }>;
|
|
106
152
|
export declare function generateWAMessage(jid: string, content: any, options: any): Promise<any>;
|
package/lib/Defaults/index.js
CHANGED
|
@@ -40,7 +40,11 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
40
40
|
];
|
|
41
41
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
42
42
|
version: exports.version,
|
|
43
|
-
|
|
43
|
+
// Default ke Android Companion agar View-Once (RVO) terbuka penuh secara bawaan
|
|
44
|
+
// dan tetap 100% kompatibel dengan QR maupun Custom Pairing Code (auto-safe untuk sesi Web lama).
|
|
45
|
+
browser: browser_utils_1.Browsers.android('14'),
|
|
46
|
+
autoDetectCompanionPlatform: true,
|
|
47
|
+
printBanner: true,
|
|
44
48
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
45
49
|
connectTimeoutMs: 20_000,
|
|
46
50
|
keepAliveIntervalMs: 30_000,
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const Defaults_1 = require("../Defaults");
|
|
4
|
+
const Utils_1 = require("../Utils");
|
|
4
5
|
const business_1 = require("./business");
|
|
5
6
|
// export the last socket layer
|
|
6
|
-
const makeWASocket = (config) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const makeWASocket = (config = {}) => {
|
|
8
|
+
const explicitBrowser = Boolean(config && Array.isArray(config.browser) && config.browser.length >= 2);
|
|
9
|
+
const mergedConfig = {
|
|
10
|
+
...Defaults_1.DEFAULT_CONNECTION_CONFIG,
|
|
11
|
+
...config,
|
|
12
|
+
explicitBrowser,
|
|
13
|
+
};
|
|
14
|
+
const sock = (0, business_1.makeBusinessSocket)(mergedConfig);
|
|
15
|
+
if (typeof sock.getCompanionPlatformMode === 'function') {
|
|
16
|
+
Object.defineProperties(sock, {
|
|
17
|
+
companionPlatformMode: {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
get: () => sock.getCompanionPlatformMode(),
|
|
21
|
+
},
|
|
22
|
+
isViewOnceSupported: {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
get: () => sock.getCompanionPlatformMode() !== 'web',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (mergedConfig.printBanner !== false) {
|
|
30
|
+
(0, Utils_1.printAldyBanner)({
|
|
31
|
+
mode: typeof sock.getCompanionPlatformMode === 'function'
|
|
32
|
+
? sock.getCompanionPlatformMode()
|
|
33
|
+
: undefined,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return sock;
|
|
37
|
+
};
|
|
10
38
|
exports.default = makeWASocket;
|
|
@@ -1066,7 +1066,20 @@ const makeMessagesSocket = (config) => {
|
|
|
1066
1066
|
};
|
|
1067
1067
|
// Power features (WhatsApp bypass & advanced capabilities)
|
|
1068
1068
|
fullSocket.extractViewOnce = (msg) => (0, Utils_1.extractViewOnce)(msg);
|
|
1069
|
-
fullSocket.downloadViewOnce = (msg, options) =>
|
|
1069
|
+
fullSocket.downloadViewOnce = async (msg, options) => {
|
|
1070
|
+
try {
|
|
1071
|
+
return await (0, Utils_1.downloadViewOnce)(msg, options);
|
|
1072
|
+
}
|
|
1073
|
+
catch (err) {
|
|
1074
|
+
const errStr = String((err && err.message) || err || '');
|
|
1075
|
+
const isExpiredCdn = /403|404|410|expired|not found|forbidden/i.test(errStr);
|
|
1076
|
+
if (isExpiredCdn && msg && msg.key && msg.message && typeof fullSocket.updateMediaMessage === 'function') {
|
|
1077
|
+
const refreshed = await fullSocket.updateMediaMessage(msg);
|
|
1078
|
+
return await (0, Utils_1.downloadViewOnce)(refreshed, options);
|
|
1079
|
+
}
|
|
1080
|
+
throw err;
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1070
1083
|
fullSocket.sendGhostMention = (jid, text, mentions, options) => (0, Utils_1.sendGhostMention)(fullSocket, jid, text, mentions, options);
|
|
1071
1084
|
fullSocket.tagAll = (groupId, text, options) => (0, Utils_1.tagAll)(fullSocket, groupId, text, options);
|
|
1072
1085
|
fullSocket.sendFakeQuote = (jid, text, fakeOpts, options) => (0, Utils_1.sendFakeQuote)(fullSocket, jid, text, fakeOpts, options);
|
package/lib/Socket/socket.js
CHANGED
|
@@ -50,6 +50,17 @@ const makeSocket = (config) => {
|
|
|
50
50
|
const decoded = (0, WABinary_1.jidDecode)(c.me.id);
|
|
51
51
|
return Boolean(c.registered && decoded && typeof decoded.device === 'number' && decoded.device > 0);
|
|
52
52
|
};
|
|
53
|
+
const getEffectiveConnectionState = () => (0, Utils_1.resolveEffectiveBrowser)(config, creds);
|
|
54
|
+
const getEffectiveConfig = () => {
|
|
55
|
+
const effective = getEffectiveConnectionState();
|
|
56
|
+
return {
|
|
57
|
+
effective,
|
|
58
|
+
effectiveConfig: {
|
|
59
|
+
...config,
|
|
60
|
+
browser: effective.browser
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
53
64
|
let handshakeReady = false;
|
|
54
65
|
let resolveHandshake;
|
|
55
66
|
let rejectHandshake;
|
|
@@ -182,11 +193,12 @@ const makeSocket = (config) => {
|
|
|
182
193
|
};
|
|
183
194
|
/** connection handshake */
|
|
184
195
|
const validateConnection = async () => {
|
|
196
|
+
const { effective, effectiveConfig } = getEffectiveConfig();
|
|
185
197
|
let helloMsg = {
|
|
186
198
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
187
199
|
};
|
|
188
200
|
helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
|
|
189
|
-
logger.info({ browser, helloMsg }, 'connected to WA');
|
|
201
|
+
logger.info({ browser: effective.browser, companionMode: effective.mode, helloMsg }, 'connected to WA');
|
|
190
202
|
const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
|
|
191
203
|
const result = await awaitNextMessage(init);
|
|
192
204
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
@@ -194,12 +206,12 @@ const makeSocket = (config) => {
|
|
|
194
206
|
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
195
207
|
let node;
|
|
196
208
|
if (!hasLinkedDeviceCreds(creds)) {
|
|
197
|
-
node = (0, Utils_1.generateRegistrationNode)(creds,
|
|
198
|
-
logger.info({ node }, 'not logged in, attempting registration...');
|
|
209
|
+
node = (0, Utils_1.generateRegistrationNode)(creds, effectiveConfig);
|
|
210
|
+
logger.info({ node, companionMode: effective.mode }, 'not logged in, attempting registration...');
|
|
199
211
|
}
|
|
200
212
|
else {
|
|
201
|
-
node = (0, Utils_1.generateLoginNode)(creds.me.id,
|
|
202
|
-
logger.info({ node }, 'logging in...');
|
|
213
|
+
node = (0, Utils_1.generateLoginNode)(creds.me.id, effectiveConfig, creds);
|
|
214
|
+
logger.info({ node, companionMode: effective.mode }, 'logging in...');
|
|
203
215
|
}
|
|
204
216
|
const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
|
|
205
217
|
await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
|
|
@@ -405,20 +417,25 @@ const makeSocket = (config) => {
|
|
|
405
417
|
}
|
|
406
418
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
407
419
|
};
|
|
408
|
-
const requestPairingCode = async (phoneNumber, pairKey = "") => {
|
|
420
|
+
const requestPairingCode = async (phoneNumber, pairKey = "", options = {}) => {
|
|
409
421
|
if (hasLinkedDeviceCreds(authState.creds)) {
|
|
410
422
|
throw new boom_1.Boom('Session is already authenticated; cannot request pairing code', { statusCode: 400 });
|
|
411
423
|
}
|
|
424
|
+
let rawPairKey = pairKey;
|
|
425
|
+
let opts = options && typeof options === 'object' ? options : {};
|
|
426
|
+
if (pairKey && typeof pairKey === 'object') {
|
|
427
|
+
opts = pairKey;
|
|
428
|
+
rawPairKey = opts.customCode || opts.pairKey || '';
|
|
429
|
+
}
|
|
412
430
|
const sanitizedPhone = String(phoneNumber || '').replace(/[^0-9]/g, '');
|
|
413
431
|
if (!sanitizedPhone || sanitizedPhone.length < 7) {
|
|
414
432
|
throw new boom_1.Boom('Invalid phone number for pairing code (must contain digits with country code, e.g. 628123456789)', { statusCode: 400 });
|
|
415
433
|
}
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (cleanedPairKey && cleanedPairKey.length !== 8) {
|
|
420
|
-
throw new boom_1.Boom('Custom pairing code must be exactly 8 alphanumeric characters', { statusCode: 400 });
|
|
434
|
+
const parsedPairKey = (0, Utils_1.normalizePairingCode)(typeof rawPairKey === 'string' ? rawPairKey : '');
|
|
435
|
+
if (!parsedPairKey.valid) {
|
|
436
|
+
throw new boom_1.Boom(parsedPairKey.error || 'Custom pairing code must be exactly 8 alphanumeric characters', { statusCode: 400 });
|
|
421
437
|
}
|
|
438
|
+
const cleanedPairKey = parsedPairKey.code;
|
|
422
439
|
await waitForSocketOpen();
|
|
423
440
|
if (!handshakeReady) {
|
|
424
441
|
await (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
|
|
@@ -437,7 +454,8 @@ const makeSocket = (config) => {
|
|
|
437
454
|
const prevPairingCode = authState.creds.pairingCode;
|
|
438
455
|
const prevMe = authState.creds.me;
|
|
439
456
|
const pairingCode = cleanedPairKey || (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
440
|
-
const
|
|
457
|
+
const { effective } = getEffectiveConfig();
|
|
458
|
+
const pairingPlatform = (0, Utils_1.resolvePairingBrowser)(effective.browser);
|
|
441
459
|
authState.creds.pairingCode = pairingCode;
|
|
442
460
|
authState.creds.registered = false;
|
|
443
461
|
authState.creds.me = {
|
|
@@ -460,7 +478,7 @@ const makeSocket = (config) => {
|
|
|
460
478
|
jid: authState.creds.me.id,
|
|
461
479
|
stage: 'companion_hello',
|
|
462
480
|
// eslint-disable-next-line camelcase
|
|
463
|
-
should_show_push_notification: 'true'
|
|
481
|
+
should_show_push_notification: opts.showPushNotification === false ? 'false' : 'true'
|
|
464
482
|
},
|
|
465
483
|
content: [
|
|
466
484
|
{
|
|
@@ -499,7 +517,9 @@ const makeSocket = (config) => {
|
|
|
499
517
|
throw err;
|
|
500
518
|
}
|
|
501
519
|
ev.emit('creds.update', authState.creds);
|
|
502
|
-
return
|
|
520
|
+
return opts.formatted
|
|
521
|
+
? (0, Utils_1.formatPairingCode)(authState.creds.pairingCode)
|
|
522
|
+
: authState.creds.pairingCode;
|
|
503
523
|
};
|
|
504
524
|
async function generatePairingKey() {
|
|
505
525
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
@@ -582,8 +602,9 @@ const makeSocket = (config) => {
|
|
|
582
602
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
583
603
|
logger.debug('pair success recv');
|
|
584
604
|
try {
|
|
585
|
-
const {
|
|
586
|
-
|
|
605
|
+
const { effectiveConfig } = getEffectiveConfig();
|
|
606
|
+
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds, effectiveConfig);
|
|
607
|
+
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform, registeredPlatformMode: updatedCreds.registeredPlatformMode }, 'pairing configured successfully, expect to restart the connection...');
|
|
587
608
|
ev.emit('creds.update', updatedCreds);
|
|
588
609
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
589
610
|
await sendNode(reply);
|
|
@@ -600,7 +621,14 @@ const makeSocket = (config) => {
|
|
|
600
621
|
await sendPassiveIq('active');
|
|
601
622
|
logger.info('opened connection to WA');
|
|
602
623
|
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
603
|
-
|
|
624
|
+
const { effective } = getEffectiveConfig();
|
|
625
|
+
const credsUpdate = { me: { ...authState.creds.me, lid: node.attrs.lid }, registered: true };
|
|
626
|
+
if (!authState.creds.registeredPlatformMode) {
|
|
627
|
+
credsUpdate.registeredPlatformMode = (effective.mode === 'android' && (0, Utils_1.isWABusinessPlatform)(authState.creds.platform))
|
|
628
|
+
? 'android-business'
|
|
629
|
+
: effective.mode;
|
|
630
|
+
}
|
|
631
|
+
ev.emit('creds.update', credsUpdate);
|
|
604
632
|
ev.emit('connection.update', { connection: 'open' });
|
|
605
633
|
}
|
|
606
634
|
catch (err) {
|
|
@@ -699,6 +727,8 @@ const makeSocket = (config) => {
|
|
|
699
727
|
uploadPreKeys,
|
|
700
728
|
uploadPreKeysToServerIfRequired,
|
|
701
729
|
requestPairingCode,
|
|
730
|
+
getCompanionPlatformMode: () => getEffectiveConnectionState().mode,
|
|
731
|
+
getEffectiveBrowser: () => getEffectiveConnectionState().browser,
|
|
702
732
|
/** Waits for the connection to WA to reach a state */
|
|
703
733
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
704
734
|
sendWAMBuffer,
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetAldyBannerState = exports.printAldyBanner = exports.renderAldyBanner = exports.ALDY_ASCII_LINES = void 0;
|
|
4
|
+
|
|
5
|
+
let pkgVersion = '2.1.1';
|
|
6
|
+
try {
|
|
7
|
+
pkgVersion = require('../../package.json').version || pkgVersion;
|
|
8
|
+
}
|
|
9
|
+
catch (_err) {
|
|
10
|
+
// Fallback jika package.json tidak terbaca
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ALDY_ASCII_LINES = [
|
|
14
|
+
' โโโโโโ โโโ โโโโโโโ โโโ โโโ',
|
|
15
|
+
' โโโโโโโโโโโ โโโโโโโโโโโโ โโโโ',
|
|
16
|
+
' โโโโโโโโโโโ โโโ โโโ โโโโโโโ ',
|
|
17
|
+
' โโโโโโโโโโโ โโโ โโโ โโโโโ ',
|
|
18
|
+
' โโโ โโโโโโโโโโโโโโโโโโโ โโโ ',
|
|
19
|
+
' โโโ โโโโโโโโโโโโโโโโโโ โโโ ',
|
|
20
|
+
];
|
|
21
|
+
exports.ALDY_ASCII_LINES = ALDY_ASCII_LINES;
|
|
22
|
+
|
|
23
|
+
const ANSI = {
|
|
24
|
+
reset: '\x1b[0m',
|
|
25
|
+
bold: '\x1b[1m',
|
|
26
|
+
dim: '\x1b[2m',
|
|
27
|
+
cyan: '\x1b[36m',
|
|
28
|
+
brightCyan: '\x1b[96m',
|
|
29
|
+
brightBlue: '\x1b[94m',
|
|
30
|
+
brightWhite: '\x1b[97m',
|
|
31
|
+
yellow: '\x1b[33m',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const supportsAnsiColor = () => {
|
|
35
|
+
if (process.env.NO_COLOR) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0') {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return Boolean(process.stdout && process.stdout.isTTY);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const centerText = (text, width) => {
|
|
45
|
+
const clean = String(text || '').slice(0, width);
|
|
46
|
+
const totalPad = Math.max(0, width - clean.length);
|
|
47
|
+
const leftPad = Math.floor(totalPad / 2);
|
|
48
|
+
const rightPad = totalPad - leftPad;
|
|
49
|
+
return ' '.repeat(leftPad) + clean + ' '.repeat(rightPad);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Merender banner ASCII "ALDY" untuk terminal.
|
|
54
|
+
* @param {{ color?: boolean, version?: string, mode?: string }} options
|
|
55
|
+
*/
|
|
56
|
+
const renderAldyBanner = (options = {}) => {
|
|
57
|
+
const useColor = typeof options.color === 'boolean' ? options.color : supportsAnsiColor();
|
|
58
|
+
const version = options.version || pkgVersion;
|
|
59
|
+
const modeLabel = options.mode === 'android-business'
|
|
60
|
+
? 'Android Business RVO'
|
|
61
|
+
: options.mode === 'web'
|
|
62
|
+
? 'Web/Chrome Mode'
|
|
63
|
+
: 'Android Companion RVO';
|
|
64
|
+
const innerWidth = 50;
|
|
65
|
+
const border = 'โ'.repeat(innerWidth);
|
|
66
|
+
const subtitle = centerText(`@aldy11/baileys v${version} โข ${modeLabel}`, innerWidth);
|
|
67
|
+
|
|
68
|
+
if (!useColor) {
|
|
69
|
+
return [
|
|
70
|
+
'',
|
|
71
|
+
`โ${border}โ`,
|
|
72
|
+
...ALDY_ASCII_LINES.map((line) => `โ${centerText(line, innerWidth)}โ`),
|
|
73
|
+
`โ ${border}โฃ`,
|
|
74
|
+
`โ${subtitle}โ`,
|
|
75
|
+
`โ${border}โ`,
|
|
76
|
+
'',
|
|
77
|
+
].join('\n');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lineColors = [
|
|
81
|
+
ANSI.brightCyan,
|
|
82
|
+
ANSI.brightCyan,
|
|
83
|
+
ANSI.cyan,
|
|
84
|
+
ANSI.cyan,
|
|
85
|
+
ANSI.brightBlue,
|
|
86
|
+
ANSI.brightBlue,
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const coloredArt = ALDY_ASCII_LINES.map((line, idx) => {
|
|
90
|
+
const c = lineColors[idx] || ANSI.cyan;
|
|
91
|
+
return `${ANSI.cyan}โ${ANSI.reset}${ANSI.bold}${c}${centerText(line, innerWidth)}${ANSI.reset}${ANSI.cyan}โ${ANSI.reset}`;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return [
|
|
95
|
+
'',
|
|
96
|
+
`${ANSI.cyan}โ${border}โ${ANSI.reset}`,
|
|
97
|
+
...coloredArt,
|
|
98
|
+
`${ANSI.cyan}โ ${border}โฃ${ANSI.reset}`,
|
|
99
|
+
`${ANSI.cyan}โ${ANSI.reset}${ANSI.bold}${ANSI.brightWhite}${subtitle}${ANSI.reset}${ANSI.cyan}โ${ANSI.reset}`,
|
|
100
|
+
`${ANSI.cyan}โ${border}โ${ANSI.reset}`,
|
|
101
|
+
'',
|
|
102
|
+
].join('\n');
|
|
103
|
+
};
|
|
104
|
+
exports.renderAldyBanner = renderAldyBanner;
|
|
105
|
+
|
|
106
|
+
let hasPrintedAldyBanner = false;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Mencetak banner ASCII "ALDY" ke terminal (otomatis sekali per proses agar tidak spam saat reconnect).
|
|
110
|
+
* Gunakan `{ force: true }` untuk mencetak ulang secara manual.
|
|
111
|
+
*/
|
|
112
|
+
const printAldyBanner = (options = {}) => {
|
|
113
|
+
if (options.enabled === false) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (hasPrintedAldyBanner && !options.force) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
hasPrintedAldyBanner = true;
|
|
120
|
+
const output = renderAldyBanner(options);
|
|
121
|
+
if (typeof options.writer === 'function') {
|
|
122
|
+
options.writer(output);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.log(output);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
};
|
|
129
|
+
exports.printAldyBanner = printAldyBanner;
|
|
130
|
+
|
|
131
|
+
const resetAldyBannerState = () => {
|
|
132
|
+
hasPrintedAldyBanner = false;
|
|
133
|
+
};
|
|
134
|
+
exports.resetAldyBannerState = resetAldyBannerState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePairingBrowser = exports.getPlatformId = exports.Browsers = void 0;
|
|
3
|
+
exports.formatPairingCode = exports.normalizePairingCode = exports.resolveEffectiveBrowser = exports.getCompanionBrowserMode = exports.isAndroidCompanionBrowser = exports.isSmbAndroidCompanionBrowser = exports.resolvePairingBrowser = exports.getPlatformId = exports.Browsers = void 0;
|
|
4
4
|
|
|
5
5
|
const os = require("os");
|
|
6
6
|
const { proto } = require("../../WAProto/index.js");
|
|
@@ -50,6 +50,144 @@ Browsers.appropriate = (browser = 'Chrome') => [PLATFORM_MAP[os.platform()] || '
|
|
|
50
50
|
|
|
51
51
|
exports.Browsers = Browsers;
|
|
52
52
|
|
|
53
|
+
const isSmbAndroidCompanionBrowser = (browser) => {
|
|
54
|
+
const name = Array.isArray(browser) ? String(browser[1] || '').toLowerCase() : '';
|
|
55
|
+
return name.includes('smb_android') || name === 'smba';
|
|
56
|
+
};
|
|
57
|
+
exports.isSmbAndroidCompanionBrowser = isSmbAndroidCompanionBrowser;
|
|
58
|
+
|
|
59
|
+
const isAndroidCompanionBrowser = (browser) => {
|
|
60
|
+
const name = Array.isArray(browser) ? String(browser[1] || '').toLowerCase() : '';
|
|
61
|
+
return name.includes('android') || name === 'smba';
|
|
62
|
+
};
|
|
63
|
+
exports.isAndroidCompanionBrowser = isAndroidCompanionBrowser;
|
|
64
|
+
|
|
65
|
+
const getCompanionBrowserMode = (browser) => {
|
|
66
|
+
if (isSmbAndroidCompanionBrowser(browser)) {
|
|
67
|
+
return 'android-business';
|
|
68
|
+
}
|
|
69
|
+
if (isAndroidCompanionBrowser(browser)) {
|
|
70
|
+
return 'android';
|
|
71
|
+
}
|
|
72
|
+
return 'web';
|
|
73
|
+
};
|
|
74
|
+
exports.getCompanionBrowserMode = getCompanionBrowserMode;
|
|
75
|
+
|
|
76
|
+
const isBusinessPlatformName = (platform) => {
|
|
77
|
+
const normalized = String(platform || '').toLowerCase();
|
|
78
|
+
return normalized === 'smba' || normalized === 'smbi';
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const hasLinkedSessionCreds = (creds) => {
|
|
82
|
+
if (!(creds && creds.me && creds.me.id)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (creds.account) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return Boolean(creds.registered && /:\d+@/.test(String(creds.me.id)));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Menentukan tuple browser dan mode companion yang paling akurat untuk sesi baru maupun sesi tertaut:
|
|
93
|
+
* - Sesi baru (default): memakai Android Companion (`Browsers.android('14')`) agar View-Once (RVO)
|
|
94
|
+
* terbuka penuh sekaligus tetap kompatibel dengan QR & Custom Pairing Code.
|
|
95
|
+
* - Sesi tertaut baru (punya `creds.registeredPlatformMode`): otomatis menyelaraskan `android`,
|
|
96
|
+
* `android-business` (deteksi WA Business `smba`/`smbi`), atau `web` tanpa konfigurasi tambahan.
|
|
97
|
+
* - Sesi legacy lama (tertaut sebelum v2.1.0 tanpa `registeredPlatformMode` & tanpa `browser` eksplisit):
|
|
98
|
+
* otomatis memakai `Browsers.ubuntu('Chrome')` (mode `web`) agar tidak memicu logout 401 saat upgrade.
|
|
99
|
+
*/
|
|
100
|
+
const resolveEffectiveBrowser = (config = {}, creds = undefined) => {
|
|
101
|
+
const configuredBrowser = Array.isArray(config.browser) && config.browser.length >= 2
|
|
102
|
+
? config.browser
|
|
103
|
+
: Browsers.android('14');
|
|
104
|
+
const explicitBrowser = Boolean(config.explicitBrowser);
|
|
105
|
+
const autoDetect = config.autoDetectCompanionPlatform !== false;
|
|
106
|
+
const isLinked = hasLinkedSessionCreds(creds);
|
|
107
|
+
|
|
108
|
+
if (!isLinked || !autoDetect) {
|
|
109
|
+
const mode = getCompanionBrowserMode(configuredBrowser);
|
|
110
|
+
return {
|
|
111
|
+
browser: configuredBrowser,
|
|
112
|
+
mode,
|
|
113
|
+
isViewOnceSupported: mode !== 'web',
|
|
114
|
+
isLegacyWebFallback: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const savedMode = typeof creds?.registeredPlatformMode === 'string'
|
|
119
|
+
? creds.registeredPlatformMode.trim().toLowerCase()
|
|
120
|
+
: '';
|
|
121
|
+
const isBizAccount = isBusinessPlatformName(creds?.platform);
|
|
122
|
+
|
|
123
|
+
if (savedMode === 'android-business' || (savedMode === 'android' && isBizAccount)) {
|
|
124
|
+
const browser = isSmbAndroidCompanionBrowser(configuredBrowser)
|
|
125
|
+
? configuredBrowser
|
|
126
|
+
: Browsers.androidBusiness('14');
|
|
127
|
+
return {
|
|
128
|
+
browser,
|
|
129
|
+
mode: 'android-business',
|
|
130
|
+
isViewOnceSupported: true,
|
|
131
|
+
isLegacyWebFallback: false,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (savedMode === 'android') {
|
|
136
|
+
const browser = (isAndroidCompanionBrowser(configuredBrowser) && !isSmbAndroidCompanionBrowser(configuredBrowser))
|
|
137
|
+
? configuredBrowser
|
|
138
|
+
: Browsers.android('14');
|
|
139
|
+
return {
|
|
140
|
+
browser,
|
|
141
|
+
mode: 'android',
|
|
142
|
+
isViewOnceSupported: true,
|
|
143
|
+
isLegacyWebFallback: false,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (savedMode === 'web') {
|
|
148
|
+
const browser = (explicitBrowser && !isAndroidCompanionBrowser(configuredBrowser))
|
|
149
|
+
? configuredBrowser
|
|
150
|
+
: Browsers.ubuntu('Chrome');
|
|
151
|
+
return {
|
|
152
|
+
browser,
|
|
153
|
+
mode: 'web',
|
|
154
|
+
isViewOnceSupported: false,
|
|
155
|
+
isLegacyWebFallback: false,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Sesi legacy (sebelum v2.1.0, belum memiliki registeredPlatformMode di creds.json)
|
|
160
|
+
if (explicitBrowser) {
|
|
161
|
+
if (isAndroidCompanionBrowser(configuredBrowser) && isBizAccount) {
|
|
162
|
+
const browser = isSmbAndroidCompanionBrowser(configuredBrowser)
|
|
163
|
+
? configuredBrowser
|
|
164
|
+
: Browsers.androidBusiness('14');
|
|
165
|
+
return {
|
|
166
|
+
browser,
|
|
167
|
+
mode: 'android-business',
|
|
168
|
+
isViewOnceSupported: true,
|
|
169
|
+
isLegacyWebFallback: false,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const mode = getCompanionBrowserMode(configuredBrowser);
|
|
173
|
+
return {
|
|
174
|
+
browser: configuredBrowser,
|
|
175
|
+
mode,
|
|
176
|
+
isViewOnceSupported: mode !== 'web',
|
|
177
|
+
isLegacyWebFallback: false,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Default aman untuk sesi legacy tanpa explicit browser: pertahankan mode Web (hindari 401)
|
|
182
|
+
return {
|
|
183
|
+
browser: Browsers.ubuntu('Chrome'),
|
|
184
|
+
mode: 'web',
|
|
185
|
+
isViewOnceSupported: false,
|
|
186
|
+
isLegacyWebFallback: true,
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
exports.resolveEffectiveBrowser = resolveEffectiveBrowser;
|
|
190
|
+
|
|
53
191
|
const getPlatformId = (browser) => {
|
|
54
192
|
const key = String(browser || '').toUpperCase();
|
|
55
193
|
if (key === 'ANDROID' || key === 'SMB_ANDROID') {
|
|
@@ -81,4 +219,55 @@ const resolvePairingBrowser = (browserTuple) => {
|
|
|
81
219
|
};
|
|
82
220
|
};
|
|
83
221
|
|
|
84
|
-
exports.resolvePairingBrowser = resolvePairingBrowser;
|
|
222
|
+
exports.resolvePairingBrowser = resolvePairingBrowser;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Memformat kode pairing 8 karakter menjadi XXXX-XXXX agar mudah dibaca & diketik di WhatsApp HP.
|
|
226
|
+
*/
|
|
227
|
+
const formatPairingCode = (code) => {
|
|
228
|
+
const clean = String(code || '').replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
|
|
229
|
+
if (clean.length === 8) {
|
|
230
|
+
return `${clean.slice(0, 4)}-${clean.slice(4)}`;
|
|
231
|
+
}
|
|
232
|
+
return clean;
|
|
233
|
+
};
|
|
234
|
+
exports.formatPairingCode = formatPairingCode;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Menormalisasi & memvalidasi custom pairing code (8 karakter alfanumerik, otomatis hapus strip/spasi).
|
|
238
|
+
*/
|
|
239
|
+
const normalizePairingCode = (pairKey) => {
|
|
240
|
+
const raw = typeof pairKey === 'string' ? pairKey : '';
|
|
241
|
+
const cleaned = raw.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
|
|
242
|
+
if (!cleaned) {
|
|
243
|
+
return {
|
|
244
|
+
valid: true,
|
|
245
|
+
code: '',
|
|
246
|
+
formatted: '',
|
|
247
|
+
warnings: [],
|
|
248
|
+
error: null,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (cleaned.length !== 8) {
|
|
252
|
+
return {
|
|
253
|
+
valid: false,
|
|
254
|
+
code: '',
|
|
255
|
+
formatted: '',
|
|
256
|
+
warnings: [],
|
|
257
|
+
error: `Custom pairing code must be exactly 8 alphanumeric characters (got ${cleaned.length}: "${cleaned}")`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const warnings = [];
|
|
261
|
+
const ambiguous = [...new Set(cleaned.split('').filter((ch) => '0ILOU'.includes(ch)))];
|
|
262
|
+
if (ambiguous.length > 0) {
|
|
263
|
+
warnings.push(`Code "${cleaned}" contains potentially ambiguous characters (${ambiguous.join(', ')}) on some WhatsApp clients; prefer 1-9 and A-Z excluding I, L, O, U.`);
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
valid: true,
|
|
267
|
+
code: cleaned,
|
|
268
|
+
formatted: formatPairingCode(cleaned),
|
|
269
|
+
warnings,
|
|
270
|
+
error: null,
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
exports.normalizePairingCode = normalizePairingCode;
|
package/lib/Utils/index.js
CHANGED
|
@@ -33,4 +33,5 @@ __exportStar(require("./event-buffer"), exports);
|
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
34
|
__exportStar(require("./message-retry-manager"), exports);
|
|
35
35
|
__exportStar(require("./browser-utils"), exports);
|
|
36
|
+
__exportStar(require("./banner"), exports);
|
|
36
37
|
__exportStar(require("./power-features"), exports);
|
|
@@ -9,16 +9,10 @@ const WABinary_1 = require("../WABinary");
|
|
|
9
9
|
const crypto_2 = require("./crypto");
|
|
10
10
|
const generics_1 = require("./generics");
|
|
11
11
|
const signal_1 = require("./signal");
|
|
12
|
+
const browser_utils_1 = require("./browser-utils");
|
|
12
13
|
|
|
13
|
-
const isSmbAndroidBrowser =
|
|
14
|
-
|
|
15
|
-
return name.includes('smb_android') || name === 'smba';
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const isAndroidBrowser = (browser) => {
|
|
19
|
-
const name = Array.isArray(browser) ? String(browser[1] || '').toLowerCase() : '';
|
|
20
|
-
return name.includes('android') || name === 'smba';
|
|
21
|
-
};
|
|
14
|
+
const isSmbAndroidBrowser = browser_utils_1.isSmbAndroidCompanionBrowser;
|
|
15
|
+
const isAndroidBrowser = browser_utils_1.isAndroidCompanionBrowser;
|
|
22
16
|
|
|
23
17
|
const getUserAgent = (config) => {
|
|
24
18
|
const userAgentPlatform = isSmbAndroidBrowser(config.browser)
|
|
@@ -69,10 +63,16 @@ const getClientPayload = (config) => {
|
|
|
69
63
|
return payload;
|
|
70
64
|
};
|
|
71
65
|
|
|
72
|
-
const generateLoginNode = (userJid, config) => {
|
|
66
|
+
const generateLoginNode = (userJid, config, creds) => {
|
|
73
67
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
68
|
+
const effectiveConfig = creds
|
|
69
|
+
? {
|
|
70
|
+
...config,
|
|
71
|
+
browser: (0, browser_utils_1.resolveEffectiveBrowser)(config, creds).browser
|
|
72
|
+
}
|
|
73
|
+
: config;
|
|
74
74
|
const payload = {
|
|
75
|
-
...getClientPayload(
|
|
75
|
+
...getClientPayload(effectiveConfig),
|
|
76
76
|
passive: true,
|
|
77
77
|
pull: true,
|
|
78
78
|
username: +user,
|
|
@@ -149,7 +149,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
149
149
|
};
|
|
150
150
|
exports.generateRegistrationNode = generateRegistrationNode;
|
|
151
151
|
|
|
152
|
-
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
152
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }, config) => {
|
|
153
153
|
const msgId = stanza.attrs.id;
|
|
154
154
|
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
155
155
|
const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
@@ -224,6 +224,19 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
224
224
|
]
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
+
const platformName = platformNode?.attrs.name;
|
|
228
|
+
let registeredPlatformMode;
|
|
229
|
+
if (config && Array.isArray(config.browser)) {
|
|
230
|
+
if (isAndroidBrowser(config.browser)) {
|
|
231
|
+
registeredPlatformMode = (isSmbAndroidBrowser(config.browser) || (0, generics_1.isWABusinessPlatform)(platformName))
|
|
232
|
+
? 'android-business'
|
|
233
|
+
: 'android';
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
registeredPlatformMode = 'web';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
227
240
|
const authUpdate = {
|
|
228
241
|
account,
|
|
229
242
|
me: { id: jid, name: bizName, lid },
|
|
@@ -231,8 +244,9 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
231
244
|
...(signalIdentities || []),
|
|
232
245
|
identity
|
|
233
246
|
],
|
|
234
|
-
platform:
|
|
235
|
-
registered: true
|
|
247
|
+
platform: platformName,
|
|
248
|
+
registered: true,
|
|
249
|
+
...(registeredPlatformMode ? { registeredPlatformMode } : {})
|
|
236
250
|
};
|
|
237
251
|
|
|
238
252
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aldy11/baileys",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "WhatsApp Multi-Device API Library with Native Flow Buttons, Meta AI Primitives
|
|
3
|
+
"version": "2.1.1",
|
|
4
|
+
"description": "WhatsApp Multi-Device API Library with Out-of-the-Box Android Companion View-Once (RVO), Universal Custom Pairing Code, Native Flow Buttons, and Meta AI Primitives",
|
|
5
5
|
"author": "aldy11",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"whatsapp-api",
|
|
19
19
|
"whatsapp-bot",
|
|
20
20
|
"multi-device",
|
|
21
|
+
"view-once",
|
|
22
|
+
"rvo",
|
|
23
|
+
"pairing-code",
|
|
21
24
|
"interactive-buttons",
|
|
22
25
|
"meta-ai"
|
|
23
26
|
],
|