From 328532bcbbc71815088e65a48e1e89324f83e7ae Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Tue, 11 Aug 2026 21:39:07 +0200 Subject: [PATCH] =?UTF-8?q?P-051:=20action=5Fid=20in=20allen=20Button-Dict?= =?UTF-8?q?s=20erg=C3=A4nzen=20(RC=206.x=20Rendering-Fix)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - button_builder.py: _make_action_id() Helper + action_id in Regular/Special Buttons - __init__.py _build_custom_buttons: action_id via SHA1(msg_payload:idx) - adapter.py _get_build_custom_buttons local fallback: action_id ergänzt - adapter.py send_clarify: action_id=f'clarify_{clarify_id}_{i}' (deterministisch) - adapter.py _send_archivar_buttons: action_id via SHA1(selector:i) Rocket.Chat 6.x ignoriert das actions-Array komplett wenn kein action_id-Feld vorhanden ist. Buttons erscheinen als plain-text statt klickbar. --- plugin/__init__.py | 4 ++++ plugin/adapter.py | 15 +++++++++++++-- plugin/archivar/button_builder.py | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/plugin/__init__.py b/plugin/__init__.py index 354cd37..b683ec1 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -81,6 +81,7 @@ def _build_custom_buttons(labels: list, prefix: str = "", style: str = "default" prefix: Payload prefix for correlation (e.g. "ONBOARD:") style: Rocket.Chat button style — "default" (grey) or "primary" (blue) """ + import hashlib buttons = [] for idx, label in enumerate(labels): # Sanitize label for button text (keep short) @@ -89,12 +90,15 @@ def _build_custom_buttons(labels: list, prefix: str = "", style: str = "default" msg_payload = display if prefix: msg_payload = f"{prefix}::{msg_payload}" + # P-051: action_id zwingend für RC 6.x (sonst actions-Array ignoriert) + action_id = hashlib.sha1(f"{msg_payload}:{idx}".encode()).hexdigest()[:12] buttons.append({ "type": "button", "text": display, "msg": msg_payload, "msg_in_chat_window": True, "style": style, + "action_id": action_id, }) return buttons diff --git a/plugin/adapter.py b/plugin/adapter.py index f7db36d..2e8f1bd 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -5150,18 +5150,22 @@ class RocketChatAdapter(BasePlatformAdapter): log_tag = "clarification" # Build native RC buttons from Archivar actions + import hashlib buttons = [] for i, action in enumerate(actions): action_type = action.get("type", f"action_{i}") action_text = action.get("text", f"Option {i+1}") # Move-request buttons use :: separator for line 722 parsing selector = f"{msg_prefix}::{action_type}" if move_req_ctx else f"{msg_prefix}:{action_type}" + # P-051: action_id zwingend für RC 6.x + action_id = hashlib.sha1(f"{selector}:{i}".encode()).hexdigest()[:12] buttons.append({ "type": "button", "text": action_text, "msg": selector, "msg_in_chat_window": True, "style": "default", + "action_id": action_id, }) attachments = [{ @@ -5208,18 +5212,22 @@ class RocketChatAdapter(BasePlatformAdapter): return fn # Fallback: local implementation (Bug 3 fix — ensures buttons always render) def _local_build(labels, prefix='', style='default'): + import hashlib buttons = [] - for label in labels: + for idx, label in enumerate(labels): display = label.strip() msg_payload = display if prefix: msg_payload = f"{prefix}::{msg_payload}" + # P-051: action_id zwingend für RC 6.x + action_id = hashlib.sha1(f"{msg_payload}:{idx}".encode()).hexdigest()[:12] buttons.append({ "type": "button", "text": display, "msg": msg_payload, "msg_in_chat_window": True, "style": style, + "action_id": action_id, }) return buttons logger.warning("[rocketchat] _build_custom_buttons not found in rocketchat module — using local fallback") @@ -7627,12 +7635,14 @@ class RocketChatAdapter(BasePlatformAdapter): buttons = [] for i in range(len(choices)): emoji = self.EMOJI_NUMBERS[i] if i < len(self.EMOJI_NUMBERS) else str(i + 1) + msg_payload = f"CLARIFY:{clarify_id}::{i + 1}" buttons.append({ "type": "button", "text": emoji, - "msg": f"CLARIFY:{clarify_id}::{i + 1}", + "msg": msg_payload, "msg_in_chat_window": False, "style": "default", + "action_id": f"clarify_{clarify_id}_{i}", }) # Add "Other" button with special handling @@ -7642,6 +7652,7 @@ class RocketChatAdapter(BasePlatformAdapter): "msg": f"CLARIFY:{clarify_id}:other", "msg_in_chat_window": False, "style": "default", + "action_id": f"clarify_{clarify_id}_other", }) # Create attachment(s) with buttons — max 3 per row (UX: mobile readability) diff --git a/plugin/archivar/button_builder.py b/plugin/archivar/button_builder.py index 2aae2b2..94a1930 100644 --- a/plugin/archivar/button_builder.py +++ b/plugin/archivar/button_builder.py @@ -11,12 +11,23 @@ Regeln: - Jedes Attachment hat max 3 actions """ +import hashlib from typing import Any, List, Tuple # Emoji-Nummern für bis zu 10 Buttons EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] +def _make_action_id(msg_payload: str, index: int = 0) -> str: + """Deterministische action_id aus msg-Payload (SHA1, 12 Zeichen). + + Rocket.Chat 6.x benötigt zwingend ein action_id-Feld im Button-Dict, + sonst wird das gesamte actions-Array ignoriert (P-051). + """ + raw = f"{msg_payload}:{index}".encode() + return hashlib.sha1(raw).hexdigest()[:12] + + def build_button_attachments( num_buttons: List[Tuple[Any, ...]], special_buttons: List[Tuple[Any, ...]], @@ -75,6 +86,7 @@ def build_button_attachments( "msg": msg_payload, "msg_in_chat_window": True, "style": button_style, + "action_id": _make_action_id(msg_payload, i + j), }) att = { "color": color, @@ -87,7 +99,7 @@ def build_button_attachments( # Sonderschaltflächen in separatem Attachment if special_buttons: special_actions = [] - for tup in special_buttons: + for s_idx, tup in enumerate(special_buttons): label = tup[0] prefix = tup[1] style = tup[2] @@ -99,6 +111,7 @@ def build_button_attachments( "msg": msg_payload, "msg_in_chat_window": True, "style": style, + "action_id": _make_action_id(msg_payload, s_idx), }) attachments.append({ "color": color,