getMessage()); return false; } } else { error_log("ADVERTENCIA: La extensión 'sodium' de PHP no está instalada. La verificación de firma de Discord es INSEGURA."); return false; } } // Obtener headers y body $headers = array_change_key_case(getallheaders(), CASE_LOWER); $body = file_get_contents('php://input'); // Registrar la solicitud para depuración error_log("Solicitud recibida: " . json_encode([ 'headers' => array_intersect_key($headers, ['x-signature-ed25519' => true, 'x-signature-timestamp' => true]), 'body' => $body ])); // Verificar firma if (\!verifySignature($body, $headers)) { http_response_code(401); error_log("Firma no válida"); echo 'Invalid Signature'; exit; } // Decodificar JSON para verificar si es un PING $data = json_decode($body, true); $type = $data['type'] ?? 0; // Manejar PING (requerido por Discord para validar la URL del webhook) if ($type === 1) { header('Content-Type: application/json'); echo json_encode(['type' => 1]); exit; } // Para otras interacciones, redirigir al daemon $interactionId = $data['id'] ?? 'unknown'; error_log("Interacción recibida (ID: $interactionId). El daemon debería manejar esto."); // NO responder aquí. El daemon se encargará de la respuesta completa. // Simplemente terminamos el script del webhook con un 200 OK. http_response_code(200); exit;