介绍
# Telegram CLI
用于阅读、搜索和发送消息的快速 Telegram CLI。
## 何时使用
当用户执行以下操作时使用此技能: - 询问查看 Telegram 消息或收件箱 - 想要在 Telegram 中搜索主题/关键词 - 想要给某人发送 Telegram 消息 - 询问 Telegram 群组、联系人或聊天 - 想要查看未读消息 - 需要查找群组成员或管理员
## 安装
```bash npm install -g @cyberdrk/tg ```
或从源代码安装: ```bash cd ~/Code/cyberdrk305/telegram && npm install && npm run build && npm link ```
## 身份验证
首次设置需要来自 https://my.telegram.org/apps 的 API 凭证。
```bash tg auth ```
## 命令
### 阅读 ```bash tg inbox # Unread messages summary tg chats # List all chats tg read "ChatName" -n 50 # Read last 50 messages tg read "ChatName" --since "1h" # Messages from last hour tg read @username -n 20 # Read DM with user tg search "query" --chat "ChatName" # Search within chat tg search "query" --all # Search all chats ```
### 写入 ```bash tg send @username "message" # Send DM tg send "GroupName" "message" # Send to group tg reply "ChatName" 12345 "response" # Reply to message ID ```
### 联系人与群组 ```bash tg contact @username # Get contact info tg members "GroupName" # List group members tg admins "GroupName" # List admins only tg groups --admin # Groups where you're admin ```
### 状态 ```bash tg whoami # Show logged-in account tg check # Verify session ```
## 输出格式
所有命令都支持 `--json`,以生成适合处理的结构化输出:
```bash tg inbox --json # JSON format tg read "Chat" --json # JSON with messages array tg chats --json # JSON with chat list ```
## 示例
检查收件箱: ```bash tg inbox ```
读取聊天的最近消息: ```bash tg read "MetaDAO Community" -n 20 ```
搜索主题: ```bash tg search "futarchy" --chat "MetaDAO" ```
发送消息: ```bash tg send @username "Hello, checking in!" ```
## 注意事项
- 聊天名称可以是部分匹配(例如,"MetaDAO" 匹配 "MetaDAO Community") - 用户名必须以 @ 开头(例如,@username) - 消息按时间倒序返回(最新的在前) - `--since` 标志接受诸如 "1h"、"30m"、"7d" 之类的格式