Skip to content

Commit cb7de02

Browse files
authored
Merge pull request #359 from iceljc/features/refine-conversation
Features/refine conversation
2 parents 4548023 + 0579a15 commit cb7de02

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ConversationFilter
1111
public string? Status { get; set; }
1212
public string? Channel { get; set; }
1313
public string? UserId { get; set; }
14+
public DateTime? StartTime { get; set; }
1415

1516
/// <summary>
1617
/// Agent task id

src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public class RoutingRule
2222

2323
public bool Required { get; set; }
2424

25+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2526
public string? RedirectTo { get; set; }
27+
28+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
29+
[JsonPropertyName("redirect_to_agent")]
2630
public string? RedirectToAgentName { get; set; }
2731

2832
public override string ToString()

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,34 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
256256
if (record == null) continue;
257257

258258
var matched = true;
259-
if (filter?.Id != null) matched = matched && record.Id == filter.Id;
260-
if (filter?.AgentId != null) matched = matched && record.AgentId == filter.AgentId;
261-
if (filter?.Status != null) matched = matched && record.Status == filter.Status;
262-
if (filter?.Channel != null) matched = matched && record.Channel == filter.Channel;
263-
if (filter?.UserId != null) matched = matched && record.UserId == filter.UserId;
264-
if (filter?.TaskId != null) matched = matched && record.TaskId == filter.TaskId;
259+
if (filter?.Id != null)
260+
{
261+
matched = matched && record.Id == filter.Id;
262+
}
263+
if (filter?.AgentId != null)
264+
{
265+
matched = matched && record.AgentId == filter.AgentId;
266+
}
267+
if (filter?.Status != null)
268+
{
269+
matched = matched && record.Status == filter.Status;
270+
}
271+
if (filter?.Channel != null)
272+
{
273+
matched = matched && record.Channel == filter.Channel;
274+
}
275+
if (filter?.UserId != null)
276+
{
277+
matched = matched && record.UserId == filter.UserId;
278+
}
279+
if (filter?.TaskId != null)
280+
{
281+
matched = matched && record.TaskId == filter.TaskId;
282+
}
283+
if (filter?.StartTime != null)
284+
{
285+
matched = matched && record.CreatedTime >= filter.StartTime.Value;
286+
}
265287

266288
// Check states
267289
if (filter != null && !filter.States.IsNullOrEmpty())

src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public override async Task OnMessageReceived(RoleDialogModel message)
5252
var convService = _services.GetRequiredService<IConversationService>();
5353
var results = await convService.GetConversations(new ConversationFilter
5454
{
55-
UserId = user.Id
55+
UserId = user.Id,
56+
StartTime = DateTime.UtcNow.AddHours(-24),
5657
});
5758

5859
if (results.Count > rateLimit.MaxConversationPerDay)

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/RoutingRuleUpdateModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ namespace BotSharp.OpenAPI.ViewModels.Agents;
44

55
public class RoutingRuleUpdateModel
66
{
7-
public string Field { get; set; }
7+
public string? Field { get; set; }
88
public string? Description { get; set; }
9+
public string? Type { get; set; }
10+
public string? FieldType { get; set; }
911
public bool Required { get; set; }
1012
public string? RedirectTo { get; set; }
1113

@@ -20,6 +22,8 @@ public static RoutingRule ToDomainElement(RoutingRuleUpdateModel model)
2022
{
2123
Field = model.Field,
2224
Description = model.Description,
25+
Type = model.Type,
26+
FieldType = model.FieldType,
2327
Required = model.Required,
2428
RedirectTo = model.RedirectTo
2529
};

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,37 @@ public PagedItems<Conversation> GetConversations(ConversationFilter filter)
232232
var builder = Builders<ConversationDocument>.Filter;
233233
var filters = new List<FilterDefinition<ConversationDocument>>() { builder.Empty };
234234

235-
if (!string.IsNullOrEmpty(filter.Id)) filters.Add(builder.Eq(x => x.Id, filter.Id));
236-
if (!string.IsNullOrEmpty(filter.AgentId)) filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
237-
if (!string.IsNullOrEmpty(filter.Status)) filters.Add(builder.Eq(x => x.Status, filter.Status));
238-
if (!string.IsNullOrEmpty(filter.Channel)) filters.Add(builder.Eq(x => x.Channel, filter.Channel));
239-
if (!string.IsNullOrEmpty(filter.UserId)) filters.Add(builder.Eq(x => x.UserId, filter.UserId));
240-
if (!string.IsNullOrEmpty(filter.TaskId)) filters.Add(builder.Eq(x => x.TaskId, filter.TaskId));
235+
if (!string.IsNullOrEmpty(filter?.Id))
236+
{
237+
filters.Add(builder.Eq(x => x.Id, filter.Id));
238+
}
239+
if (!string.IsNullOrEmpty(filter?.AgentId))
240+
{
241+
filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
242+
}
243+
if (!string.IsNullOrEmpty(filter?.Status))
244+
{
245+
filters.Add(builder.Eq(x => x.Status, filter.Status));
246+
}
247+
if (!string.IsNullOrEmpty(filter?.Channel))
248+
{
249+
filters.Add(builder.Eq(x => x.Channel, filter.Channel));
250+
}
251+
if (!string.IsNullOrEmpty(filter?.UserId))
252+
{
253+
filters.Add(builder.Eq(x => x.UserId, filter.UserId));
254+
}
255+
if (!string.IsNullOrEmpty(filter?.TaskId))
256+
{
257+
filters.Add(builder.Eq(x => x.TaskId, filter.TaskId));
258+
}
259+
if (filter?.StartTime != null)
260+
{
261+
filters.Add(builder.Gte(x => x.CreatedTime, filter.StartTime.Value));
262+
}
241263

242264
// Check states
243-
if (!filter.States.IsNullOrEmpty())
265+
if (filter != null && !filter.States.IsNullOrEmpty())
244266
{
245267
var targetConvIds = new List<string>();
246268

0 commit comments

Comments
 (0)