@xbibzlibrary/whatsbibz 2.0.0 → 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/ANALISIS-ALUR.md +1 -1
- package/CHANGELOG.md +39 -1
- package/KOMPATIBILITAS-WHATSAPP-2026-11.md +1 -1
- package/README.cn.md +192 -17
- package/README.id.md +195 -20
- package/README.md +195 -20
- package/SECURITY.md +8 -8
- package/WAProto/WAProto.proto +4 -0
- package/WAProto/index.d.ts +5 -0
- package/WAProto/index.js +61 -0
- package/lib/BibzWhats/banner.d.ts +5 -3
- package/lib/BibzWhats/banner.js +20 -10
- package/lib/BibzWhats/client.d.ts +5 -5
- package/lib/BibzWhats/client.js +73 -40
- package/lib/BibzWhats/extract.js +2 -1
- package/lib/BibzWhats/version.js +6 -1
- package/lib/Socket/auto-follow-channel.d.ts +1 -1
- package/lib/Socket/auto-follow-channel.js +11 -5
- package/lib/Socket/socket.js +31 -11
- package/lib/Types/Socket.d.ts +6 -4
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/link-preview.js +6 -1
- package/lib/Utils/messages-media.js +18 -17
- package/lib/Utils/messages.js +2 -1
- package/lib/Utils/sound-sticker.d.ts +57 -0
- package/lib/Utils/sound-sticker.js +326 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +4 -1
- package/lib/Utils/use-multi-file-auth-state.js +32 -34
- package/lib/VoIP/audio-feeder.d.ts +1 -1
- package/lib/VoIP/audio-feeder.js +136 -92
- package/lib/VoIP/index.d.ts +53 -7
- package/lib/VoIP/index.js +278 -164
- package/lib/VoIP/relay-transport.d.ts +10 -0
- package/lib/VoIP/relay-transport.js +174 -126
- package/lib/VoIP/signaling.js +46 -12
- package/lib/VoIP/types.d.ts +6 -2
- package/lib/VoIP/wasm-engine.d.ts +7 -0
- package/lib/VoIP/wasm-engine.js +230 -99
- package/lib/index.d.ts +1 -0
- package/package.json +20 -12
package/lib/BibzWhats/banner.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/** @module @xbibzlibrary/whatsbibz/lib/BibzWhats/banner */
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// sebagai string statis, jadi TIDAK butuh dependency figlet saat runtime.
|
|
6
|
-
// • Warna : filter pelangi (gradien hue mengalir dari kiri ke kanan), gaya
|
|
7
|
-
// truecolor (24-bit) dengan fallback palet 256 bila terminal tidak
|
|
8
|
-
// mendukungnya, dan otomatis tanpa warna (plain) bila stdout bukan TTY.
|
|
9
|
-
// • Matikan : NO_COLOR=1, atau opsi client `banner: false`.
|
|
2
|
+
// Small Slant figlet logo with a restrained rainbow and live package version.
|
|
3
|
+
// Automatic output is once per process on stderr, never at module import.
|
|
4
|
+
import { BIBZWHATS_VERSION } from './version.js';
|
|
10
5
|
|
|
11
6
|
// Baris asli hasil figlet.textSync('WhatsBibz.', { font: 'Small Slant' }).
|
|
12
7
|
// Perhatikan: sebagian besar glyph saling berimpit karena font-nya miring rapat —
|
|
@@ -16,6 +11,7 @@ const LINES = [
|
|
|
16
11
|
" | | /| / / / ___ _/ /____ / _ )(_) / ___ ",
|
|
17
12
|
" | |/ |/ / _ \\/ _ `/ __(_-</ _ / / _ \\/_ /_ ",
|
|
18
13
|
" |__/|__/_//_/\\_,_/\\__/___/____/_/_.__//__(_)",
|
|
14
|
+
` WhatsBibz v${BIBZWHATS_VERSION}`,
|
|
19
15
|
];
|
|
20
16
|
|
|
21
17
|
export const BANNER_FONT = 'Small Slant';
|
|
@@ -23,7 +19,7 @@ export const BANNER_FILTER = 'Rainbow 2';
|
|
|
23
19
|
|
|
24
20
|
const MAX_WIDTH = Math.max(...LINES.map((l) => l.length));
|
|
25
21
|
|
|
26
|
-
/** Banner polos (tanpa ANSI)
|
|
22
|
+
/** Banner polos (tanpa ANSI), termasuk versi paket, tanpa newline di ujung. */
|
|
27
23
|
export const BANNER_TEXT = LINES.map((l) => l.trimEnd()).join('\n');
|
|
28
24
|
|
|
29
25
|
const RESET = '\x1b[0m';
|
|
@@ -102,7 +98,7 @@ export function renderBanner({ color = 'auto', cycles = 1, env = process.env, st
|
|
|
102
98
|
continue;
|
|
103
99
|
}
|
|
104
100
|
const hue = ((c / MAX_WIDTH) * 360 * cycles) % 360;
|
|
105
|
-
const [r, g, b] = hslToRgb(hue,
|
|
101
|
+
const [r, g, b] = hslToRgb(hue, 0.78, 0.60);
|
|
106
102
|
out += `\x1b[${colorCode(r, g, b, trueColor)}m${ch}${RESET}`;
|
|
107
103
|
}
|
|
108
104
|
return out.trimEnd();
|
|
@@ -119,3 +115,17 @@ export function printBanner(opts = {}) {
|
|
|
119
115
|
write(renderBanner(rest) + '\n');
|
|
120
116
|
return true;
|
|
121
117
|
}
|
|
118
|
+
|
|
119
|
+
let automaticBannerPrinted = false;
|
|
120
|
+
/** @internal Print once per process on socket creation; stdout remains usable for structured output. */
|
|
121
|
+
export function printAutomaticBanner(enabled, { env = process.env, stream = process.stderr } = {}) {
|
|
122
|
+
if (automaticBannerPrinted || enabled === false || (enabled !== true && env.WHATSBIBZ_BANNER === '0')) return false;
|
|
123
|
+
try {
|
|
124
|
+
printBanner({ env, stream, write: (s) => stream.write(s) });
|
|
125
|
+
automaticBannerPrinted = true;
|
|
126
|
+
return true;
|
|
127
|
+
} catch {
|
|
128
|
+
// A closed or custom diagnostic stream must not stop a bot connecting.
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -36,9 +36,8 @@ export interface BibzWhatsOptions {
|
|
|
36
36
|
/** cetak QR ASCII ke console saat fallback (butuh qrcode-terminal) */
|
|
37
37
|
printQR?: boolean;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* true = selalu cetak, false = jangan pernah.
|
|
39
|
+
* Banner versi sekali per proses di stderr saat socket dibuat (default aktif).
|
|
40
|
+
* false = matikan; true = aktif meski WHATSBIBZ_BANNER=0. Non-TTY polos kecuali FORCE_COLOR aktif.
|
|
42
41
|
*/
|
|
43
42
|
banner?: boolean;
|
|
44
43
|
/** opsi tambahan langsung ke makeWASocket (override) */
|
|
@@ -85,7 +84,7 @@ export interface BibzWhatsEvents {
|
|
|
85
84
|
'first-ready': (sock: WASocket) => void;
|
|
86
85
|
user: (digits: string) => void;
|
|
87
86
|
close: (info: { status?: number; error?: Error }) => void;
|
|
88
|
-
reconnecting: (info: { delay: number; attempt: number; fresh: boolean; identity?: string; /** 401 setelah
|
|
87
|
+
reconnecting: (info: { delay: number; attempt: number; fresh: boolean; identity?: string; /** Heuristik 401 segera setelah permintaan pairing; bukan bukti penyebab di server. */ pairingPending?: boolean }) => void;
|
|
89
88
|
/** hanya mode auto: identitas diganti karena server menolak profil sebelumnya */
|
|
90
89
|
'identity-changed': (info: IdentityDescription & { profileId: string; reason: string }) => void;
|
|
91
90
|
'session-wiped': (reason: string) => void;
|
|
@@ -105,7 +104,8 @@ export interface BibzWhatsClient extends EventEmitter {
|
|
|
105
104
|
readonly initialSock: WASocket;
|
|
106
105
|
readonly options: Required<BibzWhatsOptions>;
|
|
107
106
|
isConnected(): boolean;
|
|
108
|
-
|
|
107
|
+
/** Stop without logout and await socket cleanup plus already-emitted credential saves. Save errors are logged; this is not a durability guarantee. */
|
|
108
|
+
close(): Promise<void>;
|
|
109
109
|
logout(): Promise<void>;
|
|
110
110
|
}
|
|
111
111
|
export declare function createBibzWhats(options?: BibzWhatsOptions): Promise<BibzWhatsClient>;
|
package/lib/BibzWhats/client.js
CHANGED
|
@@ -25,7 +25,6 @@ import { Browsers } from '../Utils/browser-utils.js';
|
|
|
25
25
|
import { lintIdentity, derivePairingDisplay } from '../Utils/platform-identity.js';
|
|
26
26
|
import { resolveDeviceIdentity, createIdentityRotator, isIdentityRejection, describeIdentity, clearIdentityState, loadIdentityState, saveIdentityState } from './device-identity.js';
|
|
27
27
|
import { createPairingController } from './pairing.js';
|
|
28
|
-
import { printBanner } from './banner.js';
|
|
29
28
|
import { selectWaWebVersion } from './version.js';
|
|
30
29
|
|
|
31
30
|
export const BIBZWHATS_DEFAULTS = Object.freeze({
|
|
@@ -72,7 +71,7 @@ export function wipeAuthDir(dir) {
|
|
|
72
71
|
try {
|
|
73
72
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
74
73
|
} catch {}
|
|
75
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
76
75
|
return true;
|
|
77
76
|
}
|
|
78
77
|
|
|
@@ -119,9 +118,8 @@ function mergeLogger(logger) {
|
|
|
119
118
|
* @property {[string,string,string]} [browser] alias lama `identity` (tuple eksplisit)
|
|
120
119
|
* @property {object} [logger] {info,warn,error,ok,debug}
|
|
121
120
|
* @property {boolean} [printQR] cetak QR ASCII ke console saat fallback (butuh qrcode-terminal)
|
|
122
|
-
* @property {boolean} [banner]
|
|
123
|
-
*
|
|
124
|
-
* true = selalu, false = jangan pernah.
|
|
121
|
+
* @property {boolean} [banner] banner versi sekali per proses di stderr (default aktif);
|
|
122
|
+
* false = matikan, true = abaikan WHATSBIBZ_BANNER=0.
|
|
125
123
|
* @property {object} [socketConfig] opsi tambahan langsung ke makeWASocket (override)
|
|
126
124
|
* @property {boolean} [preserveSession] stop instead of automatically wiping auth on session errors (default false)
|
|
127
125
|
* @property {string} [companionPlatformDisplay] override `companion_platform_display` (WA memvalidasi dgn allow-list; default diturunkan otomatis, mis. "Chrome (Mac OS)" / "Chrome (Linux)")
|
|
@@ -144,14 +142,6 @@ export async function createBibzWhats(options = {}) {
|
|
|
144
142
|
const emitter = new EventEmitter();
|
|
145
143
|
const groupMetadataCache = new Map();
|
|
146
144
|
|
|
147
|
-
// Banner ASCII 'WhatsBibz.' (Small Slant, pelangi) — hanya terminal interaktif secara
|
|
148
|
-
// bawaan; `banner: true` memaksa cetak (mis. untuk log/daemon), `banner: false` mematikan.
|
|
149
|
-
const wantBanner =
|
|
150
|
-
opts.banner === true || (opts.banner !== false && !!process.stdout.isTTY);
|
|
151
|
-
if (wantBanner) {
|
|
152
|
-
try { printBanner(); } catch {}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
145
|
// ── Identitas perangkat tertaut: kustom (opsi/env) atau otomatis (paling stabil) ──
|
|
156
146
|
const resolved = resolveDeviceIdentity({ identity: opts.identity === 'auto' ? undefined : opts.identity, browser: opts.browser, authDir: opts.authDir });
|
|
157
147
|
for (const note of resolved.notes) (note.level === 'warn' ? log.warn : log.info)(`BibzWhats: ${note.message}`);
|
|
@@ -176,11 +166,18 @@ export async function createBibzWhats(options = {}) {
|
|
|
176
166
|
let attempts = 0;
|
|
177
167
|
let wipeCount = 0;
|
|
178
168
|
let currentSock = null;
|
|
169
|
+
let currentConnectionHandler = null;
|
|
170
|
+
let closePromise = null;
|
|
171
|
+
let credentialWriteFailure = null;
|
|
172
|
+
const pendingCredSaves = new Set();
|
|
173
|
+
const waitForCredSaves = async () => {
|
|
174
|
+
while (pendingCredSaves.size) await Promise.all([...pendingCredSaves]);
|
|
175
|
+
};
|
|
179
176
|
let readyCalled = false;
|
|
180
177
|
let stopPairingRef = () => {};
|
|
181
178
|
// Pairing code sudah diterbitkan server untuk kredensial saat ini (belum terdaftar).
|
|
182
|
-
//
|
|
183
|
-
//
|
|
179
|
+
// 401 segera setelah permintaan pairing adalah heuristik untuk memilih
|
|
180
|
+
// recovery; status ini saja tidak membuktikan penyebab penolakan server.
|
|
184
181
|
let pairingIssuedAt = 0;
|
|
185
182
|
let pendingPairingWipes = 0;
|
|
186
183
|
// Semua reconnect dijadwalkan lewat satu tempat supaya close() bisa membatalkannya
|
|
@@ -221,8 +218,8 @@ export async function createBibzWhats(options = {}) {
|
|
|
221
218
|
log.warn(`BibzWhats: sesi dihapus otomatis (${reason}) — folder ${opts.authDir} dibersihkan`);
|
|
222
219
|
if (counted && wipeCount > opts.maxSessionWipes) {
|
|
223
220
|
const message =
|
|
224
|
-
`BibzWhats: ${wipeCount}x hapus sesi tapi masih ditolak
|
|
225
|
-
'
|
|
221
|
+
`BibzWhats: ${wipeCount}x hapus sesi tapi masih ditolak; penyebab belum pasti. ` +
|
|
222
|
+
'Periksa status akun, nomor, sesi, serta jaringan sebelum mencoba lagi.';
|
|
226
223
|
log.error(message);
|
|
227
224
|
emitter.emit('give-up', message);
|
|
228
225
|
closedByUser = true;
|
|
@@ -232,6 +229,17 @@ export async function createBibzWhats(options = {}) {
|
|
|
232
229
|
|
|
233
230
|
async function connect() {
|
|
234
231
|
if (closedByUser) return currentSock;
|
|
232
|
+
// A prior socket may have emitted credentials just before closing.
|
|
233
|
+
// Do not load/reconnect with an older snapshot while its save is pending.
|
|
234
|
+
await waitForCredSaves();
|
|
235
|
+
if (closedByUser) return currentSock;
|
|
236
|
+
if (opts.preserveSession && credentialWriteFailure) {
|
|
237
|
+
closedByUser = true;
|
|
238
|
+
const message = 'BibzWhats: gagal menyimpan kredensial; sesi dipertahankan dan reconnect dihentikan.';
|
|
239
|
+
log.error(message);
|
|
240
|
+
emitter.emit('give-up', message);
|
|
241
|
+
throw new Error(message);
|
|
242
|
+
}
|
|
235
243
|
let authState;
|
|
236
244
|
let saveCreds;
|
|
237
245
|
try {
|
|
@@ -275,6 +283,7 @@ export async function createBibzWhats(options = {}) {
|
|
|
275
283
|
sock = makeWASocket({
|
|
276
284
|
...(version ? { version } : {}),
|
|
277
285
|
auth: authState,
|
|
286
|
+
banner: opts.banner,
|
|
278
287
|
logger: pino({ level: 'silent' }),
|
|
279
288
|
browser: currentBrowser(),
|
|
280
289
|
...(opts.companionPlatformDisplay ? { companionPlatformDisplay: opts.companionPlatformDisplay } : {}),
|
|
@@ -372,19 +381,23 @@ export async function createBibzWhats(options = {}) {
|
|
|
372
381
|
stopPairingRef = stopPairing;
|
|
373
382
|
|
|
374
383
|
sock.ev.on('creds.update', (update) => {
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
saveCreds(update).
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
384
|
+
// Keep track of asynchronous writes so an awaited close can drain
|
|
385
|
+
// the updates already emitted, without printing credential data.
|
|
386
|
+
const pending = saveCreds(update).then(() => {
|
|
387
|
+
credentialWriteFailure = null;
|
|
388
|
+
}, (e) => {
|
|
389
|
+
credentialWriteFailure = /^[A-Z0-9_]+$/.test(String(e?.code || '')) ? e.code : 'WRITE_FAILED';
|
|
390
|
+
try {
|
|
391
|
+
if (credentialWriteFailure === 'ENOENT') log.warn('BibzWhats: folder sesi tidak tersedia; kredensial belum tersimpan.');
|
|
392
|
+
else log.error(`BibzWhats: gagal menyimpan kredensial (${credentialWriteFailure}).`);
|
|
393
|
+
} catch {}
|
|
383
394
|
});
|
|
395
|
+
pendingCredSaves.add(pending);
|
|
396
|
+
void pending.then(() => pendingCredSaves.delete(pending));
|
|
384
397
|
if (sock.authState.creds.registered) stopPairing();
|
|
385
398
|
});
|
|
386
399
|
|
|
387
|
-
|
|
400
|
+
const onConnectionUpdate = (u) => {
|
|
388
401
|
const { connection, qr, lastDisconnect } = u;
|
|
389
402
|
emitter.emit('connection.update', u);
|
|
390
403
|
|
|
@@ -482,9 +495,9 @@ export async function createBibzWhats(options = {}) {
|
|
|
482
495
|
pendingPairingWipes += 1;
|
|
483
496
|
const delay = pendingPairingWipes <= 3 ? Math.max(opts.restartDelayMs, 2000) : opts.wipeReconnectDelayMs;
|
|
484
497
|
log.warn(opts.preserveSession
|
|
485
|
-
? 'BibzWhats:
|
|
486
|
-
: `BibzWhats:
|
|
487
|
-
wipeSession('401 pairing
|
|
498
|
+
? 'BibzWhats: 401 segera setelah permintaan pairing; penyebab belum pasti — sesi akan dipertahankan.'
|
|
499
|
+
: `BibzWhats: 401 segera setelah permintaan pairing; penyebab belum pasti — kredensial diganti, pairing code diminta ulang dalam ${delay / 1000}s...`);
|
|
500
|
+
wipeSession('401 setelah permintaan pairing', { counted: false });
|
|
488
501
|
if (closedByUser) return;
|
|
489
502
|
emitter.emit('reconnecting', { delay, attempt: 0, fresh: true, pairingPending: true });
|
|
490
503
|
scheduleReconnect(delay);
|
|
@@ -492,9 +505,11 @@ export async function createBibzWhats(options = {}) {
|
|
|
492
505
|
}
|
|
493
506
|
|
|
494
507
|
if (status === DisconnectReason.loggedOut && sock.authState.creds.registered) {
|
|
508
|
+
// A generic 401 alone does not identify why the server
|
|
509
|
+
// refused the session or prove that a device was removed.
|
|
495
510
|
log.error(opts.preserveSession
|
|
496
|
-
? 'BibzWhats:
|
|
497
|
-
: 'BibzWhats:
|
|
511
|
+
? 'BibzWhats: server menolak sesi (401); penyebab belum pasti — sesi dipertahankan, pairing ulang mungkin diperlukan.'
|
|
512
|
+
: 'BibzWhats: server menolak sesi (401); penyebab belum pasti — konfigurasi saat ini akan menghapus sesi & pairing ulang.');
|
|
498
513
|
} else if (status === DisconnectReason.loggedOut) {
|
|
499
514
|
log.error('BibzWhats: koneksi DITOLAK sebelum pairing (401) — nomor belum aktif / digit salah / pairing pending / IP dibatasi.');
|
|
500
515
|
} else if (status) {
|
|
@@ -527,7 +542,9 @@ export async function createBibzWhats(options = {}) {
|
|
|
527
542
|
emitter.emit('reconnecting', { delay, attempt: attempts, fresh: false });
|
|
528
543
|
scheduleReconnect(delay);
|
|
529
544
|
}
|
|
530
|
-
}
|
|
545
|
+
};
|
|
546
|
+
currentConnectionHandler = onConnectionUpdate;
|
|
547
|
+
sock.ev.on('connection.update', onConnectionUpdate);
|
|
531
548
|
|
|
532
549
|
return sock;
|
|
533
550
|
}
|
|
@@ -550,21 +567,37 @@ export async function createBibzWhats(options = {}) {
|
|
|
550
567
|
options: opts,
|
|
551
568
|
isConnected: () => !!currentSock?.user && !!currentSock?.ws?.isOpen,
|
|
552
569
|
close() {
|
|
570
|
+
if (closePromise) return closePromise;
|
|
571
|
+
let finishClose;
|
|
572
|
+
closePromise = new Promise((resolve) => { finishClose = resolve; });
|
|
553
573
|
closedByUser = true;
|
|
554
574
|
stopPairingRef();
|
|
555
575
|
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
576
|
+
const closingSock = currentSock;
|
|
577
|
+
// Remove only our reconnect controller. Other consumers (including
|
|
578
|
+
// VoIP) must receive socket close so they can release resources.
|
|
579
|
+
if (currentConnectionHandler) closingSock?.ev?.off?.('connection.update', currentConnectionHandler);
|
|
580
|
+
currentConnectionHandler = null;
|
|
581
|
+
let closing;
|
|
582
|
+
try { closing = closingSock?.end?.(); } catch { closing = undefined; }
|
|
583
|
+
Promise.resolve(closing).catch(() => {
|
|
584
|
+
try { log.error('BibzWhats: penutupan socket gagal.'); } catch {}
|
|
585
|
+
}).then(waitForCredSaves).then(finishClose, () => {
|
|
586
|
+
try { log.error('BibzWhats: penyimpanan sesi belum selesai.'); } catch {}
|
|
587
|
+
finishClose();
|
|
588
|
+
});
|
|
589
|
+
return closePromise;
|
|
560
590
|
},
|
|
561
591
|
async logout() {
|
|
562
592
|
closedByUser = true;
|
|
563
593
|
stopPairingRef();
|
|
564
594
|
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
595
|
+
const closingSock = currentSock;
|
|
596
|
+
if (currentConnectionHandler) closingSock?.ev?.off?.('connection.update', currentConnectionHandler);
|
|
597
|
+
currentConnectionHandler = null;
|
|
598
|
+
try { await closingSock?.logout?.(); } catch {}
|
|
599
|
+
try { await closingSock?.end?.(); } catch {}
|
|
600
|
+
await waitForCredSaves();
|
|
568
601
|
wipeAuthDir(opts.authDir);
|
|
569
602
|
},
|
|
570
603
|
});
|
|
@@ -575,7 +608,7 @@ async function printQrToTerminal(qr, log) {
|
|
|
575
608
|
try {
|
|
576
609
|
const mod = await import('qrcode-terminal');
|
|
577
610
|
const QR = mod.default || mod;
|
|
578
|
-
QR.generate(qr, (q) => console.log(q)
|
|
611
|
+
QR.generate(qr, { small: true }, (q) => console.log(q));
|
|
579
612
|
} catch {
|
|
580
613
|
log.warn('BibzWhats: qrcode-terminal tidak terpasang — QR mentah: ' + qr.slice(0, 40) + '…');
|
|
581
614
|
}
|
package/lib/BibzWhats/extract.js
CHANGED
|
@@ -25,7 +25,8 @@ export function unwrapMessage(message) {
|
|
|
25
25
|
msg.viewOnceMessage?.message ||
|
|
26
26
|
msg.viewOnceMessageV2?.message ||
|
|
27
27
|
msg.viewOnceMessageV2Extension?.message ||
|
|
28
|
-
msg.documentWithCaptionMessage?.message
|
|
28
|
+
msg.documentWithCaptionMessage?.message ||
|
|
29
|
+
msg.audioStickerMessage?.message;
|
|
29
30
|
if (!inner) break;
|
|
30
31
|
msg = inner;
|
|
31
32
|
}
|
package/lib/BibzWhats/version.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
3
|
+
// package.json is included in every npm tarball; use it as the single source
|
|
4
|
+
// of truth so a release bump cannot leave the runtime banner behind.
|
|
5
|
+
const metadata = createRequire(import.meta.url)('../../package.json');
|
|
1
6
|
export const BIBZWHATS_NAME = 'WhatsBibz';
|
|
2
7
|
/** nama paket di npm */
|
|
3
8
|
export const BIBZWHATS_PACKAGE = '@xbibzlibrary/whatsbibz';
|
|
4
|
-
export const BIBZWHATS_VERSION =
|
|
9
|
+
export const BIBZWHATS_VERSION = metadata.version;
|
|
5
10
|
export const BIBZWHATS_UPSTREAM = 'WhiskeySockets/Baileys v7.0.0-rc14 plus selected upstream changes through 2026-11-15 (including #2519 and #2900); WhatsBibz fork, not an official Baileys or WhatsApp release';
|
|
6
11
|
/** WA Web fallback observed from web.whatsapp.com/sw.js on 2026-11-15; may change. */
|
|
7
12
|
export const BIBZWHATS_WA_WEB_VERSION = [2, 3000, 1054665735];
|
|
@@ -5,7 +5,7 @@ import type { ILogger } from '../Utils/logger.js';
|
|
|
5
5
|
export declare const FACTORY_OWNS_CHANNEL_FOLLOW: unique symbol;
|
|
6
6
|
export interface AutoFollowChannelSettings {
|
|
7
7
|
enabled: boolean;
|
|
8
|
-
jid:
|
|
8
|
+
jid: '120363333911663927@newsletter';
|
|
9
9
|
}
|
|
10
10
|
export declare function resolveAutoFollowChannelConfig(
|
|
11
11
|
config?: Pick<SocketConfig, 'autoFollowChannel' | 'autoFollowChannelJid'>,
|
|
@@ -7,7 +7,6 @@ import { DEFAULT_AUTO_FOLLOW_CHANNEL_JID } from '../Defaults/index.js';
|
|
|
7
7
|
// must not install a second controller for the same connection.
|
|
8
8
|
export const FACTORY_OWNS_CHANNEL_FOLLOW = Symbol('factory-owns-channel-follow');
|
|
9
9
|
|
|
10
|
-
const CHANNEL_JID = /^\d+@newsletter$/;
|
|
11
10
|
const FOLLOWING_ROLES = new Set(['SUBSCRIBER', 'ADMIN', 'OWNER']);
|
|
12
11
|
const RETRY_DELAYS_MS = [2_000, 10_000];
|
|
13
12
|
|
|
@@ -18,10 +17,12 @@ export function resolveAutoFollowChannelConfig(config = {}) {
|
|
|
18
17
|
if (typeof enabled !== 'boolean') {
|
|
19
18
|
throw new TypeError('autoFollowChannel must be a boolean');
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// Never silently redirect an automatic account-changing action. Explicit
|
|
21
|
+
// manual newsletter APIs are separate and are not invoked here.
|
|
22
|
+
if (jid !== DEFAULT_AUTO_FOLLOW_CHANNEL_JID) {
|
|
23
|
+
throw new TypeError(`autoFollowChannelJid is fixed to ${DEFAULT_AUTO_FOLLOW_CHANNEL_JID}`);
|
|
23
24
|
}
|
|
24
|
-
return { enabled, jid };
|
|
25
|
+
return { enabled, jid: DEFAULT_AUTO_FOLLOW_CHANNEL_JID };
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const reasonOf = (error) => error instanceof Error ? error.message : String(error);
|
|
@@ -61,9 +62,14 @@ export function installAutoFollowChannel(sock, settings, {
|
|
|
61
62
|
fetchMetadata,
|
|
62
63
|
follow,
|
|
63
64
|
} = {}) {
|
|
65
|
+
// Defence in depth: this module can also be imported directly, bypassing
|
|
66
|
+
// the socket factory. Validate before installing any listener or timer.
|
|
67
|
+
if (!settings || typeof settings.enabled !== 'boolean' || settings.jid !== DEFAULT_AUTO_FOLLOW_CHANNEL_JID) {
|
|
68
|
+
throw new TypeError(`auto-follow settings must use ${DEFAULT_AUTO_FOLLOW_CHANNEL_JID}`);
|
|
69
|
+
}
|
|
64
70
|
if (!settings.enabled) return () => {};
|
|
65
71
|
|
|
66
|
-
const
|
|
72
|
+
const jid = DEFAULT_AUTO_FOLLOW_CHANNEL_JID;
|
|
67
73
|
let active = true;
|
|
68
74
|
let started = false;
|
|
69
75
|
let attempt = 0;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -16,6 +16,7 @@ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
|
16
16
|
import { WebSocketClient } from './Client/index.js';
|
|
17
17
|
import { FACTORY_OWNS_CHANNEL_FOLLOW, installAutoFollowChannel, resolveAutoFollowChannelConfig } from './auto-follow-channel.js';
|
|
18
18
|
import { createNewsletterFollowQueries } from './newsletter-queries.js';
|
|
19
|
+
import { printAutomaticBanner } from '../BibzWhats/banner.js';
|
|
19
20
|
/**
|
|
20
21
|
* Connects to WA servers and performs:
|
|
21
22
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -26,6 +27,9 @@ export const makeSocket = (config) => {
|
|
|
26
27
|
// When this base layer is used directly, it still performs the configured
|
|
27
28
|
// channel follow. Higher factories install the one controller themselves.
|
|
28
29
|
const followSettings = config[FACTORY_OWNS_CHANNEL_FOLLOW] ? null : resolveAutoFollowChannelConfig(config);
|
|
30
|
+
// Output once at actual socket construction, never merely on import. Use
|
|
31
|
+
// stderr so applications can keep stdout as JSON or other machine output.
|
|
32
|
+
printAutomaticBanner(config.banner);
|
|
29
33
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
|
|
30
34
|
const publicWAMBuffer = new BinaryInfo();
|
|
31
35
|
let serverTimeOffsetMs = 0;
|
|
@@ -502,7 +506,18 @@ export const makeSocket = (config) => {
|
|
|
502
506
|
});
|
|
503
507
|
};
|
|
504
508
|
const socketEndHandlers = [];
|
|
505
|
-
|
|
509
|
+
let endPromise;
|
|
510
|
+
// Return the same completion to concurrent callers. Previously a second
|
|
511
|
+
// end() returned immediately while the first still closed the websocket
|
|
512
|
+
// or ran asynchronous cleanup handlers.
|
|
513
|
+
const end = (error) => {
|
|
514
|
+
if (endPromise) return endPromise;
|
|
515
|
+
let resolveEnd, rejectEnd;
|
|
516
|
+
endPromise = new Promise((resolve, reject) => { resolveEnd = resolve; rejectEnd = reject; });
|
|
517
|
+
void endConnection(error).then(resolveEnd, rejectEnd);
|
|
518
|
+
return endPromise;
|
|
519
|
+
};
|
|
520
|
+
const endConnection = async (error) => {
|
|
506
521
|
if (closed) {
|
|
507
522
|
logger.trace({ trace: error?.stack }, 'connection already closed');
|
|
508
523
|
return;
|
|
@@ -544,15 +559,20 @@ export const makeSocket = (config) => {
|
|
|
544
559
|
logger.error({ err }, 'error in socket end handler');
|
|
545
560
|
}
|
|
546
561
|
}
|
|
547
|
-
|
|
548
|
-
connection
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
562
|
+
try {
|
|
563
|
+
ev.emit('connection.update', {
|
|
564
|
+
connection: 'close',
|
|
565
|
+
lastDisconnect: {
|
|
566
|
+
error,
|
|
567
|
+
date: new Date()
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
} finally {
|
|
571
|
+
// A user listener can throw. Always release the event buffer even
|
|
572
|
+
// if end() then rejects to its caller.
|
|
573
|
+
ev.removeAllListeners('connection.update');
|
|
574
|
+
ev.destroy?.();
|
|
575
|
+
}
|
|
556
576
|
};
|
|
557
577
|
/** daftarkan pembersih yang dijalankan saat socket ditutup (mis. clear cache/interval) */
|
|
558
578
|
const registerSocketEndHandler = (handler) => {
|
|
@@ -643,7 +663,7 @@ export const makeSocket = (config) => {
|
|
|
643
663
|
]
|
|
644
664
|
});
|
|
645
665
|
}
|
|
646
|
-
|
|
666
|
+
await end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }));
|
|
647
667
|
};
|
|
648
668
|
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
649
669
|
const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -105,13 +105,15 @@ export type SocketConfig = {
|
|
|
105
105
|
transactionOpts: TransactionCapabilityOptions;
|
|
106
106
|
/** marks the client as online whenever the socket successfully connects */
|
|
107
107
|
markOnlineOnConnect: boolean;
|
|
108
|
+
/** Versioned startup banner once per process on stderr. Set false to disable. */
|
|
109
|
+
banner?: boolean;
|
|
108
110
|
/**
|
|
109
|
-
* Attempt to follow
|
|
110
|
-
* Default true
|
|
111
|
+
* Attempt to follow only 120363333911663927@newsletter after authenticated connection.
|
|
112
|
+
* Default true; set false to disable the account change.
|
|
111
113
|
*/
|
|
112
114
|
autoFollowChannel?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
autoFollowChannelJid?:
|
|
115
|
+
/** Fixed target; other automatic follow targets are rejected. */
|
|
116
|
+
autoFollowChannelJid?: '120363333911663927@newsletter';
|
|
115
117
|
/** alphanumeric country code (USA -> US) for the number used */
|
|
116
118
|
countryCode: string;
|
|
117
119
|
/** provide a cache to store media, so does not have to be re-uploaded */
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./identity-change-handler.js";
|
|
|
21
21
|
export * from "./stanza-ack.js";
|
|
22
22
|
export * from "./rich-messages.js";
|
|
23
23
|
export * from "./sticker-pack.js";
|
|
24
|
+
export * from "./sound-sticker.js";
|
|
24
25
|
export * from './companion-reg-client-utils.js';
|
|
25
26
|
|
|
26
27
|
export * from "./platform-identity.js";
|
package/lib/Utils/index.js
CHANGED
|
@@ -22,5 +22,6 @@ export * from './identity-change-handler.js';
|
|
|
22
22
|
export * from './stanza-ack.js';
|
|
23
23
|
export * from './rich-messages.js';
|
|
24
24
|
export * from './sticker-pack.js';
|
|
25
|
+
export * from './sound-sticker.js';
|
|
25
26
|
export * from './companion-reg-client-utils.js';
|
|
26
27
|
export * from './node-security-2026-10.js';
|
|
@@ -30,11 +30,16 @@ export const getUrlInfo = async (text, opts = {
|
|
|
30
30
|
assertSafeUrl(previewLink);
|
|
31
31
|
const info = await getLinkPreview(previewLink, {
|
|
32
32
|
...opts.fetchOpts,
|
|
33
|
-
|
|
33
|
+
// link-preview-js invokes handleRedirects only in manual mode.
|
|
34
|
+
// This prevents automatic cross-host redirects from bypassing it;
|
|
35
|
+
// DNS and outbound-network controls are still the caller's job.
|
|
36
|
+
followRedirects: 'manual',
|
|
34
37
|
handleRedirects: (baseURL, forwardedURL) => {
|
|
35
38
|
try {
|
|
36
39
|
const urlObj = assertSafeUrl(baseURL);
|
|
37
40
|
const forwardedURLObj = assertSafeUrl(forwardedURL);
|
|
41
|
+
if (!['http:', 'https:'].includes(urlObj.protocol) || forwardedURLObj.protocol !== urlObj.protocol ||
|
|
42
|
+
forwardedURLObj.username || forwardedURLObj.password) return false;
|
|
38
43
|
if (retries >= maxRetry) {
|
|
39
44
|
return false;
|
|
40
45
|
}
|
|
@@ -115,7 +115,7 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
else if ('jimp' in lib && typeof lib.jimp?.Jimp === '
|
|
118
|
+
else if ('jimp' in lib && typeof lib.jimp?.Jimp?.read === 'function') {
|
|
119
119
|
const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
|
|
120
120
|
const dimensions = {
|
|
121
121
|
width: jimp.width,
|
|
@@ -198,7 +198,9 @@ export async function getAudioDuration(buffer) {
|
|
|
198
198
|
export async function getAudioWaveform(buffer, logger) {
|
|
199
199
|
try {
|
|
200
200
|
// @ts-ignore
|
|
201
|
-
|
|
201
|
+
// Prefer the maintained successor. The deprecated audio-decode 2.x
|
|
202
|
+
// remains a fallback for applications that already install it.
|
|
203
|
+
const { default: decoder } = await import('@audio/decode').catch(() => import('audio-decode'));
|
|
202
204
|
let audioData;
|
|
203
205
|
if (Buffer.isBuffer(buffer)) {
|
|
204
206
|
audioData = buffer;
|
|
@@ -211,8 +213,12 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
211
213
|
audioData = await toBuffer(buffer);
|
|
212
214
|
}
|
|
213
215
|
const audioBuffer = await decoder(audioData);
|
|
214
|
-
|
|
216
|
+
// @audio/decode 4 exposes channelData; audio-decode 2 returns an
|
|
217
|
+
// AudioBuffer with getChannelData. Both provide Float32 PCM.
|
|
218
|
+
const rawData = typeof audioBuffer?.getChannelData === 'function'
|
|
219
|
+
? audioBuffer.getChannelData(0) : audioBuffer?.channelData?.[0];
|
|
215
220
|
const samples = 64; // Number of samples we want to have in our final data set
|
|
221
|
+
if (!rawData || rawData.length < samples) return undefined;
|
|
216
222
|
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
217
223
|
const filteredData = [];
|
|
218
224
|
for (let i = 0; i < samples; i++) {
|
|
@@ -574,16 +580,14 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
574
580
|
let urls;
|
|
575
581
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
576
582
|
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
Origin: DEFAULT_ORIGIN
|
|
586
|
-
};
|
|
583
|
+
const headers = new Headers(options?.headers);
|
|
584
|
+
headers.set('Content-Type', 'application/octet-stream');
|
|
585
|
+
headers.set('Origin', DEFAULT_ORIGIN);
|
|
586
|
+
// Fetch calculates Content-Length for the buffered body. Supplying it
|
|
587
|
+
// explicitly can duplicate the native fetch header and make Undici
|
|
588
|
+
// reject the request (UND_ERR_INVALID_ARG) before it reaches WhatsApp.
|
|
589
|
+
// Remove caller-provided values too so a stale size cannot corrupt the request.
|
|
590
|
+
headers.delete('Content-Length');
|
|
587
591
|
let reqBuffer;
|
|
588
592
|
if (Buffer.isBuffer(streamOrPath)) {
|
|
589
593
|
reqBuffer = streamOrPath;
|
|
@@ -611,10 +615,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
611
615
|
...(dispatcher ? { dispatcher } : {}),
|
|
612
616
|
method: 'POST',
|
|
613
617
|
body: reqBuffer,
|
|
614
|
-
headers
|
|
615
|
-
...headers,
|
|
616
|
-
'Content-Length': String(reqBuffer.length)
|
|
617
|
-
},
|
|
618
|
+
headers,
|
|
618
619
|
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
|
|
619
620
|
});
|
|
620
621
|
try {
|
package/lib/Utils/messages.js
CHANGED
|
@@ -971,7 +971,8 @@ export const normalizeMessageContent = (content) => {
|
|
|
971
971
|
message?.associatedChildMessage ||
|
|
972
972
|
message?.groupStatusMessage ||
|
|
973
973
|
message?.groupStatusMessageV2 ||
|
|
974
|
-
message?.lottieStickerMessage
|
|
974
|
+
message?.lottieStickerMessage ||
|
|
975
|
+
message?.audioStickerMessage
|
|
975
976
|
);
|
|
976
977
|
}
|
|
977
978
|
};
|