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.CallbackQuery)
            {
                long reminderId;
                if (long.TryParse(update.CallbackQuery.Data, out reminderId))
                {
                    await client.AnswerCallbackQueryAsync(update.CallbackQuery.Id);

                    long chatId = update.CallbackQuery.Message.Chat.Id;
                    await client.EditMessageReplyMarkupAsync(chatId, update.CallbackQuery.Message.MessageId, TelegramHelper.GetHomeButtonKeyboard());

                    Program.RemindersRepository.RemoveReminder(chatId, reminderId);
                    this.Finished = true;
                    await client.SendDefaultMessageAsync(chatId);
                }
            }
        }
        public async Task Initialize(ITelegramBotClient client, Update update)
        {
            long chatId = update.GetChatId();

            if (Program.RemindersRepository.ChatExists(chatId))
            {
                this.reminder        = new Reminder();
                this.reminder.ChatId = chatId;
                await client.SendTextMessageAsync(chatId, "Enter new reminder name", replyMarkup : TelegramHelper.GetHomeButtonKeyboard());
            }
        }
Exemple #4
0
 public async Task Initialize(ITelegramBotClient client, Update update)
 {
     await client.SendTextMessageAsync(update.GetChatId(),
                                       "Enter your current local time to detect your timezone. Use 24-hour HHmm format.",
                                       replyMarkup : TelegramHelper.GetHomeButtonKeyboard());
 }