Files
arsam a4fe0cef16 Import documentation: GEMINI.md
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:14:51 +03:30

2.3 KiB

Tele2Bale Project Context

This project is a Python-based automation tool designed to transfer files and media from a Telegram bot to Bale's "Saved Messages" using a Userbot. It uses a multi-process architecture with a file-based queue system to ensure stability and reliable delivery of large files (bypassing the 50MB bot limit).

Architecture Overview

The application is split into two main components coordinated by a central runner:

  1. Orchestrator (main.py): Spawns and manages two separate processes: the Telegram bot and the Bale worker.
  2. Telegram Bot (telebot.py):
    • Built using Pyrogram.
    • Handles user interactions, receives media, and extracts URLs.
    • Manages the task queue by writing to queue/tasks.jsonl.
    • Provides a "Safe Mode" for ZIP encryption.
    • Monitors queue/status.jsonl for real-time feedback.
  3. Bale Worker (bale.py):
    • Built using aiobale.
    • Operates as a Userbot (logs in with a phone number) to allow uploading files larger than 50MB.
    • Consumes tasks from the queue sequentially.
    • Downloads files from direct URLs if necessary.
    • Performs ZIP encryption when Safe Mode is enabled.
    • Uploads files to the user's Saved Messages (BALE_TARGET_ID).

Key Files and Directories

  • main.py: Entry point that starts both the bot and the worker.
  • telebot.py: Telegram bot logic.
  • bale.py: Bale userbot worker logic.
  • queue/: JSONL files for task management and status reporting.
  • downloads/: Temporary storage for files.

Development & Configuration

Environment Variables (.env)

  • API_ID, API_HASH, BOT_TOKEN: Telegram API credentials.
  • BALE_PHONE: Phone number for Bale authentication (+98...).
  • BALE_TARGET_ID: UID of the target chat in Bale (e.g., Saved Messages ID).

Building and Running

  1. Install dependencies: pip install -r requirements.txt
  2. Initial Setup: Run python3 bale.py manually once to log in and create the bale_userbot.session file. You will need to enter the verification code from Bale.
  3. Run the application: python3 main.py

Conventions

  • Userbot for Large Files: Bale bots are limited to 50MB. This project uses a Userbot to bypass this restriction.
  • Process Isolation: The bot and worker are independent and communicate via files.