diff --git a/app/Services/TelegramBotService.php b/app/Services/TelegramBotService.php index 29afc5d..421ee1d 100644 --- a/app/Services/TelegramBotService.php +++ b/app/Services/TelegramBotService.php @@ -250,15 +250,29 @@ class TelegramBotService } try { + // response_format como query param (algunos servidores no lo leen del form) + $url = rtrim($whisperUrl, '?') . (str_contains($whisperUrl, '?') ? '&' : '?') . 'response_format=json'; + $response = Http::timeout(60) ->withBasicAuth('whisper', $whisperToken) ->attach('audio_file', $audioContent, 'audio.ogg') - ->post($whisperUrl, ['response_format' => 'json']); + ->post($url); $tiempoMs = (int) ((microtime(true) - $inicio) * 1000); - $json = $response->json(); - $texto = trim($json['text'] ?? $json['transcription'] ?? ''); - $ok = $response->successful() && $texto !== ''; + + // Intentar JSON primero, luego texto plano como fallback + $json = $response->json(); + $texto = trim($json['text'] ?? $json['transcription'] ?? ''); + + if ($texto === '' && $response->successful()) { + // El servidor devolvió texto plano + $raw = trim($response->body()); + if ($raw !== '' && ! str_starts_with($raw, '{') && ! str_starts_with($raw, '[')) { + $texto = $raw; + } + } + + $ok = $response->successful() && $texto !== ''; AiUsageLog::registrar([ 'servicio' => 'whisper',