""" Rocket.Chat Platform Plugin for Hermes Agent. Registers a gateway platform adapter that connects to a self-hosted Rocket.Chat server via DDP/WebSocket (real-time incoming messages + presence) and REST API (outgoing replies). """ import logging import os logger = logging.getLogger(__name__) # ── Interaction Templates ── _TEMPLATE_MAP = { "yes_no": { "label": "Ja/Nein", "description": "Binary confirmation", "attachment": {"color": "#1d74f5", "title": "Bitte bestätigen:"}, "buttons": [ {"text": "✅ Ja", "msg": "ja", "style": "primary"}, {"text": "❌ Nein", "msg": "nein", "style": "danger"}, ], }, "confirm_cancel": { "label": "Bestätigen/Abbrechen", "description": "Safe action with abort", "attachment": {"color": "#1d74f5", "title": "Aktion bestätigen:"}, "buttons": [ {"text": "✅ Bestätigen", "msg": "bestätigen", "style": "primary"}, {"text": "🚫 Abbrechen", "msg": "abbrechen", "style": "danger"}, ], }, "ok": { "label": "OK", "description": "Single acknowledgement", "attachment": {"color": "#1d74f5", "title": "Hinweis:"}, "buttons": [ {"text": "👍 OK", "msg": "ok", "style": "primary"}, ], }, "multi_choice_3": { "label": "3 Optionen", "description": "Three choices", "attachment": {"color": "#1d74f5", "title": "Bitte wählen:"}, "buttons": [ {"text": "1. Links", "msg": "1. Links"}, {"text": "2. Rechts", "msg": "2. Rechts"}, {"text": "3. Zwei Runden", "msg": "3. Zwei Runden"}, ], }, "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 validate_config(config): """Validate platform-specific config.""" return True, "OK" def is_connected(adapter): """Check if the adapter has an active connection.""" if adapter is None: return False return getattr(adapter, "_running", False) 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 ctx.register_platform( name="rocketchat", label="Rocket.Chat", adapter_factory=lambda cfg: RocketChatAdapter(cfg), check_fn=check_requirements, validate_config=validate_config, is_connected=is_connected, required_env=["ROCKETCHAT_BASE_URL", "ROCKETCHAT_USER", "ROCKETCHAT_PASSWORD"], install_hint="No extra packages needed (stdlib only)", allowed_users_env="ROCKETCHAT_ALLOWED_USERS", allow_all_env="ROCKETCHAT_ALLOW_ALL_USERS", max_message_length=4000, emoji="🚀", pii_safe=False, allow_update_command=True, platform_hint=( "You are chatting via Rocket.Chat. You support markdown formatting: " "**bold**, *italic*, `inline code`, ```code blocks```, and [links](url). " "Messages can be up to ~4000 characters. You have a green online dot " "via DDP presence. Use professional but friendly tone." ), ) if register_tools is not None: register_tools(ctx)