How to Get Linux Desktop Notifications on Telegram

A Node.js server and a bash script that will send your Linux desktop notifications to a Telegram bot for remote monitoring.

Written by Rafi
📅
Published March 18, 2023
⏱️
Read Time 2 min
📊
Difficulty Intermediate

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?

ℹ️ Info

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.

💡 Tip

Project Repository: Linux Notifications to Telegram

Setup Telegram Bot API

📖 Create Your Telegram Bot
  1. Search for “BotFather” on Telegram
  2. Create a new bot and get your API key
  3. Don’t forget to start the bot
📖 Get Your Chat ID
  1. Search for “userinfobot” on Telegram
  2. 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.

Press on a tab to see code
#!/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.

💡 Tip

With this setup, you’ll never miss important desktop notifications, even when you’re away from your computer!

Knowledge Check

Test your knowledge about Linux desktop notifications to Telegram

Discussion

0 comments
Reading Progress
4 min left 0%
Welcome back! Sign in to join the discussion.

Please verify your email to sign in.

Enter the 6-digit code from your verification email.

Didn't receive the email?

Remember your password?

Create an account to comment and join the community.
Letters, numbers, and underscores only

Check your email! We've sent a verification code.

Enter the 6-digit code to complete your registration, or click the link in your email.

Didn't receive the email?

Wrong email?

Enter your email address and we'll send you a code to reset your password.

Remember your password?

Enter the 6-digit code from your email and create a new password.

Didn't receive code?

Welcome aboard!

Your account has been created successfully.

Welcome back! Sign in to join the discussion.

Please verify your email to sign in.

Enter the 6-digit code from your verification email.

Didn't receive the email?

Remember your password?

Create an account to comment and join the community.
Letters, numbers, and underscores only

Check your email! We've sent a verification code.

Enter the 6-digit code to complete your registration, or click the link in your email.

Didn't receive the email?

Wrong email?

Enter your email address and we'll send you a code to reset your password.

Remember your password?

Enter the 6-digit code from your email and create a new password.

Didn't receive code?

Welcome aboard!

Your account has been created successfully.