diff --git a/config.py b/config.py index 654d57c..741c3a9 100644 --- a/config.py +++ b/config.py @@ -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, + } diff --git a/dockercompose.yml b/dockercompose.yml index 27407fd..5c95c03 100644 --- a/dockercompose.yml +++ b/dockercompose.yml @@ -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: ХХХ diff --git a/telegram_client.py b/telegram_client.py index 5a59fff..545bdf5 100644 --- a/telegram_client.py +++ b/telegram_client.py @@ -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