tlgrm
Drives a personal Telegram account from the terminal or via MCP, enabling AI assistants to list chats, send/edit messages, fetch history, manage groups, and more with tiered read/write/destructive permissions.
README
<div align="center">
tlgrm
An unofficial, feature-rich command-line client, MCP server, and webhook daemon for Telegram, built on Telethon.
Drive your personal Telegram account from the terminal — or from an AI assistant — and bridge incoming messages to an HTTP webhook in real time.
</div>
Unofficial app notice: tlgrm is an independent, unofficial client built on the Telegram API (via Telethon). It is not affiliated with, endorsed by, or sponsored by Telegram.
Features
- Personal account — acts as you (MTProto user account, not a bot): read history, list members, message anyone you can.
- 29 commands — send/reply/edit/delete, history & global search, reactions, forwarding, pin & mute, group management, scheduling, polls.
- Clean JSON output — commands print JSON to stdout (logs go to stderr), so it pipes straight into
jqand scripts. - Real-time webhooks + daemon — forward incoming messages to an HTTP endpoint, optionally as a
systemdbackground service. - MCP server —
tlgrm-mcplets AI assistants drive Telegram, read-only by default. - Speech-to-text — auto-transcribe incoming voice notes (multilingual, GPU-aware), or transcribe any file with
tlgrm transcribe.
Quick start
# 1. Get your API credentials from my.telegram.org → API development tools
export TG_API_ID=1234567
export TG_API_HASH=your_api_hash_here
# 2. Install
pip install tlgrm # CLI only
pip install "tlgrm[mcp]" # + MCP server
pip install "tlgrm[stt]" # + speech-to-text (faster-whisper)
pip install "tlgrm[all]" # everything
# 3. Log in once
tlgrm login
# 4. Go
tlgrm chats --limit 10
tlgrm send --target @username --text "Hello!"
tlgrm chats | jq '.[].name' # stdout is clean JSON; logs go to stderr
With uv: uv tool install "tlgrm[mcp]".
Telegram API credentials
tlgrm does not ship with API credentials — you must supply your own:
- Go to my.telegram.org → API development tools.
- Create an application (Platform: Desktop). The title must not contain the word "Telegram".
- Copy the
api_id(a number) andapi_hash(a hex string). - Export them (add to your shell profile to persist):
export TG_API_ID=1234567
export TG_API_HASH=your_api_hash_here
See docs/configuration.md for all configuration options.
Commands (29)
Every command prints clean JSON to stdout — logs and progress go to stderr, so piping into jq works reliably.
Account & read
| Command | Description |
|---|---|
tlgrm login |
Authenticate your Telegram account (interactive, one-time) |
tlgrm whoami |
Show the logged-in account |
tlgrm chats [--limit N] |
List recent chats/dialogs |
tlgrm history --target T [--limit N] [--offset-id ID] |
Fetch message history |
tlgrm search --query Q [--target T] [--limit N] |
Search messages globally or in a chat |
tlgrm members --target T |
List members of a group or channel |
tlgrm user-info --target T |
Show profile info for a user |
tlgrm chat-info --target T |
Show info about a chat/channel |
tlgrm download --target T --message-id ID [--output PATH] |
Download media from a message |
Write
| Command | Description |
|---|---|
tlgrm send --target T (--text … | --file …) [--caption …] [--voice] [--reply-to ID] [--silent] |
Send a message, file, media, or voice note |
tlgrm reply --target T --message-id ID (--text … | --file …) [--caption …] [--voice] [--silent] |
Reply to a specific message |
tlgrm edit --target T --message-id ID --text … |
Edit a sent message |
tlgrm read --target T [--max-id ID] |
Mark a chat as read |
tlgrm forward --from A --to B --message-ids ID … |
Forward messages between chats |
tlgrm react --target T --message-id ID --emoji E [--big] |
React to a message |
tlgrm pin --target T --message-id ID [--notify] |
Pin a message |
tlgrm unpin --target T [--message-id ID] |
Unpin a message (or all) |
tlgrm mute --target T [--duration SECONDS] |
Mute a chat |
tlgrm unmute --target T |
Unmute a chat |
tlgrm saved (--text … | --file …) [--caption …] [--voice] |
Send to Saved Messages |
Groups, scheduling & advanced
| Command | Description |
|---|---|
tlgrm create-group --title TITLE [--members …] [--channel] |
Create a group or channel |
tlgrm add-members --target T --members … |
Add members to a group/channel |
tlgrm remove-members --target T --members … |
Remove members from a group/channel |
tlgrm leave --target T |
Leave a group or channel |
tlgrm schedule --target T --text TEXT --at (SECONDS|ISO8601) |
Schedule a text message |
tlgrm poll --target T --question Q --option A --option B … [--quiz --correct N] |
Send a poll or quiz |
tlgrm transcribe --file PATH [--backend …] [--model …] |
Transcribe audio (no login required) |
Webhook daemon
| Command | Description |
|---|---|
tlgrm listen [--webhook-url URL] [--webhook-header "N: V"] [--verbose] |
Listen for incoming messages (foreground) |
tlgrm daemon install|uninstall|status|logs |
Manage the background systemd daemon |
Full reference with all flags, output shapes, and examples: docs/commands.md.
MCP server
tlgrm ships a stdio MCP server (tlgrm-mcp). It is read-only by default; add --allow-write for write tools and --allow-write --allow-destructive for delete/leave/remove.
{
"mcpServers": {
"tlgrm": {
"command": "uvx",
"args": ["--from", "tlgrm[mcp]", "tlgrm-mcp"],
"env": { "TG_API_ID": "...", "TG_API_HASH": "..." }
}
}
}
Requires a prior tlgrm login. The MCP server reuses the same session file as the CLI.
Speech-to-text (optional)
Install the stt extra to auto-transcribe incoming voice notes in the webhook daemon, or to run tlgrm transcribe standalone (no login needed).
pip install "tlgrm[stt]" # faster-whisper (default, recommended)
pip install "tlgrm[stt-whisper]" # original openai-whisper
pip install "tlgrm[stt-all]" # all local backends
Cloud backends (openai, groq, deepgram, elevenlabs, google) need no extra package — just set the API key:
export OPENAI_API_KEY=sk-... # auto-selects openai backend
Model tip: the default model is tiny (fast, lower accuracy). For good Arabic / multilingual accuracy, use a larger model:
export TG_STT_MODEL=large-v3-turbo # recommended for Arabic
GPU: faster-whisper auto-detects NVIDIA GPUs (TG_STT_DEVICE=auto). CUDA 12 runtime required: pip install nvidia-cublas-cu12 nvidia-cudnn-cu12. Full backend reference: docs/configuration.md.
Security
- Your session file (
~/.tlgrm/tg_session.session) grants full account access — keep it private (git-ignored by default). - Enable Two-Step Verification on your Telegram account.
- The systemd unit file is written owner-only (
0600).
Troubleshooting
| Symptom | Fix |
|---|---|
Telegram API credentials are not configured |
Export TG_API_ID and TG_API_HASH (see above) |
Not authorized. Run 'tlgrm login' first. |
Run tlgrm login |
| Transcription never appears | Install the stt extra and FFmpeg |
systemctl not found |
The daemon needs systemd; use tlgrm listen directly |
| Cannot create an app at my.telegram.org | Brand-new accounts are sometimes blocked; wait and retry |
| MCP tool not available | Check the permission tier — write/destructive tools need explicit flags |
Documentation
| Guide | What it covers |
|---|---|
| Getting Started | Install, credentials, login, first message |
| Configuration | All env vars, paths, STT backends |
| Command Reference | Every command, flag, output shape |
| Webhook & Daemon Guide | Webhooks, systemd, payload schema |
Contributing & License
Contributions welcome — see CONTRIBUTING.md. Released under the MIT License © 2026 Ali Alrabeei. tlgrm is unofficial and not affiliated with, endorsed by, or sponsored by Telegram.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。