34 lines
986 B
Python
34 lines
986 B
Python
import requests as _rqsts
|
|
import syms as _bot_syms
|
|
|
|
|
|
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': 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)
|