Lightweight Python-based Telegram daemon for notification
Project description
tgrad
tgrad is a minimal, efficient Telegram notification daemon for Linux systems. It allows local programs and scripts to send messages to a Telegram bot via a Unix domain socket. Designed for simplicity and automation, it includes both a command-line interface and a Python API for seamless integration into your workflows.
Whether you're monitoring system health, tracking long-running jobs, or debugging servers, tgrad gives you a simple, secure way to receive instant alerts on your phone — without running your own server, building a mobile app, or paying for third-party services.
[!NOTE]
This is mostly for personal use and with the intention to extend as personal needs evolve. Works for me. Hope it helps you too.
⚡ Quick Start
pip install tgrad
tgrad-config -t <BOT_TOKEN> -c <CHAT_ID>
tgrad-server &
tgrad-client -t "Test" -m "It works!"
✨ Features
- 🧵 Runs as a background daemon
- 🧾 Message delivery to Telegram via local socket
- ⚙️ Easy CLI tools to configure, run, and send messages
- 🐍 Python API (
tgrad.send()) for direct integration
💪 Use-cases
- ✅ Notify when a long-running script finishes
- 🧠 Alert when memory usage exceeds 90%
- 💾 Warn when disk space drops below 10%
- ⏰ Send alerts from
cronjobs or customebpfmonitors
📦 Installation
pip install tgrad
From latest in Github
git clone https://github.com/tareqmahmood/tgrad.git
cd tgrad
pip install .
🔐 Bot Setup
Details on setting up a Telegram bot
Before using tgrad, you need to create a Telegram bot and get the bot token and chat ID.
Step 1: Create a Telegram Bot
-
Open Telegram and search for
@BotFather. -
Start the chat and send:
/newbot -
Follow the prompts:
- Set a display name (e.g.,
MyNotifierBot) - Choose a unique username ending in
bot(e.g.,my_notifier_bot)
- Set a display name (e.g.,
-
BotFather will respond with a message containing your bot token:
Use this token to access the HTTP API: 123456789:ABCdefGhIJKlmNoPQRstUvWXyZ12345678🔑 Save this as your BOT_TOKEN.
Step 2: Get Your Chat ID
-
Start a chat with your bot (click the link BotFather gives you).
-
Send a message like
helloor/start. -
Open this in your browser:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdatesExample:
https://api.telegram.org/bot123456789:ABCdefGhIJKlmNoPQRstUvWXyZ12345678/getUpdates -
Look for a JSON field like this in the response:
"chat": { "id": 987654321, "first_name": "Your Name", ... }
📩 Use the
idvalue as your CHAT_ID.
For groups: Add the bot to the group, send a message, and check
getUpdatesagain. Thechat.idwill be a negative number like-1001234567890.
Once you have your BOT_TOKEN and CHAT_ID, configure tgrad:
tgrad-config -t <BOT_TOKEN> -c <CHAT_ID> [-s ~/.tgrad/tgrad.sock]
This saves your bot token, chat ID, and socket path to ~/.tgrad/config.json.
🚀 Usage
Start the Daemon Server
tgrad-server
It will listen for messages on the configured Unix socket.
Send a Message via CLI
tgrad-client -t "Title" -m "Hello from CLI"
Send a Message from Python
import tgrad
tgrad.send("Alert", "Something happened!")
🛣️ Roadmap
- Send messages from a Linux server to a Telegram bot
- Bi-directional Telegram interaction (e.g., respond to /status)
- Accept user-defined Python scripts for trigger actions
- Event templating and message formatting
📄 License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tgrad-0.1.2.tar.gz.
File metadata
- Download URL: tgrad-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f482fc3a75ebcfacc8f9d7ce447aadfd23e18a0242ae71ae64d80f03364d4672
|
|
| MD5 |
7422817be5a9ad5811e8f10fc304de64
|
|
| BLAKE2b-256 |
7cca42fb480fbb51886c1b3b3e0e079a06e74aafbb84a780b1a0b309a9f98abc
|
File details
Details for the file tgrad-0.1.2-py3-none-any.whl.
File metadata
- Download URL: tgrad-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b509b82fd564f49e68ad7b2c8634299abbcefe79edd3d8b92460cda4f088b4d1
|
|
| MD5 |
89af1bf50fcf1ad6cdb0d0a3463d6e81
|
|
| BLAKE2b-256 |
415fd674964819fe63a580e8811180fcb39a6e5d6e411e0b923eec34ef415fc3
|