P1: Quick-Reply Dedup — zentraler Helper, kontextabhängiger Text, Same-Room-Erkennung
- _maybe_send_quick_reply() in adapter.py: Dedup via OutboundGate-Flag - outbound_gate.py: quick_reply_sent-Flag in _TurnHandle, mark/check-Methoden - Same-Room: 'Ich bin gerade beschäftigt' (kein Raum-Name) - Cross-Room: 'Ich antworte gerade in #RaumX' - Tests: test_outbound_gate.py +50 Zeilen, test_quick_reply_dedup.py +83 Zeilen Re-Implementierung nach .45 Clean-Install (31.07.2026).
This commit is contained in:
+61
-23
@@ -6537,6 +6537,53 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
self.ddp = None
|
||||
logger.info("[rocketchat] Disconnected")
|
||||
|
||||
# ── P1: Quick-Reply Dedup Helper ──────────────────────────────────
|
||||
# Zentraler Helper für Quick-Reply — verhindert 3x-Senden durch
|
||||
# Dedup-Flag im _TurnHandle und kontextabhängigen Text (same-room
|
||||
# vs cross-room).
|
||||
|
||||
async def _maybe_send_quick_reply(
|
||||
self, gate_room_id: str, active_room_id: Optional[str], active_room_name: str
|
||||
) -> Optional[SendResult]:
|
||||
"""Sendet Quick-Reply wenn noch keiner für diesen Raum gesendet wurde.
|
||||
|
||||
Dedup: quick_reply_already_sent prüft das Flag im _TurnHandle.
|
||||
Kontextabhängiger Text:
|
||||
- Same-Raum (active_room_id == gate_room_id): kein Raum-Name
|
||||
- Cross-Raum mit Name: „Ich antworte gerade in #RaumX — …"
|
||||
- Cross-Raum ohne Name: generischer Fallback
|
||||
|
||||
Returns:
|
||||
SendResult wenn Quick-Reply gesendet wurde, None wenn bereits
|
||||
gesendet (Dedup).
|
||||
"""
|
||||
if self._outbound_gate.quick_reply_already_sent(gate_room_id):
|
||||
return None
|
||||
|
||||
# Kontextabhängiger Text
|
||||
same_room = (active_room_id is not None and active_room_id == gate_room_id)
|
||||
if same_room:
|
||||
text = "Ich bin gerade beschäftigt — einen Moment bitte, ich bin gleich bei dir."
|
||||
elif active_room_name:
|
||||
text = (
|
||||
f"Ich antworte gerade in #{active_room_name} — "
|
||||
f"einen Moment bitte, ich bin gleich bei dir."
|
||||
)
|
||||
else:
|
||||
text = (
|
||||
"Ich antworte gerade in einem anderen Raum — "
|
||||
"einen Moment bitte, ich bin gleich bei dir."
|
||||
)
|
||||
|
||||
await self._post_message_unlocked(gate_room_id, text)
|
||||
self._outbound_gate.mark_quick_reply_sent(gate_room_id)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
logger.info(
|
||||
"[rocketchat] P5 V9.x: Quick-Reply sent to room=%s (blocked by %s)",
|
||||
gate_room_id[:8], active_room_name or "unknown",
|
||||
)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
|
||||
async def send(self, chat_id: str, content: str, reply_to: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None) -> SendResult:
|
||||
if not self.rest.auth_token:
|
||||
@@ -6627,25 +6674,18 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
decision = GateDecision(allow=False, reason="timeout")
|
||||
|
||||
if not decision.allow:
|
||||
# Quick-Reply: anderer Raum blockiert immer noch
|
||||
# Quick-Reply via zentralem Helper (Dedup + kontextabhängiger Text)
|
||||
active_room = self._outbound_gate.active_room_id
|
||||
active_name = ""
|
||||
if active_room and active_room in self._room_info:
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
quick_reply_text = (
|
||||
f"Ich antworte gerade in #{active_name} — "
|
||||
f"einen Moment bitte, ich bin gleich bei dir."
|
||||
) if active_name else (
|
||||
"Ich antworte gerade in einem anderen Raum — "
|
||||
"einen Moment bitte, ich bin gleich bei dir."
|
||||
qr_result = await self._maybe_send_quick_reply(
|
||||
_gate_room_id, active_room, active_name
|
||||
)
|
||||
await self._post_message_unlocked(_gate_room_id, quick_reply_text)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
logger.info(
|
||||
"[rocketchat] P5 V9.x: Quick-Reply sent to room=%s (blocked by %s)",
|
||||
_gate_room_id[:8], active_name,
|
||||
)
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
if qr_result is not None:
|
||||
return qr_result
|
||||
# Dedup: Quick-Reply bereits gesendet → trotzdem return
|
||||
return SendResult(success=True, message_id="quick_reply_dedup")
|
||||
# Fell through: decision.allow is True — track if WE created the entry
|
||||
# (gate_clear = we own it; same_room_same_token = someone else owns it)
|
||||
_gate_acquired = (decision.reason == "gate_clear")
|
||||
@@ -7083,20 +7123,18 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
except asyncio.TimeoutError:
|
||||
decision = GateDecision(allow=False, reason="timeout")
|
||||
if not decision.allow:
|
||||
# Quick-Reply via zentralem Helper (Dedup + kontextabhängiger Text)
|
||||
active_room = self._outbound_gate.active_room_id
|
||||
active_name = ""
|
||||
if active_room and active_room in self._room_info:
|
||||
active_name = self._room_info[active_room].get("name", active_room[:12] + "…")
|
||||
quick_reply_text = (
|
||||
f"Ich antworte gerade in #{active_name} — "
|
||||
f"einen Moment bitte, ich bin gleich bei dir."
|
||||
) if active_name else (
|
||||
"Ich antworte gerade in einem anderen Raum — "
|
||||
"einen Moment bitte, ich bin gleich bei dir."
|
||||
qr_result = await self._maybe_send_quick_reply(
|
||||
_gate_room_id, active_room, active_name
|
||||
)
|
||||
await self._post_message_unlocked(_gate_room_id, quick_reply_text)
|
||||
self._outbound_gate.stats.quick_reply += 1
|
||||
return SendResult(success=True, message_id="quick_reply")
|
||||
if qr_result is not None:
|
||||
return qr_result
|
||||
# Dedup: Quick-Reply bereits gesendet → trotzdem return
|
||||
return SendResult(success=True, message_id="quick_reply_dedup")
|
||||
# Fell through: decision.allow is True — track if WE created the entry
|
||||
# (gate_clear = we own it; same_room_same_token = someone else owns it)
|
||||
_gate_acquired = (decision.reason == "gate_clear")
|
||||
|
||||
Reference in New Issue
Block a user