openilink-tg

March 22, 2026 · View on GitHub

一个将 Telegram Bot 兼容 HTTP 接口转换为微信 iLink SDK 调用的 Go 服务。

当前能力

首版聚焦最小可用链路,只支持:

  • GET /bot<TOKEN>/getMe
  • POST /bot<TOKEN>/sendMessage
  • POST /bot<TOKEN>/sendChatAction
  • GET /healthz

约束说明:

  • chat_id 直接映射为微信 iLink 的用户 ID。
  • sendMessage 当前只支持文本消息。
  • sendChatAction 当前统一映射为微信侧 typing
  • 主动推送依赖历史入站消息中的 context_token

运行原理

服务内部做两件事:

  1. 对外暴露 Telegram Bot 风格 HTTP 路由。
  2. 对内启动 iLink monitor 长轮询,持续维护:
    • get_updates_buf
    • user_id -> context_token

服务会将这两类状态持久化到本地文件,便于重启恢复。

环境变量

变量名必填默认值说明
TELEGRAM_BOT_TOKEN-Telegram 兼容层访问 token
ILINK_TOKEN-微信 iLink bot token
ILINK_BASE_URLSDK 默认值微信 iLink API 基础地址
HTTP_ADDR:8080HTTP 监听地址
STATE_FILEdata/state.json上下文状态文件
BOT_ID1getMe 返回的 bot id
BOT_NAMEWeixin iLink BridgegetMe 返回的 bot 名称
BOT_USERNAMEopenilink_tg_botgetMe 返回的用户名
MONITOR_ENABLEDtrue是否启动 iLink monitor

本地运行

go run ./cmd/openilink-tg

编译

go build ./...

测试

go test ./...

示例请求

getMe

curl "http://localhost:8080/bot${TELEGRAM_BOT_TOKEN}/getMe"

sendMessage

curl -X POST "http://localhost:8080/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": "wx-user-id",
    "text": "hello from telegram bridge"
  }'

sendChatAction

curl -X POST "http://localhost:8080/bot${TELEGRAM_BOT_TOKEN}/sendChatAction" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": "wx-user-id",
    "action": "typing"
  }'

Docker

项目包含多阶段 Dockerfile,可直接构建:

docker build -t openilink-tg .

发版策略

GitHub Actions 负责两类自动化:

  1. ci.yml
    • push / pull_request 时运行 go testgo build
  2. release.yml
    • 在 tag 推送时构建多平台二进制
    • 自动创建 GitHub Release

后续可扩展方向

  • sendPhoto
  • sendDocument
  • QR 登录辅助接口
  • 更丰富的 Telegram Bot API 兼容面

许可证

本项目使用 MIT License,详见 LICENSE