一个基于 Telethon + Docker Compose 的 Telegram 消息中继系统:
telegram_bot.py(Userbot)负责监听源频道/群bot_relay.py(RelayBot)负责无痕重发到目标频道
- 支持多源到多目标的消息中继
- 支持相册(media group)聚合转发
- 支持命令过滤(
/)与系统回执过滤(🤖) - 统一配置模块(JSON +
.env覆盖) - 结构化 JSON 日志
- 限流 + 重试 + 死信(DLQ)
- 运行时配置热重载(检测
config.json变更)
REPO_URL="https://github.com/ike666888/Telegram-touji.git" \
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ike666888/Telegram-touji/main/scripts/install.sh)"执行后脚本会:
- 检测 Docker / Compose
- 克隆仓库(如本地不存在)
- 交互式询问配置参数
- 生成
config.json与.env - 启动容器:
docker compose up -d --build
安装脚本会提示填写这些核心参数:
api_idapi_hashmaster_account_idsource_chattarget_botrelay.bot_tokendest_channels(逗号分隔)
配置文件:
config.json:主配置(持久化).env:环境覆盖(敏感信息建议优先放这里)
docker-compose.yml 已通过 env_file: .env 自动注入运行环境。
telegram_bot.py:Userbot 主逻辑(监听、命令处理、转发映射)bot_relay.py:RelayBot 主逻辑(过滤、重发)common_config.py:统一配置读取/保存、.env支持、热重载检测structured_logger.py:JSON 日志输出delivery.py:限流、重试、DLQcommand_utils.py:命令解析工具scripts/install.sh:交互式一键安装脚本tests/:最小单元测试
python -m unittest discover -s tests -v
python -m py_compile telegram_bot.py bot_relay.py common_config.py structured_logger.py delivery.py command_utils.py
bash -n scripts/install.sh