Merge pull request #359 from iceljc/features/refine-conversation

Features/refine conversation
This commit is contained in:
C. Oceania 2024-03-25 07:29:03 -05:00 committed by GitHub
commit cb7de0297d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 69 additions and 15 deletions

View file

@ -11,6 +11,7 @@ public class ConversationFilter
public string? Status { get; set; }
public string? Channel { get; set; }
public string? UserId { get; set; }
public DateTime? StartTime { get; set; }
/// <summary>
/// Agent task id

View file

@ -22,7 +22,11 @@ public class RoutingRule
public bool Required { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? RedirectTo { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("redirect_to_agent")]
public string? RedirectToAgentName { get; set; }
public override string ToString()

View file

@ -256,12 +256,34 @@ namespace BotSharp.Core.Repository
if (record == null) continue;
var matched = true;
if (filter?.Id != null) matched = matched && record.Id == filter.Id;
if (filter?.AgentId != null) matched = matched && record.AgentId == filter.AgentId;
if (filter?.Status != null) matched = matched && record.Status == filter.Status;
if (filter?.Channel != null) matched = matched && record.Channel == filter.Channel;
if (filter?.UserId != null) matched = matched && record.UserId == filter.UserId;
if (filter?.TaskId != null) matched = matched && record.TaskId == filter.TaskId;
if (filter?.Id != null)
{
matched = matched && record.Id == filter.Id;
}
if (filter?.AgentId != null)
{
matched = matched && record.AgentId == filter.AgentId;
}
if (filter?.Status != null)
{
matched = matched && record.Status == filter.Status;
}
if (filter?.Channel != null)
{
matched = matched && record.Channel == filter.Channel;
}
if (filter?.UserId != null)
{
matched = matched && record.UserId == filter.UserId;
}
if (filter?.TaskId != null)
{
matched = matched && record.TaskId == filter.TaskId;
}
if (filter?.StartTime != null)
{
matched = matched && record.CreatedTime >= filter.StartTime.Value;
}
// Check states
if (filter != null && !filter.States.IsNullOrEmpty())

View file

@ -52,7 +52,8 @@ public class RateLimitConversationHook : ConversationHookBase
var convService = _services.GetRequiredService<IConversationService>();
var results = await convService.GetConversations(new ConversationFilter
{
UserId = user.Id
UserId = user.Id,
StartTime = DateTime.UtcNow.AddHours(-24),
});
if (results.Count > rateLimit.MaxConversationPerDay)

View file

@ -4,8 +4,10 @@ namespace BotSharp.OpenAPI.ViewModels.Agents;
public class RoutingRuleUpdateModel
{
public string Field { get; set; }
public string? Field { get; set; }
public string? Description { get; set; }
public string? Type { get; set; }
public string? FieldType { get; set; }
public bool Required { get; set; }
public string? RedirectTo { get; set; }
@ -20,6 +22,8 @@ public class RoutingRuleUpdateModel
{
Field = model.Field,
Description = model.Description,
Type = model.Type,
FieldType = model.FieldType,
Required = model.Required,
RedirectTo = model.RedirectTo
};

View file

@ -232,15 +232,37 @@ public partial class MongoRepository
var builder = Builders<ConversationDocument>.Filter;
var filters = new List<FilterDefinition<ConversationDocument>>() { builder.Empty };
if (!string.IsNullOrEmpty(filter.Id)) filters.Add(builder.Eq(x => x.Id, filter.Id));
if (!string.IsNullOrEmpty(filter.AgentId)) filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
if (!string.IsNullOrEmpty(filter.Status)) filters.Add(builder.Eq(x => x.Status, filter.Status));
if (!string.IsNullOrEmpty(filter.Channel)) filters.Add(builder.Eq(x => x.Channel, filter.Channel));
if (!string.IsNullOrEmpty(filter.UserId)) filters.Add(builder.Eq(x => x.UserId, filter.UserId));
if (!string.IsNullOrEmpty(filter.TaskId)) filters.Add(builder.Eq(x => x.TaskId, filter.TaskId));
if (!string.IsNullOrEmpty(filter?.Id))
{
filters.Add(builder.Eq(x => x.Id, filter.Id));
}
if (!string.IsNullOrEmpty(filter?.AgentId))
{
filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
}
if (!string.IsNullOrEmpty(filter?.Status))
{
filters.Add(builder.Eq(x => x.Status, filter.Status));
}
if (!string.IsNullOrEmpty(filter?.Channel))
{
filters.Add(builder.Eq(x => x.Channel, filter.Channel));
}
if (!string.IsNullOrEmpty(filter?.UserId))
{
filters.Add(builder.Eq(x => x.UserId, filter.UserId));
}
if (!string.IsNullOrEmpty(filter?.TaskId))
{
filters.Add(builder.Eq(x => x.TaskId, filter.TaskId));
}
if (filter?.StartTime != null)
{
filters.Add(builder.Gte(x => x.CreatedTime, filter.StartTime.Value));
}
// Check states
if (!filter.States.IsNullOrEmpty())
if (filter != null && !filter.States.IsNullOrEmpty())
{
var targetConvIds = new List<string>();