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()); }