From 09779861ccf39aa1b10e950e3b349b569ed9af67 Mon Sep 17 00:00:00 2001 From: banteg <4562643+banteg@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:30:06 +0400 Subject: [PATCH] refactor: lock down to single chat_id --- codex_telegram_bridge/readme.md | 1 - .../src/codex_telegram_bridge/exec_bridge.py | 33 +++++-------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/codex_telegram_bridge/readme.md b/codex_telegram_bridge/readme.md index 0385838..34e025b 100644 --- a/codex_telegram_bridge/readme.md +++ b/codex_telegram_bridge/readme.md @@ -23,7 +23,6 @@ chat_id = 123456789 Optional keys: -- common: `allowed_chat_ids`, `startup_chat_ids` - exec/resume: `startup_message`, `codex_cmd`, `codex_workspace`, `codex_exec_args`, `max_workers`, `codex_io_mode`, `codex_command_timeout_s`, `codex_no_child_timeout_s` ## Option 1: exec/resume diff --git a/codex_telegram_bridge/src/codex_telegram_bridge/exec_bridge.py b/codex_telegram_bridge/src/codex_telegram_bridge/exec_bridge.py index 0a4e630..83c044e 100644 --- a/codex_telegram_bridge/src/codex_telegram_bridge/exec_bridge.py +++ b/codex_telegram_bridge/src/codex_telegram_bridge/exec_bridge.py @@ -363,16 +363,7 @@ def run( setup_logging(log_file if log_file else None) config = load_telegram_config() token = config["bot_token"] - - def _as_int_set(value: Any) -> set[int]: - if isinstance(value, int): - return {value} - if isinstance(value, list): - return {int(v) for v in value} - raise TypeError(f"expected int or list[int], got {type(value).__name__}") - - allowed = _as_int_set(config.get("allowed_chat_ids", config["chat_id"])) - startup_ids = _as_int_set(config.get("startup_chat_ids", config["chat_id"])) + config_chat_id = int(config["chat_id"]) startup_msg = config.get("startup_message", "✅ exec_bridge started (codex exec).") startup_pwd = os.getcwd() @@ -431,19 +422,11 @@ def run( logger.info("[startup] pwd=%s", startup_pwd) logger.info("Option1 bridge running (codex exec). Long-polling Telegram...") - if startup_ids: - for chat_id in startup_ids: - try: - bot.send_message(chat_id=chat_id, text=startup_msg) - logger.info("[startup] sent startup message to chat_id=%s", chat_id) - except Exception as e: - logger.info( - "[startup] failed to send startup message to chat_id=%s: %s", - chat_id, - e, - ) - else: - logger.info("[startup] no chat_id configured; skipping startup message") + try: + bot.send_message(chat_id=config_chat_id, text=startup_msg) + logger.info("[startup] sent startup message to chat_id=%s", config_chat_id) + except Exception as e: + logger.info("[startup] failed to send startup message to chat_id=%s: %s", config_chat_id, e) def handle( chat_id: int, user_msg_id: int, text: str, resume_session: str | None @@ -634,11 +617,11 @@ def run( ) continue - if allowed is not None and int(chat_id) not in allowed: + if int(chat_id) != config_chat_id: logger.info( "[telegram] rejected by ACL chat_id=%s allowed=%s", chat_id, - sorted(allowed), + config_chat_id, ) continue