fix: Underscores aus Button-Texten entfernt + custom-Template hinzugefügt
- multi_choice_3: '1._Links' → '1. Links' etc. (Underscores zerstören RC-Rendering) - custom-Template fehlte in Gitea-Version → hinzugefügt - plugin.yaml: ROCKETCHAT_ROOM_ID env var dokumentiert
This commit is contained in:
+45
-29
@@ -11,7 +11,7 @@ import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# ── Interaction Templates ──
|
||||
# ── Interaction Templates (source of truth — zero yaml dependency) ──
|
||||
_TEMPLATE_MAP = {
|
||||
"yes_no": {
|
||||
"label": "Ja/Nein",
|
||||
@@ -41,47 +41,64 @@ _TEMPLATE_MAP = {
|
||||
},
|
||||
"multi_choice_3": {
|
||||
"label": "3 Optionen",
|
||||
"description": "Three choices",
|
||||
"attachment": {"color": "#1d74f5", "title": "Bitte wählen:"},
|
||||
"description": "Three-option selection",
|
||||
"attachment": {"color": "#1d74f5", "title": "Wähle eine Option:"},
|
||||
"buttons": [
|
||||
{"text": "1. Links", "msg": "1. Links"},
|
||||
{"text": "2. Rechts", "msg": "2. Rechts"},
|
||||
{"text": "3. Zwei Runden", "msg": "3. Zwei Runden"},
|
||||
{"text": "1._Links", "msg": "links", "style": "default"},
|
||||
{"text": "2._Rechts", "msg": "rechts", "style": "default"},
|
||||
{"text": "3._Zwei_Runden", "msg": "zwei_runden", "style": "default"},
|
||||
],
|
||||
},
|
||||
"custom": {
|
||||
"label": "Custom",
|
||||
"description": "User-defined buttons",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def check_requirements(config=None):
|
||||
"""Validate that required env vars are set."""
|
||||
required = ["ROCKETCHAT_BASE_URL", "ROCKETCHAT_USER", "ROCKETCHAT_PASSWORD"]
|
||||
missing = [v for v in required if not os.environ.get(v)]
|
||||
return len(missing) == 0, f"Missing env: {', '.join(missing)}" if missing else "Ready"
|
||||
def _build_custom_buttons(labels: list, prefix: str = "") -> list:
|
||||
"""Build Rocket.Chat action buttons from plain label strings.
|
||||
|
||||
Rocket.Chat UI truncates button text after ~11-12 chars.
|
||||
Use short labels (emoji+text without spaces, or numbered refs).
|
||||
"""
|
||||
buttons = []
|
||||
for idx, label in enumerate(labels):
|
||||
# Sanitize label for button text (keep short)
|
||||
display = label.strip()
|
||||
# Payload may carry question_id prefix for correlation
|
||||
msg_payload = display
|
||||
if prefix:
|
||||
msg_payload = f"{prefix}::{msg_payload}"
|
||||
buttons.append({
|
||||
"type": "button",
|
||||
"text": display,
|
||||
"msg": msg_payload,
|
||||
"msg_in_chat_window": True,
|
||||
"style": "default",
|
||||
})
|
||||
return buttons
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
"""Validate platform-specific config."""
|
||||
return True, "OK"
|
||||
def check_requirements():
|
||||
"""Rocket.Chat adapter uses only stdlib (urllib, socket, ssl, threading)."""
|
||||
return True
|
||||
|
||||
|
||||
def is_connected(adapter):
|
||||
"""Check if the adapter has an active connection."""
|
||||
if adapter is None:
|
||||
return False
|
||||
return getattr(adapter, "_running", False)
|
||||
def validate_config(config) -> bool:
|
||||
"""Check whether the platform is properly configured."""
|
||||
extra = getattr(config, "extra", {}) or {}
|
||||
base_url = os.getenv("ROCKETCHAT_BASE_URL") or extra.get("base_url", "")
|
||||
user = os.getenv("ROCKETCHAT_USER") or extra.get("user", "")
|
||||
password = os.getenv("ROCKETCHAT_PASSWORD") or extra.get("password", "")
|
||||
return bool(base_url and user and password)
|
||||
|
||||
|
||||
def is_connected(config) -> bool:
|
||||
"""Check whether Rocket.Chat is configured (env or config.yaml)."""
|
||||
return validate_config(config)
|
||||
|
||||
|
||||
def register(ctx):
|
||||
"""Plugin entry point — called by the Hermes plugin system at startup."""
|
||||
from .adapter import RocketChatAdapter # lazy import avoids circular deps
|
||||
try:
|
||||
from .tools import register_tools
|
||||
except ImportError:
|
||||
register_tools = None
|
||||
from .tools import register_tools
|
||||
|
||||
ctx.register_platform(
|
||||
name="rocketchat",
|
||||
@@ -106,5 +123,4 @@ def register(ctx):
|
||||
),
|
||||
)
|
||||
|
||||
if register_tools is not None:
|
||||
register_tools(ctx)
|
||||
register_tools(ctx)
|
||||
|
||||
@@ -11,6 +11,9 @@ requires_env:
|
||||
- ROCKETCHAT_BASE_URL
|
||||
- ROCKETCHAT_USER
|
||||
- ROCKETCHAT_PASSWORD
|
||||
- name: ROCKETCHAT_ROOM_ID
|
||||
description: "Default room/channel ID to subscribe (optional if auto-discovery enabled)"
|
||||
required: false
|
||||
- name: ROCKETCHAT_ALLOW_ALL_USERS
|
||||
description: "Set to 'true' to allow all users (default: false = allowlist)"
|
||||
required: false
|
||||
|
||||
Reference in New Issue
Block a user