From 0b851208ea82beec507506c84482a293359f8811 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 28 Jun 2026 11:43:57 -0500 Subject: [PATCH] fix: show navigation hint after api_report completes or fails After delivering a report (or on any error), send a text message telling the user to write "menu" or "salir" so they are never left without guidance. Also return the hint as a proper response on success (was returning null). Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index 6562a70..1038875 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -115,8 +115,11 @@ class NormalBot private static function executeApiReport(array $params, array $context, array $company, int $ctxId): ?array { $endpointKey = $params['endpoint_key'] ?? ''; + $nav = "\n\nEscribe *menu* para ver más opciones o *salir* para terminar."; + if ($endpointKey === '') { - return self::sendText('Error: endpoint no configurado.', $context['from'], $company); + ConversationContext::reset($ctxId); + return self::sendText('Error: endpoint no configurado.' . $nav, $context['from'], $company); } $stmt = db()->prepare("SELECT url, method FROM company_endpoints WHERE company_id = ? AND endpoint_key = ? AND is_active = 1 LIMIT 1"); @@ -126,7 +129,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); + return self::sendText('El informe solicitado no está configurado. Contacta al administrador.' . $nav, $context['from'], $company); } $url = $ep['url']; @@ -172,13 +175,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); + return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $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); + return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $context['from'], $company); } $mimeMap = [ @@ -212,17 +215,17 @@ 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); + return self::sendText('Error al enviar el reporte. Intenta de nuevo.' . $nav, $context['from'], $company); } $reportName = $params['filename'] ?? ('reporte.' . $ext); $caption = $params['caption'] ?? 'Aquí tienes el reporte solicitado.'; - $result = WhatsAppSender::sendDocument($context['from'], $upload['media_id'], $phoneNumberId, $caption, $reportName); + WhatsAppSender::sendDocument($context['from'], $upload['media_id'], $phoneNumberId, $caption, $reportName); ConversationContext::reset($ctxId); - return null; + return self::sendText('✅ Reporte enviado.' . $nav, $context['from'], $company); } private static function buildMenuResponse(array $menu, string $to, array $company): ?array