private async void Bot_OnMessage(object sender, MessageEventArgs e) { var userId = e.Message.From.Id; var command = e.Message.Text?.GetNetMessage(); if (e.Message.Chat.Type != ChatType.Private) { await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.InvalidRequest); return; } if (command == Localization.GetMyId.ToLower()) { await Bot.SendTextMessageAsync(userId, $"{e.Message.From.FirstName} {e.Message.From.LastName}, ID: {userId}"); } else if (UserAuthenticated(e.Message.From, out UserWrapper user)) // CommonReplyKeyboard { try { await user.ConcurrencyController.WaitAsync(); user.LastMessageQuery = e.Message; if (command == Localization.Portfolios.ToLower()) { await Bot.SendChatActionAsync(e.Message.Chat.Id, ChatAction.Typing); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.Portfolios, replyMarkup : KeyboardCollection.PortfolioInlineKeyboard(WebsiteManager.Url)); } else if (command == Localization.About.ToLower()) { await Bot.SendChatActionAsync(e.Message.Chat.Id, ChatAction.Typing); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.About + ": \n\r" + (WebsiteManager.About ?? "---"), replyMarkup : KeyboardCollection.AboutInlineKeyboard); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.Title + ": \n\r" + (WebsiteManager.Title ?? "---"), replyMarkup : KeyboardCollection.TitleInlineKeyboard); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.ContactEmail + ": \n\r" + (WebsiteManager.ContactEmail ?? "---"), replyMarkup : KeyboardCollection.ContactEmailInlineKeyboard); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.FeedbackEmail + ": \n\r" + (WebsiteManager.FeedbackEmail ?? "---"), replyMarkup : KeyboardCollection.FeedbackEmailInlineKeyboard); await Bot.SendTextMessageAsync(e.Message.Chat.Id, Localization.ContactPhone + ": \n\r" + (WebsiteManager.ContactPhone ?? "---"), replyMarkup : KeyboardCollection.ContactPhoneInlineKeyboard); } else if (command == Localization.Logo.ToLower()) { await Bot.SendChatActionAsync(e.Message.Chat.Id, ChatAction.UploadPhoto); using (var stream = new MemoryStream(WebsiteManager.Logo)) { await Bot.SendPhotoAsync(e.Message.Chat.Id, photo : new FileToSend("logo", stream), caption : Localization.Logo, replyMarkup : KeyboardCollection.LogoInlineKeyboard()); } } else if (command == Localization.Links.ToLower()) { await Bot.SendChatActionAsync(e.Message.Chat.Id, ChatAction.Typing); await Bot.SendTextMessageAsync(e.Message.Chat.Id, $"{Emoji.Link + Emoji.Link} L I N K S {Emoji.Link + Emoji.Link}", replyMarkup : KeyboardCollection.LinksInlineKeyboard(WebsiteManager)); } else if (command == Localization.Inbox.ToLower()) { await Bot.SendChatActionAsync(e.Message.Chat.Id, ChatAction.Typing); await Bot.SendTextMessageAsync(e.Message.Chat.Id, $"{Emoji.SpeechBalloon + Emoji.SpeechBalloon} Messages {Emoji.SpeechBalloon + Emoji.SpeechBalloon}"); foreach (var msg in InboxManager.GetMessages()) { var replyLink = $"https://mail.google.com/mail/u/0/?view=cm&tf=0&to={msg.Email}&su=feedback+(via+{WebsiteManager.SiteName})&body=%0D%0A--%0D%0Avia+{WebsiteManager.SiteName}&bcc&cc&fs=1"; await Bot.SendTextMessageAsync(e.Message.Chat.Id, $"{Emoji.WomanArtistLightSkinTone} {msg.Name}: {msg.Subject}\n\r\n\r{Emoji.SpeechBalloon} {msg.Message}", parseMode : ParseMode.Html, replyMarkup : KeyboardCollection.InboxMessageInlineKeyboard(msg.Id, $"Reply {msg.Name}", replyLink)); } } else { if (user.WaitingMessageQuery != null) { var t = typeof(BotManager); var m = t.GetMethod(user.WaitingMessageQuery); m?.Invoke(this, new object[] { user }); } else { await Bot.SendTextMessageAsync( e.Message.Chat.Id, Localization.PleaseChooseYourOptionDoubleDot, replyMarkup : KeyboardCollection.CommonReplyKeyboard()); } } } catch (Exception exp) { Console.WriteLine(exp); } finally { user.ConcurrencyController.Release(); } } else // RegisterReplyKeyboard { if (command == Localization.Start.ToLower()) { await Bot.SendTextMessageAsync( e.Message.Chat.Id, Localization.PleaseChooseYourOptionDoubleDot, replyMarkup : KeyboardCollection.RegisterReplyKeyboard()); } else if (command == Localization.Register.ToLower()) { Accounts[userId].Password = ""; await Bot.SendTextMessageAsync(e.Message.Chat.Id, $"{Emoji.Key} {Localization.Password}: ", replyMarkup : KeyboardCollection.PasswordInlineKeyboard()); } else { await Bot.SendTextMessageAsync( e.Message.Chat.Id, Localization.PleaseChooseYourOptionDoubleDot, replyMarkup : KeyboardCollection.RegisterReplyKeyboard()); } } }
public async Task <bool> GoNextPasswordStep(CallbackQueryEventArgs e) { var userId = e.CallbackQuery.From.Id; if (!Accounts.ContainsKey(userId)) { await Bot.AnswerCallbackQueryAsync(e.CallbackQuery.Id, Localization.EntryPasswordIsIncorrect); return(false); } var data = e.CallbackQuery.Data.ToLower(); if (!data.StartsWith("password_")) { return(false); } if (data.StartsWith("password_num.")) { Accounts[userId].Password += data.Replace("password_num.", ""); } else if (data == "password_enter") { if (Accounts[userId].Password == BotApiPassword) { Accounts[userId].IsAuthenticated = true; await DeleteMessageAsync(e.CallbackQuery.Message); await Bot.AnswerCallbackQueryAsync(e.CallbackQuery.Id, Localization.PasswordIsOk); await Bot.SendTextMessageAsync(e.CallbackQuery.Message.Chat.Id, Localization.PleaseChooseYourOptionDoubleDot, replyMarkup : KeyboardCollection.CommonReplyKeyboard()); return(true); } else // password is incorrect { Accounts[userId].Password = ""; await Bot.AnswerCallbackQueryAsync(e.CallbackQuery.Id, Localization.EntryPasswordIsIncorrect); await DeleteMessageAsync(e.CallbackQuery.Message); return(true); } } else if (data == "password_backspace") { if (Accounts[userId].Password.Length > 0) { Accounts[userId].Password = Accounts[userId].Password.Remove(Accounts[userId].Password.Length - 1, 1); } } else { return(false); } await Bot.EditMessageTextAsync(e.CallbackQuery.Message.Chat.Id, e.CallbackQuery.Message.MessageId, $"{Emoji.Key} {Localization.Password}: " + new string(Accounts[userId].Password.Select(x => '*').ToArray()), ParseMode.Default, false, KeyboardCollection.PasswordInlineKeyboard()); return(true); }