&download=1 $tenant = getenv('CODEB_TENANT') ?: 'https://'; $apiKey = getenv('CODEB_API_KEY'); $outDir = getenv('OUT_DIR') ?: './codeb-recordings'; if (!$apiKey) { fwrite(STDERR, "CODEB_API_KEY not set\n"); exit(2); } if (!is_dir($outDir)) mkdir($outDir, 0755, true); function apiGet(string $url, string $apiKey, ?string $sinkPath = null) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey], CURLOPT_TIMEOUT => 120, CURLOPT_FOLLOWLOCATION => false, ]); if ($sinkPath !== null) { $fp = fopen($sinkPath, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($code >= 400) throw new RuntimeException("HTTP $code fetching $url"); return $sinkPath; } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($body === false || $code >= 400) throw new RuntimeException("HTTP $code fetching $url"); return $body; } $idx = json_decode(apiGet("$tenant/signal.ashx?recordings-list=1", $apiKey), true); $items = $idx['items'] ?? []; echo "[list] ", count($items), " sidecars\n"; foreach ($items as $it) { $cid = $it['callId'] ?? ''; if (!$cid) continue; $dst = rtrim($outDir, '/') . "/$cid.wav"; apiGet("$tenant/signal.ashx?recording=" . urlencode($cid) . "&download=1", $apiKey, $dst); echo "[fetch] $cid -> $dst\n"; }