I’m trying to make a bot which will be able to notify users at a certain time every day. how can I make bot to send notification at certain time every day?
I’ve tried to use while loop but it s
@bot.callback_query_handler(func=lambda c:True)
def CalendarAnswer(c):
Cid = c.message.chat.id
if c.data == 'ShowTime':
bot.send_message(Cid, timeToday)
if c.data == 'ShowDate':
bot.send_message(Cid, dateToday)
if c.data == 'SetNotification':
Ask = bot.send_message(Cid, 'Напиши мне время')
bot.register_next_step_handler(Ask,SettingNotificationTime)
def SettingNotificationTime(message):
NotificationTime = message.text
bot.send_message(message.chat.id, "that's your time:" + NotificationTime)v
i don’t have any idea of how can i solve my problem
2
Answers
For regularly scheduling batch tasks, you should you the system built-ins:
On Windows, it’s the Task Scheduler, formerly a command called “at”:
https://www.windowscentral.com/how-create-task-using-task-scheduler-command-prompt
Related to this is the “at” command:
https://support.microsoft.com/en-us/help/313565/how-to-use-the-at-command-to-schedule-tasks
On Linux, it’s “cron”:
https://opensource.com/article/17/11/how-use-cron-linux
You could use JobQueue from class telegram.ext
It has a function called run_daily.
Here is an example:
This run_daily function calls the callback_alarm function daily at 10:10:10 AM