kid / telegram_bot.py
nastaseshot's picture
telegram_bot.py
b91d334 verified
# telegram_bot.py
import requests
class TelegramBot:
def __init__(self, token, chat_id):
self.token = token
self.chat_id = chat_id
def send_message(self, text):
url = f"https://api.telegram.org/bot{self.token}/sendMessage"
payload = {
"chat_id": self.chat_id,
"text": text,
"parse_mode": "HTML"
}
try:
response = requests.post(url, data=payload)
response.raise_for_status()
print("[TelegramBot] Alert sent.")
except Exception as e:
print(f"[TelegramBot] Failed to send message: {e}")