public async Task ExecuteHandlerAsync(Message message) { var state = _storageService.Get <BotStateType>(StorageKeys.BotCurrentState); switch (state) { case BotStateType.ProjectCreateWaitingEnterName: await EnterName(message); break; case BotStateType.ProjectCreateWaitingEnterDescription: await EnterDescription(message); break; case BotStateType.ProjectCreateWaitingEnterPurpose: await EnterPurpose(message); _storageService.Remove(StorageKeys.Projects); _storageService.Remove(StorageKeys.NewProject); _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); break; default: throw new ArgumentOutOfRangeException(nameof(state)); } }
public async Task ExecuteHandlerAsync(Message message) { var state = _storageService.Get <BotStateType>(StorageKeys.BotCurrentState); switch (state) { case BotStateType.FirewallCreateWaitingEnterName: await EnterName(message); break; case BotStateType.FirewallCreateWaitingEnterInboundRule: await EnterInboundRule(message); break; case BotStateType.FirewallCreateWaitingEnterAddDroplet: await EnterDroplets(message); _storageService.Remove(StorageKeys.Droplets); _storageService.Remove(StorageKeys.NewFirewall); _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); break; default: throw new ArgumentOutOfRangeException(nameof(state)); } }
public async Task ExecuteCommandAsync(Message message) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : CommonMessage.GetMainMenuMessage(), replyMarkup : CommonKeyboard.GetMainMenuKeyboard()); }
public async Task ExecuteCallbackQueryAsync(long chatId, int messageId, string callbackQueryId, string payload) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.FirewallCreateWaitingEnterName); await _telegramBotClient.DeleteMessageAsync( chatId : chatId, messageId : messageId); await _telegramBotClient.SendTextMessageAsync( chatId : chatId, text : FirewallMessage.GetEnterNameMessage()); }
public async Task ExecuteCommandAsync(Message message) { var projectId = _storageService.Get <string>(StorageKeys.ProjectId); if (!string.IsNullOrEmpty(projectId)) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.ProjectUpdateWaitingEnterNewName); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : ProjectMessage.GetEnterNameMessage()); } }
public async Task ExecuteCommandAsync(Message message) { var firewallId = _storageService.Get <string>(StorageKeys.FirewallId); if (!string.IsNullOrEmpty(firewallId)) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.FirewallUpdateWaitingEnterAddDroplet); var droplets = await _digitalOceanClient.Droplets.GetAll(); if (droplets is not null and { Count : > 0 })
public async Task ExecuteCommandAsync(Message message) { var firewallId = _storageService.Get <string>(StorageKeys.FirewallId); if (!string.IsNullOrEmpty(firewallId)) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.FirewallUpdateWaitingEnterInboundRule); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : FirewallMessage.GetEnterBoundRuleMessage(), parseMode : ParseMode.Html); } }
public async Task ExecuteCommandAsync(Message message) { var projectId = _storageService.Get <string>(StorageKeys.ProjectId); if (!string.IsNullOrEmpty(projectId)) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.ProjectUpdateWaitingEnterNewEnvironment); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : ProjectMessage.GetChooseEnvironmentMessage(), replyMarkup : ProjectKeyboard.GetProjectEnvironmentKeyboard()); } }
public async Task ExecuteCommandAsync(Message message) { var dropletId = _storageService.Get <long>(StorageKeys.DropletId); if (dropletId > 0) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.DropletUpdateWaitingEnterSnapshotName); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : DropletMessage.GetEnterSnapshotNameMessage(), parseMode : ParseMode.Markdown); } }
public async Task ExecuteCallbackQueryAsync(long chatId, int messageId, string callbackQueryId, string payload) { var paginator = _firewallPaginatorService.Select(payload); _storageService.AddOrUpdate(StorageKeys.FirewallId, payload); _storageService.Remove(StorageKeys.Firewalls); await _telegramBotClient.DeleteMessageAsync(chatId, messageId); await _telegramBotClient.SendTextMessageAsync( chatId : chatId, text : paginator.MessageText, parseMode : ParseMode.Markdown, replyMarkup : paginator.Keyboard); }
public async Task ExecuteCallbackQueryAsync(long chatId, int messageId, string callbackQueryId, string payload) { var paginator = _imagePaginatorService.Select(payload); _storageService.AddOrUpdate(StorageKeys.ImageId, long.Parse(payload)); _storageService.Remove(StorageKeys.Images); await _telegramBotClient.DeleteMessageAsync(chatId, messageId); await _telegramBotClient.SendTextMessageAsync( chatId : chatId, text : paginator.MessageText, parseMode : ParseMode.Markdown); _imagePaginatorService?.OnSelectCallback(); }
public async Task ExecuteHandlerAsync(Message message) { var dropletId = _storageService.Get <long>(StorageKeys.DropletId); if (dropletId > 0) { var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(TimeSpan.FromMinutes(40)); var action = await _digitalOceanClient.DropletActions.Snapshot(dropletId, message.Text); var status = action.GetStatus(); while (status is ActionStatus.Waiting) { await Task.Delay(TimeSpan.FromSeconds(10)); var actionResult = await _digitalOceanClient.DropletActions.GetDropletAction(dropletId, action.Id); status = actionResult.GetStatus(); cancellationTokenSource.Token.ThrowIfCancellationRequested(); } switch (status) { case ActionStatus.Success: await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : CommonMessage.GetDoneMessage()); break; case ActionStatus.Error: await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : CommonMessage.GetErrorMessage()); break; default: throw new ArgumentOutOfRangeException(nameof(status)); } _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); } }
public async Task ExecuteHandlerAsync(Message message) { var projectId = _storageService.Get <string>(StorageKeys.ProjectId); if (!string.IsNullOrEmpty(projectId)) { await _digitalOceanClient.Projects.Patch(projectId, new PatchProject() { Description = message.Text }); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : CommonMessage.GetDoneMessage()); _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); } }
public async Task ExecuteCommandAsync(Message message) { var firewallId = _storageService.Get <string>(StorageKeys.FirewallId); if (!string.IsNullOrEmpty(firewallId)) { _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.FirewallUpdateWaitingEnterRemoveDroplet); var firewall = await _digitalOceanClient.Firewalls.Get(firewallId); var droplets = await _digitalOceanClient.Droplets.GetAll(); var associatedDroplets = droplets.Where(x => firewall.DropletIds.Contains(x.Id)) .OrderBy(x => x.CreatedAt) .ToList(); if (associatedDroplets is null or { Count : <= 0 })
public async Task ExecuteCommandAsync(Message message) { var droplets = await _digitalOceanClient.Droplets.GetAll(); if (droplets.Count > 0) { _storageService.AddOrUpdate(StorageKeys.Droplets, droplets); var pageModel = _dropletPaginatorService.GetPage(0); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : pageModel.MessageText, parseMode : ParseMode.Markdown, replyMarkup : pageModel.Keyboard); } else { await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : DropletMessage.GetDropletsNotFoundMessage()); } }
private async Task EnterName(Message message) { var droplet = new DropletRequest { Name = message.Text }; _storageService.AddOrUpdate(StorageKeys.NewDroplet, droplet); var distributionImages = await _digitalOceanClient.Images.GetAll(ImageType.Distribution); var privateImages = await _digitalOceanClient.Images.GetAll(ImageType.Private); distributionImages.ToList().AddRange(privateImages.ToList()); _storageService.AddOrUpdate(StorageKeys.Images, distributionImages); var paginator = _imagePaginatorService.GetPage(0); _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.DropletCreateWaitingEnterImage); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : paginator.MessageText, parseMode : ParseMode.Markdown, replyMarkup : paginator.Keyboard); }
public IActionResult SetSetting([FromBody][Required] Slack setting) { return(new JsonResult(StorageService.AddOrUpdate(setting))); }
public async Task ExecuteHandlerAsync(Message message) { var firewallId = _storageService.Get <string>(StorageKeys.FirewallId); if (string.IsNullOrEmpty(firewallId)) { return; } var outboundRules = new List <OutboundRule>(); var invalidRules = new List <string>(); var rules = message.Text.Split(";"); var regExp = new Regex(RegExpPatterns.NetworkAddress); foreach (var rule in rules) { var resultMatch = regExp.Match(rule); if (resultMatch.Success) { var inboundRule = new OutboundRule { Protocol = resultMatch.Groups[1].Value, Ports = resultMatch.Groups[2].Value, Destinations = new SourceLocation { Addresses = new List <string> { $"{resultMatch.Groups[3].Value}/{resultMatch.Groups[4].Value}" } } }; outboundRules.Add(inboundRule); } else { invalidRules.Add(rule); } } if (outboundRules.Count > 0) { await _digitalOceanClient.Firewalls.AddRules(firewallId, new FirewallRules { OutboundRules = outboundRules }); await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : FirewallMessage.GetCreatedBoundRulesMessage(outboundRules.Count), parseMode : ParseMode.Markdown); } if (invalidRules.Count > 0) { await _telegramBotClient.SendTextMessageAsync( chatId : message.Chat.Id, text : FirewallMessage.GetInvalidBoundRulesMessage(invalidRules), parseMode : ParseMode.Html); } _storageService.AddOrUpdate(StorageKeys.BotCurrentState, BotStateType.None); }