diff --git a/src/bot/core.py b/src/bot/core.py index 192bddd3..2d5e99bb 100644 --- a/src/bot/core.py +++ b/src/bot/core.py @@ -64,6 +64,18 @@ async def initialize(self) -> None: builder.write_timeout(30) builder.pool_timeout(30) + # Explicitly set proxy from environment variables. + # This is necessary because python-telegram-bot's Application.builder() + # does not automatically use HTTP_PROXY/HTTPS_PROXY environment variables. + # Without this, the httpx connection pool can become corrupted when running + # behind a proxy, causing the bot to stop responding to messages. + import os + + proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("HTTP_PROXY") + if proxy_url: + builder.proxy(proxy_url) + logger.info("Proxy configured", proxy=proxy_url) + self.app = builder.build() # Initialize feature registry