Do you ever miss important notifications while working on your desktop? Have you ever wished you could receive Linux Desktop or server notifications from your phone or other devices?
In this guide, we’ll demonstrate how to write a bash script that uses the Telegram Bot API to monitor desktop alerts and deliver them to a Telegram chat.
Project Repository: Linux Notifications to Telegram
Setup Telegram Bot API
📖 Create Your Telegram Bot
- Search for “BotFather” on Telegram
- Create a new bot and get your API key
- Don’t forget to start the bot
📖 Get Your Chat ID
- Search for “userinfobot” on Telegram
- Follow the instructions to get your chat ID
Required Environment Variables
TELEGRAM_API_KEY="YOUR_TELEGRAM_API_KEY"
TELEGRAM_CHAT_ID="YOUR_TELEGRAM_CHAT_ID"
How It Works
The bash script utilizes dbus-monitor to listen for org.freedesktop alerts. When it receives notifications, it uses the Telegram Bot API to distribute them to your Telegram chat.
#!/bin/bash
# Monitor desktop notifications
dbus-monitor "interface='org.freedesktop.Notifications'" | \
while read -r line; do
# Extract notification data
# Send to Telegram
done
#!/bin/bash
# Send notification to Telegram
curl -s -X POST https://api.telegram.org/bot$TELEGRAM_API_KEY/sendMessage \
-d chat_id=$TELEGRAM_CHAT_ID \
-d text="$NOTIFICATION_TEXT"
Complete Setup
📖 Full Documentation
For more documentation, please read the GitLab page carefully. It contains all the setup instructions and troubleshooting tips.
With this setup, you’ll never miss important desktop notifications, even when you’re away from your computer!
Discussion
0 commentsJoin the Discussion
Sign in to post comments and join the conversation.
No comments yet. Be the first to share your thoughts!