Skip to content

Instantly share code, notes, and snippets.

@linuxtechin
Last active April 16, 2024 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxtechin/8d1dbb396a54cc15038514297c5696d7 to your computer and use it in GitHub Desktop.
Save linuxtechin/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/
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