mtgo-labs/mtgo-cli

GitHub: mtgo-labs/mtgo-cli

基于 Go 构建的高性能 Telegram MTProto CLI 工具,支持直接调用任意 TL 方法、收发消息与管理群组,适用于 API 调试与自动化操作。

Stars: 0 | Forks: 0

# mtgo-cli 基于 [mtgo](https://github.com/mtgo-labs/mtgo) 构建的 Telegram MTProto 调试与调用 CLI —— 具备更高的准确性和性能。 [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![Go Reference](https://pkg.go.dev/badge/github.com/mtgo-labs/mtgo-cli.svg)](https://pkg.go.dev/github.com/mtgo-labs/mtgo-cli) [![skills.sh](https://skills.sh/b/mtgo-labs/mtgo-cli)](https://skills.sh/mtgo-labs/mtgo-cli)
## 安装 ``` go install github.com/mtgo-labs/mtgo-cli/cmd/mtgo-cli@latest # 为 Claude Code、Codex、Cursor 等安装 Agent Skill npx skills add mtgo-labs/mtgo-cli ``` ## 快速开始 ### Bot ``` export MTGO_CLI_API_ID=12345 export MTGO_CLI_API_HASH=your_hash export MTGO_CLI_BOT_TOKEN=123:ABC mtgo-cli get-me --format json mtgo-cli send-message @username "Hello!" ``` ### Userbot ``` export MTGO_CLI_API_ID=12345 export MTGO_CLI_API_HASH=your_hash export MTGO_CLI_SESSION="your_pyrogram_session_string" mtgo-cli get-me mtgo-cli create-group "Test Suite" mtgo-cli add-bot 5282748388 @my_bot mtgo-cli send-photo @username photo.jpg "Check this out" mtgo-cli download @username 2667 ``` ### 高性能监听器 ``` # Terminal 1 — 启动一次 mtgo-cli listen & # Terminal 2+ — 所有命令通过 IPC 路由,零重连 mtgo-cli get-me mtgo-cli invoke messages.getHistory '{"peer":{"_":"inputPeerSelf"},"limit":10}' ``` ## 命令 | 命令 | 描述 | |---|---| | `invoke [json]` | 调用任何 TL 方法(完整或快速路径) | | `listen` | 带有 IPC 服务器的持久监听器 | | `trace` | 带有相关 ID 追踪的监听 | | `methods [prefix]` | 列出可用的 TL 方法 | | `get-me` | 当前用户/Bot 信息 | | `send-message ` | 发送文本消息 | | `get-user ` | 获取用户信息 (users.getFullUser) | | `get-chat ` | 获取聊天信息 (messages.getFullChat) | | `list-chats` | 列出最近的对话 | | `list-messages ` | 列出最近的消息 | | `resolve-peer ` | 将 peer 解析为访问信息 | | `export-session` | 导出 session 字符串 | | `completion ` | Shell 自动补全(bash、zsh、fish) | | `version` | 打印版本 | ## Peer 格式 - `@username` —— 通过公开用户名解析 - `+1234567890` —— 通过手机号码解析 - `me` 或 `self` —— 当前用户 - `12345678` —— 数字用户/聊天 ID(自动检测) - `channel:123456` / `user:123456` —— 显式指定类型 ## 身份验证 优先级:CLI 标志 > 环境变量 > 配置文件。 | 标志 | 环境变量 | 描述 | |---|---|---| | `--api-id` | `MTGO_CLI_API_ID` | Telegram API ID | | `--api-hash` | `MTGO_CLI_API_HASH` | Telegram API Hash | | `--bot-token` | `MTGO_CLI_BOT_TOKEN` | Bot token | | `--session` | `MTGO_CLI_SESSION` | Session 字符串(自动检测) | | `--phone` | `MTGO_CLI_PHONE` | 手机号码 | 配置文件:`~/.mtgo-cli.json`(权限模式 0600) ``` { "api_id": 12345, "api_hash": "your_api_hash", "bot_token": "123:ABC" } ``` ## Session 字符串 自动检测的格式: - mtgo 原生 - Telethon - Pyrogram - GramJS - mtcute 导出:`mtgo-cli export-session` ## 性能对比 gotg-cli 1. **InvokeWithRawByte** —— 快速路径跳过完整的 TL 解码 2. **Constructor 缓存** —— 预先构建的名称↔类型映射,单次调用零反射 3. **Peer 缓存** —— `SavePeers: true` 在本地缓存用户名→ID 4. **Session 自动检测** —— `session.String()` 处理 5 种格式 5. **连接重用** —— IPC socket 避免了重新认证的开销 6. **池化 JSON 编码** —— 用于 JSON 序列化的 `sync.Pool` 缓冲区 ## 架构 ``` cmd/mtgo-cli/ CLI entrypoint (cobra commands) invoke/ Dual-path TL invoke engine ipc/ Unix socket IPC server/client trace/ Correlation ID tracer internal/ config/ Config loading (CLI > env > file) client/ mtgo client factory ``` ## 许可证 [Apache License 2.0](LICENSE) —— 版权所有 2026 mtgo-labs
标签:API调试, EVTX分析, Go, Homebrew安装, MTProto, Ruby工具, Telegram机器人, 即时通讯, 日志审计