up
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* API - Obtener conversaciones recientes
|
||||
* Fecha: 13 de noviembre de 2025
|
||||
* Fecha: 4 de enero de 2026
|
||||
*/
|
||||
|
||||
require_once '../config/config.php';
|
||||
@@ -14,28 +14,49 @@ header('Access-Control-Allow-Headers: Content-Type');
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Obtener conversaciones de la tabla conversations
|
||||
$conversations = $db->fetchAll(
|
||||
"SELECT
|
||||
c.id,
|
||||
c.user_id,
|
||||
c.content,
|
||||
COALESCE(c.content, '') as content,
|
||||
c.direction,
|
||||
c.message_type,
|
||||
c.status,
|
||||
c.created_at,
|
||||
u.phone_number,
|
||||
u.name
|
||||
COALESCE(u.name, u.phone_number) as name
|
||||
FROM conversations c
|
||||
JOIN users u ON c.user_id = u.id
|
||||
ORDER BY c.created_at DESC
|
||||
LIMIT 50"
|
||||
LIMIT 500"
|
||||
);
|
||||
|
||||
// Si no hay datos, retornar array vacío
|
||||
if (empty($conversations)) {
|
||||
$conversations = [];
|
||||
}
|
||||
|
||||
// Formatear datos para el frontend
|
||||
$conversations = array_map(function($conv) {
|
||||
return [
|
||||
'id' => intval($conv['id']),
|
||||
'user_id' => intval($conv['user_id']),
|
||||
'content' => $conv['content'] ?? '',
|
||||
'direction' => $conv['direction'] ?? 'incoming',
|
||||
'message_type' => $conv['message_type'] ?? 'text',
|
||||
'status' => $conv['status'] ?? 'sent',
|
||||
'created_at' => $conv['created_at'],
|
||||
'phone_number' => $conv['phone_number'],
|
||||
'name' => $conv['name'] ?? $conv['phone_number']
|
||||
];
|
||||
}, $conversations);
|
||||
|
||||
echo json_encode($conversations);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Error in get_conversations.php: " . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error interno del servidor']);
|
||||
echo json_encode(['error' => 'Error interno del servidor: ' . $e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user