fix(brother-printer): support --thread-id for forum topics and prevent double ask_user prompts
This commit is contained in:
@@ -50,9 +50,10 @@ TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TelegramNotifier:
|
||||
def __init__(self, token: Optional[str] = None, chat_id: Optional[str] = None, message_id: Optional[int] = None):
|
||||
def __init__(self, token: Optional[str] = None, chat_id: Optional[str] = None, thread_id: Optional[int] = None, message_id: Optional[int] = None):
|
||||
self.token = token or TELEGRAM_BOT_TOKEN
|
||||
self.chat_id = chat_id
|
||||
self.thread_id = int(thread_id) if thread_id else None
|
||||
self.message_id = int(message_id) if message_id else None
|
||||
|
||||
def can_notify(self) -> bool:
|
||||
@@ -67,6 +68,8 @@ class TelegramNotifier:
|
||||
"text": text,
|
||||
"parse_mode": "Markdown",
|
||||
}
|
||||
if self.thread_id:
|
||||
payload["message_thread_id"] = self.thread_id
|
||||
try:
|
||||
resp = requests.post(url, json=payload, timeout=8)
|
||||
if resp.ok:
|
||||
@@ -281,7 +284,7 @@ def handle_validate(args):
|
||||
|
||||
|
||||
def handle_print(args):
|
||||
notifier = TelegramNotifier(chat_id=args.chat_id, message_id=args.message_id)
|
||||
notifier = TelegramNotifier(chat_id=args.chat_id, thread_id=args.thread_id, message_id=args.message_id)
|
||||
|
||||
# 1. Resolve source document
|
||||
doc_title = args.title or "Dokument"
|
||||
@@ -464,6 +467,7 @@ def main():
|
||||
print_parser.add_argument("--max-pages", type=int, default=30, help="Safety page limit (default 30)")
|
||||
print_parser.add_argument("--force", action="store_true", help="Bypass max pages guardrail")
|
||||
print_parser.add_argument("--chat-id", help="Telegram Chat ID for live updates")
|
||||
print_parser.add_argument("--thread-id", type=int, help="Telegram Thread / Topic ID (for forum supergroups)")
|
||||
print_parser.add_argument("--message-id", help="Telegram Message ID to edit (optional, created if omitted)")
|
||||
print_parser.set_defaults(func=handle_print)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user