Add WhatsApp session bind/unbind to Admin Runtime, and fix related Admin JS errors.

Expose sidecar status, start/stop, QR bind, and unbind so 405 session failures are visible instead of a stuck connecting state.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-17 22:23:35 +08:00
parent 1bdbfc3b85
commit 5c6833612f
16 changed files with 1123 additions and 72 deletions

View file

@ -1,3 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import qrcode from "qrcode-terminal";
export function printQrToTerminal(qr: string): void {
@ -5,3 +7,20 @@ export function printQrToTerminal(qr: string): void {
qrcode.generate(qr, { small: true });
}
export async function writeQrImage(stateDir: string, qr: string): Promise<{ pngPath: string; dataUrl: string }> {
const pngPath = path.join(stateDir, "qr.png");
try {
// Optional dependency: installed by whatsapp_install.ps1 when available.
const QRCode = await import("qrcode");
await QRCode.toFile(pngPath, qr, { width: 320, margin: 1, errorCorrectionLevel: "M" });
const dataUrl = await QRCode.toDataURL(qr, { width: 320, margin: 1, errorCorrectionLevel: "M" });
return { pngPath, dataUrl: String(dataUrl || "") };
} catch {
try {
if (fs.existsSync(pngPath)) fs.unlinkSync(pngPath);
} catch {
// ignore
}
return { pngPath: "", dataUrl: "" };
}
}