1- using System . Text . Json ;
21using BotSharp . Core . Rules . Models ;
32
43namespace BotSharp . Core . Rules . Conditions ;
@@ -16,11 +15,13 @@ namespace BotSharp.Core.Rules.Conditions;
1615/// (A AND B) OR (C AND NOT D)
1716///
1817/// Leaf node format:
19- /// { "node": "node_name", "key": "data_key" }
20- /// - "node": The Name of a parent condition node whose result to inspect.
21- /// - "key": The key in the parent node's RuleNodeResult.Data dictionary that holds
22- /// a boolean string ("true"/"false"). If omitted, falls back to the parent
23- /// node's RuleNodeResult.Success flag.
18+ /// { "node_alias": "node_alias", "key": "data_key" }
19+ /// - "node_alias": The Alias of a parent condition node whose result to inspect.
20+ /// Using Alias instead of Name avoids collisions when multiple nodes
21+ /// share the same Name (e.g. several "http_request" nodes).
22+ /// - "key": The key in the parent node's RuleNodeResult.Data dictionary that holds
23+ /// a boolean string ("true"/"false"). If omitted, falls back to the parent
24+ /// node's RuleNodeResult.Success flag.
2425///
2526/// Node config:
2627/// "expression" - A JSON-encoded LogicExpression tree.
@@ -30,20 +31,20 @@ namespace BotSharp.Core.Rules.Conditions;
3031/// Example: work_order_valid AND (client_name_valid OR NOT affiliate_name_valid)
3132///
3233/// Given three parent condition nodes:
33- /// - Node A ("check_work_order") returns Data["work_order_valid"] = "true"
34- /// - Node B ("check_client") returns Data["client_name_valid"] = "false"
35- /// - Node C ("check_affiliate") returns Data["affiliate_name_valid"] = "false"
34+ /// - Node A (node_alias "check_work_order") returns Data["work_order_valid"] = "true"
35+ /// - Node B (node_alias "check_client") returns Data["client_name_valid"] = "false"
36+ /// - Node C (node_alias "check_affiliate") returns Data["affiliate_name_valid"] = "false"
3637///
3738/// The gate node config would be:
3839/// {
3940/// "expression": {
4041/// "op": "and",
4142/// "children": [
42- /// { "node ": "check_work_order", "key": "work_order_valid" },
43+ /// { "node_alias ": "check_work_order", "key": "work_order_valid" },
4344/// { "op": "or", "children": [
44- /// { "node ": "check_client", "key": "client_name_valid" },
45+ /// { "node_alias ": "check_client", "key": "client_name_valid" },
4546/// { "op": "not", "children": [
46- /// { "node ": "check_affiliate", "key": "affiliate_name_valid" }
47+ /// { "node_alias ": "check_affiliate", "key": "affiliate_name_valid" }
4748/// ]}
4849/// ]}
4950/// ]
@@ -142,10 +143,10 @@ public async Task<RuleNodeResult> EvaluateAsync(
142143
143144 var defaultValue = currentNode . Config ? . GetValueOrDefault ( "default_value" ) ?? "false" ;
144145
145- // 3. Build lookup: parent node name → its latest RuleFlowStepResult
146+ // 3. Build lookup: parent node alias → its latest RuleFlowStepResult
146147 var parentResults = ( context . PrevStepResults ?? [ ] )
147148 . Where ( r => parentNodeIds . Contains ( r . Node . Id ) )
148- . GroupBy ( r => r . Node . Name , StringComparer . OrdinalIgnoreCase )
149+ . GroupBy ( r => r . Node . Alias , StringComparer . OrdinalIgnoreCase )
149150 . ToDictionary ( g => g . Key , g => g . Last ( ) , StringComparer . OrdinalIgnoreCase ) ;
150151
151152 // 4. Evaluate the expression tree
@@ -167,13 +168,13 @@ private bool Evaluate(
167168 Dictionary < string , RuleFlowStepResult > parentResults ,
168169 string defaultValue )
169170 {
170- // Leaf node: look up a specific parent's result
171- if ( ! string . IsNullOrEmpty ( expr . Node ) )
171+ // Leaf node: look up a specific parent's result by alias
172+ if ( ! string . IsNullOrEmpty ( expr . NodeAlias ) )
172173 {
173- if ( ! parentResults . TryGetValue ( expr . Node , out var stepResult ) )
174+ if ( ! parentResults . TryGetValue ( expr . NodeAlias , out var stepResult ) )
174175 {
175- _logger . LogWarning ( "Logic gate: parent node '{Node }' not found in results, using default '{Default}'." ,
176- expr . Node , defaultValue ) ;
176+ _logger . LogWarning ( "Logic gate: parent node alias '{Alias }' not found in results, using default '{Default}'." ,
177+ expr . NodeAlias , defaultValue ) ;
177178 return ParseBool ( defaultValue ) ;
178179 }
179180
0 commit comments