From 052d10dcb6e699620afa88ea6990eee7b0692fe9 Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 9 Mar 2026 06:43:40 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20Telegram=20listener=20+=20stri?= =?UTF-8?q?p=20@botname=20=D0=B8=D0=B7=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- src/remizov_trader/cli.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/remizov_trader/cli.py b/src/remizov_trader/cli.py index 326dd72..66ba49e 100644 --- a/src/remizov_trader/cli.py +++ b/src/remizov_trader/cli.py @@ -351,7 +351,7 @@ def _start_telegram_listener(cfg, get_db_fn): def handle_command(text: str): # Resolve button text to command mapped = _button_map.get(text.strip().lower(), text.strip()) - cmd = mapped.split()[0].lower() + cmd = mapped.split()[0].split("@")[0].lower() # strip @botname if cmd == "/status": conn = get_db_fn() report = format_status_report(cfg, conn) @@ -365,14 +365,18 @@ def _start_telegram_listener(cfg, get_db_fn): _send_help(cfg) def poll_loop(): + import logging + log = logging.getLogger(__name__) offset = 0 base_url = f"https://api.telegram.org/bot{cfg.telegram.bot_token}" + log.info("Telegram listener started") while True: try: resp = httpx.get(f"{base_url}/getUpdates", params={"offset": offset, "timeout": 30}, timeout=35) if resp.status_code != 200: + log.warning(f"Telegram poll: HTTP {resp.status_code}") time.sleep(5) continue updates = resp.json().get("result", []) @@ -382,8 +386,13 @@ def _start_telegram_listener(cfg, get_db_fn): text = msg.get("text", "") chat_id = str(msg.get("chat", {}).get("id", "")) if text and chat_id == cfg.telegram.chat_id: - handle_command(text) - except Exception: + log.info(f"Telegram cmd: {text}") + try: + handle_command(text) + except Exception as e: + log.error(f"Telegram command error: {e}", exc_info=True) + except Exception as e: + log.error(f"Telegram poll error: {e}") time.sleep(10) t = threading.Thread(target=poll_loop, daemon=True)