get chat_id and thread_id from caller

This commit is contained in:
Crystal
2025-12-01 16:11:23 +01:00
parent fd62653dce
commit 46fba104db
2 changed files with 31 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
TOKEN= '8381960173:AAFfHKWUNu8WMAAf1dvTnrDraING_ZNTY8k' TOKEN= '8381960173:AAFfHKWUNu8WMAAf1dvTnrDraING_ZNTY8k'
USERS= [ USERS= [
('245431596', None), #cry ('245431596', None), # cry
('-1003426627369', 2), # gruppo, kas ('-1003426627369', 2), # gruppo, kas
('-1003426627369', 16), # gruppo, woodoo ('-1003426627369', 16), # gruppo, woodoo
] ]

View File

@@ -2,32 +2,36 @@ import requests as _rqsts
import syms as _bot_syms import syms as _bot_syms
def _wb_telegram_send_alert(message: str): def _wb_telegram_send_alert(message, chat_id, thread_id= None):
print(f"wb_alert_bot _wb_telegram_send_alert: sending message to {chat_id}, {thread_id}...")
payload = {
'chat_id': chat_id,
'text': message,
'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)
res.raise_for_status()
jres = res.json()
if jres.get('ok'):
print(f"wb_alert_bot _wb_telegram_send_alert: message sent to {chat_id}, {thread_id}!")
else:
print(f"wb_alert_bot _wb_telegram_send_alert: Message not sent to {chat_id}, {thread_id}: {jres}")
except _rqsts.exceptions.RequestException as e:
print(f"wb_alert_bot _wb_telegram_send_alert: Connection error {chat_id}, {thread_id}: {e}")
def wb_telegram_send_alert(msg, chat_id, thread_id= None):
_wb_telegram_send_alert(msg, chat_id, thread_id)
def wb_telegram_send_alert_debug(msg):
users= _bot_syms.USERS users= _bot_syms.USERS
for user in users: for user in users:
u= user[0] chat_id= user[0]
thread_id= user[1] thread_id= user[1]
print(f"wb_alert_bot _wb_telegram_send_alert: sending message to {user}...") _wb_telegram_send_alert(msg, chat_id, thread_id)
payload = {
'chat_id': u,
'text': message,
'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)
res.raise_for_status()
jres = res.json()
if jres.get('ok'):
print(f"wb_alert_bot _wb_telegram_send_alert: message sent to {user}!")
else:
print(f"wb_alert_bot _wb_telegram_send_alert: Message not sent to {user}: {jres}")
except _rqsts.exceptions.RequestException as e:
print(f"wb_alert_bot _wb_telegram_send_alert: Connection error: {e}")
def wb_telegram_send_alert(msg):
_wb_telegram_send_alert(msg)