add redirect to agent

This commit is contained in:
Jicheng Lu 2024-03-22 01:30:57 -05:00
parent ed860f3631
commit 19dfe06ce2
3 changed files with 21 additions and 2 deletions

View file

@ -1,3 +1,5 @@
using BotSharp.Abstraction.Messaging.Enums;
namespace BotSharp.Abstraction.Messaging;
public interface IRichMessage
@ -5,5 +7,5 @@ public interface IRichMessage
string Text { get; set; }
[JsonPropertyName("rich_type")]
string RichType => "text";
string RichType => RichTypeEnum.Text;
}

View file

@ -23,6 +23,7 @@ public class RoutingRule
public bool Required { get; set; }
public string? RedirectTo { get; set; }
public string? RedirectToAgentName { get; set; }
public override string ToString()
{

View file

@ -29,7 +29,23 @@ public class AgentController : ControllerBase
{
AgentIds = new List<string> { id }
});
return agents.Items.FirstOrDefault();
var targetAgent = agents.Items.FirstOrDefault();
var redirectAgentIds = targetAgent.RoutingRules
.Where(x => !string.IsNullOrEmpty(x.RedirectTo))
.Select(x => x.RedirectTo).ToList();
var redirectAgents = await _agentService.GetAgents(new AgentFilter
{
AgentIds = redirectAgentIds
});
foreach (var rule in targetAgent.RoutingRules)
{
var found = redirectAgents.Items.FirstOrDefault(x => x.Id == rule.RedirectTo);
if (found == null) continue;
rule.RedirectToAgentName = found.Name;
}
return targetAgent;
}
[HttpGet("/agents")]