From bd579bd1129e5dc26e3d29ae89a238e07fa4fab8 Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Mon, 10 Aug 2026 10:28:12 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Clarify-UX=20=E2=80=94=20Emoji-Zahlen=20?= =?UTF-8?q?in=20Buttons=20+=20Plain-Digit=20Text-Intercept?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROBLEM 1: Button-Labels waren nackte Zahlen ('1','2','3'). → Jetzt Emoji-Zahlen ('1️⃣','2️⃣','3️⃣') via EMOJI_NUMBERS. Payload bleibt plain-digit (CLARIFY:id::1) damit isdigit() greift. PROBLEM 2: Eingabe '1' als Text wurde nicht als CLARIFY-Antwort erkannt. → Neues _room_clarify mapping (room_id → clarify_id) in send_clarify. → Plain-digit text intercept VOR CLARIFY-Button-Handler: Wenn Text.strip().isdigit() und room_id in _room_clarify → als CLARIFY-Antwort verarbeiten (resolve_gateway_clarify). → Cleanup in Button-Handler und _cmd_reset. P-013 beachtet: is_clarify_response (CLARIFY:-Prefix) wird weiterhin zuerst geprüft; der neue Block fängt NUR plain-digit Texte ab. --- plugin/adapter.py | 71 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/plugin/adapter.py b/plugin/adapter.py index 1d48585..90341a8 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -1300,6 +1300,8 @@ class RocketChatAdapter(BasePlatformAdapter): # The router's _check_never_route_topic handles per-topic blocking now. # Clarify state: maps clarify_id → session_key for gateway resolution self._clarify_state: Dict[str, str] = {} + # Clarify room mapping: room_id → clarify_id for plain-digit text intercept + self._room_clarify: Dict[str, str] = {} # FIX 2 (P0): ISSUE 3 — Pending Clarify Dispatch Slot # {room_id: {text, username, msg_id, msg_obj, is_button_response}} self._pending_clarify_dispatch: Dict[str, dict] = {} @@ -2402,10 +2404,52 @@ class RocketChatAdapter(BasePlatformAdapter): return # ── Ende Thema B Onboarding-Guard ──────────────────────────────────── + # ── CLARIFY Plain-Digit Text Intercept ────────────────────────── + # Wenn der User eine einfache Zahl (1, 2, 3) tippt statt auf einen + # Button zu klicken, als CLARIFY-Antwort verarbeiten. + # P-013: Button-Detection VOR CLARIFY-Filter — is_clarify_response + # (CLARIFY: prefix) wird weiterhin zuerst geprüft, dieser Block + # fängt NUR plain-digit Texte ab. + is_archivar_clarify = text.startswith("ARCHIVAR_CLARIFY:") if text else False + if not is_clarify_response and not is_archivar_clarify: + stripped = text.strip() + if stripped.isdigit() and room_id in self._room_clarify: + clarify_id = self._room_clarify[room_id] + idx = int(stripped) - 1 # 1-basierte Eingabe → 0-basierter Index + resolved_text: Optional[str] = None + try: + from tools.clarify_gateway import _entries as _clarify_entries + entry = _clarify_entries.get(clarify_id) + if entry and entry.choices and 0 <= idx < len(entry.choices): + resolved_text = entry.choices[idx] + except Exception: + resolved_text = None + if resolved_text is None: + resolved_text = f"choice {idx + 1}" + # Resolve via gateway and clean up + self._clarify_state.pop(clarify_id, None) + self._room_clarify.pop(room_id, None) + try: + from tools.clarify_gateway import resolve_gateway_clarify + resolved = resolve_gateway_clarify(clarify_id, resolved_text) + if resolved: + logger.info( + "[rocketchat] Clarify %s resolved via plain-digit: %s (session=%s)", + clarify_id, resolved_text[:60], + self._clarify_state.get(clarify_id, "?"), + ) + else: + logger.warning("[rocketchat] Clarify %s resolve returned False", clarify_id) + except Exception as exc: + logger.error("[rocketchat] resolve_gateway_clarify failed: %s", exc) + routing_counter.increment('clarify_plain_digit_bypass') + logger.info("ROUTING BYPASS: reason=clarify_plain_digit_bypass, origin_room=%s", room_id) + return + # ── Ende CLARIFY Plain-Digit Text Intercept ───────────────────── + # ── CLARIFY Response Handling ─────────────────────────────────── # Handle CLARIFY button responses: CLARIFY:: or CLARIFY::other # V8.2.1 A2: Handle ARCHIVAR_CLARIFY (Nachklärung) responses - is_archivar_clarify = text.startswith("ARCHIVAR_CLARIFY:") if text else False if is_clarify_response and text.startswith("CLARIFY:"): routing_counter.increment('clarify_answer_bypass') logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id) @@ -2446,6 +2490,10 @@ class RocketChatAdapter(BasePlatformAdapter): resolved_text = f"choice {idx + 1}" # Resolve via gateway and clean up self._clarify_state.pop(clarify_id, None) + # Clean up room→clarify mapping (button click resolved it) + for rid, cid in list(self._room_clarify.items()): + if cid == clarify_id: + self._room_clarify.pop(rid, None) try: from tools.clarify_gateway import resolve_gateway_clarify resolved = resolve_gateway_clarify(clarify_id, resolved_text) @@ -4026,6 +4074,7 @@ class RocketChatAdapter(BasePlatformAdapter): self._explicit_switch_sticky.clear() self._pending_move_requests.clear() self._rooms_with_pending_questions.clear() + self._room_clarify.clear() # Onboarding-State zurücksetzen falls aktiv if self._onboarding_state: @@ -7475,9 +7524,19 @@ class RocketChatAdapter(BasePlatformAdapter): ) text += f"\n\n{option_lines}" - # Build buttons with short labels to avoid truncation - button_labels = [str(i + 1) for i in range(len(choices))] - buttons = _build_custom_buttons(button_labels, prefix=f"CLARIFY:{clarify_id}") + # Build buttons with emoji-number labels (UX: shorter, clearer). + # Payload uses plain digits so the CLARIFY handler's isdigit() + # check still works. + buttons = [] + for i in range(len(choices)): + emoji = self.EMOJI_NUMBERS[i] if i < len(self.EMOJI_NUMBERS) else str(i + 1) + buttons.append({ + "type": "button", + "text": emoji, + "msg": f"CLARIFY:{clarify_id}::{i + 1}", + "msg_in_chat_window": True, + "style": "default", + }) # Add "Other" button with special handling buttons.append({ @@ -7502,6 +7561,10 @@ class RocketChatAdapter(BasePlatformAdapter): # Store clarify state for gateway identification self._clarify_state = getattr(self, '_clarify_state', {}) self._clarify_state[clarify_id] = session_key + + # Store room→clarify mapping for plain-digit text intercept + self._room_clarify = getattr(self, '_room_clarify', {}) + self._room_clarify[real_room_id] = clarify_id # For "Other" button, we need to enable text capture mode # This is done by calling mark_awaiting_text when the user clicks "Other"