Skip to main content

Simple Interface for Telegram read and listen

Project description

TelegramManager

A Python CLI tool and module for fetching and monitoring Telegram messages from public channels and groups. Built with Telethon for reliable Telegram API integration.

Installation

Install TelegramManager using pip:

pip install .

For development installation:

pip install -e .[dev]

Configuration

Environment Configuration

Create a .env file in your project root directory:

TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
TELEGRAM_PHONE_NUMBER=+1234567890

The default TelegramManager() constructor automatically loads these environment variables.

Manual Configuration

For programmatic usage without environment files:

from telegram_manager.controller import TelegramManager

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

Command Line Interface

The tm command provides two primary operations:

Fetch Messages

Retrieve historical messages from a channel or group:

tm fetch <channel> [--min-id <id>] [--limit <n>] [--since <relative-time>] [--search <text>] [--json] [--verbose]

Options:

  • --min-id: Minimum message ID to fetch from.
  • --limit: Maximum number of messages to retrieve.
  • --since: Filter messages newer than a relative time expression.
  • --search: Filter messages containing the given search string.
  • --json: Output each message in JSON format.
  • --verbose: Print detailed metadata per message.

Supported --since formats:

  • mo: months (e.g. 1mo)
  • w: weeks (e.g. 2w)
  • d: days (e.g. 3d)
  • h: hours (e.g. 4h)
  • m: minutes (e.g. 30m)

You can combine units:

tm fetch @openai --since "1mo 2w 3d 4h 30m" --search GPT --verbose

Listen for Messages

Monitor channels for new messages in real-time:

tm listen <channel>

Example:

tm listen "Some Group Chat"

Verbose Mode

When --verbose is enabled in fetch, each message will include:

  • Message ID
  • Date in local time and UTC
  • Sender username and ID
  • Message type (text, photo, document, video)
  • Reply-to message ID (if any)
  • Raw text content

A final summary is also printed, including:

  • Total messages
  • Unique user count
  • Breakdown by media type
  • Minimum message ID fetched

JSON Output

Use --json to emit each message as a structured JSON object. This is useful for piping into other programs or saving to file.

Python API

Basic Usage

from telegram_manager import TelegramManager

tg = TelegramManager()

Fetching Messages

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

Real-time Message Monitoring

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

Supported Input Formats

TelegramManager accepts multiple channel identifier formats:

  • Telegram URLs: https://t.me/channelname
  • Username format: @channelname
  • Dialog names: "Channel Display Name"

Authentication

  • Session files are created locally to maintain authentication across sessions
  • First-time usage requires verification code entry
  • Authentication state persists between program runs

Requirements

  • Python 3.7 or higher
  • Valid Telegram API credentials
  • Network connectivity for Telegram API access

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: telegrammanager-0.1.10.tar.gz
  • Upload date:
  • Size: 7.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.10.tar.gz
Algorithm Hash digest
SHA256 0f67e236975b4003b855a0ada9df9913c82f3a77a247ea17f5a1f8e6f91d837f
MD5 d5227ec2e3ed8cb3a6abc9c39e437209
BLAKE2b-256 2af57f6f39f93e74dbbdc40541066d8bc4873af19f7b90a965e6a13ff1c45ad4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for telegrammanager-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 27799a28516546a8c302fb4cbd7171a2d6ec8d00dd43708c6c95dfcdeee80984
MD5 16a14038c0fa2fbe12ced147859cc41f
BLAKE2b-256 0482bf52d4f5afdb1ed69c9e24a1f5f3c1883340a1d28f4f89f393c20e57ba0f

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