Files
Hermes_rocket.chat_Plugin/plugin/archivar/button_builder.py
T
Bernd (Hermes) 68f3845929 fix(P0): button_builder msg-Payload mit :: Suffix — Onboarding-Button-Klick wird wieder erkannt
ROOT CAUSE: button_builder.py setzte msg = prefix (nur 'ONBOARD:<rid>'),
aber _process_onboarding_response erwartet '::' in text als Trigger fuer
Button-Klick-Handler. Ohne '::' -> Fallthrough zu Text-Antwort-Handler
-> Theme wird mit Room-ID als Literal ueberschrieben (stille Korruption).

FIX (Rainer Option B — explizite Signatur):
- build_button_attachments: num_buttons jetzt (label, prefix[, suffix]),
  special_buttons (label, prefix, style[, suffix])
- msg_payload = f'{prefix}::{suffix}' wenn suffix, sonst prefix (backward-compat)
- adapter.py: 3 Aufrufer (_send_onboarding_message, _onboarding_next_room,
  _finish_onboarding) uebergeben jetzt (clean_name, f'ONBOARD:{rid}', f'select_{rid}')
- Review-Flow (onboarding_review.py) unveraendert — 2-Tupel ohne suffix
  bleiben backward-compatibel
2026-07-24 20:23:38 +02:00

109 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Gemeinsamer Button-Builder für Onboarding und Review-Flow.
Extrahiert aus onboarding_review.py (P0-1), damit adapter.py und
onboarding_review.py die GLEICHE Button-Konstruktion nutzen — kein Drift.
Regeln:
- Nummerierte Buttons: max 3 pro Attachment, mit 1️⃣ 2️⃣ 3️⃣...
- Sonderschaltflächen (↩️ Zurück, ⏭️ Skip, ➕ Neu): KEINE Nummer,
IMMER in separatem (letztem) Attachment
- Jedes Attachment hat max 3 actions
"""
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 build_button_attachments(
num_buttons: List[Tuple[Any, ...]],
special_buttons: List[Tuple[Any, ...]],
color: str = "#1d74f5",
title: str = "",
number_buttons: bool = True,
button_style: str = "primary",
) -> List[dict]:
"""Baut Attachments nach Andreas' 2-Reihen-Button-Pattern.
Regeln:
- Nummerierte Buttons: max 3 pro Attachment, mit 1️⃣ 2️⃣ 3️⃣...
(Nummerierung kann via number_buttons=False deaktiviert werden)
- Sonderschaltflächen (↩️ Zurück, ⏭️ Skip, ➕ Neu): KEINE Nummer,
IMMER in separatem (letztem) Attachment
- Jedes Attachment hat max 3 actions
P0-Fix: msg-Payload mit '::' Suffix für Button-Klick-Erkennung.
num_buttons: (label, prefix) oder (label, prefix, suffix)
special_buttons: (label, prefix, style) oder (label, prefix, suffix, style)
Wenn suffix vorhanden: msg = f'{prefix}::{suffix}'
Sonst (backward-compat): msg = prefix
Args:
num_buttons: Liste von (label, prefix[, suffix]) Tuples
special_buttons: Liste von (label, prefix, style[, suffix]) Tuples
color: Attachment-Farbe (default: "#1d74f5")
title: Attachment-Titel (nur für erstes Attachment)
number_buttons: Wenn False, werden Buttons NICHT nummeriert
(z.B. für X-Buttons in Keywords-Edit)
button_style: Rocket.Chat button style für num_buttons (default: "primary")
Returns:
Liste von Attachment-Dicts (jedes mit max 3 actions)
"""
attachments: List[dict] = []
# Nummerierte Buttons in 3er-Blöcke aufteilen
for i in range(0, len(num_buttons), 3):
chunk = num_buttons[i:i + 3]
actions = []
for j, tup in enumerate(chunk):
label = tup[0]
prefix = tup[1]
suffix = tup[2] if len(tup) >= 3 else None
msg_payload = f"{prefix}::{suffix}" if suffix else prefix
if number_buttons:
num_idx = i + j
emoji = EMOJI_NUMBERS[num_idx] if num_idx < len(EMOJI_NUMBERS) else str(num_idx + 1)
text = f"{emoji} {label}"
else:
text = label
actions.append({
"type": "button",
"text": text,
"msg": msg_payload,
"msg_in_chat_window": True,
"style": button_style,
})
att = {
"color": color,
"actions": actions,
}
if i == 0 and title:
att["title"] = title
attachments.append(att)
# Sonderschaltflächen in separatem Attachment
if special_buttons:
special_actions = []
for tup in special_buttons:
label = tup[0]
prefix = tup[1]
style = tup[2]
suffix = tup[3] if len(tup) >= 4 else None
msg_payload = f"{prefix}::{suffix}" if suffix else prefix
special_actions.append({
"type": "button",
"text": label,
"msg": msg_payload,
"msg_in_chat_window": True,
"style": style,
})
attachments.append({
"color": color,
"actions": special_actions,
})
return attachments