Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
49
telegram/api/messages/retry.php
Executable file
49
telegram/api/messages/retry.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* API - Reintentar Mensaje Telegram
|
||||
* Cambia el estado de un mensaje a 'pendiente'.
|
||||
*/
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
require_once __DIR__ . '/../../../shared/database/connection.php';
|
||||
|
||||
// Verificar autenticación
|
||||
$userData = JWTAuth::authenticate();
|
||||
if (!$userData) {
|
||||
jsonResponse(['success' => false, 'error' => 'No autenticado'], 401);
|
||||
}
|
||||
|
||||
// Verificar permiso (reutilizamos 'send_messages' ya que es una acción relacionada)
|
||||
if (!hasPermission('send_messages', 'telegram')) {
|
||||
jsonResponse(['success' => false, 'error' => 'No tienes permiso para gestionar mensajes de Telegram.'], 403);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
jsonResponse(['success' => false, 'error' => 'Método no permitido'], 405);
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$messageId = $input['id'] ?? null;
|
||||
|
||||
if (empty($messageId)) {
|
||||
jsonResponse(['success' => false, 'error' => 'Falta el ID del mensaje.'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$db = getDB();
|
||||
|
||||
// Cambiar el estado del mensaje a 'pendiente'
|
||||
$stmt = $db->prepare("UPDATE mensajes_telegram SET estado = 'pendiente' WHERE id = ?");
|
||||
$stmt->execute([$messageId]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonResponse(['success' => true, 'message' => 'Mensaje marcado como pendiente.']);
|
||||
} else {
|
||||
jsonResponse(['success' => false, 'error' => 'No se encontró el mensaje o no se pudo actualizar.']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
jsonResponse(['success' => false, 'error' => 'Error en la base de datos: ' . $e->getMessage()], 500);
|
||||
}
|
||||
Reference in New Issue
Block a user