feat: SOCKS5 proxy для Telegram (обход RKN через Xray VLESS-Reality)
- TelegramConfig.proxy — новое поле конфига - send_telegram(), poll_loop, _send_with_keyboard — proxy параметр - config.yaml — socks5://127.0.0.1:10808 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -112,6 +112,7 @@ telegram:
|
||||
enabled: false
|
||||
bot_token: "" # set via REMIZOV_TG_TOKEN env var
|
||||
chat_id: ""
|
||||
proxy: "socks5://127.0.0.1:10808" # Xray VLESS-Reality (RKN bypass)
|
||||
|
||||
llm:
|
||||
enabled: false
|
||||
|
||||
@@ -367,7 +367,8 @@ def _send_with_keyboard(cfg, text: str, keyboard=None):
|
||||
if keyboard:
|
||||
payload["reply_markup"] = keyboard
|
||||
try:
|
||||
httpx.post(url, json=payload, timeout=30)
|
||||
proxy = cfg.telegram.proxy or None
|
||||
httpx.post(url, json=payload, timeout=30, proxy=proxy)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -496,9 +497,10 @@ def _start_telegram_listener(cfg, get_db_fn):
|
||||
log.info("Telegram listener started")
|
||||
while True:
|
||||
try:
|
||||
proxy = cfg.telegram.proxy or None
|
||||
resp = httpx.get(f"{base_url}/getUpdates",
|
||||
params={"offset": offset, "timeout": 30},
|
||||
timeout=60)
|
||||
timeout=60, proxy=proxy)
|
||||
if resp.status_code != 200:
|
||||
log.warning(f"Telegram poll: HTTP {resp.status_code}")
|
||||
time.sleep(5)
|
||||
|
||||
@@ -99,6 +99,7 @@ class TelegramConfig:
|
||||
enabled: bool = False
|
||||
bot_token: str = ""
|
||||
chat_id: str = ""
|
||||
proxy: str = "" # SOCKS5/HTTP proxy, e.g. "socks5://127.0.0.1:10808"
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -22,13 +22,14 @@ def send_telegram(cfg: TelegramConfig, message: str) -> bool:
|
||||
return False
|
||||
|
||||
url = f"https://api.telegram.org/bot{cfg.bot_token}/sendMessage"
|
||||
proxy = cfg.proxy or None
|
||||
for attempt in range(2):
|
||||
try:
|
||||
resp = httpx.post(url, json={
|
||||
"chat_id": cfg.chat_id,
|
||||
"text": message,
|
||||
"parse_mode": "HTML",
|
||||
}, timeout=20)
|
||||
}, timeout=20, proxy=proxy)
|
||||
if resp.status_code != 200:
|
||||
log.warning("Telegram API error: %s", resp.text)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user