204 lines
7.1 KiB
PHP
204 lines
7.1 KiB
PHP
<?php
|
|
/**
|
|
* Script de prueba del sistema WhatsApp Bot
|
|
* Fecha: 13 de noviembre de 2025
|
|
*/
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
echo "<h1>🤖 Test del Sistema WhatsApp Bot</h1>";
|
|
|
|
// Verificar archivos principales
|
|
$files = [
|
|
'config/config.php' => 'Configuración principal',
|
|
'classes/Database.php' => 'Clase Database',
|
|
'services/WhatsAppService.php' => 'Servicio WhatsApp',
|
|
'services/BotService.php' => 'Servicio Bot',
|
|
'api/webhook.php' => 'Webhook principal',
|
|
'database/schema.sql' => 'Esquema de BD',
|
|
'index.php' => 'Página principal'
|
|
];
|
|
|
|
echo "<h2>📂 Verificación de Archivos:</h2>";
|
|
echo "<ul>";
|
|
foreach ($files as $file => $description) {
|
|
$exists = file_exists($file);
|
|
$status = $exists ? "✅ Existe" : "❌ Faltante";
|
|
echo "<li><strong>{$description}</strong> ({$file}): {$status}</li>";
|
|
}
|
|
echo "</ul>";
|
|
|
|
// Probar configuración
|
|
echo "<h2>⚙️ Verificación de Configuración:</h2>";
|
|
try {
|
|
require_once 'config/config.php';
|
|
echo "<p>✅ Configuración cargada correctamente</p>";
|
|
echo "<ul>";
|
|
echo "<li>DB Host: " . DB_HOST . "</li>";
|
|
echo "<li>DB Name: " . DB_NAME . "</li>";
|
|
echo "<li>WhatsApp Phone ID: " . WHATSAPP_PHONE_NUMBER_ID . "</li>";
|
|
echo "<li>App URL: " . APP_URL . "</li>";
|
|
echo "</ul>";
|
|
} catch (Exception $e) {
|
|
echo "<p>❌ Error en configuración: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// Probar conexión a base de datos
|
|
echo "<h2>💾 Verificación de Base de Datos:</h2>";
|
|
try {
|
|
$db = Database::getInstance();
|
|
echo "<p>✅ Conexión a base de datos exitosa</p>";
|
|
|
|
// Verificar tablas principales
|
|
$tables = ['users', 'conversations', 'menus', 'menu_options', 'system_config'];
|
|
echo "<ul>";
|
|
foreach ($tables as $table) {
|
|
try {
|
|
$count = $db->fetch("SELECT COUNT(*) as count FROM {$table}")['count'];
|
|
echo "<li>Tabla <strong>{$table}</strong>: {$count} registros</li>";
|
|
} catch (Exception $e) {
|
|
echo "<li>Tabla <strong>{$table}</strong>: ❌ Error: " . $e->getMessage() . "</li>";
|
|
}
|
|
}
|
|
echo "</ul>";
|
|
|
|
} catch (Exception $e) {
|
|
echo "<p>❌ Error de conexión: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// Probar servicios
|
|
echo "<h2>🔧 Verificación de Servicios:</h2>";
|
|
try {
|
|
$whatsappService = new WhatsAppService();
|
|
echo "<p>✅ WhatsAppService inicializado</p>";
|
|
|
|
$botService = new BotService();
|
|
echo "<p>✅ BotService inicializado</p>";
|
|
|
|
} catch (Exception $e) {
|
|
echo "<p>❌ Error en servicios: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// Probar APIs
|
|
echo "<h2>🌐 Verificación de APIs:</h2>";
|
|
$apis = [
|
|
'api/get_stats.php',
|
|
'api/get_users.php',
|
|
'api/get_menus.php',
|
|
'api/get_conversations.php',
|
|
'api/webhook.php'
|
|
];
|
|
|
|
echo "<ul>";
|
|
foreach ($apis as $api) {
|
|
$exists = file_exists($api);
|
|
$readable = $exists ? is_readable($api) : false;
|
|
$status = $readable ? "✅ Disponible" : "❌ No disponible";
|
|
echo "<li><strong>{$api}</strong>: {$status}</li>";
|
|
}
|
|
echo "</ul>";
|
|
|
|
// Probar funcionalidad básica del bot
|
|
echo "<h2>🤖 Test Básico del Bot:</h2>";
|
|
try {
|
|
// Crear usuario de prueba
|
|
$testPhone = '573000000000';
|
|
|
|
// Verificar si el usuario existe
|
|
$existingUser = $db->fetch(
|
|
"SELECT * FROM users WHERE phone_number = :phone",
|
|
['phone' => $testPhone]
|
|
);
|
|
|
|
if (!$existingUser) {
|
|
$userId = $db->insert('users', [
|
|
'phone_number' => $testPhone,
|
|
'name' => 'Usuario de Prueba',
|
|
'status' => 'active',
|
|
'created_at' => date('Y-m-d H:i:s')
|
|
]);
|
|
echo "<p>✅ Usuario de prueba creado (ID: {$userId})</p>";
|
|
} else {
|
|
echo "<p>✅ Usuario de prueba ya existe</p>";
|
|
}
|
|
|
|
// Probar menú principal
|
|
$mainMenu = $db->fetch(
|
|
"SELECT * FROM menus WHERE is_root = 1 AND is_active = 1 LIMIT 1"
|
|
);
|
|
|
|
if ($mainMenu) {
|
|
echo "<p>✅ Menú principal configurado: " . $mainMenu['title'] . "</p>";
|
|
|
|
// Probar opciones del menú
|
|
$options = $db->fetchAll(
|
|
"SELECT * FROM menu_options WHERE menu_id = :id ORDER BY option_number",
|
|
['id' => $mainMenu['id']]
|
|
);
|
|
|
|
echo "<p>✅ Opciones del menú principal: " . count($options) . " opciones</p>";
|
|
|
|
} else {
|
|
echo "<p>❌ No hay menú principal configurado</p>";
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "<p>❌ Error en test del bot: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// URLs de prueba
|
|
echo "<h2>🔗 URLs del Sistema:</h2>";
|
|
echo "<ul>";
|
|
echo "<li><strong>Panel Principal:</strong> <a href='index.php'>index.php</a></li>";
|
|
echo "<li><strong>🧪 SUITE DE TESTS COMPLETA:</strong> <a href='run_tests.php' class='btn btn-primary btn-sm'>run_tests.php</a></li>";
|
|
echo "<li><strong>Webhook:</strong> <a href='api/webhook.php?hub_mode=subscribe&hub_verify_token=mi_token_secreto_123&hub_challenge=test'>webhook.php (test)</a></li>";
|
|
echo "<li><strong>API Stats:</strong> <a href='api/get_stats.php'>get_stats.php</a></li>";
|
|
echo "<li><strong>API Users:</strong> <a href='api/get_users.php'>get_users.php</a></li>";
|
|
echo "</ul>";
|
|
|
|
echo "<div class='alert alert-info mt-4'>";
|
|
echo "<h5><i class='fas fa-rocket'></i> Nueva Suite de Tests Implementada</h5>";
|
|
echo "<p>Se ha implementado una <strong>suite completa de tests</strong> que cubre:</p>";
|
|
echo "<ul>";
|
|
echo "<li>✅ <strong>50+ Tests</strong> exhaustivos</li>";
|
|
echo "<li>🔌 <strong>17 APIs</strong> validadas</li>";
|
|
echo "<li>🔒 <strong>Seguridad</strong> completa</li>";
|
|
echo "<li>📝 <strong>Sistema de plantillas</strong></li>";
|
|
echo "<li>🔗 <strong>Webhook y servicios</strong></li>";
|
|
echo "<li>💾 <strong>Base de datos</strong></li>";
|
|
echo "</ul>";
|
|
echo "<p class='mb-0'><a href='run_tests.php' class='btn btn-success'><i class='fas fa-play'></i> Ejecutar Tests Completos</a></p>";
|
|
echo "</div>";
|
|
|
|
echo "<h2>📋 Resumen:</h2>";
|
|
echo "<p><strong>El sistema WhatsApp Bot está:</strong></p>";
|
|
|
|
// Calcular estado general
|
|
$allGood = file_exists('config/config.php') &&
|
|
file_exists('classes/Database.php') &&
|
|
file_exists('api/webhook.php') &&
|
|
class_exists('Database');
|
|
|
|
if ($allGood) {
|
|
echo "<div style='background: #d4edda; color: #155724; padding: 15px; border-radius: 5px; border-left: 5px solid #28a745;'>";
|
|
echo "<h3>✅ SISTEMA FUNCIONANDO</h3>";
|
|
echo "<p>Todos los componentes principales están funcionando correctamente.</p>";
|
|
echo "<p><strong>Próximos pasos:</strong></p>";
|
|
echo "<ul>";
|
|
echo "<li>1. Configura el webhook en Facebook Developers</li>";
|
|
echo "<li>2. Ajusta la configuración en el panel</li>";
|
|
echo "<li>3. Personaliza los menús según tus necesidades</li>";
|
|
echo "<li>4. ¡Comienza a recibir mensajes!</li>";
|
|
echo "</ul>";
|
|
echo "</div>";
|
|
} else {
|
|
echo "<div style='background: #f8d7da; color: #721c24; padding: 15px; border-radius: 5px; border-left: 5px solid #dc3545;'>";
|
|
echo "<h3>❌ HAY PROBLEMAS</h3>";
|
|
echo "<p>Algunos componentes no están funcionando correctamente. Revisa los errores arriba.</p>";
|
|
echo "</div>";
|
|
}
|
|
|
|
echo "<hr>";
|
|
echo "<p><small>Test ejecutado el: " . date('Y-m-d H:i:s') . "</small></p>";
|
|
?>
|