public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; // Bot.UserStates[message.Chat.Id].SetState(UserState.InMainMenu); Logger.GetState(message.Chat.Username, Bot.UserStates[message.Chat.Id]); Regex regex = new Regex(@"Id: (\d+)"); string flightId = regex.Match(message.Text).Groups[1].Value; IReservation ir = new ApiClientWrapper(AppSettings.GetEntry("URL")); var reservation = await ir.GetReservationByIdAsync(int.Parse(flightId)); if (reservation == null) { answer = "Reservation has not been found!"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); return; } if (await ir.DeleteReservationAsync(reservation.Id)) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Reservation has been successfully deleted!", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); } else { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Something went wrong. Return to main menu.", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); } }
public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; Regex regex = new Regex(@"Id: (\d+)"); string flightId = regex.Match(message.Text).Groups[1].Value; IReservation ir = new ApiClientWrapper(AppSettings.GetEntry("URL")); var reservation = await ir.GetReservationByIdAsync(int.Parse(flightId)); if (reservation == null) { answer = "Reservation has not been found!"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); return; } // TODO: add compressing to string //*For example: huffman coding string rawData = JsonConvert.SerializeObject(reservation); string data = await Encrypter.EncryptAsync(rawData); using (QRCodeGenerator qrcodeGenerator = new QRCodeGenerator()) using (QRCodeData qrcodeData = qrcodeGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q)) using (QRCode qrcode = new QRCode(qrcodeData)) using (Bitmap bitmap = qrcode.GetGraphic(50)) using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Png); ms.Position = 0; TimeSpan timeSpan = DateTime.Now - new DateTime(1970, 1, 1); string filename = $"{timeSpan.TotalMilliseconds.ToString()}.png"; await client.SendPhotoAsync( chatId : message.Chat.Id, photo : new InputOnlineFile(ms, filename), caption : "QrCode generated!", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); } }
public Task <ServerTaskResource> QueueImport(ImportTaskArgumentsResource args) => ApiClientWrapper.Create <ServerTaskResource>( RootUri + "/import", new ServerTaskQueueRequest <ImportTaskArgumentsResource>() { Arguments = args } );
public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; IUser iu = new ApiClientWrapper(AppSettings.GetEntry("URL")); var user = (await iu.GetUsersAsync()) .Where(u => { Logger.Get().Debug("u.TgUid: " + u.TgUid); return(u.TgUid == message.Chat.Id.ToString()); }) .Single(); if (user == null) { answer = "No user with such ID has been found! Returning to main menu..."; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer ); await Bot.Callbacks .Where(c => c.Query == "menu") .SingleOrDefault() .Execute(message, client, from); return; } Regex regex = new Regex(@"Id: (\d+)"); string flightId = regex.Match(message.Text).Groups[1].Value; Logger.Get().Debug($"UserId: {user.Id}\nFlightId: {flightId}"); IReservation ir = new ApiClientWrapper(AppSettings.GetEntry("URL")); await ir.CreateReservationAsync(new Client.Models.Reservation { Flight = new Client.Models.Flight { Id = int.Parse(flightId) }, User = new Client.Models.User { Id = user.Id } }); answer = "Reservation has been created successfully!"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); }
public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; if (!Bot.UserStates.ContainsKey(message.Chat.Id)) { Bot.UserStates.Add( message.Chat.Id, new UserStateMachine { CurrentState = UserState.None, PreviousState = UserState.None } ); } IUser iuser = new ApiClientWrapper(AppSettings.GetEntry("URL")); var users = (await iuser.GetUsersAsync()) .Where(u => u.TgUid == message.Chat.Id.ToString()) .ToList(); if (users == null || users.Count == 0) { await iuser.CreateUserAsync(new Client.Models.User { Name = message.Chat.Username, TgUid = message.Chat.Id.ToString() }); answer = "User has been created successfully!"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); } else { answer = $"You are already signed up.\nProcess to menu, please"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Go to menu", "menu") } }) ); } }
public Task <InternalUpstreamResource> Update(InternalUpstreamResource resource) => ApiClientWrapper.Update <InternalUpstreamResource>($"{RootUri}/{resource.Id}", resource);
public Task <InternalUpstreamResource> Get(Guid id) => ApiClientWrapper.Get <InternalUpstreamResource>($"{RootUri}/{id}");
public Task <BillingResource> Update(BillingResource resource) => ApiClientWrapper.Update <BillingResource>(RootUri, resource);
public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; IFlight ifl = new ApiClientWrapper(AppSettings.GetEntry("URL")); if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.InMainMenu) { Bot.UserStates[message.Chat.Id].SetState(UserState.InFlightsMenu); } Logger.GetState(message.Chat.Username, Bot.UserStates[message.Chat.Id]); if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.InFlightsMenu) { answer = "Find the country you're going..."; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("From", "fromCountry") // TODO: change name }, new [] { InlineKeyboardButton.WithCallbackData("To", "toCountry") // TODO: change name }, new [] { InlineKeyboardButton.WithCallbackData("From... To...", "fromTo") }, new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.DepartureCountryInputStarted) { answer = "Please, reply on this message with name country of departure:"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new ForceReplyMarkup() ); Bot.UserStates[message.Chat.Id].SetState(StateMachine.UserState.DepartureCountryInputEnded); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.DepartureCountryInputEnded) { // Command logic var flights = (await ifl.GetFlightsAsync()) .Where(f => f.From.Name == message.Text) .ToList(); // Show all found flights if (flights == null) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "No flights from this country yet. Sorry for inconvenience.", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Found {flights.Count} flights" ); foreach (var flight in flights) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Id: {flight.Id}\n" + $"From: {flight.From.Name}\n" + $"To: {flight.To.Name}" + $"Date: {flight.Departure.ToString("dd-MM-yyyy HH:mm:ss")}", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Create reservation", "createReservation") } }) ); } } // Print message with button to return to main menu await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "Choose an action:", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.ArrivalCountryInputStarted) { answer = "Please, reply on this message with name country of arrival:"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new ForceReplyMarkup() ); Bot.UserStates[message.Chat.Id].SetState(StateMachine.UserState.ArrivalCountryInputEnded); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.ArrivalCountryInputEnded) { // Command logic var flights = (await ifl.GetFlightsAsync()) .Where(f => f.To.Name == message.Text) .ToList(); // Show all found flights if (flights == null) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "No flights to this country yet. Sorry for inconvenience.", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Found {flights.Count} flights" ); foreach (var flight in flights) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Id: {flight.Id}\n" + $"From: {flight.From.Name}\n" + $"To: {flight.To.Name}" + $"Date: {flight.Departure.ToString("dd-MM-yyyy HH:mm:ss")}", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Create reservation", "createReservation") } }) ); } } // Print message with button to return to main menu await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "Choose an action:", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.DACountryInputStarted) { answer = "Please, reply on this message with name country of departure and arrival(for example, Ukraine USA):"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new ForceReplyMarkup() ); Bot.UserStates[message.Chat.Id].SetState(StateMachine.UserState.DACountryInputEnded); } else if (Bot.UserStates[message.Chat.Id].CurrentState == UserState.DACountryInputEnded) { string[] countries = message.Text.Split(" ").ToArray(); // Command logic var flights = (await ifl.GetFlightsAsync()) .Where(f => f.From.Name == countries[0] && f.To.Name == countries[1]) .ToList(); // Show all found flights if (flights == null) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "No flights with such parameters yet. Sorry for inconvenience.", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Found {flights.Count} flights" ); foreach (var flight in flights) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Id: {flight.Id}\n" + $"From: {flight.From.Name}\n" + $"To: {flight.To.Name}" + $"Date: {flight.Departure.ToString("dd-MM-yyyy HH:mm:ss")}", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Create reservation", "createReservation") } }) ); } } // Print message with button to return to main menu await client.SendTextMessageAsync( chatId : message.Chat.Id, text : "Choose an action:", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } }
public Task Remove(MemberResource resource) => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
public Task <MemberResource> Get(Guid id) => ApiClientWrapper.Get <MemberResource>($"{RootUri}/{id}");
public Task Remove(CustomDomainResource resource) => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
public Task <CustomDomainResource> Create(CustomDomainResource resource) => ApiClientWrapper.Create <CustomDomainResource>(RootUri, resource);
public Task <CustomDomainResource> Get(Guid id) => ApiClientWrapper.Get <CustomDomainResource>($"{RootUri}/{id}");
public Task <IReadOnlyList <CustomDomainResource> > List() => ApiClientWrapper.List <CustomDomainResource>(RootUri);
public override async Task Execute(Message message, TelegramBotClient client, User from) { string answer = ""; Bot.UserStates[message.Chat.Id].SetState(UserState.InReservations); Logger.GetState(message.Chat.Username, Bot.UserStates[message.Chat.Id]); IReservation ir = new ApiClientWrapper(AppSettings.GetEntry("URL")); var reservations = (await ir.GetReservationsAsync()) .Where(r => r.User.TgUid == message.Chat.Id.ToString()) .ToList(); if (reservations == null || reservations.Count == 0) { answer = "You haven't booked anything yet!"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } else { answer = "Your reservations:"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer ); foreach (var r in reservations) { await client.SendTextMessageAsync( chatId : message.Chat.Id, text : $"Id: {r.Id.ToString()}\n" + $"Departure: {r.Flight.Departure.ToString("dd-MM-yyyy HH:mm:ss")}\n" + $"From: {r.Flight.From.Name}\n" + $"To: {r.Flight.To.Name}\n" + $"User: {r.User.Name}", replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Get info in QR code", "generateQRCode") }, new [] { InlineKeyboardButton.WithCallbackData("Delete resrvation", "deleteResrvation") } }) ); } answer = $"Choose an action:"; await client.SendTextMessageAsync( chatId : message.Chat.Id, text : answer, replyMarkup : new InlineKeyboardMarkup(new [] { new [] { InlineKeyboardButton.WithCallbackData("Back to menu", "menu") } }) ); } }
public Task <IReadOnlyList <MemberResource> > List() => ApiClientWrapper.List <MemberResource>(RootUri);
public Task <IReadOnlyList <OrganisationResource> > List() => ApiClientWrapper.List <OrganisationResource>(RootUri);
public Task <MemberResource> Update(MemberResource resource) => ApiClientWrapper.Update <MemberResource>($"{RootUri}/{resource.Id}", resource);
public Task <OrganisationResource> Get(string slug) => ApiClientWrapper.Get <OrganisationResource>($"{RootUri}/{slug}");
public Task SendInvites(MemberInviteRequest request) => ApiClientWrapper.Create($"{RootUri}/invite", request);
public Task <OrganisationResource> Create(OrganisationCreateResource resource) => ApiClientWrapper.Create <OrganisationResource>(RootUri, resource);
public Task <BillingResource> Get() => ApiClientWrapper.Get <BillingResource>(RootUri);
public Task <OrganisationResource> Update(OrganisationResource resource, string currentSlug = null) => ApiClientWrapper.Update <OrganisationResource>($"{RootUri}/{currentSlug ?? resource.Slug}", resource);
public Task <IReadOnlyList <InternalUpstreamResource> > List() => ApiClientWrapper.List <InternalUpstreamResource>(RootUri);
public Task Remove(OrganisationResource resource) => ApiClientWrapper.Remove($"{RootUri}/{resource.Slug}");
public Task <InternalUpstreamResource> Create(InternalUpstreamResource resource) => ApiClientWrapper.Create <InternalUpstreamResource>(RootUri, resource);
public Task <TeamResource> Create(TeamResource resource) => ApiClientWrapper.Create <TeamResource>(RootUri, resource);
public Task Remove(InternalUpstreamResource resource) => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
public Task <TeamResource> Update(TeamResource resource) => ApiClientWrapper.Update <TeamResource>($"{RootUri}/{resource.Id}", resource);