Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat: use aiohttp_socks ProxyConnector for SOCKS proxy support

ReWiG6da5fb2aa062
diff --git a/docs/TELEGRAM_SETUP.md b/docs/TELEGRAM_SETUP.md
index 039eafc70..825ce383a 100644
--- a/docs/TELEGRAM_SETUP.md
+++ b/docs/TELEGRAM_SETUP.md
@@ -124,11 +124,15 @@ The wizard exposes two important Telegram defaults:
## Using a Proxy
-If Telegram API is blocked in your region, you can configure a proxy server.
+If Telegram API is blocked in your region, you can configure a proxy server. The easiest way is to set it up in the setup wizard: enter the proxy URL in the "Proxy URL" field before validating your bot token.
-### Configuration
+### Configuration via Setup Wizard
-Add `proxy_url` to your config in `~/.vibe_remote/config/config.json`:
+In the Telegram setup wizard (Step 2: Paste the Token), you'll see a "Proxy URL" field below the bot token input. Enter your proxy URL there and click "Validate Token" — the validation will use the proxy automatically.
+
+### Configuration via Config File
+
+Alternatively, add `proxy_url` to your config in `~/.vibe_remote/config/config.json`:
```json
{
diff --git a/modules/im/telegram_api.py b/modules/im/telegram_api.py
index 015ec0967..c7981e9e7 100644
--- a/modules/im/telegram_api.py
+++ b/modules/im/telegram_api.py
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import Any, Optional
import aiohttp
+from aiohttp_socks import ProxyConnector
def _api_url(bot_token: str, method: str) -> str:
@@ -29,13 +30,13 @@ async def call_api(
timeout = aiohttp.ClientTimeout(total=timeout_seconds)
connector = None
if proxy_url:
- connector = aiohttp.TCPConnector()
+ connector = ProxyConnector.from_url(proxy_url)
async with aiohttp.ClientSession(timeout=timeout, connector=connector) as session:
if form is not None:
- async with session.post(_api_url(bot_token, method), data=form, proxy=proxy_url) as resp:
+ async with session.post(_api_url(bot_token, method), data=form) as resp:
data = await resp.json()
else:
- async with session.post(_api_url(bot_token, method), json=payload or {}, proxy=proxy_url) as resp:
+ async with session.post(_api_url(bot_token, method), json=payload or {}) as resp:
data = await resp.json()
if not data.get("ok"):
raise RuntimeError(data.get("description") or f"Telegram API call failed: {method}")
@@ -64,9 +65,9 @@ async def download_file(bot_token: str, file_path: str, *, timeout_seconds: int
timeout = aiohttp.ClientTimeout(total=timeout_seconds)
connector = None
if proxy_url:
- connector = aiohttp.TCPConnector()
+ connector = ProxyConnector.from_url(proxy_url)
async with aiohttp.ClientSession(timeout=timeout, connector=connector) as session:
- async with session.get(_file_url(bot_token, file_path), proxy=proxy_url) as resp:
+ async with session.get(_file_url(bot_token, file_path)) as resp:
resp.raise_for_status()
return await resp.read()
diff --git a/tests/test_telegram_proxy.py b/tests/test_telegram_proxy.py
new file mode 100644
index 000000000..974e3dbef
--- /dev/null
+++ b/tests/test_telegram_proxy.py
@@ -0,0 +1,38 @@
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+
+from config.v2_config import TelegramConfig
+
+
+def test_telegram_config_proxy_url_default_none() -> None:
+ """Test that proxy_url defaults to None when not specified."""
+ config = TelegramConfig(bot_token="123456:test-token")
+ assert config.proxy_url is None
+
+
+def test_telegram_config_proxy_url_socks5() -> None:
+ """Test that proxy_url can be set to SOCKS5 URL."""
+ config = TelegramConfig(bot_token="123456:test-token", proxy_url="socks5://user:[email protected]:1080")
+ assert config.proxy_url == "socks5://user:[email protected]:1080"
+
+
+def test_telegram_config_proxy_url_http() -> None:
+ """Test that proxy_url can be set to HTTP URL."""
+ config = TelegramConfig(bot_token="123456:test-token", proxy_url="http://127.0.0.1:8080")
+ assert config.proxy_url == "http://127.0.0.1:8080"
+
+
+def test_telegram_config_proxy_url_socks4() -> None:
+ """Test that proxy_url can be set to SOCKS4 URL."""
+ config = TelegramConfig(bot_token="123456:test-token", proxy_url="socks4://127.0.0.1:1080")
+ assert config.proxy_url == "socks4://127.0.0.1:1080"
+
+
+def test_telegram_config_proxy_url_without_auth() -> None:
+ """Test that proxy_url works without authentication."""
+ config = TelegramConfig(bot_token="123456:test-token", proxy_url="socks5://127.0.0.1:1080")
+ assert config.proxy_url == "socks5://127.0.0.1:1080"
\ No newline at end of file
diff --git a/vibe/api.py b/vibe/api.py
index 479fd58e6..e2d3de8dd 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -744,10 +744,10 @@ def _discord_api_get(bot_token: str, path: str) -> dict:
return json.loads(payload)
-async def _telegram_get_me(bot_token: str) -> dict:
+async def _telegram_get_me(bot_token: str, proxy_url: str | None = None) -> dict:
from modules.im import telegram_api
- result = await telegram_api.get_me(bot_token)
+ result = await telegram_api.get_me(bot_token, proxy_url=proxy_url)
return result.get("result") or {}