TG Agent

Telegram automation for coding agents — Claude Code, OpenCode, Codex. Ships as a Claude Code plugin (skill + CLI): install the plugin and your agent can act on Telegram for you — read and send messages, manage channels and chats, download media, run LLM content pipelines. The content factory (collect → search → generate → publish) is one module among many.
Русская версия
How it works
- Skill + Claude Code plugin — this repo ships a skill (installed from the plugin marketplace, or copied manually) that teaches your agent the command catalog, the runtime model and safety rules. The skill drives the CLI — no MCP tool surface eating your context window.
tg-agent CLI — the product surface: ~250 commands covering the full Telegram spectrum (channel, dialogs, messages, search, pipeline, photo-loader, analytics, scheduler, account, …). Every command is a self-contained one-shot: it does the work and exits. No daemon required — without one, the command connects the account itself.
- Worker daemon (
tg-agent restart) — optional long-lived process for scheduled collection and queued sends. While it runs it owns every account's Telegram connection (one connection per account per machine): live commands (messages read --live, all dialogs actions, account info, search --mode telegram, pipeline run, …) run on the daemon's connection through a local relay (127.0.0.1, token file readable by the owner only) — same output, no second login, nothing queued. Collection hand-offs go to the daemon's queue and wake it at once. In gateway mode (tg-agent global enable) the shared gateway is that owner.
Upgrading to 0.2.5: restart a running daemon once (tg-agent restart), and the shared gateway if you use one (tg-agent gateway restart --shared) — an older daemon or gateway serves no relay, and live commands next to it fail at once with that hint. The web panel (serve, the optional tg-webui package) and the embedded agent chat (agent …; its interactive TUI is the optional tg-tui package) stay available as deprecated, optional surfaces. The stdio MCP bridge (mcp-server) and the Codex/ADK agent backends were removed in #1868.
Quick Start (coding agents)
Prerequisites
1. Install the plugin (Claude Code) — or the skill alone
/plugin marketplace add https://github.com/axisrow/tg_content_factory
/plugin install tg-agent@tg-agent-marketplace
The short form (axisrow/tg_content_factory) clones over SSH — without GitHub SSH keys it
fails; use the full HTTPS URL as above. If the marketplace is not visible right after
marketplace add, run /reload-plugins before plugin install.
OpenCode / Codex / other agents — skip the plugin: point the agent at skills/tg-agent/SKILL.md as an instruction file (AGENTS.md include, system-prompt attachment, etc.), or copy the skill folder:
cp -r skills/tg-agent ~/.claude/skills/tg-agent
2. Install the CLI
The skill drives the tg-agent CLI, which must be on the machine where your agent runs:
pip install tg-agent
Create .env in your working directory (auto-loaded by every command):
TG_API_ID=your_api_id
TG_API_HASH=your_api_hash
SESSION_ENCRYPTION_KEY=your_random_secret # required before adding/importing accounts
For several projects on one machine you can skip the per-project key copies:
store it once in the OS secret store with tg-agent key set (macOS Keychain /
Windows Credential Manager / secret-tool). An explicit SESSION_ENCRYPTION_KEY
still wins over the stored secret.
3. Authorize an account (interactive, once)
tg-agent account add
You will receive a Telegram login code — enter it yourself. Verify with tg-agent account list.
4. Just ask your agent
- "Show yesterday's posts from @durov"
- "Send this draft to my Saved Messages"
- "Collect new messages from my channels and find mentions of <keyword>"
Features