The Problem: Manual Media Curation is a Time Sink
As developers, we build automation so we don't have to do repetitive tasks. For months, I was manually downloading alerts, logs, and screenshots from various server monitoring dashboards, converting them, and posting them into specific Telegram channels for my clients and team. It took 2-3 hours of fragmented attention daily.
I decided to automate this with a central Python-based forwarding daemon that integrates with the Telegram Bot API.
The Architecture: Queue-Based Forwarding
To avoid hitting Telegram's strict API rate limits (max 30 messages per second, and 20 messages per minute in groups), I built a small asynchronous worker queue using Python's asyncio and python-telegram-bot.
import asyncio
from telegram import Bot
from telegram.error import RetryAfter
class TelegramQueue:
def __init__(self, token):
self.bot = Bot(token=token)
self.queue = asyncio.Queue()
async def add_message(self, chat_id, text, media=None):
await self.queue.put((chat_id, text, media))
async def worker(self):
while True:
chat_id, text, media = await self.queue.get()
try:
if media:
await self.bot.send_photo(chat_id=chat_id, photo=media, caption=text)
else:
await self.bot.send_message(chat_id=chat_id, text=text)
await asyncio.sleep(0.1) # Safe spacing
except RetryAfter as e:
# Handle flood limits gracefully
await asyncio.sleep(e.retry_after)
await self.queue.put((chat_id, text, media))
finally:
self.queue.task_done()
Handling Media Groups (Albums)
One major challenge was grouping multiple screenshots together. If you send images one-by-one, Telegram rings notification bells multiple times. The solution is to batch messages dynamically by listening for a short 0.5s window of silence, then sending them as an input_media_group.
The Results
Now, my monitoring servers simply hit a local FastAPI webhook, which puts the log file and screenshot in the queue. The bot handles the rest. Total daily maintenance time: 0 minutes. I reclaimed 3 hours every day to focus on building new code features.