fix(upload): 2-step flow — rooms.media + chat.postMessage mit title_link

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.
This commit is contained in:
Hermes Agent
2026-05-31 00:17:37 +02:00
parent 923c76a6be
commit 369f617bdf
+24 -12
View File
@@ -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}")