Fix WhatsApp Admin QR bind and show the scan prompt only after Bind.

Use a current WA protocol version, start the sidecar via local tsx with inherited proxy, and stop auto-opening the QR UI on unbound connecting.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-17 23:54:48 +08:00
parent 5c6833612f
commit 9cf026f605
12 changed files with 593 additions and 101 deletions

View file

@ -23,16 +23,53 @@ if (-not (Test-Path (Join-Path $sidecarRoot "baileys_runner.ts"))) {
throw "whatsapp sidecar not installed. Run whatsapp_install.ps1 first."
}
$bridgeSrc = Join-Path $oclawRoot "runtime\\operations\\whatsapp_bridge"
if (Test-Path $bridgeSrc) {
foreach ($name in @("baileys_runner.ts", "auth.ts", "qr.ts", "status.ts")) {
$srcPath = Join-Path $bridgeSrc $name
if (Test-Path $srcPath) {
Copy-Item -Path $srcPath -Destination (Join-Path $sidecarRoot $name) -Force
}
}
}
$stopScript = Join-Path $PSScriptRoot "whatsapp_stop.ps1"
if (Test-Path $stopScript) {
Write-Host "[info] stopping existing sidecar so this console can print QR."
& $stopScript -ChannelId $ChannelId -Force
}
. (Join-Path $PSScriptRoot "lib\ResolveWhatsAppProxy.ps1")
$proxyUrl = Get-OclawWhatsAppProxyUrl -StateDir $stateDir -Persist
if ($proxyUrl) {
$env:AIA_WHATSAPP_PROXY_URL = $proxyUrl
$env:HTTPS_PROXY = $proxyUrl
$env:HTTP_PROXY = $proxyUrl
Write-Host "[info] whatsapp login proxy=$proxyUrl"
}
Set-Content -Path (Join-Path $sidecarRoot "pid.txt") -Value $PID
$nodeExe = Join-Path $systemNodeDir "node.exe"
if (-not (Test-Path $nodeExe)) { $nodeExe = "node.exe" }
$tsxCli = Join-Path $sidecarRoot "node_modules\tsx\dist\cli.mjs"
Push-Location $sidecarRoot
try {
$env:OCLAW_STATE_DIR = $stateDir
Write-Host "[info] whatsapp login started (foreground)."
Write-Host "[info] QR prints here if WhatsApp issues one. Background sidecar logs: data\\logs\\whatsapp_sidecar.log"
Write-Host "[info] If QR appears, scan it in WhatsApp -> Linked devices."
$runnerArgs = @("-y", "tsx", "baileys_runner.ts", "--login")
if ($VerboseRunner) {
$runnerArgs += "--verbose"
$runnerArgs = @()
if (Test-Path $tsxCli) {
$runnerArgs = @($tsxCli, "baileys_runner.ts", "--login")
if ($VerboseRunner) { $runnerArgs += "--verbose" }
& $nodeExe @runnerArgs
} else {
$runnerArgs = @("-y", "tsx", "baileys_runner.ts", "--login")
if ($VerboseRunner) { $runnerArgs += "--verbose" }
& npx.cmd @runnerArgs
}
& npx.cmd @runnerArgs
if ($LASTEXITCODE -ne 0) {
throw "whatsapp login runner exited with code $LASTEXITCODE"
}