From 3166c15cffa4217e24be4c55fa25f9436370801c Mon Sep 17 00:00:00 2001 From: alan Date: Sat, 7 Feb 2026 20:37:41 +0800 Subject: [PATCH] feat: add telegram proxy support and add error handling for channel startup --- nanobot/channels/manager.py | 13 ++++++++++--- nanobot/channels/telegram.py | 2 ++ pyproject.toml | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nanobot/channels/manager.py b/nanobot/channels/manager.py index 64ced48..846ea70 100644 --- a/nanobot/channels/manager.py +++ b/nanobot/channels/manager.py @@ -78,8 +78,15 @@ class ChannelManager: except ImportError as e: logger.warning(f"Feishu channel not available: {e}") + async def _start_channel(self, name: str, channel: BaseChannel) -> None: + """Start a channel and log any exceptions.""" + try: + await channel.start() + except Exception as e: + logger.error(f"Failed to start channel {name}: {e}") + async def start_all(self) -> None: - """Start WhatsApp channel and the outbound dispatcher.""" + """Start all channels and the outbound dispatcher.""" if not self.channels: logger.warning("No channels enabled") return @@ -87,11 +94,11 @@ class ChannelManager: # Start outbound dispatcher self._dispatch_task = asyncio.create_task(self._dispatch_outbound()) - # Start WhatsApp channel + # Start channels tasks = [] for name, channel in self.channels.items(): logger.info(f"Starting {name} channel...") - tasks.append(asyncio.create_task(channel.start())) + tasks.append(asyncio.create_task(self._start_channel(name, channel))) # Wait for all to complete (they should run forever) await asyncio.gather(*tasks, return_exceptions=True) diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py index 23e1de0..b62c63b 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -104,6 +104,8 @@ class TelegramChannel(BaseChannel): self._app = ( Application.builder() .token(self.config.token) + .proxy(self.config.proxy) + .get_updates_proxy(self.config.proxy) .build() ) diff --git a/pyproject.toml b/pyproject.toml index 2a952a1..f60f7a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,13 +23,14 @@ dependencies = [ "pydantic-settings>=2.0.0", "websockets>=12.0", "websocket-client>=1.6.0", - "httpx>=0.25.0", + "httpx[socks]>=0.25.0", "loguru>=0.7.0", "readability-lxml>=0.8.0", "rich>=13.0.0", "croniter>=2.0.0", - "python-telegram-bot>=21.0", + "python-telegram-bot[socks]>=21.0", "lark-oapi>=1.0.0", + "socksio>=1.0.0", ] [project.optional-dependencies]