fix(archivar): Move-Request-Zielraum an _CURRENT_ORIGIN_ROOM übergeben
ZWEI-PUNKT-FIX (Miguel): 1. adapter_integration.py (Zeile 458-466): _send_move_request() übergibt jetzt _move_request-Payload an den Button-Send-Callback — mit target_room, target_name, text. 2. adapter.py _send_archivar_buttons (Zeile 978-1004): Erkennt den _move_request-Payload, befüllt _pending_move_requests, verwendet MOVE_REQ:: Separator für korrektes Button-Parsing. 3. adapter.py Move-Request-Handler (Zeile 739): Akzeptiert 'confirm_move' und '✅ja' als Routing-Trigger. Flow: Archivar v4 → _send_move_request → _send_archivar_buttons → _pending_move_requests gesetzt → ✅Ja-Button → Response-Handler findet pending request → _CURRENT_ORIGIN_ROOM auf Zielraum gesetzt ✓
This commit is contained in:
+58
-11
@@ -736,10 +736,11 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
|
||||
# Neue Mapping-Logik für verbesserte Button-UX
|
||||
feedback_type = "stay" # Default
|
||||
if choice in ("1", "1️⃣", "Rüber", "rüber", "rüberkopieren", "kopieren"):
|
||||
if choice in ("1", "1️⃣", "Rüber", "rüber", "rüberkopieren", "kopieren", "confirm_move", "✅ja"):
|
||||
# Rüberkopieren
|
||||
self.rest.post_message(move_req["target_room"],
|
||||
f"*(Auftrag von @{move_req['username']}, hierher kopiert)*\n{move_req['text']}")
|
||||
target_txt = f"*(Auftrag von @{move_req['username']}, hierher kopiert)*\n{move_req['text']}"
|
||||
if move_req.get("username"):
|
||||
self.rest.post_message(move_req["target_room"], target_txt)
|
||||
_CURRENT_ORIGIN_ROOM.set(move_req["target_room"])
|
||||
forwarded = True
|
||||
feedback_type = "confirm"
|
||||
@@ -786,6 +787,21 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
decision = await self.archivar.classify_and_route(text, origin_room_id=room_id)
|
||||
if decision and decision.category:
|
||||
category = decision.category
|
||||
# Archivar v4 Move-Request: _pending_move_requests befüllen, damit
|
||||
# der Button-Response-Handler (lines 717-764) die Antwort korrekt
|
||||
# verarbeiten und _CURRENT_ORIGIN_ROOM auf den Zielraum setzen kann.
|
||||
if (getattr(decision, 'move_request_sent', False)
|
||||
and hasattr(decision, 'target_room')
|
||||
and decision.target_room):
|
||||
self._pending_move_requests[room_id] = {
|
||||
'text': text,
|
||||
'origin_room': room_id,
|
||||
'target_room': decision.target_room,
|
||||
'target_name': getattr(
|
||||
decision, 'move_request_target_name', 'Zielraum'),
|
||||
'username': username,
|
||||
'message_id': msg_id,
|
||||
}
|
||||
# Lernsystem: Keywords für Feedback-Loop speichern
|
||||
if hasattr(decision, 'matched_keywords') and decision.matched_keywords:
|
||||
self.archivar._routed_messages[msg_id] = {
|
||||
@@ -804,7 +820,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if (decision and hasattr(decision, 'target_room') and decision.target_room
|
||||
and decision.target_room != room_id
|
||||
and not getattr(decision, 'is_unrouteable', False)
|
||||
and not getattr(decision, 'stay_in_room', False)): # ← Router sagt "bleib hier"
|
||||
and not getattr(decision, 'stay_in_room', False)
|
||||
and not getattr(decision, 'move_request_sent', False)): # Archivar v4 hat bereits Buttons gesendet → kein Doppel-Routing
|
||||
|
||||
target_name = getattr(decision, 'matched_room_name', None)
|
||||
if not target_name:
|
||||
@@ -928,15 +945,23 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
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.
|
||||
"""Callback for Archivar — 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.
|
||||
Handles both clarification (ARCHIVAR_CLARIFY:) and move-request
|
||||
(MOVE_REQ:) buttons. Move-request context is stored in
|
||||
self._pending_move_requests so the response handler picks it up.
|
||||
|
||||
Args:
|
||||
room_id: Target room ID
|
||||
text: Message text
|
||||
payload: {"actions": [{"text": "...", "type": "..."}, ...]}
|
||||
payload: {
|
||||
"actions": [{"text": "...", "type": "..."}, ...],
|
||||
"_move_request": { # optional, set by Archivar v4 _send_move_request
|
||||
"target_room": "...",
|
||||
"target_name": "...",
|
||||
"text": "...",
|
||||
}
|
||||
}
|
||||
|
||||
Returns:
|
||||
True if sent successfully, False on error
|
||||
@@ -950,15 +975,37 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if not actions:
|
||||
return self.rest.post_message(room_id, text)
|
||||
|
||||
# Detect Archivar v4 Move-Request (Butler-Prinzip: ✅Ja / 📍Hier)
|
||||
move_req_ctx = payload.get("_move_request")
|
||||
if move_req_ctx:
|
||||
# Store pending move request so line 717 handler finds it
|
||||
self._pending_move_requests[room_id] = {
|
||||
"text": move_req_ctx.get("text", ""),
|
||||
"origin_room": room_id,
|
||||
"target_room": move_req_ctx.get("target_room", ""),
|
||||
"target_name": move_req_ctx.get("target_name", ""),
|
||||
"username": "", # filled from user_info in handler (line 718)
|
||||
"message_id": "", # no msg_id for Archivar v4 move-request flow
|
||||
}
|
||||
# Use MOVE_REQ: prefix so the existing handler at line 717-764
|
||||
# parses the response correctly (see line 722-724)
|
||||
msg_prefix = f"MOVE_REQ:{room_id}"
|
||||
log_tag = "move-request"
|
||||
else:
|
||||
msg_prefix = "ARCHIVAR_CLARIFY"
|
||||
log_tag = "clarification"
|
||||
|
||||
# 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}")
|
||||
# Move-request buttons use :: separator for line 722 parsing
|
||||
selector = f"{msg_prefix}::{action_type}" if move_req_ctx else f"{msg_prefix}:{action_type}"
|
||||
buttons.append({
|
||||
"type": "button",
|
||||
"text": action_text,
|
||||
"msg": f"ARCHIVAR_CLARIFY:{action_type}",
|
||||
"msg": selector,
|
||||
"msg_in_chat_window": True,
|
||||
"style": "default",
|
||||
})
|
||||
@@ -973,8 +1020,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
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])
|
||||
logger.info("[rocketchat] Sent Archivar %s with %d buttons to %s",
|
||||
log_tag, len(buttons), room_id[:8])
|
||||
return success
|
||||
|
||||
async def _start_onboarding(self, missing_rooms: list) -> None:
|
||||
|
||||
Reference in New Issue
Block a user