feat(config): add mtproto proxy support
Introduce optional MTProto proxy configuration sourced from environment variables, expose related settings in `config.py`, document the variables in `dockercompose.yml`, and pass the proxy configuration to the Telegram client initialization.
This commit is contained in:
@@ -47,6 +47,17 @@ def get_settings() -> dict[str, Any]:
|
||||
|
||||
log_level = os.getenv("LOG_LEVEL", "INFO")
|
||||
|
||||
# Build MTProto proxy config if proxy host is provided
|
||||
proxy_host = os.getenv("TG_PROXY_HOST")
|
||||
proxy: dict[str, Any] | None = None
|
||||
if proxy_host:
|
||||
proxy = {
|
||||
"scheme": "mtproto",
|
||||
"hostname": proxy_host,
|
||||
"port": int(os.getenv("TG_PROXY_PORT") or 443),
|
||||
"secret": os.getenv("TG_PROXY_SECRET", ""),
|
||||
}
|
||||
|
||||
return {
|
||||
"tg_api_id": int(tg_api_id),
|
||||
"tg_api_hash": tg_api_hash,
|
||||
@@ -60,4 +71,5 @@ def get_settings() -> dict[str, Any]:
|
||||
"time_based_merge": os.getenv("TIME_BASED_MERGE", "False").strip() in ["True", "true"],
|
||||
"show_bridge_link": os.getenv("SHOW_BRIDGE_LINK", "False").strip() in ["True", "true"],
|
||||
"show_post_flags": os.getenv("SHOW_POST_FLAGS", "False").strip() in ["True", "true"],
|
||||
}
|
||||
"proxy": proxy,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ services:
|
||||
environment:
|
||||
TG_API_ID: XXX
|
||||
TG_API_HASH: XXX
|
||||
# TG_PROXY_HOST: 127.0.0.1 # MTProto proxy host (optional)
|
||||
# TG_PROXY_PORT: 443 # MTProto proxy port (default: 443)
|
||||
# TG_PROXY_SECRET: XXX # MTProto proxy secret
|
||||
PYROGRAM_BRIDGE_URL: https://pgbridge.example.com
|
||||
API_PORT: 80
|
||||
TOKEN: ХХХ
|
||||
|
||||
@@ -32,6 +32,7 @@ class TelegramClient:
|
||||
api_id=settings["tg_api_id"],
|
||||
api_hash=settings["tg_api_hash"],
|
||||
workdir=settings["session_path"],
|
||||
proxy=settings["proxy"], # MTProto proxy config, None if not set
|
||||
)
|
||||
self.disconnect_count = 0
|
||||
self.max_disconnects = 3
|
||||
|
||||
Reference in New Issue
Block a user