Compare commits
2 Commits
fa9091eb6c
...
cc687c79ad
| Author | SHA1 | Date | |
|---|---|---|---|
| cc687c79ad | |||
| bd579bd112 |
+80
-5
@@ -1300,6 +1300,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# The router's _check_never_route_topic handles per-topic blocking now.
|
# The router's _check_never_route_topic handles per-topic blocking now.
|
||||||
# Clarify state: maps clarify_id → session_key for gateway resolution
|
# Clarify state: maps clarify_id → session_key for gateway resolution
|
||||||
self._clarify_state: Dict[str, str] = {}
|
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
|
# FIX 2 (P0): ISSUE 3 — Pending Clarify Dispatch Slot
|
||||||
# {room_id: {text, username, msg_id, msg_obj, is_button_response}}
|
# {room_id: {text, username, msg_id, msg_obj, is_button_response}}
|
||||||
self._pending_clarify_dispatch: Dict[str, dict] = {}
|
self._pending_clarify_dispatch: Dict[str, dict] = {}
|
||||||
@@ -2402,10 +2404,52 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
return
|
return
|
||||||
# ── Ende Thema B Onboarding-Guard ────────────────────────────────────
|
# ── 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 ───────────────────────────────────
|
# ── CLARIFY Response Handling ───────────────────────────────────
|
||||||
# Handle CLARIFY button responses: CLARIFY:<clarify_id>:<choice> or CLARIFY:<clarify_id>:other
|
# Handle CLARIFY button responses: CLARIFY:<clarify_id>:<choice> or CLARIFY:<clarify_id>:other
|
||||||
# V8.2.1 A2: Handle ARCHIVAR_CLARIFY (Nachklärung) responses
|
# 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:"):
|
if is_clarify_response and text.startswith("CLARIFY:"):
|
||||||
routing_counter.increment('clarify_answer_bypass')
|
routing_counter.increment('clarify_answer_bypass')
|
||||||
logger.info("ROUTING BYPASS: reason=clarify_answer_bypass, origin_room=%s", room_id)
|
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}"
|
resolved_text = f"choice {idx + 1}"
|
||||||
# Resolve via gateway and clean up
|
# Resolve via gateway and clean up
|
||||||
self._clarify_state.pop(clarify_id, None)
|
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:
|
try:
|
||||||
from tools.clarify_gateway import resolve_gateway_clarify
|
from tools.clarify_gateway import resolve_gateway_clarify
|
||||||
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
resolved = resolve_gateway_clarify(clarify_id, resolved_text)
|
||||||
@@ -4026,6 +4074,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
self._explicit_switch_sticky.clear()
|
self._explicit_switch_sticky.clear()
|
||||||
self._pending_move_requests.clear()
|
self._pending_move_requests.clear()
|
||||||
self._rooms_with_pending_questions.clear()
|
self._rooms_with_pending_questions.clear()
|
||||||
|
self._room_clarify.clear()
|
||||||
|
|
||||||
# Onboarding-State zurücksetzen falls aktiv
|
# Onboarding-State zurücksetzen falls aktiv
|
||||||
if self._onboarding_state:
|
if self._onboarding_state:
|
||||||
@@ -7475,9 +7524,19 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
)
|
)
|
||||||
text += f"\n\n{option_lines}"
|
text += f"\n\n{option_lines}"
|
||||||
|
|
||||||
# Build buttons with short labels to avoid truncation
|
# Build buttons with emoji-number labels (UX: shorter, clearer).
|
||||||
button_labels = [str(i + 1) for i in range(len(choices))]
|
# Payload uses plain digits so the CLARIFY handler's isdigit()
|
||||||
buttons = _build_custom_buttons(button_labels, prefix=f"CLARIFY:{clarify_id}")
|
# 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
|
# Add "Other" button with special handling
|
||||||
buttons.append({
|
buttons.append({
|
||||||
@@ -7488,12 +7547,24 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
"style": "default",
|
"style": "default",
|
||||||
})
|
})
|
||||||
|
|
||||||
# Create attachment with buttons
|
# Create attachment(s) with buttons — max 3 per row (UX: mobile readability)
|
||||||
|
MAX_BUTTONS_PER_ROW = 3
|
||||||
attachments = [{
|
attachments = [{
|
||||||
"color": "#1d74f5",
|
"color": "#1d74f5",
|
||||||
"title": "Please choose an option:",
|
"title": "Please choose an option:",
|
||||||
"actions": buttons,
|
"actions": buttons,
|
||||||
}]
|
}]
|
||||||
|
if len(buttons) > MAX_BUTTONS_PER_ROW:
|
||||||
|
attachments = []
|
||||||
|
for i in range(0, len(buttons), MAX_BUTTONS_PER_ROW):
|
||||||
|
chunk = buttons[i:i + MAX_BUTTONS_PER_ROW]
|
||||||
|
attachments.append({
|
||||||
|
"color": "#1d74f5",
|
||||||
|
"actions": chunk,
|
||||||
|
})
|
||||||
|
# First attachment gets the title
|
||||||
|
if attachments:
|
||||||
|
attachments[0]["title"] = "Please choose an option:"
|
||||||
|
|
||||||
# Send message with buttons
|
# Send message with buttons
|
||||||
success = await self._post_message_with_retry(real_room_id, text, attachments=attachments)
|
success = await self._post_message_with_retry(real_room_id, text, attachments=attachments)
|
||||||
@@ -7503,6 +7574,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
self._clarify_state = getattr(self, '_clarify_state', {})
|
self._clarify_state = getattr(self, '_clarify_state', {})
|
||||||
self._clarify_state[clarify_id] = session_key
|
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
|
# For "Other" button, we need to enable text capture mode
|
||||||
# This is done by calling mark_awaiting_text when the user clicks "Other"
|
# This is done by calling mark_awaiting_text when the user clicks "Other"
|
||||||
# The actual implementation will be in the message handling logic
|
# The actual implementation will be in the message handling logic
|
||||||
|
|||||||
Reference in New Issue
Block a user