Scheduling Tasks

Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is useful, for example, to send recurring messages to specific chats or users.

This page will show examples of how to integrate Electrogram with apscheduler. For more detailed information, you can visit and learn from the library documentation.


Using apscheduler

from apscheduler.schedulers.asyncio import AsyncIOScheduler

from pyrogram import Client

app = Client("my_account")


async def job():
    await app.send_message("me", "Hi!")


scheduler = AsyncIOScheduler()
scheduler.add_job(job, "interval", seconds=3)

scheduler.start()
app.run()