fix(archivar): wire button_send_callback — Archivar now sends native RC buttons
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.
This commit is contained in:
+54
-1
@@ -441,7 +441,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
self._last_ddp_ping_ok = False
|
self._last_ddp_ping_ok = False
|
||||||
self._running = False
|
self._running = False
|
||||||
# Archivar: Embedding-basierte Nachrichten-Klassifikation
|
# 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
|
# User-Flow C: Move-Requests + Sticky Rooms
|
||||||
self._pending_move_requests: Dict[str, dict] = {}
|
self._pending_move_requests: Dict[str, dict] = {}
|
||||||
self._sticky_rooms: Dict[str, float] = {} # room_id → timestamp
|
self._sticky_rooms: Dict[str, float] = {} # room_id → timestamp
|
||||||
@@ -864,6 +867,56 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
return False
|
return False
|
||||||
return self.rest.post_message(room_id, text)
|
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:
|
async def _start_onboarding(self, missing_rooms: list) -> None:
|
||||||
"""Sendet EINE DM an den Operator mit der Liste fehlender Räume.
|
"""Sendet EINE DM an den Operator mit der Liste fehlender Räume.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user