Skip to content

Telegram integration + Herramientas (external connectors) section - #9

Merged
TraX22 merged 2 commits into
mainfrom
feature/telegram-integration
Aug 20, 2026
Merged

Telegram integration + Herramientas (external connectors) section#9
TraX22 merged 2 commits into
mainfrom
feature/telegram-integration

Conversation

@TraX22

@TraX22 TraX22 commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Telegram integration + "Herramientas" (external connectors) section

Drive the HydraOps agents from a phone via a Telegram bot, and add a new
Herramientas section in the sidebar (below Add-ons) for connectors toward
external services (Telegram now; GitHub/Discord/Signal/Reddit shown as
coming-soon). Conceptually: Add-ons = tools the agents call; Herramientas =
connectors that operate on HydraOps from the outside.

How it works

  • Send to an agent = POST /api/tasks with channel = <agentId> (deterministic
    routing in the orchestrator). Reply = poll GET /api/tasks/:id until completed
    (no SSE/WebSocket in the stack). Loopback is auth-exempt, so no token needed.

Backend

  • New service apps/telegram-bot (mirrors outbox-worker): long-polls the
    Telegram Bot API with native fetch (no telegram library), relays messages to
    agents, polls the task, and sends the reply back. Heartbeats to worker_status;
    hot-reloads config so enabling/disabling and token changes take effect without a
    restart. Registered in KNOWN_SERVICES, the desktop services supervisor
    (phase 2), and the backend bundler.
  • Transport-agnostic command layer (telegram-bot/src/commands/): agents,
    use, help, whoami, one-off /<agentId> <msg>, and active-agent fallback —
    decoupled from Telegram so a future global command system can reuse it as a
    shared package. /use <id> <message> switches and sends in one step.
  • Access control: allowlist of Telegram user ids + pairing code (/start <code>).
  • Secrets: the bot token is stored in the key store via PROVIDER_KEY_NAMES +
    envMapping (telegramBotToken), never DB/.env; masked in GET /config.
    Non-secret config in system_configs.telegram_config. New
    GET/POST /system/integrations/telegram (report tokenConfigured without the value).
  • Telegram replies use parse_mode: HTML so fenced code renders as a real code
    frame; POST /tasks accepts isRead so bot tasks show unread activity in the app.

Frontend

  • New Herramientas view + route + sidebar entry. Telegram card: enable toggle,
    token field (reuses the key-store save flow), default-agent picker, pairing code,
    allowlist editor; plus coming-soon placeholders. i18n in all 5 locales.
  • Chat code blocks: fenced code now renders as a framed dark block with a
    language label, a copy button, and syntax highlighting via prismjs
    (already a dependency). Styles live in the global sheet because the markdown is
    injected via [innerHTML]; Prism is put on the global eagerly in main.ts so
    its language components load under esbuild.
  • Scroll-to-bottom button centered.

Verified end-to-end (live)

  • Pairing (/start <code>), /agents, /elena …, /use sofia <msg> → real agent
    replies back to Telegram; token stays in the key store (.env/DB show proxy).
  • App chat code blocks: frame, One Dark highlighting, and copy button confirmed via
    a headless browser (copy writes the code to the clipboard).

Out of scope (follow-ups): proactive push notifications (bot messages you when a
task/cron completes), attachments/voice, and the other connectors.

TraX22 added 2 commits August 19, 2026 10:33
Add a Telegram bot to drive the agents from a phone, and a new 'Herramientas'
sidebar section (below Add-ons) to host external connectors (Telegram now;
GitHub/Discord/Signal/Reddit shown as coming-soon).

Backend
- New apps/telegram-bot service (mirrors outbox-worker): long-polls the Telegram
  Bot API with native fetch (no telegram lib), relays messages to agents via
  POST /api/tasks (channel = agent id → deterministic orchestrator routing) and
  polls the task for the reply. Heartbeats to worker_status; hot-reloads config
  so enable/disable and token changes take effect without a restart.
- Transport-agnostic command layer in telegram-bot/src/commands (agents/use/help/
  whoami + one-off /<agentId> + active-agent fallback), decoupled from Telegram
  so a future global command system can reuse it as a shared package.
- Access control: allowlist of Telegram user ids + pairing code (/start <code>).
- Config: bot token is a secret → key store via PROVIDER_KEY_NAMES + envMapping
  (telegramBotToken), never DB/.env; non-secret config in system_configs
  (telegram_config). New GET/POST /system/integrations/telegram endpoints
  (report tokenConfigured without the value). Registered in KNOWN_SERVICES,
  desktop services supervisor (phase 2), and the backend bundler.

Frontend
- New Herramientas view + route + sidebar entry (icon 'tools', below Add-ons).
- Telegram card: enable toggle, token field (reuses the key-store save flow),
  default-agent picker, pairing code, allowlist editor.
- ApiService: TelegramIntegration type + get/saveTelegramIntegration, plus
  telegramBotToken on AppConfig. i18n for nav + herramientas namespace in 5 locales.
…ighlight

Telegram bot
- Send replies with parse_mode HTML so fenced code renders as a real code frame;
  new toTelegramHtml() converts markdown code to <pre><code>, HTML-escapes the
  rest, chunks under the size limit with a plain-text fallback on malformed HTML.
- /use <id> <message> now switches AND sends that first message in one go.
- Bot-created tasks post isRead:false so the agent shows unread activity in the
  app until the user opens that chat (POST /tasks honors an isRead flag).
- Log relayed messages and agent replies for observability.

App chat
- Render fenced code as a framed, dark code block (global styles, since the
  markdown is injected via [innerHTML] and can't be reached by scoped rules).
- Syntax highlighting via prismjs (already a dependency); Prism is put on the
  global eagerly in main.ts so language components load under esbuild.
- Per-block copy button with language label (event delegation in the chat view).
- Center the scroll-to-bottom button.
@TraX22
TraX22 merged commit ad41715 into main Aug 20, 2026
3 checks passed
@TraX22
TraX22 deleted the feature/telegram-integration branch August 20, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant