You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(result.context.messages); // [{ type: 'info', text: 'Alice: Good morning!' }]
145
145
```
146
+
147
+
## 6. Logical Grouping (AND/OR)
148
+
`neuron-js` uses a "Sum of Products" approach to logic. Conditions are grouped into blocks.
149
+
-**AND**: All conditions within a block must be true.
150
+
-**OR**: If any block is true, the entire rule evaluates to true.
151
+
152
+
### How to trigger OR
153
+
Setting `orCondition: true` on a condition starts a **new block**. This new block is joined to the previous block with an `OR` operator.
154
+
155
+
### Example: (A AND B) OR (C AND D)
156
+
```json
157
+
{
158
+
"id": "complex-logic",
159
+
"conditions": [
160
+
{ "id": "A", "type": "is_gold_member" },
161
+
{ "id": "B", "type": "has_high_balance" },
162
+
{
163
+
"id": "C",
164
+
"type": "is_new_user",
165
+
"options": { "orCondition": true }
166
+
},
167
+
{ "id": "D", "type": "has_promo_code" }
168
+
]
169
+
}
170
+
```
171
+
**Evaluation Logic**: `(A && B) || (C && D)`
172
+
173
+
## 7. Condition Inversion (NOT)
174
+
Any condition can be negated by setting `inverted: true` in its options. This is handled by the runtime, so your plugin implementation doesn't need to worry about it.
Copy file name to clipboardExpand all lines: docs/concepts/scripts-and-rules.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,21 @@ A `Rule` is a self-contained logical unit. It consists of two main parts:
19
19
```
20
20
21
21
## Condition Logic
22
-
Conditions are evaluated sequentially. By default, they follow an**AND** logic (all must be true).
22
+
Conditions are evaluated sequentially and follow a**Sum of Products** logic (ANDs grouped by ORs).
23
23
24
-
### Advanced Condition Features:
25
-
-**Inversion**: A condition can be "inverted" (NOT logic).
26
-
-**OR Grouping**: A condition can be marked as an `orCondition`. If the next condition is an `orCondition`, they are treated as a group where only one needs to pass.
24
+
### AND Logic
25
+
By default, all conditions in the list are joined by **AND**. Every condition must evaluate to `true` for the actions to trigger.
26
+
27
+
### OR Grouping
28
+
You can create an **OR** relationship by setting `orCondition: true` in a condition's options. This starts a **new block** of conditions.
29
+
- Each block is evaluated as an **AND** group.
30
+
- All blocks are joined by **OR**.
31
+
- If **any** block evaluates to `true`, the rule fires.
32
+
33
+
**Example result**: `(Block 1 AND Block 1) OR (Block 2 AND Block 2)`
34
+
35
+
### Advanced Features:
36
+
-**Inversion**: Set `inverted: true` to negate a condition (NOT logic).
27
37
-**Disabling**: Rules or individual conditions can be disabled via options without removing them from the script.
0 commit comments