elsa-core/specs/006-state-machine-activity/contracts/state-machine-json.md
Sipke Schoorstra 6485f05a87
Add state machine activity (#7457)
* Add state machine activity

* address greptile state machine feedback

* address state machine trigger cancellation feedback
2026-05-18 02:09:03 +02:00

1.1 KiB

State Machine JSON Contract

The backend activity accepts the following shape when serialized through Elsa's existing activity JSON pipeline:

{
  "type": "StateMachine",
  "initialState": "NewOrder",
  "currentState": "NewOrder",
  "states": [
    {
      "name": "NewOrder",
      "entry": { "type": "WriteLine", "text": "New order" },
      "exit": { "type": "WriteLine", "text": "Leaving new order" }
    },
    {
      "name": "Paid",
      "entry": { "type": "WriteLine", "text": "Paid" }
    }
  ],
  "transitions": [
    {
      "name": "MarkPaid",
      "displayName": "Mark paid",
      "from": "NewOrder",
      "to": "Paid",
      "trigger": { "type": "Event" },
      "condition": true,
      "action": { "type": "WriteLine", "text": "Payment accepted" }
    }
  ]
}

The exact activity payloads inside entry, exit, trigger, and action are resolved by Elsa's existing activity serialization. A target state without valid outbound transitions is terminal. A transition whose condition evaluates false leaves the source state current and keeps that transition trigger active for a future attempt.