diff --git a/services/NormalBot.php b/services/NormalBot.php index 74af543..7dc46fd 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -30,6 +30,12 @@ class NormalBot } if ($dirty) ConversationContext::updateMetadata($ctxId, $m); + // "menu/inicio/volver" → prefer per-type greeting_menu over global show_main_menu + $greetingMenuKey = $perType['greeting_menu'] ?? null; + if ($action === 'show_main_menu' && $greetingMenuKey && isset($menus[$greetingMenuKey])) { + $action = $greetingMenuKey; + } + ConversationContext::updateNode($ctxId, $action); // Commands that match a flow if (isset($flows[$action])) { @@ -943,9 +949,19 @@ class NormalBot } // Direct flow match (button id == flow key) - if (isset($flows[$input])) { - ConversationContext::updateNode($ctxId, $input); - return self::handleFlow($flows[$input], $context, $company, $ctxId, $menus); + // Redirect show_main_menu → per-type greeting_menu if configured + $resolvedInput = $input; + $greetingMenuKey = $perType['greeting_menu'] ?? null; + if ($resolvedInput === 'show_main_menu' && $greetingMenuKey && isset($menus[$greetingMenuKey])) { + $resolvedInput = $greetingMenuKey; + } + if (isset($flows[$resolvedInput])) { + ConversationContext::updateNode($ctxId, $resolvedInput); + return self::handleFlow($flows[$resolvedInput], $context, $company, $ctxId, $menus); + } + if (isset($menus[$resolvedInput])) { + ConversationContext::updateNode($ctxId, $resolvedInput); + return self::buildMenuResponse($menus[$resolvedInput], $context['from'], $company); } return null;