feat: add telegram proxy support and add error handling for channel startup

This commit is contained in:
alan 2026-02-07 20:37:41 +08:00
parent 625fc60282
commit 3166c15cff
3 changed files with 15 additions and 5 deletions

View File

@ -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)

View File

@ -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()
)

View File

@ -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]