예제 #1
0
        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")
                                    }
                                })
                                    );
                            }
        }
예제 #3
0
 public Task <ServerTaskResource> QueueImport(ImportTaskArgumentsResource args)
 => ApiClientWrapper.Create <ServerTaskResource>(
     RootUri + "/import",
     new ServerTaskQueueRequest <ImportTaskArgumentsResource>()
 {
     Arguments = args
 }
     );
예제 #4
0
        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")
                }
            })
                );
        }
예제 #5
0
        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")
                    }
                })
                    );
            }
        }
예제 #6
0
 public Task <InternalUpstreamResource> Update(InternalUpstreamResource resource)
 => ApiClientWrapper.Update <InternalUpstreamResource>($"{RootUri}/{resource.Id}", resource);
예제 #7
0
 public Task <InternalUpstreamResource> Get(Guid id)
 => ApiClientWrapper.Get <InternalUpstreamResource>($"{RootUri}/{id}");
예제 #8
0
 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")
                    }
                })
                    );
            }
        }
예제 #10
0
 public Task Remove(MemberResource resource)
 => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
예제 #11
0
 public Task <MemberResource> Get(Guid id)
 => ApiClientWrapper.Get <MemberResource>($"{RootUri}/{id}");
예제 #12
0
 public Task Remove(CustomDomainResource resource)
 => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
예제 #13
0
 public Task <CustomDomainResource> Create(CustomDomainResource resource)
 => ApiClientWrapper.Create <CustomDomainResource>(RootUri, resource);
예제 #14
0
 public Task <CustomDomainResource> Get(Guid id)
 => ApiClientWrapper.Get <CustomDomainResource>($"{RootUri}/{id}");
예제 #15
0
 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")
                    }
                })
                    );
            }
        }
예제 #17
0
 public Task <IReadOnlyList <MemberResource> > List()
 => ApiClientWrapper.List <MemberResource>(RootUri);
예제 #18
0
 public Task <IReadOnlyList <OrganisationResource> > List()
 => ApiClientWrapper.List <OrganisationResource>(RootUri);
예제 #19
0
 public Task <MemberResource> Update(MemberResource resource)
 => ApiClientWrapper.Update <MemberResource>($"{RootUri}/{resource.Id}", resource);
예제 #20
0
 public Task <OrganisationResource> Get(string slug)
 => ApiClientWrapper.Get <OrganisationResource>($"{RootUri}/{slug}");
예제 #21
0
 public Task SendInvites(MemberInviteRequest request)
 => ApiClientWrapper.Create($"{RootUri}/invite", request);
예제 #22
0
 public Task <OrganisationResource> Create(OrganisationCreateResource resource)
 => ApiClientWrapper.Create <OrganisationResource>(RootUri, resource);
예제 #23
0
 public Task <BillingResource> Get()
 => ApiClientWrapper.Get <BillingResource>(RootUri);
예제 #24
0
 public Task <OrganisationResource> Update(OrganisationResource resource, string currentSlug = null)
 => ApiClientWrapper.Update <OrganisationResource>($"{RootUri}/{currentSlug ?? resource.Slug}", resource);
예제 #25
0
 public Task <IReadOnlyList <InternalUpstreamResource> > List()
 => ApiClientWrapper.List <InternalUpstreamResource>(RootUri);
예제 #26
0
 public Task Remove(OrganisationResource resource)
 => ApiClientWrapper.Remove($"{RootUri}/{resource.Slug}");
예제 #27
0
 public Task <InternalUpstreamResource> Create(InternalUpstreamResource resource)
 => ApiClientWrapper.Create <InternalUpstreamResource>(RootUri, resource);
예제 #28
0
 public Task <TeamResource> Create(TeamResource resource)
 => ApiClientWrapper.Create <TeamResource>(RootUri, resource);
예제 #29
0
 public Task Remove(InternalUpstreamResource resource)
 => ApiClientWrapper.Remove($"{RootUri}/{resource.Id}");
예제 #30
0
 public Task <TeamResource> Update(TeamResource resource)
 => ApiClientWrapper.Update <TeamResource>($"{RootUri}/{resource.Id}", resource);