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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0555b35766
commit
dee459d53f
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user