From 19dfe06ce2a9ffed25484cc526c379b08f30d1ba Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 22 Mar 2024 01:30:57 -0500 Subject: [PATCH] add redirect to agent --- .../Messaging/IRichMessage.cs | 4 +++- .../Routing/Models/RoutingRule.cs | 1 + .../Controllers/AgentController.cs | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs index fb87f381..ca74a3f2 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs @@ -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; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs index b0353ce6..e0eb1da3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingRule.cs @@ -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() { diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 1a9389ef..5d7f7b56 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -29,7 +29,23 @@ public class AgentController : ControllerBase { AgentIds = new List { 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")]