funcional
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
+2
-2
@@ -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', ''),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Página principal del sistema WhatsApp Bot
|
||||
* Fecha: 13 de noviembre de 2025
|
||||
@@ -29,6 +30,7 @@ try {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@@ -38,6 +40,7 @@ try {
|
||||
<link href="./assets/css/styles.css" rel="stylesheet">
|
||||
<link href="./assets/css/diagnostic.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Sidebar -->
|
||||
<nav class="sidebar">
|
||||
@@ -66,7 +69,7 @@ try {
|
||||
<div>
|
||||
<h1><i class="fas fa-robot"></i> Sistema de Gestión WhatsApp Bot</h1>
|
||||
<small class="text-muted">
|
||||
<i class="fas fa-user"></i> Conectado como <strong><?= htmlspecialchars(ADMIN_USERNAME) ?></strong>
|
||||
<i class="fas fa-user"></i> Conectado como <strong><?= htmlspecialchars(ADMIN_USERNAME) ?></strong>
|
||||
| <i class="fas fa-clock"></i> Sesión desde: <?= date('H:i:s', $_SESSION['login_time'] ?? time()) ?>
|
||||
</small>
|
||||
</div>
|
||||
@@ -101,7 +104,7 @@ try {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card card-stat bg-success text-white">
|
||||
<div class="card-body">
|
||||
@@ -117,7 +120,7 @@ try {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card card-stat bg-info text-white">
|
||||
<div class="card-body">
|
||||
@@ -133,7 +136,7 @@ try {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-xl-3 col-md-6 mb-4">
|
||||
<div class="card card-stat bg-warning text-white">
|
||||
<div class="card-body">
|
||||
@@ -470,8 +473,12 @@ try {
|
||||
<label class="form-label">Webhook Verify Token</label>
|
||||
<input type="text" class="form-control" id="webhook-token" placeholder="Token de verificación del webhook">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">API URL</label>
|
||||
<input type="text" class="form-control" id="api-url" placeholder="URL de la API" value="https://graph.facebook.com/v22.0/">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="mb-4">
|
||||
<h6 class="text-muted">Configuración General</h6>
|
||||
<div class="mb-3">
|
||||
@@ -483,7 +490,7 @@ try {
|
||||
<textarea class="form-control" id="welcome-message" rows="3" placeholder="Mensaje que se envía a usuarios nuevos"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save"></i> Guardar Configuración
|
||||
</button>
|
||||
@@ -514,7 +521,7 @@ try {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Información del Sistema -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@@ -524,13 +531,13 @@ try {
|
||||
<dl class="row">
|
||||
<dt class="col-sm-6">Versión:</dt>
|
||||
<dd class="col-sm-6">1.0.0</dd>
|
||||
|
||||
|
||||
<dt class="col-sm-6">PHP:</dt>
|
||||
<dd class="col-sm-6"><?php echo PHP_VERSION; ?></dd>
|
||||
|
||||
|
||||
<dt class="col-sm-6">Base de Datos:</dt>
|
||||
<dd class="col-sm-6"><?php echo $dbStatus; ?></dd>
|
||||
|
||||
|
||||
<dt class="col-sm-6">Webhook URL:</dt>
|
||||
<dd class="col-sm-6">
|
||||
<code><?php echo APP_URL; ?>/api/webhook.php</code>
|
||||
@@ -615,7 +622,7 @@ try {
|
||||
</select>
|
||||
</div>
|
||||
<div class="alert alert-info">
|
||||
<strong>⚠️ Importante:</strong> La plantilla debe ser creada y aprobada primero en WhatsApp Business Manager.
|
||||
<strong>⚠️ Importante:</strong> La plantilla debe ser creada y aprobada primero en WhatsApp Business Manager.
|
||||
Este formulario solo registra plantillas ya existentes en WhatsApp.
|
||||
</div>
|
||||
</form>
|
||||
@@ -669,13 +676,13 @@ try {
|
||||
const resultsDiv = document.getElementById('diagnostic-results');
|
||||
const actionsDiv = document.getElementById('diagnostic-actions');
|
||||
resultsDiv.innerHTML = '<p class="text-muted"><i class="fas fa-spinner fa-spin"></i> Ejecutando diagnóstico...</p>';
|
||||
|
||||
|
||||
fetch('/api/diagnose_whatsapp.php')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
let html = '<div class="diagnostic-report">';
|
||||
|
||||
|
||||
// Configuración
|
||||
html += `<div class="mb-3">
|
||||
<h6><i class="fas fa-cog"></i> Configuración WhatsApp</h6>
|
||||
@@ -683,7 +690,7 @@ try {
|
||||
${data.config.message} (${data.config.completion}% completa)
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
|
||||
// Plantillas
|
||||
const templateIssues = data.templates.approved === 0 && data.templates.pending > 0;
|
||||
html += `<div class="mb-3">
|
||||
@@ -693,7 +700,7 @@ try {
|
||||
<br><small>Aprobadas: ${data.templates.approved} | Pendientes: ${data.templates.pending}</small>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
|
||||
// API
|
||||
html += `<div class="mb-3">
|
||||
<h6><i class="fas fa-plug"></i> Conectividad API</h6>
|
||||
@@ -701,30 +708,30 @@ try {
|
||||
${data.api.message}
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
|
||||
// Recomendaciones
|
||||
if (data.recommendations && data.recommendations.length > 0) {
|
||||
html += `<div class="mb-3">
|
||||
<h6><i class="fas fa-lightbulb"></i> Recomendaciones</h6>
|
||||
<ul class="list-unstyled">`;
|
||||
|
||||
|
||||
data.recommendations.forEach(rec => {
|
||||
html += `<li class="mb-1"><i class="fas fa-arrow-right text-primary"></i> ${rec}</li>`;
|
||||
});
|
||||
|
||||
|
||||
html += `</ul></div>`;
|
||||
}
|
||||
|
||||
|
||||
html += '</div>';
|
||||
resultsDiv.innerHTML = html;
|
||||
|
||||
|
||||
// Mostrar botones de acción si hay problemas con plantillas
|
||||
if (templateIssues) {
|
||||
actionsDiv.style.display = 'block';
|
||||
} else {
|
||||
actionsDiv.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
resultsDiv.innerHTML = `<div class="alert alert-danger">Error: ${data.message}</div>`;
|
||||
actionsDiv.style.display = 'none';
|
||||
@@ -738,4 +745,5 @@ try {
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,4 @@
|
||||
[2026-01-12 13:25:44] [INFO] Configuración de WhatsApp actualizada {"configured_fields":{"token":true,"phone_id":true,"webhook_token":true},"user":"debug_user"}
|
||||
[2026-01-12 13:26:51] [INFO] Configuración de WhatsApp actualizada {"configured_fields":{"token":true,"phone_id":true,"webhook_token":true},"user":"debug_user"}
|
||||
[2026-01-12 13:28:56] [INFO] Configuración de WhatsApp actualizada {"configured_fields":{"token":true,"phone_id":true,"webhook_token":true},"user":"debug_user"}
|
||||
[2026-01-12 14:07:16] [INFO] Configuración de WhatsApp actualizada {"configured_fields":{"token":true,"phone_id":true,"webhook_token":true},"user":"debug_user"}
|
||||
Reference in New Issue
Block a user