Update BotService.php
This commit is contained in:
@@ -222,11 +222,13 @@ class BotService {
|
||||
*/
|
||||
private function processSpecialCommands($phoneNumber, $messageText) {
|
||||
$command = strtolower($messageText);
|
||||
try { error_log("[BotService] processSpecialCommands - command={$command} phone={$phoneNumber}"); } catch (Throwable $t) {}
|
||||
|
||||
switch ($command) {
|
||||
case 'menu':
|
||||
case 'menú':
|
||||
case 'inicio':
|
||||
try { error_log("[BotService] processSpecialCommands - detected MENU command, calling showMainMenu for phone={$phoneNumber}"); } catch (Throwable $t) {}
|
||||
$this->showMainMenu($phoneNumber);
|
||||
return true;
|
||||
|
||||
@@ -250,13 +252,16 @@ class BotService {
|
||||
* Mostrar menú principal
|
||||
*/
|
||||
private function showMainMenu($phoneNumber) {
|
||||
try { error_log("[BotService] showMainMenu - phone={$phoneNumber} fetching root menu"); } catch (Throwable $t) {}
|
||||
$mainMenu = $this->db->fetch(
|
||||
"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) {
|
||||
$this->showMenu($phoneNumber, $mainMenu['id']);
|
||||
} else {
|
||||
try { error_log("[BotService] showMainMenu - no root menu found for phone={$phoneNumber}"); } catch (Throwable $t) {}
|
||||
$this->whatsappService->sendTextMessage(
|
||||
$phoneNumber,
|
||||
"❌ No hay menús configurados. Contacte con soporte."
|
||||
@@ -268,13 +273,16 @@ class BotService {
|
||||
* Mostrar menú específico
|
||||
*/
|
||||
private function showMenu($phoneNumber, $menuId) {
|
||||
try { error_log("[BotService] showMenu - phone={$phoneNumber} menuId={$menuId} fetching menu"); } catch (Throwable $t) {}
|
||||
// Obtener información del menú
|
||||
$menu = $this->db->fetch(
|
||||
"SELECT * FROM menus WHERE id = :id AND is_active = 1",
|
||||
['id' => $menuId]
|
||||
);
|
||||
try { error_log("[BotService] showMenu - fetched menu=" . json_encode($menu)); } catch (Throwable $t) {}
|
||||
|
||||
if (!$menu) {
|
||||
try { error_log("[BotService] showMenu - menu not found id={$menuId} phone={$phoneNumber}"); } catch (Throwable $t) {}
|
||||
$this->whatsappService->sendTextMessage(
|
||||
$phoneNumber,
|
||||
"❌ 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",
|
||||
['menu_id' => $menuId]
|
||||
);
|
||||
try { error_log("[BotService] showMenu - menuId={$menuId} options_count=" . count($options)); } catch (Throwable $t) {}
|
||||
|
||||
if (empty($options)) {
|
||||
$this->whatsappService->sendTextMessage(
|
||||
|
||||
Reference in New Issue
Block a user