Update BotService.php
This commit is contained in:
@@ -231,6 +231,54 @@ class BotService {
|
||||
$isNav = in_array($normalized, ['menu','menú','inicio','atras','atrás','volver','back'], true) || is_numeric(trim($messageText));
|
||||
if ($isNav) {
|
||||
try { error_log("[BotService] processMessage - bot_paused_until active but allowing navigation input for phone={$phoneNumber} message='{$messageText}'"); } catch (Throwable $t) {}
|
||||
|
||||
// Si es un número, procesarlo inmediatamente como selección de menú
|
||||
if (is_numeric(trim($messageText))) {
|
||||
try {
|
||||
$stateSvc2 = new ConversationStateService();
|
||||
$resolvedMenuId2 = $stateSvc2->getCurrentMenuId($phoneNumber);
|
||||
} catch (Exception $e) {
|
||||
$resolvedMenuId2 = null;
|
||||
}
|
||||
|
||||
if (empty($resolvedMenuId2)) {
|
||||
try {
|
||||
$cur = $this->db->fetch("SELECT current_menu_id FROM users WHERE phone_number = :phone", ['phone' => $phoneNumber]);
|
||||
$resolvedMenuId2 = $cur ? $cur['current_menu_id'] : null;
|
||||
} catch (Exception $e) {
|
||||
$resolvedMenuId2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Si aún no hay menú activo, intentar con historial
|
||||
if (empty($resolvedMenuId2)) {
|
||||
try {
|
||||
$hist = (array)$stateSvc2->getStateData($phoneNumber, 'menu_history');
|
||||
if (!empty($hist)) $resolvedMenuId2 = end($hist);
|
||||
} catch (Exception $e) {
|
||||
$resolvedMenuId2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($resolvedMenuId2)) {
|
||||
// Asegurar que la BD refleje el menu activo para que processMenuSelection lo resuelva correctamente
|
||||
try {
|
||||
$this->db->update('users', ['current_menu_id' => $resolvedMenuId2, 'current_step' => 1], 'phone_number = :phone', ['phone' => $phoneNumber]);
|
||||
try {
|
||||
$stateSvc2->setCurrentMenu($phoneNumber, (int)$resolvedMenuId2);
|
||||
} catch (Exception $e) {
|
||||
// ignore
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log('[BotService] failed to set current_menu_id before processing numeric selection during pause: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$user['current_menu_id'] = $resolvedMenuId2;
|
||||
$this->processMenuSelection($user, $messageText);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// proceed to let navigation/menus be processed
|
||||
} else {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user