Skip to content

feat: add proxy support for Telegram Bot API#211

Open
bor799 wants to merge 1 commit intoop7418:mainfrom
bor799:feat/telegram-proxy-support
Open

feat: add proxy support for Telegram Bot API#211
bor799 wants to merge 1 commit intoop7418:mainfrom
bor799:feat/telegram-proxy-support

Conversation

@bor799
Copy link

@bor799 bor799 commented Mar 7, 2026

概述

为 Telegram Bot 功能添加代理支持,解决国内网络环境下无法访问 Telegram API 的问题。

变更内容

  • 新增 proxyFetch 函数,使用 undici 的 ProxyAgent
  • 自动读取 HTTP_PROXYHTTPS_PROXYALL_PROXY 环境变量
  • 替换所有 Telegram 模块中的 fetch 调用
  • 添加代理配置日志,方便调试

代理配置

临时配置(当前终端会话)

# 根据你的代理软件设置相应的端口
export HTTPS_PROXY=http://127.0.0.1:端口
export HTTP_PROXY=http://127.0.0.1:端口

# 例如 Clash Verge
export HTTPS_PROXY=http://127.0.0.1:7891

永久配置(添加到 shell 配置文件)

# macOS - 编辑 ~/.zshrc
echo 'export HTTPS_PROXY=http://127.0.0.1:你的端口' >> ~/.zshrc
echo 'export HTTP_PROXY=http://127.0.0.1:你的端口' >> ~/.zshrc
source ~/.zshrc

# Windows - 设置环境变量
setx HTTPS_PROXY http://127.0.0.1:你的端口
setx HTTP_PROXY http://127.0.0.1:你的端口

查找你的代理端口

# macOS/Linux - 查看常见代理软件端口
lsof -iTCP -sTCP:LISTEN -P | grep -E ':(7890|7891|10809|1087|6152|6153)'

# 或查看系统代理设置
scutil --proxy  # macOS
netsh winhttp show proxy  # Windows

测试步骤

  1. 配置代理环境变量(见上方)
  2. 启动 CodePilot,查看日志确认代理生效:[telegram-adapter] Using proxy: ...
  3. 配置 Telegram Bot Token 和 Chat ID
  4. 点击验证按钮确认连接成功
  5. 发送测试消息确认双向通信正常

关闭 Issue

Fixes #210

- Add proxyFetch function using undici ProxyAgent
- Support HTTP_PROXY, HTTPS_PROXY, ALL_PROXY environment variables
- Replace all fetch calls in Telegram modules
- Add proxy configuration logging on startup

Fixes op7418#210

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram Bot 功能需要支持代理配置(Proxy Support for Telegram Bot)

1 participant