diff --git a/services/AiBot.php b/services/AiBot.php index 2f09771..f4dd86c 100644 --- a/services/AiBot.php +++ b/services/AiBot.php @@ -88,21 +88,13 @@ class AiBot if ($httpCode !== 200 || $response === false) { WpWebhook::log('ERROR', "OpenAI API error: {$error} HTTP:{$httpCode}"); - return [ - 'content' => 'Lo siento, tengo problemas para procesar tu mensaje. Por favor intenta de nuevo más tarde.', - ]; + return null; } $data = json_decode($response, true); $text = $data['choices'][0]['message']['content'] ?? null; - if ($text === null) { - return [ - 'content' => 'No pude generar una respuesta adecuada. ¿Puedes reformular tu pregunta?', - ]; - } - - return ['content' => $text]; + return $text !== null ? ['content' => $text] : null; } private static function callGemini(string $systemPrompt, array $history): ?array @@ -146,13 +138,14 @@ class AiBot curl_close($ch); if ($httpCode !== 200 || $response === false) { - return ['content' => 'Lo siento, tengo problemas para procesar tu mensaje. Por favor intenta de nuevo.']; + WpWebhook::log('ERROR', "Gemini API error: {$error} HTTP:{$httpCode}"); + return null; } $data = json_decode($response, true); $text = $data['candidates'][0]['content']['parts'][0]['text'] ?? null; - return $text !== null ? ['content' => $text] : ['content' => 'No pude generar una respuesta. ¿Puedes reformular tu pregunta?']; + return $text !== null ? ['content' => $text] : null; } private static function mockResponse(array $history): array