From a261c771fc9d6a730dcbb92d5c19c74875a3b777 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 12 Jun 2026 07:24:57 +0200 Subject: [PATCH] =?UTF-8?q?fix(archivar):=20wire=20button=5Fsend=5Fcallbac?= =?UTF-8?q?k=20=E2=80=94=20Archivar=20now=20sends=20native=20RC=20buttons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ArchivarMessageHandler was initialized without button_send_callback, so every clarification request fell back to text-only ('Antworte mit einer Zahl: 1 = Ja...'). Added _send_archivar_buttons() method that translates Archivar button format into native Rocket.Chat Action-Buttons with msg_in_chat_window=True. Also marks room in _rooms_with_pending_questions so the response stays in the same room. --- plugin/adapter.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/plugin/adapter.py b/plugin/adapter.py index 7b39e55..b622bbe 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -441,7 +441,10 @@ class RocketChatAdapter(BasePlatformAdapter): self._last_ddp_ping_ok = False self._running = False # Archivar: Embedding-basierte Nachrichten-Klassifikation - self.archivar = ArchivarMessageHandler(send_callback=self._send_via_archivar) + self.archivar = ArchivarMessageHandler( + send_callback=self._send_via_archivar, + button_send_callback=self._send_archivar_buttons, + ) # User-Flow C: Move-Requests + Sticky Rooms self._pending_move_requests: Dict[str, dict] = {} self._sticky_rooms: Dict[str, float] = {} # room_id → timestamp @@ -864,6 +867,56 @@ class RocketChatAdapter(BasePlatformAdapter): return False return self.rest.post_message(room_id, text) + async def _send_archivar_buttons(self, room_id: str, text: str, payload: dict) -> bool: + """Callback for Archivar clarification — sends native Rocket.Chat Action-Buttons. + + Translates Archivar button format into native RC buttons with + msg_in_chat_window=True so the Gateway can identify the response. + + Args: + room_id: Target room ID + text: Message text + payload: {"actions": [{"text": "...", "type": "..."}, ...]} + + Returns: + True if sent successfully, False on error + """ + if not self.rest.auth_token: + return False + + from . import _build_custom_buttons + + actions = payload.get("actions", []) + if not actions: + return self.rest.post_message(room_id, text) + + # Build native RC buttons from Archivar actions + buttons = [] + for i, action in enumerate(actions): + action_type = action.get("type", f"action_{i}") + action_text = action.get("text", f"Option {i+1}") + buttons.append({ + "type": "button", + "text": action_text, + "msg": f"ARCHIVAR_CLARIFY:{action_type}", + "msg_in_chat_window": True, + "style": "default", + }) + + attachments = [{ + "color": "#1d74f5", + "title": text, + "actions": buttons, + }] + + success = self.rest.post_message(room_id, text, attachments=attachments) + if success: + # Mark room so the response stays here (no Archivar routing) + self._rooms_with_pending_questions.add(room_id) + logger.info("[rocketchat] Sent Archivar clarification with %d buttons to %s", + len(buttons), room_id[:8]) + return success + async def _start_onboarding(self, missing_rooms: list) -> None: """Sendet EINE DM an den Operator mit der Liste fehlender Räume.