Spaces:
No application file
No application file
| # 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}") | |