// tech stack
// the challenge
A network of Telegram groups needs constant promo posts, but Telegram has no recurring messages and posting by hand does not scale. Group owners cannot be trusted with the bot settings, and a restart must not duplicate or drop a scheduled post.
// the solution
Every ad is stored with its media type, Telegram file id, interval and status, and APScheduler re-arms one interval job per active ad on each boot, so a restart neither loses nor duplicates a schedule. Human-readable intervals ("30 daqiqa", "2h", "1 kun") are parsed into seconds. Only superadmins in private chat can create, edit, pause or delete ads; /check_admin verifies the bot's admin rights and posting permission in every connected group. When the bot is promoted or kicked the group row updates and its ads pause automatically, and a minimal aiohttp health server keeps Koyeb happy.
// measurable impact
One private chat controls every group: an ad is created in a few taps, paused or resumed with inline buttons, and each one reports how many times it was sent. A failed send (demoted or kicked bot) pauses the ad instead of looping errors, and the same code runs on SQLite locally and PostgreSQL in production.
- Timeline
- Oct 2026 · single shipped commit
- Team
- Solo
- Role
- Bot architecture, FSM flows, scheduler and deployment
// key highlights
- ◆FSM-driven ad creation: pick a group, send text or media, choose an interval
- ◆Human interval parser for 30m, 2 soat, 1 kun and plain seconds
- ◆APScheduler re-arms every active ad on startup, so schedules survive restarts
- ◆Inline pause, resume, edit and delete controls on every ad card
- ◆/check_admin audits bot rights and posting permission across all connected groups
// implementation sample
trigger = IntervalTrigger(seconds=ad.interval_seconds)
self.scheduler.add_job(
func=self.send_ad_job,
trigger=trigger,
args=[ad.id],
id=job_id,
replace_existing=True,
name=f"Send Ad #{ad.id} to group {ad.group_id}",
)