From fd62653dce3e4015582582993b973cb25efef010 Mon Sep 17 00:00:00 2001 From: Crystal Date: Mon, 1 Dec 2025 09:57:03 +0100 Subject: [PATCH] support threaded groups --- bot.py | 6 +++++- local_settings.py | 6 +++++- msg_sender.py | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 5325421..7764413 100644 --- a/bot.py +++ b/bot.py @@ -4,7 +4,11 @@ import syms as _bot_syms async def bot_start(update, context): chat_id = update.effective_chat.id - await update.message.reply_text(f'wb_alert bot: {chat_id}', parse_mode='HTML') + try: thread_id= update.message.message_thread_id + except: thread_id= None + txt= f'wb_alert bot: {chat_id}' + if thread_id: txt= f'wb_alert bot: {chat_id} thread: {thread_id}' + await update.message.reply_text(txt, parse_mode='HTML') print(f'alert_bot bot_start: {chat_id}') def main(): diff --git a/local_settings.py b/local_settings.py index 907c535..a869915 100644 --- a/local_settings.py +++ b/local_settings.py @@ -1,2 +1,6 @@ TOKEN= '8381960173:AAFfHKWUNu8WMAAf1dvTnrDraING_ZNTY8k' -USERS= ['245431596'] +USERS= [ + ('245431596', None), #cry + ('-1003426627369', 2), # gruppo, kas + ('-1003426627369', 16), # gruppo, woodoo + ] diff --git a/msg_sender.py b/msg_sender.py index 8bdc97e..80f98dd 100644 --- a/msg_sender.py +++ b/msg_sender.py @@ -6,12 +6,15 @@ def _wb_telegram_send_alert(message: str): users= _bot_syms.USERS for user in users: + u= user[0] + thread_id= user[1] print(f"wb_alert_bot _wb_telegram_send_alert: sending message to {user}...") payload = { - 'chat_id': user, + 'chat_id': u, 'text': message, - 'parse_mode': 'Markdown' + 'parse_mode': 'Markdown', } + if thread_id: payload['message_thread_id']= thread_id try: res = _rqsts.post(_bot_syms.TELEGRAM_API_URL, data=payload, timeout=3)