fix(P0-1): Raum-Setup 3er-Chunking via build_button_attachments — gemeinsames Modul button_builder.py
This commit is contained in:
+20
-25
@@ -4644,8 +4644,8 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# Bug 3 fix: Robuster Zugriff auf _build_custom_buttons
|
# Bug 3 fix: Robuster Zugriff auf _build_custom_buttons
|
||||||
_build = self._get_build_custom_buttons()
|
_build = self._get_build_custom_buttons()
|
||||||
|
|
||||||
# Emoji-Zahlen für bis zu 10 Räume
|
# P0-1: build_button_attachments aus gemeinsamem Modul nutzen
|
||||||
EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]
|
from archivar.button_builder import build_button_attachments, EMOJI_NUMBERS
|
||||||
|
|
||||||
lines = [
|
lines = [
|
||||||
"🤖 **Auto-Onboarding** — Ich habe Räume gefunden, die noch nicht in meiner Raum-Map stehen.",
|
"🤖 **Auto-Onboarding** — Ich habe Räume gefunden, die noch nicht in meiner Raum-Map stehen.",
|
||||||
@@ -4667,27 +4667,28 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
lines.append("👉 Klicke auf eine Nummer, um den Raum einzurichten:")
|
lines.append("👉 Klicke auf eine Nummer, um den Raum einzurichten:")
|
||||||
text = "\n".join(lines)
|
text = "\n".join(lines)
|
||||||
|
|
||||||
# Raum-Buttons: blaue Nummern (style='primary')
|
# Raum-Buttons via build_button_attachments (3er-Chunking)
|
||||||
buttons = []
|
num_buttons = []
|
||||||
for i, room in enumerate(missing_rooms):
|
for room in missing_rooms:
|
||||||
rid = room["room_id"]
|
rid = room["room_id"]
|
||||||
emoji = EMOJI_NUMBERS[i] if i < len(EMOJI_NUMBERS) else f"{i+1}."
|
clean_name = room["name"].lstrip("#")
|
||||||
prefix = f"ONBOARD:{rid}"
|
num_buttons.append((clean_name, f"ONBOARD:{rid}"))
|
||||||
buttons.extend(_build(
|
|
||||||
[emoji],
|
|
||||||
prefix=prefix,
|
|
||||||
style="primary"
|
|
||||||
))
|
|
||||||
|
|
||||||
# Globale Buttons (style='default' = grau)
|
special_buttons = [
|
||||||
buttons.extend(_build(
|
("⏭️ Alle überspringen", "ONBOARD", "default"),
|
||||||
["⏭️ Alle überspringen", "⏰ Später"],
|
("⏰ Später", "ONBOARD", "default"),
|
||||||
prefix="ONBOARD"
|
]
|
||||||
))
|
|
||||||
|
attachments = build_button_attachments(
|
||||||
|
num_buttons,
|
||||||
|
special_buttons,
|
||||||
|
color="#1d74f5",
|
||||||
|
title="Raum-Map unvollständig — Räume einrichten?",
|
||||||
|
)
|
||||||
|
|
||||||
# Bug 3 fix: Wenn keine Buttons gebaut werden konnten, sende als Text
|
# Bug 3 fix: Wenn keine Buttons gebaut werden konnten, sende als Text
|
||||||
# mit klarer Anleitung (Fallback, sollte nie eintreten)
|
# mit klarer Anleitung (Fallback, sollte nie eintreten)
|
||||||
if not buttons:
|
if not attachments:
|
||||||
logger.error("[rocketchat] Onboarding: Konnte keine Buttons bauen — sende Text-Fallback")
|
logger.error("[rocketchat] Onboarding: Konnte keine Buttons bauen — sende Text-Fallback")
|
||||||
fallback_lines = lines + [
|
fallback_lines = lines + [
|
||||||
"",
|
"",
|
||||||
@@ -4696,15 +4697,9 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
await self._post_message_with_retry(operator_room_id, "\n".join(fallback_lines))
|
await self._post_message_with_retry(operator_room_id, "\n".join(fallback_lines))
|
||||||
return
|
return
|
||||||
|
|
||||||
attachments = [{
|
|
||||||
"color": "#1d74f5",
|
|
||||||
"title": "Raum-Map unvollständig — Räume einrichten?",
|
|
||||||
"actions": buttons,
|
|
||||||
}]
|
|
||||||
|
|
||||||
success = await self._post_message_with_retry(operator_room_id, text, attachments=attachments)
|
success = await self._post_message_with_retry(operator_room_id, text, attachments=attachments)
|
||||||
if success:
|
if success:
|
||||||
logger.info("[rocketchat] Onboarding v2 gestartet: %d Räume fehlen, %d Buttons", len(missing_rooms), len(buttons))
|
logger.info("[rocketchat] Onboarding v2 gestartet: %d Räume fehlen, %d Buttons", len(missing_rooms), sum(len(a.get("actions", [])) for a in attachments))
|
||||||
else:
|
else:
|
||||||
logger.error("[rocketchat] Fehler beim Senden der Onboarding-Nachricht")
|
logger.error("[rocketchat] Fehler beim Senden der Onboarding-Nachricht")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
"""
|
||||||
|
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 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[str, str]],
|
||||||
|
special_buttons: List[Tuple[str, str, str]],
|
||||||
|
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
|
||||||
|
|
||||||
|
Args:
|
||||||
|
num_buttons: Liste von (label, prefix) Tuples für nummerierte Buttons
|
||||||
|
special_buttons: Liste von (label, prefix, style) Tuples für Sonderschaltflächen
|
||||||
|
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, (label, prefix) in enumerate(chunk):
|
||||||
|
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": prefix,
|
||||||
|
"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 label, prefix, style in special_buttons:
|
||||||
|
special_actions.append({
|
||||||
|
"type": "button",
|
||||||
|
"text": label,
|
||||||
|
"msg": prefix,
|
||||||
|
"msg_in_chat_window": True,
|
||||||
|
"style": style,
|
||||||
|
})
|
||||||
|
attachments.append({
|
||||||
|
"color": color,
|
||||||
|
"actions": special_actions,
|
||||||
|
})
|
||||||
|
|
||||||
|
return attachments
|
||||||
@@ -154,85 +154,10 @@ def _persist_room_map_changes(
|
|||||||
|
|
||||||
|
|
||||||
# ── UX REFACTOR: build_button_attachments() Helper ──────────────────────────
|
# ── UX REFACTOR: build_button_attachments() Helper ──────────────────────────
|
||||||
|
# P0-1: In gemeinsames Modul button_builder.py extrahiert,
|
||||||
|
# damit adapter.py und onboarding_review.py die GLEICHE Button-Konstruktion nutzen.
|
||||||
|
|
||||||
# Emoji-Nummern für bis zu 10 Buttons
|
from archivar.button_builder import build_button_attachments, EMOJI_NUMBERS
|
||||||
_EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]
|
|
||||||
|
|
||||||
|
|
||||||
def build_button_attachments(
|
|
||||||
num_buttons: List[Tuple[str, str]],
|
|
||||||
special_buttons: List[Tuple[str, str, str]],
|
|
||||||
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
|
|
||||||
|
|
||||||
Args:
|
|
||||||
num_buttons: Liste von (label, prefix) Tuples für nummerierte Buttons
|
|
||||||
special_buttons: Liste von (label, prefix, style) Tuples für Sonderschaltflächen
|
|
||||||
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, (label, prefix) in enumerate(chunk):
|
|
||||||
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": prefix,
|
|
||||||
"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 label, prefix, style in special_buttons:
|
|
||||||
special_actions.append({
|
|
||||||
"type": "button",
|
|
||||||
"text": label,
|
|
||||||
"msg": prefix,
|
|
||||||
"msg_in_chat_window": True,
|
|
||||||
"style": style,
|
|
||||||
})
|
|
||||||
attachments.append({
|
|
||||||
"color": color,
|
|
||||||
"actions": special_actions,
|
|
||||||
})
|
|
||||||
|
|
||||||
return attachments
|
|
||||||
|
|
||||||
|
|
||||||
# ── Schritt 1: review_room Top-Level Renderer ─────────────────────────────
|
# ── Schritt 1: review_room Top-Level Renderer ─────────────────────────────
|
||||||
@@ -297,7 +222,7 @@ def render_review_room_step(
|
|||||||
# Nummerierte Optionen im Text
|
# Nummerierte Optionen im Text
|
||||||
lines.append("👉 Klicke auf einen Raum zum Anpassen:")
|
lines.append("👉 Klicke auf einen Raum zum Anpassen:")
|
||||||
for i, (label, _) in enumerate(num_buttons):
|
for i, (label, _) in enumerate(num_buttons):
|
||||||
emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1)
|
emoji = EMOJI_NUMBERS[i] if i < len(EMOJI_NUMBERS) else str(i + 1)
|
||||||
lines.append(f" {emoji} {label}")
|
lines.append(f" {emoji} {label}")
|
||||||
|
|
||||||
# Sonderschaltflächen
|
# Sonderschaltflächen
|
||||||
@@ -702,7 +627,7 @@ def render_review_room_add_new(
|
|||||||
name = room.get("name", rid)
|
name = room.get("name", rid)
|
||||||
rtype = room.get("type", "c")
|
rtype = room.get("type", "c")
|
||||||
type_label = "💬" if rtype == "d" else "#"
|
type_label = "💬" if rtype == "d" else "#"
|
||||||
emoji = _EMOJI_NUMBERS[i] if i < len(_EMOJI_NUMBERS) else str(i + 1)
|
emoji = EMOJI_NUMBERS[i] if i < len(EMOJI_NUMBERS) else str(i + 1)
|
||||||
lines.append(f" {emoji} {type_label} {name}")
|
lines.append(f" {emoji} {type_label} {name}")
|
||||||
# Kurzer Button-Name (max 9 Zeichen)
|
# Kurzer Button-Name (max 9 Zeichen)
|
||||||
short_name = name[:9] if len(name) > 9 else name
|
short_name = name[:9] if len(name) > 9 else name
|
||||||
|
|||||||
Reference in New Issue
Block a user