# Hermes Rocket.Chat Plugin > Bidirectional real-time messaging between Hermes Agent and self-hosted Rocket.Chat servers. > Zero external dependencies β€” uses WebSocket/DDP + REST API. **⚠️ Community Add-on β€” not an official Nous Research product.** This plugin is maintained independently. Use at your own risk. See [LICENSE](LICENSE). --- ## Features ### Core Messaging - 🟒 **Real-time messaging** via DDP/WebSocket (`stream-room-messages`) - 🟒 **Online presence** β€” Green dot via DDP `UserPresence` - ♻️ **Auto-reconnect** with exponential backoff - 🌍 **Bilingual installer** β€” German & English (`--lang de|en`) ### Interactive Buttons (Button-Garantie) - πŸ’¬ **Native Rocket.Chat Action Buttons** β€” All user interactions use clickable buttons, never raw text input - 🎯 **Button-Garantie (Button Guarantee):** REST-Path first, text fallback only on HTTP error. Every clarify prompt, every move request, every multi-choice question uses native buttons - πŸ“‹ **Built-in templates:** `yes_no`, `confirm_cancel`, `ok`, `multi_choice_3`, `custom` - πŸ”— **`question_id::choice` correlation** β€” Button clicks return structured payloads the agent can resolve - πŸ“ **Desktop-safe labels** β€” Emoji+text pattern (βœ…Ja, ❌Nein) with ~7 char truncation awareness ### Smart Room Routing (Archivar v4) - 🧭 **LLM-based room router** β€” Determines the TARGET ROOM directly, not an intent category. The LLM receives the full message text + room list with keywords and returns the room ID. - ⚑ **2-stage pipeline:** Embedding pre-filter (nomic-embed-text, <100ms) β†’ LLM room router (qwen2.5:7b, ~2.4s median) - 🎯 **Keywords as anchors** β€” Room-specific keywords in the LLM prompt give precise hints. "RC" at the end of a sentence is recognized. - πŸ›‘οΈ **Butler principle** β€” Before routing: Move-Request button (βœ…Ja / πŸ“Hier). The human decides, never the machine. - πŸ’° **Zero DeepSeek tokens for routing** β€” The entire routing process runs on local models (nomic-embed-text + qwen2.5:7b). DeepSeek only receives the final answer context. - ⏱️ **Timeout & fallback:** 10s LLM timeout (covers cold starts up to 7.8s). Fallback: CATCH_ALL room. **No answer is not an option.** - 🏠 **Catch-All room** β€” Unclassified messages land in a designated fallback room, not lost - πŸ“Š **Operating stage log:** `Archivar Stufe 1: Embedding-Vorfilter + LLM-Raum-Router aktiv (5 RΓ€ume)` ### Auto-Onboarding - πŸ†• **New rooms auto-detected** β€” When the bot is added to a new channel/group/DM, it starts an onboarding interview - πŸ“ **Room-map.json** β€” Persistent room configuration (names, topics, keywords, sticky status) - πŸ”‘ **`#Name =` parser** β€” Users set room names inline during onboarding ### Knowledge Integration (FAKT) - πŸ“š **FAKT β†’ Obsidian Vault** β€” Pure facts (documentation, not communication) are automatically saved to the user's Obsidian Vault inbox - πŸ—‚οΈ **`StartObsidian` workflow** β€” Morning routine processes FAKT files into themed documents via WikiLinks - 🚫 **No chat-room pollution** β€” Facts never appear in chat rooms; they go straight to the knowledge base ### File Attachments - πŸ“Ž **Upload** (`rocketchat_upload`) β€” Send files to any room with native Rocket.Chat rendering - πŸ“₯ **Download** (`rocketchat_download`) β€” Retrieve files users attach to messages - πŸ“‹ **List** (`rocketchat_files`) β€” Browse all files in a room ### REST Tools (7 total) | Tool | Function | |------|----------| | `rocketchat_rooms` | List, create, archive, delete rooms; invite/kick users; fetch history | | `rocketchat_users` | List all users, get user info, search by name | | `rocketchat_dm` | Open or send direct messages | | `rocketchat_send` | Send messages with optional interactive buttons | | `rocketchat_upload` | Upload files with message and description | | `rocketchat_download` | Download files by ID | | `rocketchat_files` | List files in a room with pagination | ### Multi-Room Architecture - 🌐 **One agent, all rooms, one memory** β€” The agent maintains a single context across all subscribed rooms - 🧠 **Shared session** β€” Knowledge from one room is available in all others - 🎯 **Virtual chat IDs** β€” `user:alice` collapses all of Alice's rooms into one Hermes session - πŸ”€ **Butler principle** β€” The agent suggests, the human decides. Nothing is silently rerouted --- ## Quick Install ```bash git clone https://gitea.myowntools.org/andreas/Hermes_rocket.chat_Plugin.git cd Hermes_rocket.chat_Plugin ./install.sh ``` The installer will ask for: - Rocket.Chat server URL - Bot username (the bot account on your Rocket.Chat server) - Bot password - Home channel (name or room ID) **After installation:** The gateway will output a pairing code β€” enter it in your home channel to activate the bot. ### Options ``` ./install.sh --help # Show all options ./install.sh --lang en # English ./install.sh --lang de # German (default) ./install.sh --non-interactive # Batch mode (reads from env vars) ./install.sh --update-only # Update plugin files without reconfiguring ``` --- ## Architecture ``` Rocket.Chat Server ↕ WebSocket/DDP + REST Hermes Gateway (plugin) β”œβ”€β”€ adapter.py β€” DDP client, message routing, button handling β”œβ”€β”€ __init__.py β€” Plugin registration, button builders β”œβ”€β”€ tools.py β€” 7 REST API tools └── archivar/ β€” Smart room routing subsystem β”œβ”€β”€ classifier.py β€” Embedding pre-filter (nomic-embed-text) β”œβ”€β”€ router.py β€” LLM-based room router (qwen2.5:7b) β”œβ”€β”€ config.py β€” LLM_ROOM_PROMPT, thresholds, room-map β”œβ”€β”€ room_map.py β€” Room-map.json loader + keyword matching β”œβ”€β”€ doc_store.py β€” FAKT β†’ Obsidian Vault integration └── adapter_integration.py β€” Archivar ↔ Adapter bridge ↕ Hermes Agent ← β†’ LLM inference ``` The plugin registers as `rocketchat-platform` in Hermes' plugin path. **Deployment note:** The gateway loads from `~/.hermes/hermes-agent/plugins/platforms/rocketchat/`. The `install.sh` copies files there. A secondary path at `/usr/local/lib/hermes-agent/plugins/platforms/rocketchat/` exists for system-wide installs but is not the active path for user-level gateway runs. --- ## Interactive Buttons The plugin supports native Rocket.Chat Action Buttons. The agent sends them via `send_message` with metadata: ```python send_message( target="rocketchat:protonbridge", text="Proceed?", metadata={ "template": "custom", "question_id": "confirm_42", "button_title": "Choose:", "custom_buttons": ["βœ…Ja", "❌Nein"] } ) ``` User click returns: `confirm_42::βœ…Ja` ### Built-in Templates | Template | Buttons | Use Case | |----------|---------|----------| | `yes_no` | βœ…Ja / ❌Nein | Binary decisions | | `confirm_cancel` | βœ…BestΓ€tigen / 🚫Abbrechen | Destructive actions | | `ok` | πŸ‘OK | Acknowledgement | | `multi_choice_3` | 1. Links / 2. Rechts / 3. Zwei Runden | Directional choices | | `custom` | User-defined | Any multi-choice scenario | ### Button Label Rules 1. **NO underscores (`_`)** β€” destroys button rendering completely 2. **Desktop truncation at ~7 chars** β€” first 7 characters must be distinguishable 3. **Mobile shows full text** β€” but design for desktop-first 4. **Spaces ARE allowed** β€” `1. Links` works; `1._Links` breaks 5. **Emoji+Text pattern preferred:** `βœ…Ja`, `❌Nein`, `🟑SpΓ€ter` See [docs/BUTTON_GUIDE.md](docs/BUTTON_GUIDE.md) for full details. --- ## Environment Variables Set in `~/.hermes/.env` (generated by install.sh): ```bash ROCKETCHAT_BASE_URL=rocketchat.thomander.de # WITHOUT https:// prefix! ROCKETCHAT_USER=botuser ROCKETCHAT_PASSWORD=... ``` > ⚠️ **Important:** `ROCKETCHAT_BASE_URL` must NOT include the protocol (`https://`). The DDP client prepends `wss://` automatically. Including `https://` causes `getaddrinfo ENOTFOUND https` and the gateway will crash-loop. ### Optional: Archivar LLM Stage ```bash ARCHIVAR_ENABLE_LLM=1 # Enable LLM stage for borderline classifications ``` Requires `qwen2.5:7b` pulled via Ollama (~4.7 GB). Without this, the Archivar runs in 2-stage mode (Keyword + Embedding only). --- ## Requirements - Hermes Agent installed and running - Self-hosted Rocket.Chat server (v5+) - Bot user account on the Rocket.Chat server with `bot` role - Python 3.10+ (hermes-agent venv) - **Optional:** `nomic-embed-text` via Ollama for embedding-based routing - **Optional:** `qwen2.5:7b` via Ollama for LLM-based routing (set `ARCHIVAR_ENABLE_LLM=1`) --- ## Room Routing β€” How It Works ### The Archivar (v4) The Archivar is a **thematic room router**, not a category classifier. It answers: "Which room does this message belong in?" β€” not "Is this a fact, question, or alarm?" **2-stage pipeline:** | Stage | Method | Speed | Role | |-------|--------|-------|------| | 0 | Embedding pre-filter (nomic-embed-text, 768-dim) | <100ms | Binary: Smalltalk β†’ stay. Everything else β†’ LLM router | | 1 | LLM room router (qwen2.5:7b) | ~2.4s median | Full message + room list + keywords β†’ room ID | **The LLM receives:** - The complete message text - All available rooms with their IDs, names, and keywords - Keywords act as anchors β€” "RC" at the end of a sentence is recognized **The LLM returns:** A single room ID (or `CATCH_ALL`). No categories, no fuzzy matching. **Routing decisions:** | Scenario | Behavior | |----------|----------| | **Smalltalk / greeting** | Embedding pre-filter catches it β†’ stays in origin room | | **Clear topic match** | LLM returns room ID β†’ Move-Request button (βœ…Ja / πŸ“Hier) | | **User clicks βœ…Ja** | Message copied to target room. Agent answers there. | | **User clicks πŸ“Hier** | No routing. Answer stays in origin room. | | **No clear match** | LLM returns CATCH_ALL β†’ falls to designated catch-all room | | **LLM timeout (10s)** | Automatic fallback to CATCH_ALL. **No answer is not an option.** | ### Zero Token Cost for Routing The entire routing process runs on **local models** (nomic-embed-text + qwen2.5:7b). Your primary LLM (DeepSeek, Claude, etc.) receives only the final answer context β€” it never spends tokens on figuring out where to reply. ### Butler Principle The agent **suggests**, the human **decides**. Before any routing, a Move-Request button appears. Nothing is silently rerouted. --- ## Troubleshooting | Symptom | Cause | Fix | |---------|-------|-----| | Gateway shows `No adapter available for rocketchat` | Plugin loading failed β€” missing `plugin.yaml` or `__init__.py` in plugin path, or ImportError in plugin code | Check `~/.hermes/hermes-agent/plugins/platforms/rocketchat/` has both files. Clear `__pycache__`. Check `journalctl --user -u hermes-gateway` for import errors. | | Gateway loses Rocket.Chat after restart (Discovery Bug) | `gateway_state.json` corruption after SIGTERM | `rm ~/.hermes/gateway_state.json ~/.hermes/.gateway_state_*.tmp && systemctl --user reset-failed hermes-gateway && systemctl --user start hermes-gateway` | | Gateway crash-loops after restart | Auto-resume of interrupted sessions | Same fix as Discovery Bug β€” clearing state files also clears interrupted session markers | | `getaddrinfo ENOTFOUND https` | `ROCKETCHAT_BASE_URL` contains `https://` prefix | Remove the protocol: `rocketchat.thomander.de` (not `https://rocketchat.thomander.de`) | | Buttons show as text options instead of native buttons | Old plugin version in `~/.hermes/...` path, or stale `__pycache__` | `cp` updated `adapter.py` to `~/.hermes/hermes-agent/plugins/platforms/rocketchat/`, clear `__pycache__`, restart gateway | | `Built user-room map: 0 users` after restart | Timing: user-map built before DDP fully connected | Usually self-heals on next message. If persistent, restart gateway with state-file cleanup. | | `install.sh --update-only` deploys to wrong path | `install.sh` targets `/usr/local/lib/...` but gateway loads from `~/.hermes/...` | Manually `cp` to `~/.hermes/hermes-agent/plugins/platforms/rocketchat/` after install. Don is fixing `install.sh`. | | Plugin import fails after code changes | Stale `.pyc` bytecode in `__pycache__/` | `find ~/.hermes/hermes-agent/plugins/platforms/rocketchat -name '__pycache__' -type d -exec rm -rf {} +` | --- ## Known Limitations - **Desktop button truncation:** Rocket.Chat desktop app truncates button labels at ~7 characters. Use short emoji+text labels. - **Gateway Discovery Bug:** After SIGTERM, the gateway may lose the Rocket.Chat platform. Workaround: clear state files before restart. Root cause in Hermes Core β€” not fixable in the plugin. - **`install.sh` path mismatch:** Currently deploys to `/usr/local/lib/...` but the user-level gateway loads from `~/.hermes/...`. Manual `cp` needed after `--update-only`. Being fixed. - **User-Map timing:** After cold start, user-room map may show 0 users briefly. Self-heals on first message. - **No multi-user bot support:** One bot user = one agent session. Multiple bot users on the same server are not tested. --- ## Project Status **Active development.** Current focus: Archivar v4 stabilization, install.sh path fix. | Component | Status | |-----------|--------| | DDP/WebSocket messaging | βœ… Production | | REST API tools (7) | βœ… Production | | Interactive buttons | βœ… Production | | Archivar v4 (LLM room router) | βœ… Deployed (2026-06-14) | | Button-Garantie | βœ… Enforced (2026-06-12) | | Move-Request buttons | βœ… Native (2026-06-12) | | Auto-Onboarding | βœ… Production | | FAKT β†’ Obsidian Vault | βœ… Production | | File attachments | βœ… Production | | `install.sh` path fix | πŸ”§ In progress (Don) | --- ## License [Unlicense](LICENSE) β€” Public Domain. See [LICENSE](LICENSE).