Telegram bots2 minutes to read

How can my Telegram bot send reminders when nobody is messaging it?

Design an opt-in reminder with a stored chat ID, a due time and a scheduled sender. Check delivery, retries and cancellation using one private chat.

A reminder needs a clock and a destination

A Telegram bot can send a reminder to a private chat after the user has started the conversation and opted in. Store the chat ID and the reminder’s due time when you accept it. A running worker or scheduled job can later call sendMessage without waiting for the user to send another command. An individual’s username alone is insufficient to start that private conversation.

For a small personal bot, the command handler and a timer can share one deployment. Store pending reminders on disk so a restart can reconstruct the schedule. A timer living only in process memory loses its list when you redeploy.

Work through a concrete delivery time

Suppose a user requests a reminder at 09:07 UTC. A checker that runs on the quarter hour may send it around 09:15. A promised minute-accurate alarm would need a different schedule and a policy for downtime. Store the user’s time zone when accepting a local time, then calculate the due instant in UTC.

If you separate the checker into a scheduled Python deployment, reserve a second slot and give both processes access to a shared store. Separate deployments have separate local files. A database hosted in a third deployment also needs its own slot and allocation. The free account has one slot, so keep the timing and command logic together if the project must fit there.

Rehearse delivery and cancellation

  1. Create a reminder for your own chat, restart the worker before it is due, and check that the saved reminder reappears.
  2. Send it when due and record Telegram’s successful result. If the process can crash after sending but before saving, define how to handle an uncertain result before automatically retrying.
  3. Create a second reminder and cancel it. Check that the due-time scan skips it and that the first reminder is not sent again on every scan.

Telegram documents the required destination and text in sendMessage.