public async Task <ActionResult> CreateCommandAsync([FromBody] Command command) { if (command is null) { return(BadRequest()); } var checkCommand = await _commandRepository.GetCommandByTokenAndRequestAsync(command.Token, command.Request); if (checkCommand != null) { return(Conflict()); } await _commandRepository.CreateCommandAsync(command); return(Ok()); }
public async Task <string> GenerateResponseTextAsync(string command, string botToken, int chatId) { string result = ""; if (command == "/help") { StringBuilder sb = new StringBuilder(); var botCommands = await _commandRepository.GetCommandsByTokenAsync(botToken); foreach (Command cmd in botCommands) { sb.Append($"{cmd.Request} - {cmd.Description}\n"); } result = sb.ToString(); } else if (command == "/start") { var subscribeEvent = new SubscribeIntegrationEvent(botToken, chatId); await _telegramIntegrationEventService.SaveEventAsync(subscribeEvent, Guid.NewGuid()); await _telegramIntegrationEventService.PublishThroughEventBusAsync(subscribeEvent); result = "Hello!"; } else { var botCommand = await _commandRepository.GetCommandByTokenAndRequestAsync(botToken, command); if (botCommand != null) { result = botCommand.Response; } } return(result); }