From 932a7a78a7a05eb1df46da7432768ec1b055dff7 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:53:41 -0500 Subject: [PATCH] fix: fallback_flow por categoria, menu directo en saludo/fallback --- scripts/apply-menus.php | 29 +++++++++++++++++++---------- services/NormalBot.php | 7 +++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/scripts/apply-menus.php b/scripts/apply-menus.php index fc48f40..14b9870 100644 --- a/scripts/apply-menus.php +++ b/scripts/apply-menus.php @@ -83,7 +83,7 @@ $menuConfig = [ ], ], 'flows' => [ - 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_main_menu'], + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], 'recibir_info' => ['type' => 'function', 'function' => 'forward_to_ai'], 'descargar_informes' => ['type' => 'menu', 'menu' => 'submenu_informes'], 'menu_mixto' => ['type' => 'menu', 'menu' => 'menu_mixto'], @@ -98,15 +98,18 @@ $menuConfig = [ ], 'per_type' => [ '3' => [ - 'greeting' => '¡Bienvenido! Escribe *menu* para ver las opciones disponibles.', - 'fallback' => 'No entendí. Escribe *menu* para ver las opciones disponibles.', + 'greeting_flow' => 'show_main_menu', + 'fallback_flow' => 'show_main_menu', + 'greeting' => null, + 'fallback' => null, ], '1' => [ - 'greeting' => '¡Bienvenido! Escribe *menu* para recibir información.', - 'fallback' => 'Escribe *menu* para recibir información.', + 'greeting_flow' => 'show_menu_cat1', + 'fallback_flow' => 'show_menu_cat1', + 'greeting' => null, + 'fallback' => null, 'commands' => [ 'menu' => 'show_menu_cat1', - 'info' => 'recibir_info_cat1', ], 'menus' => [ 'show_menu_cat1' => [ @@ -128,14 +131,16 @@ $menuConfig = [ 'flows' => [ 'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], 'recibir_info_cat1' => ['type' => 'function', 'function' => 'forward_to_ai'], + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], ], ], '2' => [ - 'greeting' => '¡Bienvenido! Escribe *menu* para descargar informes.', - 'fallback' => 'Escribe *menu* para descargar informes.', + 'greeting_flow' => 'show_menu_cat2', + 'fallback_flow' => 'show_menu_cat2', + 'greeting' => null, + 'fallback' => null, 'commands' => [ - 'menu' => 'show_menu_cat2', - 'informes' => 'descargar_informes', + 'menu' => 'show_menu_cat2', ], 'menus' => [ 'show_menu_cat2' => [ @@ -154,6 +159,10 @@ $menuConfig = [ ], ], ], + 'flows' => [ + 'show_menu_cat2' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + ], ], ], ]; diff --git a/services/NormalBot.php b/services/NormalBot.php index 5cc5732..a4fc806 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -59,8 +59,15 @@ class NormalBot return $response; } + $fallbackFlowId = $perType['fallback_flow'] ?? $config['fallback_flow'] ?? null; + if ($fallbackFlowId !== null && isset($flows[$fallbackFlowId])) { + ConversationContext::updateNode($ctxId, $fallbackFlowId); + return self::handleFlow($flows[$fallbackFlowId], $context, $company, $ctxId); + } + $fallback = $perType['fallback'] ?? $config['fallback'] ?? null; if ($fallback !== null) { + ConversationContext::updateNode($ctxId, null); return self::sendText($fallback, $context['from'], $company); }