Skip to content

Features/add conversation user #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

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

[HttpGet("/conversation/{conversationId}/user")]
public async Task<UserViewModel> GetConversationUser([FromRoute] string conversationId)
{
var service = _services.GetRequiredService<IConversationService>();
var conversations = await service.GetConversations(new ConversationFilter
{
Id = conversationId
});

var userService = _services.GetRequiredService<IUserService>();
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,
UserName = _user.UserName,
FirstName = _user.FirstName,
LastName = _user.LastName,
Email = _user.Email,
Source = "Unknown"
};
}

return UserViewModel.FromUser(user);
}

[HttpDelete("/conversation/{conversationId}")]
public async Task<bool> DeleteConversation([FromRoute] string conversationId)
{
Expand Down