diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 172d4a013..37f8685c1 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -50,7 +50,7 @@ List GetUsersByAffiliateId(string affiliateId) => throw new NotImplementedException(); void UpdateUserName(string userId, string userName) => throw new NotImplementedException(); - Dashboard? GetDashboard(string id = null) + Dashboard? GetDashboard(string userId = null) => throw new NotImplementedException(); void CreateUser(User user) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index f92d72251..8563b215f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -33,8 +33,8 @@ public interface IUserService Task UpdatePassword(string newPassword, string verificationCode); Task GetUserTokenExpires(); Task UpdateUsersIsDisable(List userIds, bool isDisable); - Task AddDashboardConversation(string userId, string conversationId); - Task RemoveDashboardConversation(string userId, string conversationId); - Task UpdateDashboardConversation(string userId, DashboardConversation dashConv); - Task GetDashboard(string userId); + Task AddDashboardConversation(string conversationId); + Task RemoveDashboardConversation(string conversationId); + Task UpdateDashboardConversation(DashboardConversation dashConv); + Task GetDashboard(); } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 9d5b42bed..5c9846840 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -53,7 +53,7 @@ public List GetUsersByAffiliateId(string affiliateId) return Users.FirstOrDefault(x => x.UserName == userName.ToLower()); } - public Dashboard? GetDashboard(string id = null) + public Dashboard? GetDashboard(string userId = null) { return Dashboards.FirstOrDefault(); } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 730530636..18bf96ebe 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -810,40 +810,47 @@ public async Task UpdateUsersIsDisable(List userIds, bool isDisabl return true; } - public async Task AddDashboardConversation(string userId, string conversationId) + public async Task AddDashboardConversation(string conversationId) { + var user = await GetUser(_user.Id); var db = _services.GetRequiredService(); - db.AddDashboardConversation(userId, conversationId); - + db.AddDashboardConversation(user?.Id, conversationId); await Task.CompletedTask; return true; } - public async Task RemoveDashboardConversation(string userId, string conversationId) + public async Task RemoveDashboardConversation(string conversationId) { + var user = await GetUser(_user.Id); var db = _services.GetRequiredService(); - db.RemoveDashboardConversation(userId, conversationId); - + db.RemoveDashboardConversation(user?.Id, conversationId); await Task.CompletedTask; return true; } - public async Task UpdateDashboardConversation(string userId, DashboardConversation newDashConv) + public async Task UpdateDashboardConversation(DashboardConversation newDashConv) { var db = _services.GetRequiredService(); - var dashConv = db.GetDashboard(userId)?.ConversationList.FirstOrDefault(x => string.Equals(x.ConversationId, newDashConv.ConversationId)); + + var user = await GetUser(_user.Id); + var dashConv = db.GetDashboard(user?.Id)? + .ConversationList + .FirstOrDefault(x => string.Equals(x.ConversationId, newDashConv.ConversationId)); if (dashConv == null) return; + dashConv.Name = newDashConv.Name ?? dashConv.Name; dashConv.Instruction = newDashConv.Instruction ?? dashConv.Instruction; - db.UpdateDashboardConversation(userId, dashConv); + db.UpdateDashboardConversation(user?.Id, dashConv); await Task.CompletedTask; return; } - public async Task GetDashboard(string userId) + public async Task GetDashboard() { var db = _services.GetRequiredService(); - var dash = db.GetDashboard(); + + var user = await GetUser(_user.Id); + var dash = db.GetDashboard(user?.Id); await Task.CompletedTask; return dash; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 226783d32..5704655f9 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -66,16 +66,16 @@ public AgentSettings GetSettings() return targetAgent; } - [HttpGet("/agents")] - public async Task> GetAgents([FromQuery] AgentFilter filter, [FromQuery] bool checkAuth = false) + [HttpPost("/agents")] + public async Task> GetAgents([FromBody] AgentQueryRequest request) { var agentSetting = _services.GetRequiredService(); var userService = _services.GetRequiredService(); List agents; - var pagedAgents = await _agentService.GetAgents(filter); + var pagedAgents = await _agentService.GetAgents(request.Filter); - if (!checkAuth) + if (!request.CheckAuth) { agents = pagedAgents?.Items?.Select(x => AgentViewModel.FromAgent(x))?.ToList() ?? []; return new PagedItems @@ -160,4 +160,20 @@ public IEnumerable GetAgentUtilityOptions() } return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList(); } + + [HttpGet("/agent/labels")] + public async Task> GetAgentLabels() + { + var agentService = _services.GetRequiredService(); + var agents = await agentService.GetAgents(new AgentFilter + { + Pager = new Pagination { Size = 1000 } + }); + + var labels = agents.Items?.SelectMany(x => x.Labels) + .Distinct() + .OrderBy(x => x) + .ToList() ?? []; + return labels; + } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 266c5ac57..b2defb2ed 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -535,14 +535,12 @@ public IActionResult DownloadMessageFile([FromRoute] string conversationId, [Fro } #endregion - #region miscellaneous + #region Dashboard [HttpPut("/agent/{agentId}/conversation/{conversationId}/dashboard")] public async Task PinConversationToDashboard([FromRoute] string agentId, [FromRoute] string conversationId) { var userService = _services.GetRequiredService(); - - var user = await userService.GetUser(_user.Id); - var pinned = await userService.AddDashboardConversation(user.Id, conversationId); + var pinned = await userService.AddDashboardConversation(conversationId); return pinned; } @@ -550,9 +548,7 @@ public async Task PinConversationToDashboard([FromRoute] string agentId, [ public async Task UnpinConversationFromDashboard([FromRoute] string agentId, [FromRoute] string conversationId) { var userService = _services.GetRequiredService(); - - var user = await userService.GetUser(_user.Id); - var unpinned = await userService.RemoveDashboardConversation(user.Id, conversationId); + var unpinned = await userService.RemoveDashboardConversation(conversationId); return unpinned; } #endregion diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs index 0534b01d9..c95d819d2 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs @@ -19,11 +19,12 @@ public DashboardController(IServiceProvider services, } #region User Components [HttpGet("/dashboard/components")] - public async Task GetComponents(string userId) + public async Task GetComponents() { var userService = _services.GetRequiredService(); - var dashboardProfile = await userService.GetDashboard(userId); + var dashboardProfile = await userService.GetDashboard(); if (dashboardProfile == null) return new UserDashboardModel(); + var result = new UserDashboardModel { ConversationList = dashboardProfile.ConversationList.Select( @@ -39,7 +40,7 @@ public async Task GetComponents(string userId) } [HttpPost("/dashboard/component/conversation")] - public async Task UpdateDashboardConversationInstruction(string userId, UserDashboardConversationModel dashConv) + public async Task UpdateDashboardConversationInstruction(UserDashboardConversationModel dashConv) { if (string.IsNullOrEmpty(dashConv.Name) && string.IsNullOrEmpty(dashConv.Instruction)) { @@ -60,7 +61,7 @@ public async Task UpdateDashboardConversationInstruction(string userId, UserDash } var userService = _services.GetRequiredService(); - await userService.UpdateDashboardConversation(userId, newDashConv); + await userService.UpdateDashboardConversation(newDashConv); return; } #endregion diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs new file mode 100644 index 000000000..4d53b60cb --- /dev/null +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs @@ -0,0 +1,7 @@ +namespace BotSharp.OpenAPI.ViewModels.Agents; + +public class AgentQueryRequest +{ + public AgentFilter Filter { get; set; } = AgentFilter.Empty(); + public bool CheckAuth { get; set; } +}