Skip to content

Your lightweight open-source personal agent.

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

alan3166c15cffa4
diff --git a/nanobot/channels/manager.py b/nanobot/channels/manager.py
index 64ced48a8..846ea703d 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 23e1de00e..b62c63b83 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 2a952a16c..f60f7a7a4 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]