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:
+43
-27
@@ -11,7 +11,7 @@ import os
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# ── Interaction Templates ──
|
# ── Interaction Templates (source of truth — zero yaml dependency) ──
|
||||||
_TEMPLATE_MAP = {
|
_TEMPLATE_MAP = {
|
||||||
"yes_no": {
|
"yes_no": {
|
||||||
"label": "Ja/Nein",
|
"label": "Ja/Nein",
|
||||||
@@ -41,47 +41,64 @@ _TEMPLATE_MAP = {
|
|||||||
},
|
},
|
||||||
"multi_choice_3": {
|
"multi_choice_3": {
|
||||||
"label": "3 Optionen",
|
"label": "3 Optionen",
|
||||||
"description": "Three choices",
|
"description": "Three-option selection",
|
||||||
"attachment": {"color": "#1d74f5", "title": "Bitte wählen:"},
|
"attachment": {"color": "#1d74f5", "title": "Wähle eine Option:"},
|
||||||
"buttons": [
|
"buttons": [
|
||||||
{"text": "1. Links", "msg": "1. Links"},
|
{"text": "1._Links", "msg": "links", "style": "default"},
|
||||||
{"text": "2. Rechts", "msg": "2. Rechts"},
|
{"text": "2._Rechts", "msg": "rechts", "style": "default"},
|
||||||
{"text": "3. Zwei Runden", "msg": "3. Zwei Runden"},
|
{"text": "3._Zwei_Runden", "msg": "zwei_runden", "style": "default"},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"custom": {
|
|
||||||
"label": "Custom",
|
|
||||||
"description": "User-defined buttons",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def check_requirements(config=None):
|
def _build_custom_buttons(labels: list, prefix: str = "") -> list:
|
||||||
"""Validate that required env vars are set."""
|
"""Build Rocket.Chat action buttons from plain label strings.
|
||||||
required = ["ROCKETCHAT_BASE_URL", "ROCKETCHAT_USER", "ROCKETCHAT_PASSWORD"]
|
|
||||||
missing = [v for v in required if not os.environ.get(v)]
|
Rocket.Chat UI truncates button text after ~11-12 chars.
|
||||||
return len(missing) == 0, f"Missing env: {', '.join(missing)}" if missing else "Ready"
|
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):
|
def check_requirements():
|
||||||
"""Validate platform-specific config."""
|
"""Rocket.Chat adapter uses only stdlib (urllib, socket, ssl, threading)."""
|
||||||
return True, "OK"
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_connected(adapter):
|
def validate_config(config) -> bool:
|
||||||
"""Check if the adapter has an active connection."""
|
"""Check whether the platform is properly configured."""
|
||||||
if adapter is None:
|
extra = getattr(config, "extra", {}) or {}
|
||||||
return False
|
base_url = os.getenv("ROCKETCHAT_BASE_URL") or extra.get("base_url", "")
|
||||||
return getattr(adapter, "_running", False)
|
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):
|
def register(ctx):
|
||||||
"""Plugin entry point — called by the Hermes plugin system at startup."""
|
"""Plugin entry point — called by the Hermes plugin system at startup."""
|
||||||
from .adapter import RocketChatAdapter # lazy import avoids circular deps
|
from .adapter import RocketChatAdapter # lazy import avoids circular deps
|
||||||
try:
|
|
||||||
from .tools import register_tools
|
from .tools import register_tools
|
||||||
except ImportError:
|
|
||||||
register_tools = None
|
|
||||||
|
|
||||||
ctx.register_platform(
|
ctx.register_platform(
|
||||||
name="rocketchat",
|
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_BASE_URL
|
||||||
- ROCKETCHAT_USER
|
- ROCKETCHAT_USER
|
||||||
- ROCKETCHAT_PASSWORD
|
- 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
|
- name: ROCKETCHAT_ALLOW_ALL_USERS
|
||||||
description: "Set to 'true' to allow all users (default: false = allowlist)"
|
description: "Set to 'true' to allow all users (default: false = allowlist)"
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
Reference in New Issue
Block a user