A Python bot that automatically forwards messages from Telegram to Bale messenger with support for text formatting, inline links, media groups, and inline keyboards.
- Forward text messages with proper link formatting
- Forward single photos and media groups
- Support for inline keyboards (buttons)
- Automatic text cleaning and formatting
- UTF-16 to UTF-8 text entity conversion
- Retry mechanisms for failed requests
- Environment variable configuration
- Comprehensive logging
- Python 3.7+
- Telegram Bot Token
- Bale Bot Token
- Target Bale chat/channel ID
- Clone the repository:
git clone https://github.com/yourusername/telegram-bale-forwarder.git
cd telegram-bale-forwarder- Install dependencies:
pip install -r requirements.txt- Create your configuration file:
cp .env.example .env- Edit
.envfile with your bot tokens:
nano .envEdit the .env file with your bot credentials:
# Telegram Bot Token (get from @BotFather)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
# Bale Bot Token (get from Bale BotFather)
BALE_BOT_TOKEN=your_bale_bot_token_here
# Bale target chat ID (channel username with @ or chat ID)
BALE_CHAT_ID=@your_bale_channel_or_chat_idRun the bot:
python main.pyThe bot will:
- Connect to both Telegram and Bale APIs
- Start polling for new messages
- Forward messages with proper formatting
- Log all activities to
telegram_bale_forwarder.log
To stop the bot, press Ctrl+C.
- Message Detection: Bot polls Telegram API for new messages
- Link Processing: Extracts and formats inline links using UTF-16 entity data
- Media Handling: Downloads photos and forwards them as media groups or single photos
- Keyboard Support: Converts Telegram inline keyboards to Bale format
- Text Cleaning: Removes problematic Unicode characters and formats text
- Error Handling: Retries failed requests and falls back to plain text if markdown fails
- ✅ Text messages with inline links
- ✅ Single photos with captions
- ✅ Media groups (multiple photos)
- ✅ Messages with inline keyboards
- ✅ Mentions (@username)
- ✅ URL entities
The bot creates detailed logs in telegram_bale_forwarder.log including:
- Connection status
- Message processing details
- Error messages and retry attempts
- Success/failure status for each forward operation
- Ensure the Telegram bot token is correct
- Verify the bot is added to the source chat/channel
- Check that the bot has permission to read messages
- Verify Bale bot token is correct
- Ensure the bot is added to the target Bale chat/channel
- Check chat ID format (@channel_name or numeric ID)
- The bot automatically handles Persian/Arabic text with proper UTF-16 conversion
- Links are converted to Markdown format with proper spacing
- Keep your
.envfile private and never commit it to version control - The
.env.examplefile is safe to share as it contains no real tokens - Bot tokens provide full access to your bots - treat them like passwords
This project is licensed under the MIT License - see the LICENSE file for details.