Skip to content

Commit d02b16d

Browse files
authored
Merge pull request #456 from iceljc/features/add-conversation-user
Features/add conversation user
2 parents 03837c1 + 2a9b5ec commit d02b16d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using BotSharp.Abstraction.Routing;
22
using Newtonsoft.Json.Serialization;
33
using Newtonsoft.Json;
4-
using BotSharp.Abstraction.Files.Models;
5-
using BotSharp.Abstraction.Files;
64

75
namespace BotSharp.OpenAPI.Controllers;
86

@@ -138,6 +136,35 @@ public async Task<ConversationViewModel> GetConversation([FromRoute] string conv
138136
return result;
139137
}
140138

139+
[HttpGet("/conversation/{conversationId}/user")]
140+
public async Task<UserViewModel> GetConversationUser([FromRoute] string conversationId)
141+
{
142+
var service = _services.GetRequiredService<IConversationService>();
143+
var conversations = await service.GetConversations(new ConversationFilter
144+
{
145+
Id = conversationId
146+
});
147+
148+
var userService = _services.GetRequiredService<IUserService>();
149+
var conversation = conversations?.Items?.FirstOrDefault();
150+
var userId = conversation == null ? _user.Id : conversation.UserId;
151+
var user = await userService.GetUser(userId);
152+
if (user == null)
153+
{
154+
return new UserViewModel
155+
{
156+
Id = _user.Id,
157+
UserName = _user.UserName,
158+
FirstName = _user.FirstName,
159+
LastName = _user.LastName,
160+
Email = _user.Email,
161+
Source = "Unknown"
162+
};
163+
}
164+
165+
return UserViewModel.FromUser(user);
166+
}
167+
141168
[HttpDelete("/conversation/{conversationId}")]
142169
public async Task<bool> DeleteConversation([FromRoute] string conversationId)
143170
{

0 commit comments

Comments
 (0)