Update BotService.php

This commit is contained in:
Lizandro Guarnizo
2026-01-24 01:56:24 -05:00
parent 14275e4e0a
commit 6e89b1868b
+9
View File
@@ -222,11 +222,13 @@ class BotService {
*/ */
private function processSpecialCommands($phoneNumber, $messageText) { private function processSpecialCommands($phoneNumber, $messageText) {
$command = strtolower($messageText); $command = strtolower($messageText);
try { error_log("[BotService] processSpecialCommands - command={$command} phone={$phoneNumber}"); } catch (Throwable $t) {}
switch ($command) { switch ($command) {
case 'menu': case 'menu':
case 'menú': case 'menú':
case 'inicio': case 'inicio':
try { error_log("[BotService] processSpecialCommands - detected MENU command, calling showMainMenu for phone={$phoneNumber}"); } catch (Throwable $t) {}
$this->showMainMenu($phoneNumber); $this->showMainMenu($phoneNumber);
return true; return true;
@@ -250,13 +252,16 @@ class BotService {
* Mostrar menú principal * Mostrar menú principal
*/ */
private function showMainMenu($phoneNumber) { private function showMainMenu($phoneNumber) {
try { error_log("[BotService] showMainMenu - phone={$phoneNumber} fetching root menu"); } catch (Throwable $t) {}
$mainMenu = $this->db->fetch( $mainMenu = $this->db->fetch(
"SELECT * FROM menus WHERE is_root = 1 AND is_active = 1 ORDER BY order_position LIMIT 1" "SELECT * FROM menus WHERE is_root = 1 AND is_active = 1 ORDER BY order_position LIMIT 1"
); );
try { error_log("[BotService] showMainMenu - fetched root menu=" . json_encode($mainMenu)); } catch (Throwable $t) {}
if ($mainMenu) { if ($mainMenu) {
$this->showMenu($phoneNumber, $mainMenu['id']); $this->showMenu($phoneNumber, $mainMenu['id']);
} else { } else {
try { error_log("[BotService] showMainMenu - no root menu found for phone={$phoneNumber}"); } catch (Throwable $t) {}
$this->whatsappService->sendTextMessage( $this->whatsappService->sendTextMessage(
$phoneNumber, $phoneNumber,
"❌ No hay menús configurados. Contacte con soporte." "❌ No hay menús configurados. Contacte con soporte."
@@ -268,13 +273,16 @@ class BotService {
* Mostrar menú específico * Mostrar menú específico
*/ */
private function showMenu($phoneNumber, $menuId) { private function showMenu($phoneNumber, $menuId) {
try { error_log("[BotService] showMenu - phone={$phoneNumber} menuId={$menuId} fetching menu"); } catch (Throwable $t) {}
// Obtener información del menú // Obtener información del menú
$menu = $this->db->fetch( $menu = $this->db->fetch(
"SELECT * FROM menus WHERE id = :id AND is_active = 1", "SELECT * FROM menus WHERE id = :id AND is_active = 1",
['id' => $menuId] ['id' => $menuId]
); );
try { error_log("[BotService] showMenu - fetched menu=" . json_encode($menu)); } catch (Throwable $t) {}
if (!$menu) { if (!$menu) {
try { error_log("[BotService] showMenu - menu not found id={$menuId} phone={$phoneNumber}"); } catch (Throwable $t) {}
$this->whatsappService->sendTextMessage( $this->whatsappService->sendTextMessage(
$phoneNumber, $phoneNumber,
"❌ Menú no encontrado." "❌ Menú no encontrado."
@@ -287,6 +295,7 @@ class BotService {
"SELECT * FROM menu_options WHERE menu_id = :menu_id AND is_active = 1 ORDER BY option_number", "SELECT * FROM menu_options WHERE menu_id = :menu_id AND is_active = 1 ORDER BY option_number",
['menu_id' => $menuId] ['menu_id' => $menuId]
); );
try { error_log("[BotService] showMenu - menuId={$menuId} options_count=" . count($options)); } catch (Throwable $t) {}
if (empty($options)) { if (empty($options)) {
$this->whatsappService->sendTextMessage( $this->whatsappService->sendTextMessage(