From 369f617bdfd3f45e35f373701d7b085302475f1d Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sun, 31 May 2026 00:17:37 +0200 Subject: [PATCH] =?UTF-8?q?fix(upload):=202-step=20flow=20=E2=80=94=20room?= =?UTF-8?q?s.media=20+=20chat.postMessage=20mit=20title=5Flink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RC 8.4.1: rooms.media lädt Datei nur hoch, postet sie nicht als Chat-Nachricht. upload_file() ergänzt automatisches chat.postMessage mit: - title_link (statt image_url) - title_link_download: true - type: file Handler _handle_rocketchat_upload vereinfacht auf Durchreichen. Rainer-Review: F1-F6 geprüft. Externer Usertest bestanden. --- plugin/tools.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/plugin/tools.py b/plugin/tools.py index 465bd0b..392edb0 100644 --- a/plugin/tools.py +++ b/plugin/tools.py @@ -224,7 +224,28 @@ class RocketChatAPI: req = urllib.request.Request(url, data=body, headers=headers, method="POST") try: with urllib.request.urlopen(req, timeout=60) as resp: - return json.loads(resp.read().decode("utf-8")) + upload_result = json.loads(resp.read().decode("utf-8")) + if not upload_result.get("success"): + return upload_result + # Step 2: Post message with the uploaded file as attachment + file_info = upload_result.get("file") or {} + file_id = file_info.get("_id") + if file_id: + attachment: dict = { + "title": filename, + "title_link": f"/file-upload/{file_id}/{filename}", + "title_link_download": True, + "type": "file", + } + if description: + attachment["description"] = description + post_result = self.send_message( + room_id=room_id, + text=message or "", + attachments=[attachment], + ) + return {"success": True, "upload": upload_result, "post_message": post_result} + return upload_result except urllib.error.HTTPError as exc: msg = f"Upload HTTP {exc.code}" try: @@ -674,19 +695,10 @@ def _handle_rocketchat_upload(args: dict, **kw) -> str: if not room_id or not file_path: return tool_error("room_id and file_path are required for rocketchat_upload") + # RocketChatAPI.upload_file() already handles rooms.media + chat.postMessage try: result = client.upload_file(room_id, file_path, message, description) - if result.get("success"): - return tool_result({ - "success": True, - "file_id": result.get("file_id"), - "filename": result.get("filename"), - "file_type": result.get("file_type"), - "message": result.get("message"), - "result": result, - }) - else: - return tool_result({"success": False, "error": result.get("error", "Upload failed")}) + return tool_result(result) except Exception as exc: return tool_error(f"rocketchat_upload failed: {type(exc).__name__}: {exc}")