From 4b7bcb6924fe1193995f312f7553c65ac5a1b426 Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 12 Jan 2026 14:08:21 -0500 Subject: [PATCH] funcional --- api/diagnose_whatsapp.php | 14 ++++++----- assets/js/app_simple.js | 4 ++- config/config.php | 4 +-- index.php | 52 ++++++++++++++++++++++----------------- logs/system.log | 4 +++ 5 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 logs/system.log diff --git a/api/diagnose_whatsapp.php b/api/diagnose_whatsapp.php index 56ca198..975870e 100644 --- a/api/diagnose_whatsapp.php +++ b/api/diagnose_whatsapp.php @@ -31,9 +31,9 @@ try { // 1. Verificar configuración básica $diagnostic['config_status'] = [ 'phone_number_id' => !empty($whatsappConfig['phone_number_id']), - 'access_token' => !empty($whatsappConfig['access_token']), 'webhook_verify_token' => !empty($whatsappConfig['webhook_verify_token']), - 'business_account_id' => !empty($whatsappConfig['business_account_id']) + 'whatsapp_api_url' => !empty($whatsappConfig['whatsapp_api_url']), + 'whatsapp_token' => !empty($whatsappConfig['whatsapp_token']) ]; $diagnostic['config_status']['complete'] = array_reduce($diagnostic['config_status'], function($carry, $item) { @@ -60,9 +60,9 @@ try { // 3. Test básico de API (solo si hay configuración completa) if ($diagnostic['config_status']['complete']) { - $apiUrl = "https://graph.facebook.com/v18.0/{$whatsappConfig['phone_number_id']}"; + $apiUrl = "https://graph.facebook.com/v22.0/{$whatsappConfig['phone_number_id']}"; $headers = [ - 'Authorization: Bearer ' . $whatsappConfig['access_token'], + 'Authorization: Bearer ' . $whatsappConfig['whatsapp_token'], 'Content-Type: application/json' ]; @@ -88,7 +88,9 @@ try { } else { $diagnostic['api_status'] = [ 'reachable' => false, - 'error' => 'No se pudo conectar con la API de WhatsApp' + #'error' => 'No se pudo conectar con la API de WhatsApp', + 'error' => error_get_last() + ]; } } else { @@ -122,7 +124,7 @@ try { // Agregar compatibilidad con la estructura esperada en index.php $configComplete = $diagnostic['config_status']['complete']; $completionPercentage = 0; - $configFields = ['phone_number_id', 'access_token', 'webhook_verify_token', 'business_account_id']; + $configFields = ['phone_number_id', 'whatsapp_token', 'webhook_verify_token', 'whatsapp_api_url']; $completedFields = 0; foreach ($configFields as $field) { diff --git a/assets/js/app_simple.js b/assets/js/app_simple.js index 1092c8b..07a073c 100644 --- a/assets/js/app_simple.js +++ b/assets/js/app_simple.js @@ -489,9 +489,10 @@ class SimpleWhatsAppManager { if (!data) return; const fields = [ - { id: 'whatsapp-token', value: data.token }, + { id: 'whatsapp-token', value: data.whatsapp_token }, { id: 'phone-number-id', value: data.phone_number_id }, { id: 'webhook-token', value: data.webhook_verify_token }, + { id: 'api-url', value: data.api_url }, { id: 'business-name', value: data.business_name }, { id: 'welcome-message', value: data.welcome_message } ]; @@ -514,6 +515,7 @@ class SimpleWhatsAppManager { token: document.getElementById('whatsapp-token').value, phone_number_id: document.getElementById('phone-number-id').value, webhook_verify_token: document.getElementById('webhook-token').value, + api_url: document.getElementById('api-url').value, business_name: document.getElementById('business-name').value, welcome_message: document.getElementById('welcome-message').value }; diff --git a/config/config.php b/config/config.php index 9e24ba0..bc23e7d 100644 --- a/config/config.php +++ b/config/config.php @@ -637,9 +637,9 @@ function saveWhatsAppConfigToDB($whatsappConfig) { */ function getWhatsAppConfigFromDB() { return [ - 'token' => getConfigFromDB('whatsapp_token', ''), + 'whatsapp_token' => getConfigFromDB('whatsapp_token', ''), 'phone_number_id' => getConfigFromDB('whatsapp_phone_number_id', ''), - 'api_url' => getConfigFromDB('whatsapp_api_url', 'https://graph.facebook.com/v22.0/'), + 'whatsapp_api_url' => getConfigFromDB('whatsapp_api_url', 'https://graph.facebook.com/v22.0/'), 'webhook_verify_token' => getConfigFromDB('webhook_verify_token', ''), 'business_name' => getConfigFromDB('business_name', ''), 'welcome_message' => getConfigFromDB('welcome_message', ''), diff --git a/index.php b/index.php index 4739325..3675763 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ +
@@ -38,6 +40,7 @@ try { +