Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Forward Bot

English | 简体中文

Forward messages between Telegram chats using a simple, file‑configured bot. Users can register themselves, add forwarding rules, list or delete their own rules, while admins can inspect users and their forwards.

Features

  • Forward channel posts or group messages from one chat to another
  • High concurrency
  • YAML configuration with log level and admin controls

Requirements

  • Python >= 3.12
  • Dependencies installed from requirements.txt or pyproject.toml

Configuration

The bot reads config.yaml at startup. On first run, if config.yaml does not exist, a default file is created and the program exits. Edit the file and restart.

Example config.yaml:

log:
  level: INFO
telegram:
  token: "YOUR_BOT_TOKEN"
  only_admin_add_forward: false
  admins: [123456789]
  • log.level: Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL).
  • telegram.token: Bot token from BotFather.
  • telegram.only_admin_add_forward: If true, regular users cannot add forwards.
  • telegram.admins: Telegram user IDs who are considered admins.

Running

Needs Python 3.12 or newer.

# If uv is available
uv sync && uv run main.py

# If uv is not available
pip install -r requirements.txt

# Start the bot
python main.py

Notes:

  • Invite the bot to the source and destination chats.
  • For channels, ensure the bot has permission to read posts; for groups, it must be present and able to read messages.
  • The first successful run initializes data.db and creates tables.

Commands

User

  • /start — Register yourself with the bot.
  • /add <from_chat> <to_chat> — Add a forwarding rule. Example:
    /add -1001234567890 -1009876543210
    
    from_chat and to_chat are numeric chat IDs. Use /chat_id in a group/channel to get its ID.
  • /list — List your forwarding rules. Chat names are shown when known.
  • /del <forward_id> — Delete one of your rules by its ID.
  • /chat_id — In a group/channel, returns the chat’s numeric ID.

Admin

  • /list_users — Show all registered users.
  • /list_forwards <user_id> — Show all forwards for a specific user.

Forwarding Behavior

  • Channel posts are handled and forwarded when a matching rule exists.
  • Group messages are handled and forwarded when a matching rule exists.
  • Private chats are ignored (aside from registration via /start).

Data Storage

  • SQLite database file: data.db
  • Tables:
    • forwards(id, user_id, from_chat, to_chat)
    • users(id, user_id, name)
    • chats(id, chat_id, name)

Tips

  • Telegram supergroup and channel IDs are typically negative numbers (e.g., -100...).
  • If forwarding does not occur, verify the bot’s permissions and the chat IDs.

About

Forward messages between Telegram chats using a simple

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages