Skip to main content

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

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

  1. Open Telegram and search for @BotFather.

  2. Start the chat and send:

    /newbot
    
  3. Follow the prompts:

    • Set a display name (e.g., MyNotifierBot)
    • Choose a unique username ending in bot (e.g., my_notifier_bot)
  4. 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

  1. Start a chat with your bot (click the link BotFather gives you).

  2. Send a message like hello or /start.

  3. Open this in your browser:

    https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
    

    Example:

    https://api.telegram.org/bot123456789:ABCdefGhIJKlmNoPQRstUvWXyZ12345678/getUpdates
    
  4. Look for a JSON field like this in the response:

    "chat": {
      "id": 987654321,
      "first_name": "Your Name",
      ...
    }
    

    📩 Use the id value as your CHAT_ID.

For groups: Add the bot to the group, send a message, and check getUpdates again. The chat.id will 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:

  1. Run the server:

    tgrad-server
    
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgrad-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tgrad-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file tgrad-0.1.0.tar.gz.

File metadata

  • Download URL: tgrad-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for tgrad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ca6e977c5a06bfc6a88b86148549e44847ccb8410cac677f4cf36665cc045d9
MD5 f1c786af315ab8a27b9bdefda81d54bb
BLAKE2b-256 243736a14623ac106268517f766849280e5354aacd36ddd8632ff5dd0199c9e7

See more details on using hashes here.

File details

Details for the file tgrad-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tgrad-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for tgrad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5928eadf63dbff71e366b69d668b53dfad7b7b2b6a1cbc79c5d109804a9e975b
MD5 7a8369c382aa4bb5098697368c93b59e
BLAKE2b-256 77af992d2b5db1ecf1a36315c9881b07af1d1b1949791cf125de7e0cbdba905e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page