feat(F-119): MAIL_DETAIL-Button-Handler + Thread-Reply (tmid)
Der Proton-Mail-Trigger postet eine Ergebnis-Karte mit 'Details abrufen'- Button (Payload MAIL_DETAIL:<hash>::Details abrufen). Der Klick liest den Details-Record aus <real_home>/.config/hermes/proton/details/<hash>.json und postet die Details als Thread-Antwort (tmid=card_message_id) unter der Karte. - post_message/_post_message_with_retry: tmid-Parameter (Thread-Reply). - _load_mail_details: liest den Details-Record (deterministischer Pfad, HERMES_REAL_HOME-Vorrang, P-119). - MAIL_DETAIL-Button-Klick-Router in _process_incoming (::-Detection).
This commit is contained in:
+81
-2
@@ -545,9 +545,17 @@ class RocketChatREST:
|
|||||||
return None
|
return None
|
||||||
return r.get("members", [])
|
return r.get("members", [])
|
||||||
|
|
||||||
def post_message(self, room_id: str, text: str, attachments: Optional[List[dict]] = None) -> Optional[str]:
|
def post_message(self, room_id: str, text: str, attachments: Optional[List[dict]] = None, tmid: Optional[str] = None) -> Optional[str]:
|
||||||
"""Post a message via REST API POST /api/v1/chat.postMessage.
|
"""Post a message via REST API POST /api/v1/chat.postMessage.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
room_id: Target room.
|
||||||
|
text: Message text.
|
||||||
|
attachments: Optional Rocket.Chat attachments (buttons).
|
||||||
|
tmid: Optional parent message id → post as a thread reply under
|
||||||
|
that message (F-119: mail details hang as a thread under the
|
||||||
|
result card).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The message ``_id`` from the API response on success, ``None`` on failure.
|
The message ``_id`` from the API response on success, ``None`` on failure.
|
||||||
V8.3.1 F1: Return message_id for target_message_id tracking.
|
V8.3.1 F1: Return message_id for target_message_id tracking.
|
||||||
@@ -557,6 +565,8 @@ class RocketChatREST:
|
|||||||
payload = {"roomId": room_id, "text": text}
|
payload = {"roomId": room_id, "text": text}
|
||||||
if attachments:
|
if attachments:
|
||||||
payload["attachments"] = attachments
|
payload["attachments"] = attachments
|
||||||
|
if tmid:
|
||||||
|
payload["tmid"] = tmid
|
||||||
r = self._request("POST", "/api/v1/chat.postMessage", headers={
|
r = self._request("POST", "/api/v1/chat.postMessage", headers={
|
||||||
"X-Auth-Token": self.auth_token,
|
"X-Auth-Token": self.auth_token,
|
||||||
"X-User-Id": self.user_id,
|
"X-User-Id": self.user_id,
|
||||||
@@ -1628,6 +1638,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
self, room_id: str, text: str,
|
self, room_id: str, text: str,
|
||||||
attachments: Optional[List[dict]] = None,
|
attachments: Optional[List[dict]] = None,
|
||||||
max_retries: int = 3,
|
max_retries: int = 3,
|
||||||
|
tmid: Optional[str] = None,
|
||||||
) -> Optional[str]:
|
) -> Optional[str]:
|
||||||
"""Send chat.postMessage with exponential backoff on HTTP 429.
|
"""Send chat.postMessage with exponential backoff on HTTP 429.
|
||||||
|
|
||||||
@@ -1644,7 +1655,7 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
delays = [2, 4, 8]
|
delays = [2, 4, 8]
|
||||||
for attempt in range(max_retries + 1):
|
for attempt in range(max_retries + 1):
|
||||||
try:
|
try:
|
||||||
return self.rest.post_message(room_id, text, attachments=attachments)
|
return self.rest.post_message(room_id, text, attachments=attachments, tmid=tmid)
|
||||||
except RocketChatRateLimitError:
|
except RocketChatRateLimitError:
|
||||||
if attempt < max_retries:
|
if attempt < max_retries:
|
||||||
delay = delays[min(attempt, len(delays) - 1)]
|
delay = delays[min(attempt, len(delays) - 1)]
|
||||||
@@ -1664,6 +1675,32 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
return None
|
return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _load_mail_details(mail_hash_value: str) -> Optional[dict]:
|
||||||
|
"""@implements F-119 — liest den Details-Record einer Proton-Mail.
|
||||||
|
|
||||||
|
Der Proton-Mail-Trigger persistiert die Details unter
|
||||||
|
``<real_home>/.config/hermes/proton/details/<hash>.json``. Dieser
|
||||||
|
Handler liest dieselbe Datei (deterministischer Pfad, keine
|
||||||
|
Cross-Plugin-Import-Kopplung). ``HERMES_REAL_HOME`` hat Vorrang vor
|
||||||
|
``expanduser("~")`` (P-119: der Gateway läuft mit Profil-HOME).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Das Record-Dict oder ``None`` wenn nicht vorhanden/unlesbar.
|
||||||
|
"""
|
||||||
|
import json as _json
|
||||||
|
real_home = os.getenv("HERMES_REAL_HOME") or os.path.expanduser("~")
|
||||||
|
path = os.path.join(
|
||||||
|
real_home, ".config", "hermes", "proton", "details",
|
||||||
|
f"{mail_hash_value}.json",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with open(path, "r", encoding="utf-8") as fh:
|
||||||
|
data = _json.load(fh)
|
||||||
|
except (OSError, ValueError):
|
||||||
|
return None
|
||||||
|
return data if isinstance(data, dict) else None
|
||||||
|
|
||||||
def _sync_room_map_with_membership(self) -> None:
|
def _sync_room_map_with_membership(self) -> None:
|
||||||
"""M13: Garbage-Collect room-map.json + FAISS + Booster + State gegen tatsächliche Mitgliedschaft.
|
"""M13: Garbage-Collect room-map.json + FAISS + Booster + State gegen tatsächliche Mitgliedschaft.
|
||||||
|
|
||||||
@@ -3203,6 +3240,48 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
return
|
return
|
||||||
# ── Ende CLARIFY Plain-Digit Text Intercept ─────────────────────
|
# ── Ende CLARIFY Plain-Digit Text Intercept ─────────────────────
|
||||||
|
|
||||||
|
# ── F-119: MAIL_DETAIL Button-Klick (Proton-Mail-Ergebnis-Karte) ──
|
||||||
|
# Der Proton-Mail-Trigger postet eine Ergebnis-Karte mit einem
|
||||||
|
# "Details abrufen"-Button (Payload ``MAIL_DETAIL:<hash>::Details abrufen``).
|
||||||
|
# Der Klick liest den Details-Record aus
|
||||||
|
# <real_home>/.config/hermes/proton/details/<hash>.json und postet die
|
||||||
|
# Details als Thread-Antwort unter der Karte (tmid = card_message_id).
|
||||||
|
# Andreas-Korrektur 31.08.: Thread bleibt Teil der Lösung — Details
|
||||||
|
# hängen visuell an der Karte, der Hauptkanal bleibt flach.
|
||||||
|
if text.startswith("MAIL_DETAIL:"):
|
||||||
|
routing_counter.increment('mail_detail_bypass')
|
||||||
|
logger.info("ROUTING BYPASS: reason=mail_detail_bypass, origin_room=%s", room_id)
|
||||||
|
try:
|
||||||
|
# Payload: MAIL_DETAIL:<hash>::Details abrufen
|
||||||
|
_md_body = text.split("::", 1)[0] # MAIL_DETAIL:<hash>
|
||||||
|
_md_hash = _md_body.split(":", 1)[1].strip()
|
||||||
|
_md_record = self._load_mail_details(_md_hash)
|
||||||
|
if _md_record:
|
||||||
|
_md_text = _md_record.get("details", "") or "Keine Details verfügbar."
|
||||||
|
_md_subject = _md_record.get("subject", "")
|
||||||
|
_md_sender = _md_record.get("sender", "")
|
||||||
|
_md_lines = []
|
||||||
|
if _md_subject:
|
||||||
|
_md_lines.append(f"📧 **{_md_subject}**")
|
||||||
|
if _md_sender:
|
||||||
|
_md_lines.append(f"Von: {_md_sender}")
|
||||||
|
if _md_lines:
|
||||||
|
_md_lines.append("")
|
||||||
|
_md_lines.append(_md_text)
|
||||||
|
_md_tmid = _md_record.get("card_message_id", "") or None
|
||||||
|
await self._post_message_with_retry(
|
||||||
|
room_id, "\n".join(_md_lines), tmid=_md_tmid
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await self._post_message_with_retry(
|
||||||
|
room_id, "Keine Details verfügbar."
|
||||||
|
)
|
||||||
|
except Exception as _md_exc:
|
||||||
|
logger.warning("[rocketchat] MAIL_DETAIL handler failed: %s", _md_exc)
|
||||||
|
self._abort_early_seed_presence()
|
||||||
|
return
|
||||||
|
# ── Ende F-119 MAIL_DETAIL Button-Klick ─────────────────────────
|
||||||
|
|
||||||
# ── 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
|
||||||
|
|||||||
Reference in New Issue
Block a user