Skip to main content

◈ Telegram / Automation · 2026

Telegram Ad Bot — Scheduled Group Ads

A Telegram admin bot that reposts text, photo and video ads in groups on human intervals like 30m, 2h or 1d

Pythonaiogram 3APSchedulerPostgreSQL
Project overview
text, photo, video, doc, GIFMedia types
30m · 2h · 1dIntervals
Postgres or SQLiteStorage
ads re-armed on bootRestarts

A modular aiogram 3 bot that works as an administrator inside Telegram groups and posts scheduled ads: text, photo, video, document or GIF, each on its own interval. Ads, intervals and send counters survive restarts because they live in the database, and the scheduler re-arms every active ad on boot. Only superadmins in private chat can create or edit anything, while group admins simply get a notification when the bot is promoted, demoted or removed.

// tech stack

Pythonaiogram 3APSchedulerPostgreSQLSupabaseSQLiteaiosqlitePydantic SettingsaiohttpDockerKoyeb

// 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}",
)