Skip to content

feat: Add HTTP/HTTPS proxy support for Telegram API connections#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-proxy-server-support
Draft

feat: Add HTTP/HTTPS proxy support for Telegram API connections#1
Copilot wants to merge 2 commits intomainfrom
copilot/add-proxy-server-support

Conversation

Copy link

Copilot AI commented Mar 16, 2026

Telegram API requests had no proxy support, making the integration non-functional in regions where Telegram is blocked.

Changes

Core proxy utility (telegram-utils.ts)

  • getTelegramProxyUrl() reads telegram_proxy_url from SQLite settings
  • proxyFetchOptions() validates the URL (http/https only), instantiates undici.ProxyAgent (bundled with Node.js 22+ — zero new dependencies), and returns { dispatcher } to spread into fetch() init
// Before
const res = await fetch(url, { method: 'POST', body: JSON.stringify(params) });

// After
const res = await fetch(url, {
  method: 'POST',
  body: JSON.stringify(params),
  ...proxyFetchOptions(),
} as RequestInit);

Coverage — proxy applied to all 5 outbound Telegram fetch sites:

  • callTelegramApi() (used by all bot methods + sendMessageDraft)
  • resolveBotIdentity() (getMe) in telegram-adapter.ts
  • Long-polling getUpdates loop in telegram-adapter.ts
  • getFile API call in telegram-media.ts
  • File binary download in telegram-media.ts

Settings persistence (route.ts)

  • telegram_proxy_url added to TELEGRAM_KEYS for read/write via the existing settings API

UI (TelegramBridgeSection.tsx)

  • "Proxy Server" input field added to the Bot Credentials card
  • Client-side validation rejects non-http:///https:// URLs before saving

i18n — 5 new keys added to en.ts and zh.ts (label, description, placeholder, hint, two validation error messages)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add getTelegramProxyUrl() and proxyFetchOptions() helpers in telegram-utils.ts
  using Node.js built-in undici ProxyAgent (no new dependencies)
- Validate proxy URL protocol (http/https only) before use
- Apply proxy to all Telegram fetch calls: callTelegramApi, resolveBotIdentity,
  getUpdates polling loop, and media downloads (getFile + file download)
- Add telegram_proxy_url to settings API keys for SQLite persistence
- Add proxy URL input field with client-side validation in TelegramBridgeSection UI
- Add i18n strings (en + zh) for proxy label, description, placeholder, hint,
  and validation error messages

Co-authored-by: cccssw <1233438+cccssw@users.noreply.github.com>
Copilot AI changed the title [WIP] Add proxy server support for Telegram connection feat: Add HTTP/HTTPS proxy support for Telegram API connections Mar 16, 2026
Copilot AI requested a review from cccssw March 16, 2026 13:25
Copy link
Owner

@cccssw cccssw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made by sonet4.6

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.

2 participants