diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index 3ebafda..74a5085 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -23,6 +23,7 @@ use App\Models\Tarifas; use App\Models\User; use Carbon\Carbon; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Str; @@ -563,8 +564,10 @@ class PublicChat extends Component $datosPago = app(\App\Services\GeminiVisionService::class)->extraerPago($base64, $mimeType); - if (! $datosPago) { - $this->guardarMensajeBot($this->convId, "No pude leer el comprobante. Intenta con una foto mas clara."); + if (! $datosPago || isset($datosPago['__error']) || isset($datosPago['__parse_error'])) { + $detalle = $datosPago['__error'] ?? ($datosPago['__parse_error'] ?? ''); + Log::warning('[PublicChat] Gemini error: ' . $detalle); + $this->guardarMensajeBot($this->convId, "No pude leer el comprobante. Intenta con una foto mas clara o con mejor iluminación."); $this->cargarMensajes(); return; } diff --git a/app/Services/CorreoImapService.php b/app/Services/CorreoImapService.php index de0de89..b4e308e 100755 --- a/app/Services/CorreoImapService.php +++ b/app/Services/CorreoImapService.php @@ -51,7 +51,7 @@ class CorreoImapService } // Descargar un lote suficiente para cubrir la ventana de tiempo. - $fetchSize = min($total, max($limit * 4, 20)); + $fetchSize = min($total, max($limit * 2, 20)); $from = max(1, $total - $fetchSize + 1); $set = "{$from}:{$total}"; @@ -67,9 +67,9 @@ class CorreoImapService foreach ($emails as $email) { $ts = $email['date'] ? @strtotime($email['date']) : false; - // Correo más antiguo que la ventana → parar + // Correo más antiguo que la ventana → saltar (no parar, pueden haber más nuevos) if ($ts !== false && $ts < $cutoff) { - break; + continue; } $result[] = $email; diff --git a/app/Services/GeminiVisionService.php b/app/Services/GeminiVisionService.php index 0c00e94..8c062de 100755 --- a/app/Services/GeminiVisionService.php +++ b/app/Services/GeminiVisionService.php @@ -15,7 +15,7 @@ class GeminiVisionService public function __construct() { $this->apiKey = ChatConfig::get('gemini_api_key', ''); - $this->model = ChatConfig::get('gemini_model', 'gemini-3.5-flash'); + $this->model = ChatConfig::get('gemini_model', 'gemini-2.0-flash'); } public function extraerPago(string $base64, string $mimeType, ?int $usuarioId = null, string $canal = 'telegram'): ?array @@ -36,8 +36,7 @@ class GeminiVisionService 'contents' => $contents, 'generationConfig' => [ 'temperature' => 0.1, - 'maxOutputTokens' => 8192, - 'thinkingConfig' => ['thinkingBudget' => 0], + 'maxOutputTokens' => 512, ], ]; @@ -49,7 +48,7 @@ class GeminiVisionService $url = "https://generativelanguage.googleapis.com/{$ver}/models/{$this->model}:generateContent"; try { $resp = Http::withHeaders(['Content-Type' => 'application/json']) - ->timeout(20) + ->timeout(40) ->post("{$url}?key={$this->apiKey}", $body); if ($resp->successful()) { diff --git a/app/Services/PagoValidadorService.php b/app/Services/PagoValidadorService.php index 0add9b5..67f1e1d 100755 --- a/app/Services/PagoValidadorService.php +++ b/app/Services/PagoValidadorService.php @@ -122,7 +122,7 @@ class PagoValidadorService // ── 3. Hora exacta ─────────────────────────────────────── if ($horaIA && ($datosCorreo['hora'] ?? '')) { - if (! $this->horaProxima($horaIA, $datosCorreo['hora'], 0)) { + if (! $this->horaProxima($horaIA, $datosCorreo['hora'], 3)) { Log::info("[PagoValidador] Correo #{$i}: hora no coincide (ia={$horaIA} correo={$datosCorreo['hora']})"); continue; } @@ -265,6 +265,6 @@ class PagoValidadorService $coincidencias++; } } - return $coincidencias >= 2; + return $coincidencias >= 1; } }