commit
934aa2416f
|
|
@ -13,7 +13,7 @@ public interface IConversationService
|
|||
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
|
||||
Task<Conversation> UpdateConversationTitle(string id, string title);
|
||||
Task<Conversation> UpdateConversationTitleAlias(string id, string titleAlias);
|
||||
Task<bool> UpdateConversationTags(string conversationId, List<string> tags);
|
||||
Task<bool> UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags);
|
||||
Task<bool> UpdateConversationMessage(string conversationId, UpdateMessageRequest request);
|
||||
Task<List<Conversation>> GetLastConversations();
|
||||
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
=> throw new NotImplementedException();
|
||||
void UpdateConversationTitleAlias(string conversationId, string titleAlias)
|
||||
=> throw new NotImplementedException();
|
||||
bool UpdateConversationTags(string conversationId, List<string> tags)
|
||||
bool UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags)
|
||||
=> throw new NotImplementedException();
|
||||
bool AppendConversationTags(string conversationId, List<string> tags)
|
||||
=> throw new NotImplementedException();
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ public partial class ConversationService : IConversationService
|
|||
return conversation;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateConversationTags(string conversationId, List<string> tags)
|
||||
public async Task<bool> UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
return db.UpdateConversationTags(conversationId, tags);
|
||||
return db.UpdateConversationTags(conversationId, toAddTags, toDeleteTags);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateConversationMessage(string conversationId, UpdateMessageRequest request)
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ public partial class FileRepository
|
|||
}
|
||||
}
|
||||
|
||||
public bool UpdateConversationTags(string conversationId, List<string> tags)
|
||||
public bool UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags)
|
||||
{
|
||||
if (string.IsNullOrEmpty(conversationId)) return false;
|
||||
|
||||
|
|
@ -170,7 +170,11 @@ public partial class FileRepository
|
|||
|
||||
var json = File.ReadAllText(convFile);
|
||||
var conv = JsonSerializer.Deserialize<Conversation>(json, _options);
|
||||
conv.Tags = tags ?? new();
|
||||
|
||||
var tags = conv.Tags ?? [];
|
||||
tags = tags.Concat(toAddTags).Distinct().ToList();
|
||||
conv.Tags = tags.Where(x => !toDeleteTags.Contains(x, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
conv.UpdatedTime = DateTime.UtcNow;
|
||||
File.WriteAllText(convFile, JsonSerializer.Serialize(conv, _options));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ public class ConversationController : ControllerBase
|
|||
public async Task<bool> UpdateConversationTags([FromRoute] string conversationId, [FromBody] UpdateConversationRequest request)
|
||||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
return await conv.UpdateConversationTags(conversationId, request.Tags);
|
||||
return await conv.UpdateConversationTags(conversationId, request.ToAddTags, request.ToDeleteTags);
|
||||
}
|
||||
|
||||
[HttpPut("/conversation/{conversationId}/update-message")]
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@ namespace BotSharp.OpenAPI.ViewModels.Conversations;
|
|||
|
||||
public class UpdateConversationRequest
|
||||
{
|
||||
public List<string> Tags { get; set; } = [];
|
||||
public List<string> ToAddTags { get; set; } = [];
|
||||
public List<string> ToDeleteTags { get; set; } = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,13 +134,20 @@ public partial class MongoRepository
|
|||
_dc.Conversations.UpdateOne(filterConv, updateConv);
|
||||
}
|
||||
|
||||
public bool UpdateConversationTags(string conversationId, List<string> tags)
|
||||
public bool UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags)
|
||||
{
|
||||
if (string.IsNullOrEmpty(conversationId)) return false;
|
||||
|
||||
var filter = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
|
||||
var conv = _dc.Conversations.Find(filter).FirstOrDefault();
|
||||
if (conv == null) return false;
|
||||
|
||||
var tags = conv.Tags ?? [];
|
||||
tags = tags.Concat(toAddTags).Distinct().ToList();
|
||||
tags = tags.Where(x => !toDeleteTags.Contains(x, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
var update = Builders<ConversationDocument>.Update
|
||||
.Set(x => x.Tags, tags ?? new())
|
||||
.Set(x => x.Tags, tags)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
||||
var res = _dc.Conversations.UpdateOne(filter, update);
|
||||
|
|
|
|||
Loading…
Reference in a new issue