From 09db466fa61140ecd2d95a31acba941121014654 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 30 Jul 2026 23:50:09 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20navegaci=C3=B3n=20=E2=80=94=20atras/canc?= =?UTF-8?q?elar/regresar=20+=20NLU=20desde=20men=C3=BAs=20activos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 16 ++++++++++++++-- setup/seed_palmas.php | 15 +++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index b1737f3..ce97803 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -71,9 +71,13 @@ class NormalBot } // 3. Active node — resume conversation + // Menu-type nodes let NLU act on free text; only re-show if NLU doesn't handle it. $sentinels = ['collecting', '__greeted']; if ($currentNode !== null && !in_array($currentNode, $sentinels, true) && isset($flows[$currentNode])) { - return self::handleFlow($flows[$currentNode], $context, $company, $ctxId, $menus); + $isMenuNode = ($flows[$currentNode]['type'] ?? '') === 'menu'; + if (!$isMenuNode) { + return self::handleFlow($flows[$currentNode], $context, $company, $ctxId, $menus); + } } // 4. Welcome message — shown once for brand-new sessions before the category menu @@ -132,11 +136,19 @@ class NormalBot } } if ($route['action'] === 'chat' && ($route['text'] ?? '') !== '') { - ConversationContext::updateNode($ctxId, null); + // Preserve node when inside a menu so state isn't lost + $inMenu = $currentNode !== null && !in_array($currentNode, $sentinels, true) + && isset($flows[$currentNode]) && ($flows[$currentNode]['type'] ?? '') === 'menu'; + if (!$inMenu) ConversationContext::updateNode($ctxId, null); return self::sendText($route['text'], $context['from'], $company); } } + // Re-show current menu when NLU didn't route anything + if ($currentNode !== null && !in_array($currentNode, $sentinels, true) && isset($flows[$currentNode])) { + return self::handleFlow($flows[$currentNode], $context, $company, $ctxId, $menus); + } + // 7. Fallback flow $fallbackFlowId = $perType['fallback_flow'] ?? $config['fallback_flow'] ?? null; if ($fallbackFlowId !== null && isset($flows[$fallbackFlowId])) { diff --git a/setup/seed_palmas.php b/setup/seed_palmas.php index cf3510d..883e653 100644 --- a/setup/seed_palmas.php +++ b/setup/seed_palmas.php @@ -13,12 +13,15 @@ $configJson = [ 'fallback' => 'No entendí. Escribe *menu* para ver las opciones disponibles.', 'nlu_enabled' => true, 'commands' => [ - 'menu' => 'show_main_menu', - 'informes' => 'descargar_informes', - 'info' => 'enviar_informacion', - 'inicio' => 'show_main_menu', - 'volver' => 'show_main_menu', - 'salir' => 'show_main_menu', + 'menu' => 'show_main_menu', + 'informes' => 'descargar_informes', + 'info' => 'enviar_informacion', + 'inicio' => 'show_main_menu', + 'volver' => 'show_main_menu', + 'salir' => 'show_main_menu', + 'atras' => 'show_main_menu', + 'cancelar' => 'show_main_menu', + 'regresar' => 'show_main_menu', ], // ── Menus globales ────────────────────────────────────────────────────── 'menus' => [