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' => [