feat(plugin): attachment support — upload, download, files + adapter detection

- tools.py: rocket_upload (rooms.media for RC 8.4+), download, files
- adapter.py: _process_incoming() detects file/attachments → [FILE] enrichment
This commit is contained in:
Hermes Agent
2026-05-29 23:18:39 +02:00
parent 7872d4a47f
commit 923c76a6be
2 changed files with 279 additions and 0 deletions
+35
View File
@@ -478,6 +478,41 @@ class RocketChatAdapter(BasePlatformAdapter):
user_info = msg_obj.get("u", {})
username = (user_info.get("username", "") or "").lower() # normalize case
# NEW: Check for file attachments in the message and enrich the text
file_info = msg_obj.get("file")
attachments = msg_obj.get("attachments", [])
if file_info or attachments:
file_details = []
base_url = self.base_url.rstrip("/")
# Process file object if present
if file_info and isinstance(file_info, dict):
filename = file_info.get("name", "unknown")
filetype = file_info.get("type", "unknown")
file_id = file_info.get("_id")
if file_id and filename:
download_url = f"{base_url}/file-upload/{file_id}/{filename}"
file_details.append(f"[FILE] {filename} ({filetype})\nDownload: {download_url}")
# Process attachments if present
if attachments and isinstance(attachments, list):
for attachment in attachments:
if isinstance(attachment, dict) and attachment.get("type") == "file":
title = attachment.get("title", "unknown")
title_link = attachment.get("title_link", "")
if title_link:
if title_link.startswith("/"):
download_url = f"{base_url}{title_link}"
else:
download_url = f"{base_url}/{title_link}"
file_details.append(f"[FILE] {title} (file)\nDownload: {download_url}")
# Add file information to message text
if file_details:
file_info_text = "\n".join(file_details)
if text:
text = f"{text}\n\n{file_info_text}"
else:
text = file_info_text
msg_obj["msg"] = text
# Skip own messages (case-insensitive comparison)
if username == (self.user or "").lower() or not text or not room_id:
return