From 6fba6c8e76384af35170b6ee2000a67ad8e8334f Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 15 May 2024 11:23:02 -0500 Subject: [PATCH 1/2] add conv user endpoint --- .../Controllers/ConversationController.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 810bc08d5..d84e62fa9 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -1,8 +1,6 @@ using BotSharp.Abstraction.Routing; using Newtonsoft.Json.Serialization; using Newtonsoft.Json; -using BotSharp.Abstraction.Files.Models; -using BotSharp.Abstraction.Files; namespace BotSharp.OpenAPI.Controllers; @@ -138,6 +136,34 @@ public async Task GetConversation([FromRoute] string conv return result; } + [HttpGet("/conversation/{conversationId}/user")] + public async Task GetConversationUser([FromRoute] string conversationId) + { + var service = _services.GetRequiredService(); + var conversations = await service.GetConversations(new ConversationFilter + { + Id = conversationId + }); + + var userService = _services.GetRequiredService(); + var conversation = conversations?.Items?.FirstOrDefault(); + var userId = conversation == null ? _user.Id : conversation.UserId; + var user = await userService.GetUser(userId); + if (user == null) + { + return new UserViewModel + { + Id = _user.Id, + FirstName = _user.FirstName, + LastName = _user.LastName, + Email = _user.Email, + Source = "Unknown" + }; + } + + return UserViewModel.FromUser(user); + } + [HttpDelete("/conversation/{conversationId}")] public async Task DeleteConversation([FromRoute] string conversationId) { From 2a9b5ec0c89b51045ef956a3d4639feba40b4f0e Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 15 May 2024 11:23:29 -0500 Subject: [PATCH 2/2] minor change --- .../BotSharp.OpenAPI/Controllers/ConversationController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index d84e62fa9..34095acfd 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -154,6 +154,7 @@ public async Task GetConversationUser([FromRoute] string conversa return new UserViewModel { Id = _user.Id, + UserName = _user.UserName, FirstName = _user.FirstName, LastName = _user.LastName, Email = _user.Email,