diff --git a/debug_scheduled_api.php b/debug_scheduled_api.php new file mode 100644 index 0000000..b92817d --- /dev/null +++ b/debug_scheduled_api.php @@ -0,0 +1,95 @@ +fetchAll( + "SELECT sm.*, + u.name as user_name, + u.phone_number, + mt.name as template_display_name, + mt.body_text as template_body + FROM scheduled_messages sm + LEFT JOIN users u ON sm.user_id = u.id + LEFT JOIN message_templates mt ON sm.template_id = mt.id + WHERE sm.status = 'sent' + ORDER BY sm.sent_at DESC + LIMIT 5" + ); + + if (empty($messages)) { + echo "❌ No hay mensajes enviados\n"; + exit; + } + + echo "Encontrados " . count($messages) . " mensajes enviados:\n\n"; + + foreach ($messages as $i => $msg) { + echo "========== MENSAJE #" . ($i + 1) . " (ID: {$msg['id']}) ==========\n"; + echo "Usuario: {$msg['user_name']} ({$msg['phone_number']})\n"; + echo "Plantilla: {$msg['template_name']}\n"; + echo "Estado: {$msg['status']}\n"; + echo "Enviado: {$msg['sent_at']}\n\n"; + + echo "📝 TEMPLATE BODY:\n"; + echo $msg['template_body'] . "\n\n"; + + echo "📊 TEMPLATE_PARAMETERS (raw string):\n"; + echo $msg['template_parameters'] . "\n\n"; + + echo "🔍 TEMPLATE_PARAMETERS (decodificado):\n"; + $params = json_decode($msg['template_parameters'], true); + + if (is_array($params)) { + echo "Tipo: array\n"; + echo "Cantidad: " . count($params) . "\n"; + + // Detectar si es asociativo + $isAssoc = false; + foreach ($params as $k => $v) { + if (!is_int($k)) { + $isAssoc = true; + break; + } + } + + echo "Formato: " . ($isAssoc ? "ASOCIATIVO" : "INDEXADO") . "\n\n"; + + echo "Valores:\n"; + foreach ($params as $k => $v) { + echo " [$k] => '$v'\n"; + } + } else { + echo "⚠️ No es un array válido\n"; + } + + echo "\n"; + } + + echo "\n\n=== SIMULACIÓN DE LO QUE VE EL FRONTEND ===\n\n"; + + // Simular lo que hace get_scheduled_messages.php + $firstMsg = $messages[0]; + + echo "JSON que recibe el frontend:\n"; + + $msgForFrontend = $firstMsg; + if ($msgForFrontend['template_parameters']) { + $msgForFrontend['template_parameters'] = json_decode($msgForFrontend['template_parameters'], true); + } + + echo json_encode($msgForFrontend, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); + +} catch (Exception $e) { + echo "❌ Error: " . $e->getMessage() . "\n"; +}