|
1 | | -# State Nodes in Event Flow System |
2 | | - |
3 | | -## How State Nodes Work |
4 | | - |
5 | | -State nodes maintain persistent state between message events, acting as intelligent filters/controllers in your event flows. |
6 | | - |
7 | | -## Available State Nodes |
8 | | - |
9 | | -### 🚦 GATE Control |
10 | | -- **Purpose**: Acts as an on/off switch for message flow |
11 | | -- **States**: ALLOW (messages pass) or BLOCK (messages stop) |
12 | | -- **Control**: Use `setGateState` action to change state |
13 | | -- **Example**: Block duplicate triggers during OBS scene switches |
14 | | - |
15 | | -### 📋 QUEUE (Message Queue) |
16 | | -- **Purpose**: Buffers messages and processes them sequentially |
17 | | -- **Config**: maxSize, overflowStrategy (DROP_OLDEST, DROP_NEWEST, DROP_RANDOM) |
18 | | -- **Note**: Currently requires manual implementation of queue processing |
19 | | - |
20 | | -### 🎛️ SEMAPHORE |
21 | | -- **Purpose**: Limits concurrent operations |
22 | | -- **Config**: maxCount (how many can run simultaneously) |
23 | | -- **Use Case**: Limit simultaneous webhook calls or resource-intensive actions |
24 | | - |
25 | | -### 🔒 LATCH Memory |
26 | | -- **Purpose**: Once triggered, stays "on" until manually reset |
27 | | -- **Config**: resetOnTrigger (boolean) |
28 | | -- **Use Case**: One-time triggers, first-viewer rewards |
29 | | - |
30 | | -### ⏲️ THROTTLE (Rate Limiter) |
31 | | -- **Purpose**: Limits how often messages can pass through |
32 | | -- **Config**: intervalMs, maxPerInterval |
33 | | -- **Use Case**: Prevent spam, rate-limit commands |
34 | | - |
35 | | -### 🎬 SEQUENCER |
36 | | -- **Purpose**: Ensures messages are processed in order |
37 | | -- **Config**: sequenceField (which field to track) |
38 | | -- **Use Case**: Process events in exact order |
39 | | - |
40 | | -## How to Control State Nodes |
41 | | - |
42 | | -State nodes are controlled through specific actions: |
43 | | - |
44 | | -1. **setGateState** - Changes a GATE node between ALLOW/BLOCK |
45 | | - - Config: `targetNodeId`, `state` (ALLOW or BLOCK) |
46 | | - |
47 | | -2. **resetStateNode** - Resets any state node to initial state |
48 | | - - Config: `targetNodeId` |
49 | | - |
50 | | -## Example Workflow: OBS Scene Switch with Gate |
51 | | - |
52 | | -```json |
53 | | -Trigger (!hello) → GATE → Change Scene → Close Gate → Delay → Switch Back → Open Gate |
54 | | -``` |
55 | | - |
56 | | -This prevents multiple !hello commands from triggering while the first is still processing. |
57 | | - |
58 | | -## Important Notes |
59 | | - |
60 | | -- COUNTER, USERPOOL, ACCUMULATOR nodes are defined but not yet implemented |
61 | | -- State nodes must be connected properly (fixed in latest update) |
62 | | -- State persists across messages until explicitly changed or reset |
63 | | -- Some state nodes (QUEUE) need additional actions for full functionality |
64 | | - |
65 | | -## Connection Rules |
66 | | -State nodes can now: |
67 | | -- Receive connections FROM: Triggers, Actions, Logic nodes, other State nodes |
68 | | -- Send connections TO: Actions, Logic nodes, other State nodes |
| 1 | +# State Nodes in Event Flow |
| 2 | + |
| 3 | +State nodes keep information between events in one flow. They are useful when an automation needs to remember whether a gate is open, how many events have happened, whether a rate limit has been reached, or which users have participated. |
| 4 | + |
| 5 | +## Available State Nodes |
| 6 | + |
| 7 | +### Gate |
| 8 | + |
| 9 | +- Holds an `ALLOW` or `BLOCK` value. |
| 10 | +- Passes or stops an event on the normal execution path. |
| 11 | +- Use `Set Gate State` to change it and `Reset State Node` to restore its configured default. |
| 12 | + |
| 13 | +### Counter |
| 14 | + |
| 15 | +- Holds a numeric value and can check it against a target. |
| 16 | +- Use `Set Counter Value`, `Increment Counter`, `Check Counter`, or `Reset State Node`. |
| 17 | +- `Check Counter` adds `counterValue`, `counterTarget`, and `counterRemaining` to the event for downstream templates. |
| 18 | + |
| 19 | +### Rate Limiter |
| 20 | + |
| 21 | +- Tracks recent event timestamps and limits how many events may pass during a configured interval. |
| 22 | +- Use `Reset State Node` to clear only the selected limiter's recent-event history. |
| 23 | + |
| 24 | +### User Memory |
| 25 | + |
| 26 | +- Owns one named, isolated set of unique users. |
| 27 | +- User Memory is a shared resource, not an execution step, so it has no normal input/output ports. |
| 28 | +- `Remember User`, `Forget User`, `Clear All Users`, `Pick Random User`, and `User Is Remembered` select a User Memory node by ID. |
| 29 | +- The generic `Reset State Node` action can also clear the selected User Memory. |
| 30 | +- Users are keyed by platform plus user ID, with username fields used only as a fallback. Events without a usable user identity are ignored. |
| 31 | +- Repeated events from one user update that entry's participation count without creating duplicate draw entries. |
| 32 | + |
| 33 | +See the full [User Memory guide](user-memory-guide.html) for screenshots and participation, eligibility, and prize-draw examples. |
| 34 | + |
| 35 | +## Execution Wires and State References |
| 36 | + |
| 37 | +- Solid teal wires show event execution: which node runs next. |
| 38 | +- Dashed purple links show a shared User Memory reference: which memory an operation reads or changes. |
| 39 | +- A User Memory operation stores the target state node's ID internally. The target can be set from the node properties or by dragging its purple side connector to a User Memory node. |
| 40 | +- Selecting a User Memory highlights the operations linked to it. Deleting the memory warns that those references will be removed. |
| 41 | + |
| 42 | +Gate, Counter, and Rate Limiter nodes remain part of the normal execution path. Their control actions also select the target state node by ID, but those relationships currently do not have the dashed canvas link used by User Memory. |
| 43 | + |
| 44 | +## User Memory Persistence and Reset Scope |
| 45 | + |
| 46 | +A User Memory can last for the current app session or be saved across restarts. Each memory also has independent options to clear: |
| 47 | + |
| 48 | +- Manually from its properties. |
| 49 | +- Through `Clear All Users` or `Reset State Node` in a flow. |
| 50 | +- After a configured period of inactivity. |
| 51 | +- When a stream starts. |
| 52 | +- When a stream stops. |
| 53 | + |
| 54 | +"Clear All Users" means every user in the selected memory only. It does not clear other User Memory nodes or unrelated Event Flow state. |
| 55 | + |
| 56 | +## Example: Unique Prize Draw |
| 57 | + |
| 58 | +```text |
| 59 | +!enter -> Remember User ....> [User Memory: Prize Draw Entrants] |
| 60 | +!draw -> Pick Random User ..> [User Memory: Prize Draw Entrants] |
| 61 | +!reset -> Clear All Users ...> [User Memory: Prize Draw Entrants] |
| 62 | +``` |
| 63 | + |
| 64 | +Use normal role/user checks before `Pick Random User` and `Clear All Users` so only a host or moderator can operate the draw. Enable the draw action's remove-winner option if the same person should not be selected twice. |
| 65 | + |
| 66 | +## Setup Checklist |
| 67 | + |
| 68 | +1. Add and name the state node first. |
| 69 | +2. Add the triggers/actions that will read or change it. |
| 70 | +3. Select the intended state node in every control operation. |
| 71 | +4. Test with at least two users and reset the state between scenarios. |
| 72 | +5. For User Memory, verify persistence and automatic-reset settings before going live. |
0 commit comments