I can’t just do this
public static void myBot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs msg)
{
if (DateTime.Now.Hour == 01)
{
myBot.SendTextMessageAsync(msg.Message.Chat.Id, "Good Night");
}
}
Because that requires the user to first send a message at that exact time for them to receive the message. How can i make it autosend a message at a specific to anyone who ever started it without the person having to send message the exact time it would send the automatic message?
2
Answers
You should schedule a task by using the provided interface by Windows.
Also, you should store the ID’s of the users in a database and iterate over them every time the scheluded task is running.
You can find more about task scheduling in C# here Creating Scheduled Tasks
If you developing using .net core you can use IHostedService for realization background task. Also there exist a libraries for sheduled tasks. I recomend Hangfire.
It’s free and easy for use. You can add task like this:
You need database for using Hangfire.