Skip to content

Commit efe4d9f

Browse files
authored
Merge pull request #1102 from iceljc/master
Filter conversation by agent ids
2 parents cb7159e + 1662dde commit efe4d9f

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ConversationFilter
1010
public string? Title { get; set; }
1111
public string? TitleAlias { get; set; }
1212
public string? AgentId { get; set; }
13+
public List<string>? AgentIds { get; set; }
1314
public string? Status { get; set; }
1415
public string? Channel { get; set; }
1516
public string? ChannelId { get; set; }

src/Infrastructure/BotSharp.Abstraction/SideCar/Models/SideCarOptions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ public class SideCarOptions
77

88
public static SideCarOptions Empty()
99
{
10-
return new SideCarOptions();
10+
return new();
11+
}
12+
13+
public static SideCarOptions InheritStates(IEnumerable<string>? targetStates = null)
14+
{
15+
return new()
16+
{
17+
IsInheritStates = true,
18+
InheritStateKeys = targetStates
19+
};
1120
}
1221
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
396396
Directory.CreateDirectory(dir);
397397
}
398398

399+
if (filter?.AgentId != null)
400+
{
401+
filter.AgentIds ??= [];
402+
filter.AgentIds.Add(filter.AgentId);
403+
}
404+
399405
var totalDirs = Directory.GetDirectories(dir);
400406
foreach (var d in totalDirs)
401407
{
@@ -419,9 +425,9 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
419425
{
420426
matched = matched && record.TitleAlias.Contains(filter.TitleAlias);
421427
}
422-
if (filter?.AgentId != null)
428+
if (filter?.AgentIds != null && filter.AgentIds.Any())
423429
{
424-
matched = matched && record.AgentId == filter.AgentId;
430+
matched = matched && filter.AgentIds.Contains(record.AgentId);
425431
}
426432
if (filter?.Status != null)
427433
{

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
346346
var convBuilder = Builders<ConversationDocument>.Filter;
347347
var convFilters = new List<FilterDefinition<ConversationDocument>>() { convBuilder.Empty };
348348

349+
if (filter?.AgentId != null)
350+
{
351+
filter.AgentIds ??= [];
352+
filter.AgentIds.Add(filter.AgentId);
353+
}
354+
349355
// Filter conversations
350356
if (!string.IsNullOrEmpty(filter?.Id))
351357
{
@@ -359,9 +365,9 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
359365
{
360366
convFilters.Add(convBuilder.Regex(x => x.Title, new BsonRegularExpression(filter.TitleAlias, "i")));
361367
}
362-
if (!string.IsNullOrEmpty(filter?.AgentId))
368+
if (filter?.AgentIds != null && filter.AgentIds.Any())
363369
{
364-
convFilters.Add(convBuilder.Eq(x => x.AgentId, filter.AgentId));
370+
convFilters.Add(convBuilder.In(x => x.AgentId, filter.AgentIds));
365371
}
366372
if (!string.IsNullOrEmpty(filter?.Status))
367373
{

0 commit comments

Comments
 (0)