My task is to make a bot telegram to which the user throws some habit (for example, to drink water) and a certain time when the bot should forward this message to the user. Such a bot is a habit. The trick is that I don’t quite understand what the logic should be so that the bot can send messages at a specific time + such an option is possible, like repeating days or weeks. Therefore, I ask for help, how best to write, and how to write this mechanics in general.

UPD. Perhaps some solution through the Task list, with deferred action time

  • See work logic and source codes cron , crontab - NewView

2 answers 2

Most likely you will need a library like Quartz. And as soon as a user adds a reminder, you will need to add it to the quartz.

Quartz, when some time comes, will call a method of the type SendTeleMessage (string user, string message); within which the logic of sending a message is implemented ...

or something like that :)


UPD. Perhaps some solution through the Task list, with deferred action time

There is such a thing as TaskScheduler. You can implement through it. But not sure that this is a good solution.

  • I'm afraid that the use of third-party libraries is not provided for my task, besides, everything should be easier implemented - pluw3v0
  • This is the easiest way. Any other method without libraries - this will be the invention of a bicycle and a more complex implementation. - Andrew
  • The teacher also requires that students do not use third-party libraries - pluw3v0
  • well then TaskScheduler - Andrew
  • Is it possible to get some information about how he can, for example, wait and receive messages from the user in parallel? - pluw3v0

A little crutch method, but it will suit you.

You can run sql db and poll every minute, or build logic when you receive immediate tasks.

Both options should be suitable for you, since, in addition to the bot, you will not receive extra high performance (several thousand reminders to feed the cat at 18:05) from the bot. Due to a limit of 20 messages per minute .

  • The second option suits me better, but I don’t quite understand it - pluw3v0
  • Questioning the upcoming tasks for the next 10 minutes> receive, conditionally, 500 reminders from different clients by level> sort them by client importance or reminders (you cannot instantly send messages to everyone, so you need priorities)> and gradually send - Walker