Telegram daemon with CLI and Unix socket
Project description
tgrad
tgrad is a lightweight Python-based Telegram daemon. It lets other programs send messages to a Telegram bot using a local Unix domain socket. Includes a CLI and a Python API.
[!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.
✨ 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
📦 Installation
pip install tgrad
From latest in Github
git clone https://github.com/tareqmahmood/tgrad.git
cd tgrad
pip install .
🔐 Bot Setup
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!")
🧪 Testing
To test locally:
-
Run the server:
tgrad-server
-
In another terminal:
tgrad-client -t "Test" -m "This is a test message"
You should receive the message via your Telegram bot.
📄 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.1.tar.gz.
File metadata
- Download URL: tgrad-0.1.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b399d89c67816273b582fa9c3917c6b3681bf66398136aa1657de08ba54928e3
|
|
| MD5 |
d85be354b7026cfef9182df4a267c4c7
|
|
| BLAKE2b-256 |
4841a78d7a8ebabba87b7bfc24b07b14b8621eaa8e133363d0369bfeba9ee3f1
|
File details
Details for the file tgrad-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tgrad-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 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 |
d7a3d0afd49f991bf2838627fdccb8038f1724e268135b013d012d179eefa6e5
|
|
| MD5 |
369d22349c2da18a541ce5cd0671bbb2
|
|
| BLAKE2b-256 |
08440fbc0079f3c256ad9e096cb559affdcf773f254b0a6a719b2facaea890d8
|