private async Task CreateDroplet(Message message)
        {
            await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, $"\U0001F4C0 Create droplet...");

            var digitalOceanApi = _digitalOceanClientFactory.GetInstance(message.From.Id);
            var session         = _sessionRepo.Get(message.From.Id);
            var droplet         = session.Data.CastObject <CreateDroplet>().Droplet;
            var createdDroplet  = await digitalOceanApi.Droplets.Create(droplet);

            if (createdDroplet != null)
            {
                _sessionRepo.Update(message.From.Id, session =>
                {
                    session.State = SessionState.MainMenu;
                });

                var stringBuilder = new StringBuilder();

                stringBuilder.Append($"*All Done!* \U0001F973 \n\n");
                stringBuilder.Append($"Name: *{createdDroplet.Name} (Created at {createdDroplet.CreatedAt.ToString("dd:MM:yyyy HH:mm:ss")})*\n");
                stringBuilder.Append($"Image: *{createdDroplet.Image.Distribution} {createdDroplet.Image.Name}*\n");
                stringBuilder.Append($"vCPUs: *{createdDroplet.Vcpus.ToString()}*\n");
                stringBuilder.Append($"Memory: *{createdDroplet.Memory.ToString()}MB*\n");
                stringBuilder.Append($"Disk: *{createdDroplet.Disk.ToString()}GB*\n");
                stringBuilder.Append($"Region: *{createdDroplet.Region.Name}*\n");

                await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, stringBuilder.ToString(), ParseMode.Markdown, replyMarkup : Keyboards.GetMainMenuKeyboard());
            }
        }
Ejemplo n.º 2
0
        private void RunListeningBus()
        {
            _bus.Consume(_bus.QueueDeclare("auth-queue"), register =>
            {
                register.Add <AuthMessage>(async(message, info) =>
                {
                    try
                    {
                        if (message.Body.IsSuccess)
                        {
                            _sessionRepo.Update(message.Body.UserId, (session) =>
                            {
                                session.State = SessionState.MainMenu;
                            });

                            await _telegramBotClient.SendTextMessageAsync(message.Body.ChatId, "Authentication completed \U0001F973", replyMarkup: Keyboards.GetMainMenuKeyboard());
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"UserId={message.Body.UserId.ToString()}, ErrorMessage={ex.Message}, StackTrace={ex.StackTrace}");
                    }
                });
            });
        }
Ejemplo n.º 3
0
        private async Task BackToMainMenu(Message message)
        {
            _sessionRepo.Update(message.From.Id, session =>
            {
                session.State = SessionState.MainMenu;
            });

            await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, "You in main menu", replyMarkup : Keyboards.GetMainMenuKeyboard());
        }