private void replaceAttachments(JsonArray messages, Map<String, String> attachmentsMapping) {
        if (messages == null || messages.isEmpty()) {
            return;
        }

        for (int i = 0; i < messages.size(); i++) {
            JsonObject message = messages.getJsonObject(i);
            JsonObject customContent = message.getJsonObject("custom_content");
            if (customContent == null) {
                continue;
            }
            JsonArray attachments = customContent.getJsonArray("attachments");
            if (attachments == null || attachments.isEmpty()) {
                continue;
            }
            for (int j = 0; j < attachments.size(); j++) {
                JsonObject attachment = attachments.getJsonObject(j);
                String url = attachment.getString("url");
                if (url == null) {
                    continue;
                }
                boolean isMetadata = false;
                if (url.startsWith(ProxyUtil.METADATA_PREFIX)) {
                    isMetadata = true;
                    url = url.substring(ProxyUtil.METADATA_PREFIX.length());
                }
                String decodedUrl = UrlUtil.decodePath(url);
                String toReplace = attachmentsMapping.get(decodedUrl);
                if (toReplace != null) {
                    attachment.put("url", isMetadata ? ProxyUtil.METADATA_PREFIX + toReplace : toReplace);
                }
            }
        }
    }
Replaces conversation identity and attachment links after it has been copied from one location to another.
Replacing `id` and `folderId` - chat specific and may not be suitable for generic use-case.
Typical use-case: replace attachment links in conversation after publishing.

@param conversationBody   - source conversation body
@param targetResource     - target resource link
@param attachmentsMapping - attachments map (sourceUrl -> targetUrl) to replace
@return conversation body after replacement
server/src/main/java/com/epam/aidial/core/server/service/PublicationUtil.java