From ab7299db2c3df1ede865efb67bfc98a99b3767ce Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 24 Jan 2026 02:02:10 -0500 Subject: [PATCH] up --- services/BotService.php | 21 +++++++++++++++++++++ services/ConversationStateService.php | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/services/BotService.php b/services/BotService.php index 17571fa..4ddf3e6 100644 --- a/services/BotService.php +++ b/services/BotService.php @@ -237,6 +237,27 @@ class BotService { case 'cancelar': $this->exitMenu($phoneNumber); return true; + + case 'atras': + case 'atrás': + case 'volver': + case 'back': + try { error_log("[BotService] processSpecialCommands - detected BACK command in global handler for phone={$phoneNumber}"); } catch (Throwable $t) {} + // Resolver current_menu_id desde users y decidir la acción más adecuada + try { + $cur = $this->db->fetch("SELECT current_menu_id FROM users WHERE phone_number = :phone", ['phone' => $phoneNumber]); + $currentMenuId = $cur ? $cur['current_menu_id'] : null; + } catch (Exception $e) { + $currentMenuId = null; + } + + if (!empty($currentMenuId)) { + $this->goToParentMenu($phoneNumber, $currentMenuId); + } else { + // Intentar usar historial + $this->goToPreviousMenu($phoneNumber); + } + return true; case 'asesor': case 'ayuda': diff --git a/services/ConversationStateService.php b/services/ConversationStateService.php index 1d29fcc..8b51b83 100644 --- a/services/ConversationStateService.php +++ b/services/ConversationStateService.php @@ -243,8 +243,9 @@ class ConversationStateService * @param int $menuId * @return bool */ - public function setCurrentMenu(string $phoneNumber, int $menuId): bool + public function setCurrentMenu(string $phoneNumber, ?int $menuId): bool { + // Allow null to clear current_menu_id return $this->updateStateData($phoneNumber, ['current_menu_id' => $menuId]); }