Auto-forwarder bots are widely used by community managers, crypto signal trackers, news aggregators, and trading groups to synchronize updates across multiple Telegram channels automatically.
Telethon Auto-Forwarder Code with Filtering
# forwarder.py
import os
import asyncio
from telethon import TelegramClient, events
API_ID = int(os.environ.get("API_ID"))
API_HASH = os.environ.get("API_HASH")
SESSION_STRING = os.environ.get("SESSION_STRING")
SOURCE_CHANNELS = [-1001234567890] # Source channel ID
DESTINATION_CHANNEL = -1009876543210 # Destination channel ID
BLOCKED_KEYWORDS = ["scam", "promotion", "http://spam"]
client = TelegramClient("forwarder_session", API_ID, API_HASH)
@client.on(events.NewMessage(chats=SOURCE_CHANNELS))
async def forward_handler(event):
message_text = event.raw_text or ""
# Check keyword blacklist
if any(keyword in message_text.lower() for keyword in BLOCKED_KEYWORDS):
print(f"Skipping post due to blacklisted keyword.")
return
try:
# Re-send media or text to avoid "Forwarded from" header
if event.media:
await client.send_file(DESTINATION_CHANNEL, event.media, caption=message_text)
else:
await client.send_message(DESTINATION_CHANNEL, message_text)
print(f"Successfully forwarded message ID: {event.id}")
except Exception as e:
print(f"Failed to forward message: {str(e)}")
with client:
print("Auto-forwarder is actively monitoring channels...")
client.run_until_disconnected()
Why Cloud Hosting is Critical for Forwarders
If your forwarder bot goes offline for even 5 minutes, you miss critical trading alerts or channel posts. BotifyHost's 24/7 background worker threads keep your socket open constantly with sub-10ms ping to Telegram's MTProto datacenters.
Host Your Telegram Bot 24/7 on BotifyHost
Say goodbye to laptops running overnight and sleeping web dynos. Deploy your bot in 30 seconds with 99.99% uptime, built-in code editor, and live logs.