Skip to main content

Simple Interface for Telegram read and listen

Project description

TelegramManager

A simple CLI and Python module to fetch or listen to Telegram messages from public channels or groups. Built with Telethon, with plug-and-play configuration support.


📦 Installation

pip install .
# or for development
pip install -e .[dev]

⚙️ Configuration (Recommended)

Create a .env file in your project root:

TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
TELEGRAM_PHONE_NUMBER=+1234567890

The default TelegramManager() uses this automatically via a Config wrapper.


🔐 Manual Credential Usage (Alternative)

If you prefer not to use a .env file or Config, instantiate the class manually:

from telegram_manager.controller import TelegramManager

tg = TelegramManager(
    api_id=123456,
    api_hash="your_api_hash_here",
    phone_number="+1234567890"
)

This is useful for scripting, testing, or dynamic environments.


🚀 CLI Usage

Once installed, you can run the tm CLI command:

🔍 Fetch Messages

tm fetch <channel> [--min-id <id>] [--limit <n>]

Example:

tm fetch @openai --limit 10

👂 Listen for Messages

tm listen <channel>

Example:

tm listen "Some Group Chat"

🧩 Python Module Usage

🔧 Initialization

from telegram_manager import TelegramManager

tg = TelegramManager()  # Uses .env Config automatically

Or manually, as described in the previous section.


📥 Fetch Messages

tg.fetch_messages(
    chat_identifier="@somechannel",
    message_processor=lambda m: print(m.id, m.text),
    limit=5
)

📡 Listen for Live Messages

tg.listen("@somechannel", message_handler=lambda m: print(f"New: {m.message}"))

📝 Notes

  • Accepts URLs (https://t.me/...), usernames (@...), or dialog names.
  • A session file is created locally to persist login across runs.
  • First-time authentication may prompt for a verification code.

👤 Author

Christian Pojoni 📧 christian.pojoni@gmail.com


📄 License

MIT

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

telegrammanager-0.1.4.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

telegrammanager-0.1.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file telegrammanager-0.1.4.tar.gz.

File metadata

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

File hashes

Hashes for telegrammanager-0.1.4.tar.gz
Algorithm Hash digest
SHA256 fe2d7ba0f48a5ba0520bf2257602b0e21012422ef5ad927f7fce02147adce631
MD5 40225041afd9a900d50bd02a9cbd8a22
BLAKE2b-256 01e97f5168566416b62af96cd09640fe317e7bfcf8df05e1420d868b3bc8496c

See more details on using hashes here.

File details

Details for the file telegrammanager-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for telegrammanager-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 20ad2e748da4c7d26fb0bdd1bb376bea307f00f1c8922f862383c3fc8c9dc254
MD5 3dc6ea70b68d3e9162e6160f05028bdb
BLAKE2b-256 f67480bf5ffaa74b0f65a5df5e2cc6a4b262bf80b1e99f1050003beb335f0d89

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