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.1.tar.gz (5.1 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.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: telegrammanager-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 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.1.tar.gz
Algorithm Hash digest
SHA256 f64ddb48845e261724c673826e58544836bc6e696320ac98970c84c14089cd50
MD5 9a0196bd77b321b982bb081c45ac3538
BLAKE2b-256 b3f695ecf116100792814df170d78764c78bf4468138a5178ba4fd7ca3566c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for telegrammanager-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c9c13ce52ed4d32b648444a399d910c3e3ff13293f6eb2f4c82e5d45ca3232a
MD5 de9786356a21076dbbbcbd0428624a34
BLAKE2b-256 2fdb2a481484047539e70be7f7af4aeabd6ea6a443a3a3c136b21882cccca995

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