funcional
This commit is contained in:
@@ -31,9 +31,9 @@ try {
|
|||||||
// 1. Verificar configuración básica
|
// 1. Verificar configuración básica
|
||||||
$diagnostic['config_status'] = [
|
$diagnostic['config_status'] = [
|
||||||
'phone_number_id' => !empty($whatsappConfig['phone_number_id']),
|
'phone_number_id' => !empty($whatsappConfig['phone_number_id']),
|
||||||
'access_token' => !empty($whatsappConfig['access_token']),
|
|
||||||
'webhook_verify_token' => !empty($whatsappConfig['webhook_verify_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) {
|
$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)
|
// 3. Test básico de API (solo si hay configuración completa)
|
||||||
if ($diagnostic['config_status']['complete']) {
|
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 = [
|
$headers = [
|
||||||
'Authorization: Bearer ' . $whatsappConfig['access_token'],
|
'Authorization: Bearer ' . $whatsappConfig['whatsapp_token'],
|
||||||
'Content-Type: application/json'
|
'Content-Type: application/json'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -88,7 +88,9 @@ try {
|
|||||||
} else {
|
} else {
|
||||||
$diagnostic['api_status'] = [
|
$diagnostic['api_status'] = [
|
||||||
'reachable' => false,
|
'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 {
|
} else {
|
||||||
@@ -122,7 +124,7 @@ try {
|
|||||||
// Agregar compatibilidad con la estructura esperada en index.php
|
// Agregar compatibilidad con la estructura esperada en index.php
|
||||||
$configComplete = $diagnostic['config_status']['complete'];
|
$configComplete = $diagnostic['config_status']['complete'];
|
||||||
$completionPercentage = 0;
|
$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;
|
$completedFields = 0;
|
||||||
|
|
||||||
foreach ($configFields as $field) {
|
foreach ($configFields as $field) {
|
||||||
|
|||||||
@@ -489,9 +489,10 @@ class SimpleWhatsAppManager {
|
|||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
const fields = [
|
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: 'phone-number-id', value: data.phone_number_id },
|
||||||
{ id: 'webhook-token', value: data.webhook_verify_token },
|
{ id: 'webhook-token', value: data.webhook_verify_token },
|
||||||
|
{ id: 'api-url', value: data.api_url },
|
||||||
{ id: 'business-name', value: data.business_name },
|
{ id: 'business-name', value: data.business_name },
|
||||||
{ id: 'welcome-message', value: data.welcome_message }
|
{ id: 'welcome-message', value: data.welcome_message }
|
||||||
];
|
];
|
||||||
@@ -514,6 +515,7 @@ class SimpleWhatsAppManager {
|
|||||||
token: document.getElementById('whatsapp-token').value,
|
token: document.getElementById('whatsapp-token').value,
|
||||||
phone_number_id: document.getElementById('phone-number-id').value,
|
phone_number_id: document.getElementById('phone-number-id').value,
|
||||||
webhook_verify_token: document.getElementById('webhook-token').value,
|
webhook_verify_token: document.getElementById('webhook-token').value,
|
||||||
|
api_url: document.getElementById('api-url').value,
|
||||||
business_name: document.getElementById('business-name').value,
|
business_name: document.getElementById('business-name').value,
|
||||||
welcome_message: document.getElementById('welcome-message').value
|
welcome_message: document.getElementById('welcome-message').value
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -637,9 +637,9 @@ function saveWhatsAppConfigToDB($whatsappConfig) {
|
|||||||
*/
|
*/
|
||||||
function getWhatsAppConfigFromDB() {
|
function getWhatsAppConfigFromDB() {
|
||||||
return [
|
return [
|
||||||
'token' => getConfigFromDB('whatsapp_token', ''),
|
'whatsapp_token' => getConfigFromDB('whatsapp_token', ''),
|
||||||
'phone_number_id' => getConfigFromDB('whatsapp_phone_number_id', ''),
|
'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', ''),
|
'webhook_verify_token' => getConfigFromDB('webhook_verify_token', ''),
|
||||||
'business_name' => getConfigFromDB('business_name', ''),
|
'business_name' => getConfigFromDB('business_name', ''),
|
||||||
'welcome_message' => getConfigFromDB('welcome_message', ''),
|
'welcome_message' => getConfigFromDB('welcome_message', ''),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Página principal del sistema WhatsApp Bot
|
* Página principal del sistema WhatsApp Bot
|
||||||
* Fecha: 13 de noviembre de 2025
|
* Fecha: 13 de noviembre de 2025
|
||||||
@@ -29,6 +30,7 @@ try {
|
|||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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/styles.css" rel="stylesheet">
|
||||||
<link href="./assets/css/diagnostic.css" rel="stylesheet">
|
<link href="./assets/css/diagnostic.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- Sidebar -->
|
<!-- Sidebar -->
|
||||||
<nav class="sidebar">
|
<nav class="sidebar">
|
||||||
@@ -66,7 +69,7 @@ try {
|
|||||||
<div>
|
<div>
|
||||||
<h1><i class="fas fa-robot"></i> Sistema de Gestión WhatsApp Bot</h1>
|
<h1><i class="fas fa-robot"></i> Sistema de Gestión WhatsApp Bot</h1>
|
||||||
<small class="text-muted">
|
<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()) ?>
|
| <i class="fas fa-clock"></i> Sesión desde: <?= date('H:i:s', $_SESSION['login_time'] ?? time()) ?>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
@@ -101,7 +104,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
<div class="card card-stat bg-success text-white">
|
<div class="card card-stat bg-success text-white">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -117,7 +120,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
<div class="card card-stat bg-info text-white">
|
<div class="card card-stat bg-info text-white">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -133,7 +136,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-3 col-md-6 mb-4">
|
||||||
<div class="card card-stat bg-warning text-white">
|
<div class="card card-stat bg-warning text-white">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -470,8 +473,12 @@ try {
|
|||||||
<label class="form-label">Webhook Verify Token</label>
|
<label class="form-label">Webhook Verify Token</label>
|
||||||
<input type="text" class="form-control" id="webhook-token" placeholder="Token de verificación del webhook">
|
<input type="text" class="form-control" id="webhook-token" placeholder="Token de verificación del webhook">
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<h6 class="text-muted">Configuración General</h6>
|
<h6 class="text-muted">Configuración General</h6>
|
||||||
<div class="mb-3">
|
<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>
|
<textarea class="form-control" id="welcome-message" rows="3" placeholder="Mensaje que se envía a usuarios nuevos"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary">
|
||||||
<i class="fas fa-save"></i> Guardar Configuración
|
<i class="fas fa-save"></i> Guardar Configuración
|
||||||
</button>
|
</button>
|
||||||
@@ -514,7 +521,7 @@ try {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Información del Sistema -->
|
<!-- Información del Sistema -->
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
@@ -524,13 +531,13 @@ try {
|
|||||||
<dl class="row">
|
<dl class="row">
|
||||||
<dt class="col-sm-6">Versión:</dt>
|
<dt class="col-sm-6">Versión:</dt>
|
||||||
<dd class="col-sm-6">1.0.0</dd>
|
<dd class="col-sm-6">1.0.0</dd>
|
||||||
|
|
||||||
<dt class="col-sm-6">PHP:</dt>
|
<dt class="col-sm-6">PHP:</dt>
|
||||||
<dd class="col-sm-6"><?php echo PHP_VERSION; ?></dd>
|
<dd class="col-sm-6"><?php echo PHP_VERSION; ?></dd>
|
||||||
|
|
||||||
<dt class="col-sm-6">Base de Datos:</dt>
|
<dt class="col-sm-6">Base de Datos:</dt>
|
||||||
<dd class="col-sm-6"><?php echo $dbStatus; ?></dd>
|
<dd class="col-sm-6"><?php echo $dbStatus; ?></dd>
|
||||||
|
|
||||||
<dt class="col-sm-6">Webhook URL:</dt>
|
<dt class="col-sm-6">Webhook URL:</dt>
|
||||||
<dd class="col-sm-6">
|
<dd class="col-sm-6">
|
||||||
<code><?php echo APP_URL; ?>/api/webhook.php</code>
|
<code><?php echo APP_URL; ?>/api/webhook.php</code>
|
||||||
@@ -615,7 +622,7 @@ try {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-info">
|
<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.
|
Este formulario solo registra plantillas ya existentes en WhatsApp.
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -669,13 +676,13 @@ try {
|
|||||||
const resultsDiv = document.getElementById('diagnostic-results');
|
const resultsDiv = document.getElementById('diagnostic-results');
|
||||||
const actionsDiv = document.getElementById('diagnostic-actions');
|
const actionsDiv = document.getElementById('diagnostic-actions');
|
||||||
resultsDiv.innerHTML = '<p class="text-muted"><i class="fas fa-spinner fa-spin"></i> Ejecutando diagnóstico...</p>';
|
resultsDiv.innerHTML = '<p class="text-muted"><i class="fas fa-spinner fa-spin"></i> Ejecutando diagnóstico...</p>';
|
||||||
|
|
||||||
fetch('/api/diagnose_whatsapp.php')
|
fetch('/api/diagnose_whatsapp.php')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
let html = '<div class="diagnostic-report">';
|
let html = '<div class="diagnostic-report">';
|
||||||
|
|
||||||
// Configuración
|
// Configuración
|
||||||
html += `<div class="mb-3">
|
html += `<div class="mb-3">
|
||||||
<h6><i class="fas fa-cog"></i> Configuración WhatsApp</h6>
|
<h6><i class="fas fa-cog"></i> Configuración WhatsApp</h6>
|
||||||
@@ -683,7 +690,7 @@ try {
|
|||||||
${data.config.message} (${data.config.completion}% completa)
|
${data.config.message} (${data.config.completion}% completa)
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
// Plantillas
|
// Plantillas
|
||||||
const templateIssues = data.templates.approved === 0 && data.templates.pending > 0;
|
const templateIssues = data.templates.approved === 0 && data.templates.pending > 0;
|
||||||
html += `<div class="mb-3">
|
html += `<div class="mb-3">
|
||||||
@@ -693,7 +700,7 @@ try {
|
|||||||
<br><small>Aprobadas: ${data.templates.approved} | Pendientes: ${data.templates.pending}</small>
|
<br><small>Aprobadas: ${data.templates.approved} | Pendientes: ${data.templates.pending}</small>
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
// API
|
// API
|
||||||
html += `<div class="mb-3">
|
html += `<div class="mb-3">
|
||||||
<h6><i class="fas fa-plug"></i> Conectividad API</h6>
|
<h6><i class="fas fa-plug"></i> Conectividad API</h6>
|
||||||
@@ -701,30 +708,30 @@ try {
|
|||||||
${data.api.message}
|
${data.api.message}
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
// Recomendaciones
|
// Recomendaciones
|
||||||
if (data.recommendations && data.recommendations.length > 0) {
|
if (data.recommendations && data.recommendations.length > 0) {
|
||||||
html += `<div class="mb-3">
|
html += `<div class="mb-3">
|
||||||
<h6><i class="fas fa-lightbulb"></i> Recomendaciones</h6>
|
<h6><i class="fas fa-lightbulb"></i> Recomendaciones</h6>
|
||||||
<ul class="list-unstyled">`;
|
<ul class="list-unstyled">`;
|
||||||
|
|
||||||
data.recommendations.forEach(rec => {
|
data.recommendations.forEach(rec => {
|
||||||
html += `<li class="mb-1"><i class="fas fa-arrow-right text-primary"></i> ${rec}</li>`;
|
html += `<li class="mb-1"><i class="fas fa-arrow-right text-primary"></i> ${rec}</li>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
html += `</ul></div>`;
|
html += `</ul></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
resultsDiv.innerHTML = html;
|
resultsDiv.innerHTML = html;
|
||||||
|
|
||||||
// Mostrar botones de acción si hay problemas con plantillas
|
// Mostrar botones de acción si hay problemas con plantillas
|
||||||
if (templateIssues) {
|
if (templateIssues) {
|
||||||
actionsDiv.style.display = 'block';
|
actionsDiv.style.display = 'block';
|
||||||
} else {
|
} else {
|
||||||
actionsDiv.style.display = 'none';
|
actionsDiv.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resultsDiv.innerHTML = `<div class="alert alert-danger">Error: ${data.message}</div>`;
|
resultsDiv.innerHTML = `<div class="alert alert-danger">Error: ${data.message}</div>`;
|
||||||
actionsDiv.style.display = 'none';
|
actionsDiv.style.display = 'none';
|
||||||
@@ -738,4 +745,5 @@ try {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</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