add channels in function def
This commit is contained in:
parent
81f2b32761
commit
d631c3cf8f
|
|
@ -8,7 +8,12 @@ public class FunctionDef
|
|||
[JsonPropertyName("description")]
|
||||
public string Description { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("channels")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public List<string>? Channels { get; set; }
|
||||
|
||||
[JsonPropertyName("visibility_expression")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? VisibilityExpression { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
|
|
|
|||
|
|
@ -20,17 +20,32 @@ public partial class AgentService
|
|||
|
||||
public bool RenderFunction(Agent agent, FunctionDef def)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(def.VisibilityExpression))
|
||||
var isRender = true;
|
||||
|
||||
var channels = def.Channels;
|
||||
if (channels != null)
|
||||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var channel = state.GetState("channel");
|
||||
if (!string.IsNullOrWhiteSpace(channel))
|
||||
{
|
||||
isRender = isRender && channels.Contains(channel);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isRender) return false;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(def.VisibilityExpression))
|
||||
{
|
||||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
var result = render.Render(def.VisibilityExpression, new Dictionary<string, object>
|
||||
{
|
||||
{ "states", agent.TemplateDict }
|
||||
});
|
||||
return result == "visible";
|
||||
isRender = isRender && result == "visible";
|
||||
}
|
||||
|
||||
return true;
|
||||
return isRender;
|
||||
}
|
||||
|
||||
public FunctionParametersDef? RenderFunctionProperty(Agent agent, FunctionDef def)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@ public class AgentController : ControllerBase
|
|||
|
||||
var redirectAgentIds = targetAgent.RoutingRules
|
||||
.Where(x => !string.IsNullOrEmpty(x.RedirectTo))
|
||||
.Select(x => x.RedirectTo).ToList();
|
||||
.Select(x => x.RedirectTo)
|
||||
.ToList();
|
||||
|
||||
var redirectAgents = await _agentService.GetAgents(new AgentFilter
|
||||
{
|
||||
AgentIds = redirectAgentIds
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ public class FunctionDefMongoElement
|
|||
{
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public List<string>? Channels { get; set; }
|
||||
public string? VisibilityExpression { get; set; }
|
||||
public string? Impact { get; set; }
|
||||
public FunctionParametersDefMongoElement Parameters { get; set; } = new FunctionParametersDefMongoElement();
|
||||
|
|
@ -23,6 +24,7 @@ public class FunctionDefMongoElement
|
|||
{
|
||||
Name = function.Name,
|
||||
Description = function.Description,
|
||||
Channels = function.Channels,
|
||||
VisibilityExpression = function.VisibilityExpression,
|
||||
Impact = function.Impact,
|
||||
Parameters = new FunctionParametersDefMongoElement
|
||||
|
|
@ -34,19 +36,20 @@ public class FunctionDefMongoElement
|
|||
};
|
||||
}
|
||||
|
||||
public static FunctionDef ToDomainElement(FunctionDefMongoElement mongoFunction)
|
||||
public static FunctionDef ToDomainElement(FunctionDefMongoElement function)
|
||||
{
|
||||
return new FunctionDef
|
||||
{
|
||||
Name = mongoFunction.Name,
|
||||
Description = mongoFunction.Description,
|
||||
VisibilityExpression = mongoFunction.VisibilityExpression,
|
||||
Impact = mongoFunction.Impact,
|
||||
Name = function.Name,
|
||||
Description = function.Description,
|
||||
Channels = function.Channels,
|
||||
VisibilityExpression = function.VisibilityExpression,
|
||||
Impact = function.Impact,
|
||||
Parameters = new FunctionParametersDef
|
||||
{
|
||||
Type = mongoFunction.Parameters.Type,
|
||||
Properties = JsonSerializer.Deserialize<JsonDocument>(mongoFunction.Parameters.Properties.IfNullOrEmptyAs("{}")),
|
||||
Required = mongoFunction.Parameters.Required,
|
||||
Type = function.Parameters.Type,
|
||||
Properties = JsonSerializer.Deserialize<JsonDocument>(function.Parameters.Properties.IfNullOrEmptyAs("{}")),
|
||||
Required = function.Parameters.Required,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue