public async Task ProcessUpdate(ITelegramBotClient client, Update update) { long chatId = update.GetChatId(); if (this.state == State.WaitingForMessageText) { if (update.Type == UpdateType.Message) { this.reminder.MessageText = update.Message.Text; this.state = State.WaitingForTime; await client.SendTextMessageAsync(chatId, $"Reminder text:\n{this.reminder.MessageText}\n\nEnter redinder time. Use 24-hour HHmm format.", replyMarkup : TelegramHelper.GetHomeButtonKeyboard()); } } else if (this.state == State.WaitingForTime) { if (update.Type == UpdateType.Message) { string timeText = update.Message.Text; TimeSpan time; if (TelegramHelper.TryParseTime(timeText, out time)) { this.reminder.DayTime = time; this.state = State.WaitingForWeekDays; await client.SendTextMessageAsync(chatId, "Select reminder week days", replyMarkup : getWeekDaysKeyboard(this.reminder.WeekDays)); } else { await client.SendTextMessageAsync(chatId, "Could not parse time. Use 24-hour HHmm format.", replyMarkup : TelegramHelper.GetHomeButtonKeyboard()); } } } else if (this.state == State.WaitingForWeekDays) { if (update.Type == UpdateType.CallbackQuery) { if (update.CallbackQuery.Data == SelectDaysDone) { await client.AnswerCallbackQueryAsync(update.CallbackQuery.Id); await client.EditMessageReplyMarkupAsync(chatId, update.CallbackQuery.Message.MessageId, TelegramHelper.GetHomeButtonKeyboard()); Program.RemindersRepository.StoreReminder(this.reminder); this.Finished = true; await client.SendDefaultMessageAsync(chatId); } else if (Enum.TryParse(typeof(WeekDays), update.CallbackQuery.Data, out object parsed)) { await client.AnswerCallbackQueryAsync(update.CallbackQuery.Id); WeekDays wdSelected = (WeekDays)parsed; this.reminder.WeekDays ^= wdSelected; await client.EditMessageReplyMarkupAsync(chatId, update.CallbackQuery.Message.MessageId, getWeekDaysKeyboard(this.reminder.WeekDays)); } } } }
public async Task ProcessUpdate(ITelegramBotClient client, Update update) { if (update.Type == UpdateType.Message) { string timeText = update.Message.Text; TimeSpan time; if (TelegramHelper.TryParseTime(timeText, out time)) { long chatId = update.Message.Chat.Id; int minutes = Convert.ToInt32((time - update.Message.Date.TimeOfDay).TotalMinutes / 15) * 15; minutes = minutes > 720 ? minutes - 1440 : minutes < -720 ? minutes + 1440 : minutes; TimeSpan timeZone = TimeSpan.FromMinutes(minutes); Program.RemindersRepository.SetTimeZone(chatId, timeZone); this.Finished = true; await client.SendDefaultMessageAsync(chatId); } else { await client.SendTextMessageAsync(update.GetChatId(), "Could not parse time. Use 24-hour HHmm format."); } } }