public static async Task Start(TelegramBotClient client) { while (true) { Time = DateTime.Now; if ((Time.Hour == (20 - _ukrUtc) && Time.Minute == 00) || (Time.Hour == (7 - _ukrUtc) && Time.Minute == 30)) { if (await CheckHolidayDayAsync() == true) { continue; } var allUsers = await BalDbController.GetUsersAsync(); _users = allUsers.Where <UserInfo>(ui => ui.SchedulerNotification == true).ToList(); await SendScheduler(client); // Send message to users } ThreadPool.GetAvailableThreads(out int workerThreads, out int _); ThreadPool.GetMaxThreads(out int maxWorkerThreads, out int _); await client.SendTextMessageAsync(chatId : AppSettings.ChatIdCreator, text : $"Notification {DateTime.Now}. DateTime.Now.Hour: {DateTime.Now.Hour}; DateTime.Now.Minute: {DateTime.Now.Minute}; DateTime.UtcNow: {DateTime.UtcNow}; IsThreadPool: {Thread.CurrentThread.IsThreadPoolThread}; ThreadPool workers: {workerThreads} in max: {maxWorkerThreads}"); Task.Delay(60000).Wait(); // 60 seconds /* * 1. Каждую 1 минуту подлючаться к бд и проверять пользователей (может кто-то добавился). V * 2. Проверять, есть ли у пользователей вкл. на уведомление. * 3. Если есть, сравнивать, не нужно ли отправлять уведомление пользователю. * 4. Если уведомление отправлено, помечать это. */ } }
public async Task <OkResult> Post([FromBody] JToken result) { var botClient = await Bot.GetBotClientAsync(); var user = await BalDbController.GetUserInformationAsync(AppSettings.ChatIdCreator); //await new SchedulerAlertsController().Execute( // new Message() {Text = new SchedulerAlertsController().StopAlerts}, botClient, user); await new SchedulerAlertsController().Execute( new Message() { Text = new SchedulerAlertsController().StartAlerts }, botClient, user); await Task.Delay(1080000); // 18 min SendMessageOtherAppTask().Wait(); return(Ok()); }
public async Task <OkResult> Post([FromBody] Update update) { if (update == null) { return(Ok()); } var commands = Bot.Commands; var ikCommands = Bot.InlineKeyboardCommands; Message message = default; switch (update.Type) { case Telegram.Bot.Types.Enums.UpdateType.Message: message = update.Message; break; case Telegram.Bot.Types.Enums.UpdateType.CallbackQuery: message = update.CallbackQuery.Message; break; default: throw new NotImplementedException(); } var botClient = await Bot.GetBotClientAsync(); await botClient.SendChatActionAsync(message.Chat.Id, Telegram.Bot.Types.Enums.ChatAction.Typing); var userInformation = await BalDbController.GetUserInformationAsync(message.Chat.Id); if (userInformation == null) { await new StartCommand().Execute(message, botClient, null); return(Ok()); } // Inline keyboard commands if (update.Type == Telegram.Bot.Types.Enums.UpdateType.CallbackQuery) { foreach (var command in ikCommands) { if (command.Contains(message)) { try { await command.Execute(update.CallbackQuery, botClient, userInformation); } catch (Exception ex) { await SendMessageToCreatorOfException(ex, userInformation, botClient); } return(Ok()); } } } // Bot commands foreach (var command in commands) { if (command.Contains(message)) { try { var result = await command.Execute(message, botClient, userInformation); } catch (Exception ex) { await SendMessageToCreatorOfException(ex, userInformation, botClient); } return(Ok()); } } // State Machine Registration if (userInformation.IsRegistred == false && userInformation.State != RegistrationStateMachine.None.ToString()) // If user start registred { try { await new RegistrationState(botClient, userInformation) .HandleStateRegistrationAsync(message); // Go to state machine registration } catch (Exception ex) { await SendMessageToCreatorOfException(ex, userInformation, botClient); } return(Ok()); } // State Machine Send Message Other User if ((Regex.IsMatch(userInformation.State, SendMessagesCommand.SendMessageState.FromPupilToTeacher.ToString()) || Regex.IsMatch(userInformation.State, SendMessagesCommand.SendMessageState.FromTeacherToPupils.ToString()) || Regex.IsMatch(userInformation.State, SendMessagesCommand.SendMessageState.FromPupilToClassmates.ToString()) ) ) { await new SendMessagesCommand().Execute(message, botClient, userInformation); } return(Ok()); }