feat: add backlog processing flag
This commit is contained in:
@@ -43,6 +43,7 @@ Optional flags:
|
||||
- `--progress-edit-every FLOAT` (default `2.5`)
|
||||
- `--progress-silent/--no-progress-silent` (default silent)
|
||||
- `--final-notify/--no-final-notify` (default notify via new message)
|
||||
- `--ignore-backlog/--process-backlog` (default ignore pending updates)
|
||||
|
||||
## Option 2: MCP server
|
||||
|
||||
@@ -52,6 +53,10 @@ Run:
|
||||
uv run mcp-bridge
|
||||
```
|
||||
|
||||
Optional flags:
|
||||
|
||||
- `--ignore-backlog/--process-backlog` (default ignore pending updates)
|
||||
|
||||
## Option 3: tmux
|
||||
|
||||
Reply injector:
|
||||
@@ -60,6 +65,10 @@ Reply injector:
|
||||
uv run tmux-reply
|
||||
```
|
||||
|
||||
Optional flags:
|
||||
|
||||
- `--ignore-backlog/--process-backlog` (default ignore pending updates)
|
||||
|
||||
Notifier (call from your existing hook):
|
||||
|
||||
```bash
|
||||
|
||||
@@ -279,6 +279,11 @@ def run(
|
||||
"--final-notify/--no-final-notify",
|
||||
help="Send the final response as a new message (not an edit).",
|
||||
),
|
||||
ignore_backlog: bool = typer.Option(
|
||||
True,
|
||||
"--ignore-backlog/--process-backlog",
|
||||
help="Skip pending Telegram updates that arrived before startup.",
|
||||
),
|
||||
) -> None:
|
||||
config = load_telegram_config()
|
||||
token = config_get(config, "bot_token") or ""
|
||||
@@ -327,6 +332,7 @@ def run(
|
||||
max_workers = None
|
||||
pool = ThreadPoolExecutor(max_workers=max_workers or 4)
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
|
||||
log(f"[startup] pwd={startup_pwd}")
|
||||
log("Option1 bridge running (codex exec). Long-polling Telegram...")
|
||||
@@ -482,6 +488,13 @@ def run(
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
log(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
@@ -255,7 +255,13 @@ class MCPStdioClient:
|
||||
pass
|
||||
|
||||
|
||||
def run() -> None:
|
||||
def run(
|
||||
ignore_backlog: bool = typer.Option(
|
||||
True,
|
||||
"--ignore-backlog/--process-backlog",
|
||||
help="Skip pending Telegram updates that arrived before startup.",
|
||||
),
|
||||
) -> None:
|
||||
config = load_telegram_config()
|
||||
token = config_get(config, "bot_token") or ""
|
||||
db_path = config_get(config, "bridge_db") or "./bridge_routes.sqlite3"
|
||||
@@ -289,6 +295,7 @@ def run() -> None:
|
||||
print(f"tools/list failed: {e}")
|
||||
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
|
||||
print("Option2 bridge running (codex mcp-server). Long-polling Telegram...")
|
||||
|
||||
@@ -345,6 +352,13 @@ def run() -> None:
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
@@ -32,7 +32,13 @@ def tmux_send_text(target: str, text: str, press_enter: bool = True) -> None:
|
||||
subprocess.check_call(["tmux", "send-keys", "-t", target, "Enter"])
|
||||
|
||||
|
||||
def run() -> None:
|
||||
def run(
|
||||
ignore_backlog: bool = typer.Option(
|
||||
True,
|
||||
"--ignore-backlog/--process-backlog",
|
||||
help="Skip pending Telegram updates that arrived before startup.",
|
||||
),
|
||||
) -> None:
|
||||
config = load_telegram_config()
|
||||
token = config_get(config, "bot_token") or ""
|
||||
db_path = config_get(config, "bridge_db") or "./bridge_routes.sqlite3"
|
||||
@@ -42,6 +48,7 @@ def run() -> None:
|
||||
store = RouteStore(db_path)
|
||||
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
print("Option3 reply bot running (tmux injector). Long-polling Telegram...")
|
||||
|
||||
while True:
|
||||
@@ -52,6 +59,13 @@ def run() -> None:
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
Reference in New Issue
Block a user