From dee459d53ffde23a150d078102ff322185bee7c8 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 28 Jun 2026 11:40:23 -0500 Subject: [PATCH] fix: reset context on api_report failure so user is never stuck On any api_report failure (missing endpoint, curl error, HTTP error, upload failure), reset the bot_context so the next message goes through the normal flow instead of retrying the failed report indefinitely. Also reduce curl timeout from 60s to 15s to avoid WhatsApp webhook timeouts that cause Meta to retry the same message repeatedly. Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index 5feb9a3..6562a70 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -125,6 +125,7 @@ class NormalBot if (!$ep || empty($ep['url'])) { self::log("API report: endpoint_key '{$endpointKey}' no configurado para company {$company['id']}"); + ConversationContext::reset($ctxId); return self::sendText('El informe solicitado no está configurado. Contacta al administrador.', $context['from'], $company); } @@ -150,7 +151,7 @@ class NormalBot $curlOpts = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, - CURLOPT_TIMEOUT => 60, + CURLOPT_TIMEOUT => 15, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $apiKey, 'X-API-Key: ' . $apiKey, @@ -170,11 +171,13 @@ class NormalBot if ($error) { self::log("API report error [{$endpointKey}]: {$error}"); + ConversationContext::reset($ctxId); return self::sendText('Error al obtener el reporte. Intenta de nuevo.', $context['from'], $company); } if ($httpCode >= 400) { self::log("API report HTTP {$httpCode} [{$endpointKey}]: " . mb_substr($content, 0, 200)); + ConversationContext::reset($ctxId); return self::sendText('Error al obtener el reporte. Intenta de nuevo.', $context['from'], $company); } @@ -208,6 +211,7 @@ class NormalBot if (!$upload['success'] || !$upload['media_id']) { self::log("API report upload failed [{$endpointKey}]: " . ($upload['error'] ?? 'unknown')); + ConversationContext::reset($ctxId); return self::sendText('Error al enviar el reporte. Intenta de nuevo.', $context['from'], $company); }