Last active
December 27, 2024 14:05
-
-
Save linuxinsights/8d1dbb396a54cc15038514297c5696d7 to your computer and use it in GitHub Desktop.
How to send Alerts and Notifications with Telegram Python| Detailed How to article: https://linuxtech.in/how-to-send-alerts-and-notifications-with-telegram/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def send_telegram_notification(bot_token, chat_id, message): | |
url = f"https://api.telegram.org/bot{bot_token}/sendMessage" | |
payload = { | |
'chat_id': chat_id, | |
'text': message | |
} | |
response = requests.post(url, data=payload) | |
if response.status_code == 200: | |
print("Notification sent successfully.") | |
else: | |
print("Failed to send notification.") | |
# Usage | |
bot_token = '<YourBotToken>' | |
chat_id = '<YourChatID>' | |
message = 'Hello, world!' | |
send_telegram_notification(bot_token, chat_id, message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment