Switch routing-profile per channel.
This commit is contained in:
parent
ab813205d1
commit
7fd1a96e28
|
|
@ -0,0 +1,12 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Abstraction.Routing.Models;
|
||||
|
||||
public class RoutingProfileRecord
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("agent_ids")]
|
||||
public string[] AgentIds { get; set; }
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Routing.Models;
|
||||
using System.IO;
|
||||
using static Tensorflow.ApiDef.Types;
|
||||
|
||||
namespace BotSharp.Core.Routing;
|
||||
|
||||
|
|
@ -33,7 +32,23 @@ public class Router : IAgentRouting
|
|||
var agentSettings = _services.GetRequiredService<AgentSettings>();
|
||||
var dbSettings = _services.GetRequiredService<MyDatabaseSettings>();
|
||||
var filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, agentSettings.RouterId, "route.json");
|
||||
return JsonSerializer.Deserialize<RoutingRecord[]>(File.ReadAllText(filePath));
|
||||
var records = JsonSerializer.Deserialize<RoutingRecord[]>(File.ReadAllText(filePath));
|
||||
|
||||
// check if routing profile is specified
|
||||
filePath = Path.Combine(dbSettings.FileRepository, agentSettings.DataDir, "routing-profile.json");
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var name = state.GetState("channel");
|
||||
var profiles = JsonSerializer.Deserialize<RoutingProfileRecord[]>(File.ReadAllText(filePath));
|
||||
var spcificedProfile = profiles.FirstOrDefault(x => x.Name == name);
|
||||
if (spcificedProfile != null)
|
||||
{
|
||||
records = records.Where(x => spcificedProfile.AgentIds.Contains(x.AgentId)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
public RoutingRecord GetRecordByName(string name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue