Telegram Bot API 命令行工具。
需要 Go 1.25+,并确保 $(go env GOPATH)/bin 在 PATH 中。
# 锁定 token 安装到 GOPATH/bin
make install-tg TOKEN=123:AAA... BINARY=tg
# 锁定 token + 目标 chat
make install-tg TOKEN=123:AAA... TARGET=@mychannel BINARY=tg-chan
# 多 bot / 多目标场景
make install-tg TOKEN=123:AAA... TARGET=-100123456 BINARY=tg-work
make install-tg TOKEN=456:BBB... TARGET=@personal BINARY=tg-personal
# 单独的程序转换 std markdown -> tg HTML
make install-md2tg参考 md2tg readme
Token:--token / -T > TG_BOT_TOKEN > 编译内置
Target:--to / --chat > TG_TARGET > 编译内置
Proxy:--proxy / -x > TG_PROXY > HTTPS_PROXY / HTTP_PROXY
tg config # 查看当前配置来源
tg send -t <chat> -m "内容" # 发文本
tg send -t <chat> -i <file> # 从文件读取
tg send -t <chat> -i - --md2html # 从 stdin 读取并转 HTML
tg send -t <chat> -f ./photo.jpg -c "说明" # 发媒体文件
tg edit -c <chat> -m <id> -t "新内容"
tg delete -c <chat> -m <id>
tg forward -f <from> -t <to> -m <id>
tg copy -f <from> -t <to> -m <id>
tg pin -c <chat> -m <id>
tg unpin -c <chat> [-m <id>]
tg info -c <chat>
tg me| 选项 | 简写 | 说明 |
|---|---|---|
--to |
-t |
目标 chat,username 可省略 @ |
--chat |
-c |
目标 chat(edit/delete/pin/info) |
--text |
-m |
消息文本 |
--input-file |
-i |
从文件或 stdin(-)读取 |
--md2html |
— | 将 markdown 转换为 HTML |
--file |
-f |
文件路径(自动识别类型) |
--caption |
-c |
文件说明 |
--msg |
-m |
消息 ID |
--from |
-f |
来源 chat(forward/copy) |
--reply-to |
-r |
回复的消息 ID |
--silent |
-s |
静默发送 |
--protect |
-p |
防止转发/保存 |
--thread |
— | 话题群 message_thread_id |
--button |
-b |
Inline 按钮(多次使用 = 多行,, 同行,| 换行) |
--parse-mode |
— | 默认不传(纯文本);可选 HTML | MarkdownV2 |
--json |
-j |
输出完整 JSON 响应 |
# 发送 HTML 消息
tg send -t mychannel -m "<b>加粗</b> 内容" --parse-mode HTML
# 发送 MarkdownV2 消息
tg send -t mychannel -m "这是 *粗体* 和 _斜体_" --parse-mode MarkdownV2
# 从文件读取并自动转 HTML(.md 文件)
tg send -t mychannel -i ./readme.md
# 从 stdin 读取并转 HTML
cat readme.md | tg send -t mychannel -i - --md2html
# 带按钮
tg send -t mychannel -m "点击" \
-b "官网:https://example.com,文档:https://docs.example.com" \
-b "GitHub:https://github.com"
# 发图片
tg send -t 123456789 -f ./image.png -c "说明"
# 从管道发送
echo "定时任务完成" | tg send -t alerts -i -
# 获取 JSON 格式结果
tg info -c mychannel -j
# 检查编译内置情况
tg config