fix: corregir pipeline de validación de pagos

- GeminiVisionService: eliminar thinkingConfig (rompe modelos flash),
  reducir maxOutputTokens 8192→512, timeout 20→40s, default gemini-2.0-flash
- PublicChat: detectar correctamente errores de Gemini (__error/__parse_error)
  que antes pasaban el guard if(!$datosPago) por ser arrays truthy
- PagoValidadorService: tolerancia de hora 0→3 min, remitente >=2→>=1 palabra
- CorreoImapService: break→continue en correos fuera de ventana (IMAP no
  garantiza orden cronológico), fetchSize *4→*2 para evitar timeout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro
2026-07-31 05:00:23 +00:00
co-authored by Claude Sonnet 4.6
parent fc17e57624
commit d88f67ab5b
4 changed files with 13 additions and 11 deletions
+3 -3
View File
@@ -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;
+3 -4
View File
@@ -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()) {
+2 -2
View File
@@ -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;
}
}