up
This commit is contained in:
@@ -780,6 +780,8 @@ class BotService {
|
||||
$previousMenu = null;
|
||||
}
|
||||
|
||||
try { error_log("[BotService] updateUserMenuState - phone={$phoneNumber} previousMenu=" . json_encode($previousMenu) . " newMenu=" . json_encode($menuId)); } catch (Throwable $t) {}
|
||||
|
||||
// Si hay un menú previo diferente al nuevo, empujarlo al historial
|
||||
if (!empty($previousMenu) && $previousMenu != $menuId) {
|
||||
try {
|
||||
@@ -813,6 +815,21 @@ class BotService {
|
||||
private function pushMenuToHistory(string $phoneNumber, $menuId) {
|
||||
try {
|
||||
$stateSvc = new ConversationStateService();
|
||||
$currentState = $stateSvc->getState($phoneNumber);
|
||||
|
||||
// Si no existe una fila de estado, crearla con el historial inicial
|
||||
if (!$currentState) {
|
||||
try {
|
||||
error_log("[BotService] pushMenuToHistory - no existing state, creating initial state with menu_history for phone={$phoneNumber} menuId={$menuId}");
|
||||
$res = $stateSvc->setState($phoneNumber, ConversationStateService::STATE_INITIAL, ['menu_history' => [$menuId]]);
|
||||
error_log('[BotService] pushMenuToHistory - setState result: ' . json_encode($res));
|
||||
return $res;
|
||||
} catch (Exception $e) {
|
||||
error_log('[BotService] pushMenuToHistory create initial state failed: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$history = (array)$stateSvc->getStateData($phoneNumber, 'menu_history');
|
||||
if (!is_array($history)) $history = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user