version estable
This commit is contained in:
+47
-11
@@ -6,19 +6,15 @@ header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
|
||||
// Suprimir errores para obtener JSON limpio
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
|
||||
try {
|
||||
// Verificar autenticación si no estás en modo debug
|
||||
$debugMode = isset($_GET['debug']);
|
||||
// Modo debug: desactivar autenticación si existe el parámetro debug
|
||||
$debugMode = isset($_GET['debug']) && $_GET['debug'] === 'true';
|
||||
|
||||
if (!$debugMode) {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
requireAuthentication();
|
||||
}
|
||||
|
||||
// Obtener configuración de WhatsApp
|
||||
@@ -123,6 +119,46 @@ try {
|
||||
$diagnostic['recommendations'][] = 'Todo parece estar configurado correctamente';
|
||||
}
|
||||
|
||||
// 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'];
|
||||
$completedFields = 0;
|
||||
|
||||
foreach ($configFields as $field) {
|
||||
if (isset($diagnostic['config_status'][$field]) && $diagnostic['config_status'][$field]) {
|
||||
$completedFields++;
|
||||
}
|
||||
}
|
||||
$completionPercentage = round(($completedFields / count($configFields)) * 100);
|
||||
|
||||
// Estructura adicional para compatibilidad
|
||||
$diagnostic['config'] = [
|
||||
'status' => $configComplete ? 'complete' : 'incomplete',
|
||||
'message' => $configComplete ? 'Configuración completa' : 'Configuración incompleta',
|
||||
'completion' => $completionPercentage
|
||||
];
|
||||
|
||||
$diagnostic['templates'] = [
|
||||
'approved' => $diagnostic['template_status']['approved'],
|
||||
'pending' => $diagnostic['template_status']['pending'],
|
||||
'rejected' => $diagnostic['template_status']['rejected'],
|
||||
'total' => $diagnostic['template_status']['total'],
|
||||
'message' => $diagnostic['template_status']['approved'] > 0
|
||||
? 'Plantillas configuradas correctamente'
|
||||
: ($diagnostic['template_status']['total'] > 0
|
||||
? 'Tienes plantillas pendientes de aprobación'
|
||||
: 'No hay plantillas configuradas')
|
||||
];
|
||||
|
||||
// Estructura API para compatibilidad
|
||||
$diagnostic['api'] = [
|
||||
'status' => $diagnostic['api_status']['reachable'] ? 'ready' : 'error',
|
||||
'message' => $diagnostic['api_status']['reachable']
|
||||
? 'Conexión API establecida correctamente'
|
||||
: ($diagnostic['api_status']['error'] ?? 'No conectado')
|
||||
];
|
||||
|
||||
echo json_encode($diagnostic, JSON_PRETTY_PRINT);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user