| name | tg-cli |
| description | CLI skill for Telegram to sync chats, search messages, filter keywords, and monitor groups from the terminal |
| author | jackwener |
| version | 0.5.4 |
| tags | ["telegram","tg","chat","monitor","cli"] |
tg-cli Skill
CLI tool for Telegram — sync chats, search messages, filter keywords, send messages, and monitor groups.
Prerequisites
uv tool install kabi-tg-cli
uv tool upgrade kabi-tg-cli
Authentication
Uses your Telegram account (MTProto). Built-in Telegram Desktop API credentials are used by default — no application needed.
tg chats
tg whoami
export TG_API_ID=123456
export TG_API_HASH=your_telegram_app_hash
Command Reference
Telegram Operations
tg chats
tg chats --type group
tg status
tg status --yaml
tg whoami
tg whoami --yaml
tg history CHAT -n 1000
tg sync CHAT
tg sync-all
tg refresh
tg listen
tg listen --persist
tg info CHAT
tg send CHAT "Hello!"
Search & Query
tg search "Rust"
tg search "Rust" -c "牛油果" --yaml
tg search "Rust|Golang" --regex
tg search "Rust" --sync-first --yaml
tg recent --hours 24 -n 20 --yaml
tg recent --hours 24 --sync-first
tg filter "Rust,Golang,Java"
tg filter "招聘,remote" --hours 48
tg today --sync-first
tg stats --sync-first
tg top -c "牛油果" --hours 24 --sync-first
tg timeline --by hour --sync-first
Data Management
tg export CHAT -f json -o out.json
tg export CHAT --hours 24
tg purge CHAT -y
Structured Output
Major commands support --json and --yaml for machine-readable output.
AI agents should prefer --yaml unless a strict JSON parser is required:
tg search "Rust" --yaml
tg status --yaml
tg whoami --yaml
tg today --yaml
tg filter "招聘" --hours 48 --yaml
When stdout is not a TTY, tg-cli defaults to YAML automatically.
Use OUTPUT=yaml|json|rich|auto to override the default output mode.
All machine-readable output uses the envelope documented in SCHEMA.md.
Refresh Model
tg-cli is local-first. Query commands read from the local SQLite cache by default.
- Use
tg refresh as the normal entrypoint before analysis.
- Use
--sync-first when a single query should refresh before reading.
- Use
tg listen --persist if you want a near-real-time local cache.
- Keep
tg sync-all for lower-level scripts or schedulers.
Common Patterns for AI Agents
tg refresh --yaml
tg today --sync-first --yaml
tg filter "Rust,Golang" --hours 24 --sync-first --yaml
tg search "招聘" -n 100 --yaml > jobs.yaml
tg filter "远程,remote,Web3" --hours 72 --yaml > filtered.yaml
tg send "GroupName" "Hello from CLI!"
Debugging
tg -v sync-all
tg -v refresh
tg -v stats
Error Handling
- Commands exit with code 0 on success, non-zero on failure
- Error messages are prefixed with ✗ or shown in red
- Chat names are fuzzy-matched (partial name works)
refresh and sync-all gracefully skip chats that can't be found
Scheduling
Examples live in the repository:
examples/tg-refresh.cron
examples/systemd/tg-refresh.service
examples/systemd/tg-refresh.timer
Safety Notes
- Do not ask users to share phone numbers or verification codes in chat logs.
- Session data is stored locally and never uploaded.