Files
whatsapp/api/get_conversations.php
T
2025-11-18 20:26:36 -05:00

41 lines
1014 B
PHP

<?php
/**
* API - Obtener conversaciones recientes
* Fecha: 13 de noviembre de 2025
*/
require_once '../config/config.php';
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Headers: Content-Type');
try {
$db = Database::getInstance();
$conversations = $db->fetchAll(
"SELECT
c.id,
c.user_id,
c.content,
c.direction,
c.message_type,
c.status,
c.created_at,
u.phone_number,
u.name
FROM conversations c
JOIN users u ON c.user_id = u.id
ORDER BY c.created_at DESC
LIMIT 50"
);
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']);
}
?>