fix(HOTFIX-3): Originalnachricht nach Widerspruch-Clarify an Agenten dispatchen
Bug: Nach dem Widerspruch-Clarify (Button 1 'generell hier her' oder Button 2 'nur jetzt hier her') wurde die Originalnachricht NIE an den Agenten weitergeleitet. Der Agent hat die Frage nie gesehen. Fix: 1. _send_widerspruch_clarify speichert jetzt die Originalnachricht (text, username, msg_id, msg_obj, is_button_response) in _widerspruch_state. 2. Der WIDERSPRUCH:-Handler dispatched nach set_never_route/stay_once die Originalnachricht an den Agenten im Ursprungsraum (gleicher Pfad wie normale Nachrichten-Verarbeitung, analog zum Move-Request-Flow). Dispatch nur bei gültiger choice (1/2). Test: test_widerspruch_then_dispatch.py — 4 Tests verifizieren Dispatch nach Button 1, Button 2, Ursprungsraum-Ziel und kein Dispatch bei unbekannter choice.
This commit is contained in:
+56
-1
@@ -2659,12 +2659,16 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
logger.info("ROUTING BYPASS: reason=widerspruch_clarify_bypass, origin_room=%s", room_id)
|
||||
try:
|
||||
parts = text.split(":", 2)
|
||||
ctx = None
|
||||
origin_room_id = room_id
|
||||
valid_choice = False
|
||||
if len(parts) == 3:
|
||||
_, clarify_id, choice = parts
|
||||
ctx = self._widerspruch_state.pop(clarify_id, None)
|
||||
origin_room_id = (ctx or {}).get("origin_room_id", room_id)
|
||||
topic = (ctx or {}).get("topic", "")
|
||||
if choice == "1":
|
||||
valid_choice = True
|
||||
# Button 1: 'generell hier her' → dauerhaft never_route
|
||||
if _MULTIROOM() and self.archivar is not None and topic:
|
||||
self.archivar._state.set_never_route(origin_room_id, topic)
|
||||
@@ -2679,6 +2683,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
"Ich route es nicht mehr automatisch um.",
|
||||
)
|
||||
elif choice == "2":
|
||||
valid_choice = True
|
||||
# Button 2: 'nur jetzt hier her' → stay_once (einmalig)
|
||||
# Kein never_route, nur _recent_auto_routes löschen,
|
||||
# damit die nächste Nachricht wieder normal geroutet wird.
|
||||
@@ -2698,6 +2703,36 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
# P-067: Clear Clarify-Modal pulse (user responded)
|
||||
if hasattr(self, '_presence_engine') and self._presence_engine is not None and self._presence_engine.is_enabled():
|
||||
self._presence_engine.clear_clarify_modal()
|
||||
# ── HOTFIX 3: Originalnachricht an den Agenten dispatchen ──
|
||||
# Der Widerspruch klärt nur die Routing-Entscheidung. Die
|
||||
# Originalnachricht selbst muss IMMER beantwortet werden —
|
||||
# egal ob Button 1 (generell) oder Button 2 (nur jetzt).
|
||||
# Dispatch im Ursprungsraum (gleicher Pfad wie normale
|
||||
# Nachrichten-Verarbeitung, analog zum Move-Request-Flow).
|
||||
if valid_choice and ctx and ctx.get("text"):
|
||||
_CURRENT_ORIGIN_ROOM.set(origin_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set("")
|
||||
_set_room_context_origin(f"user:{ctx.get('username', '')}", origin_room_id)
|
||||
routing_counter.increment('widerspruch_clarify_dispatched')
|
||||
logger.info(
|
||||
"[rocketchat] HOTFIX 3: Widerspruch-Clarify dispatch — "
|
||||
"room=%s, text=%s",
|
||||
origin_room_id[:8], ctx["text"][:80],
|
||||
)
|
||||
origin_room_info = self._room_info.get(origin_room_id, {})
|
||||
origin_room_name = origin_room_info.get("name", room_name)
|
||||
origin_room_type = origin_room_info.get("type", room_type)
|
||||
await self._dispatch_agent(
|
||||
text=ctx["text"],
|
||||
room_id=origin_room_id,
|
||||
room_name=origin_room_name,
|
||||
room_type=origin_room_type,
|
||||
username=ctx.get("username", ""),
|
||||
msg_id=ctx.get("msg_id", ""),
|
||||
msg_obj=ctx.get("msg_obj", {}),
|
||||
is_button_response=ctx.get("is_button_response", False),
|
||||
category="",
|
||||
)
|
||||
# P2-Korrektur: Widerspruch-State vollständig leeren, damit keine
|
||||
# stale Einträge (z.B. bei unbekannter choice) zurückbleiben.
|
||||
self._widerspruch_state.clear()
|
||||
@@ -3515,6 +3550,11 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
room_id=room_id,
|
||||
origin_room_id=room_id,
|
||||
topic=topic,
|
||||
text=display_text,
|
||||
username=username,
|
||||
msg_id=msg_id,
|
||||
msg_obj=msg_obj,
|
||||
is_button_response=is_button_response,
|
||||
)
|
||||
routing_counter.increment('widerspruch_clarify_sent')
|
||||
logger.info(
|
||||
@@ -7764,6 +7804,11 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
room_id: str,
|
||||
origin_room_id: str,
|
||||
topic: str,
|
||||
text: str = "",
|
||||
username: str = "",
|
||||
msg_id: str = "",
|
||||
msg_obj: dict | None = None,
|
||||
is_button_response: bool = False,
|
||||
) -> bool:
|
||||
"""Sende den Widerspruch-Clarify mit zwei Buttons (V8.5).
|
||||
|
||||
@@ -7788,10 +7833,20 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
return False
|
||||
|
||||
clarify_id = uuid.uuid4().hex[:12]
|
||||
# Kontext für den WIDERSPRUCH:-Button-Handler speichern
|
||||
# Kontext für den WIDERSPRUCH:-Button-Handler speichern.
|
||||
# HOTFIX 3: Zusätzlich die Originalnachricht (text, username, msg_id,
|
||||
# msg_obj, is_button_response) speichern, damit sie nach dem
|
||||
# Button-Klick an den Agenten dispatched werden kann. Der Widerspruch
|
||||
# klärt nur die Routing-Entscheidung — die Nachricht selbst muss
|
||||
# immer beantwortet werden.
|
||||
self._widerspruch_state[clarify_id] = {
|
||||
"origin_room_id": origin_room_id,
|
||||
"topic": topic,
|
||||
"text": text,
|
||||
"username": username,
|
||||
"msg_id": msg_id,
|
||||
"msg_obj": msg_obj or {},
|
||||
"is_button_response": is_button_response,
|
||||
}
|
||||
|
||||
from archivar.button_builder import build_button_attachments
|
||||
|
||||
Reference in New Issue
Block a user