Switch
Routes workflow execution across multiple named cases based on a value. The node evaluates an expression and sends execution down the branch whose label matches the result.
Use Switch when you have more than two possible outcomes based on a single value:
- Route Stripe event types:
payment_intent.succeeded,customer.subscription.deleted,invoice.payment_failed - Handle different HTTP methods on the same workflow
- Route messages to different handlers based on a
typeoractionfield
For exactly two outcomes (true/false), use If instead.
| Handle | Type | Description |
|---|---|---|
input | any | The value used for case matching. Required. |
None. Switch has no data output handles. Execution continues through one of these control branch handles:
| Handle | Type | Description |
|---|---|---|
[case label] | control | One handle per case you define. Execution flows down the matching branch. |
default | control | Execution flows here when no case matches. |
| Setting | Type | Default | Description |
|---|---|---|---|
condition | expression | — | Expression evaluated against input. Supports template bindings. Example: input.body.type |
cases | dynamic list | — | Ordered list of case labels. Each label creates one control output handle. |
matchMode | enum | exact | How to compare the condition result against case labels: exact, contains, or regex |
Match modes:
| Mode | Behavior |
|------|----------|
| exact | Case label must exactly equal the evaluated expression result |
| contains | Case label matches if the result contains the label as a substring |
| regex | Case label is treated as a regular expression pattern |
The condition field accepts bare Python expressions — no {"{{ }}"} wrapper needed. Cases are evaluated in order; the first matching case wins.
Route Stripe webhook events to different logic:
Webhook → Switch (input.body.type)
→ payment_intent.succeeded → [charge logic]
→ customer.subscription.deleted → [cancel logic]
→ invoice.payment_failed → [retry logic]
→ default → Stop
Switch settings:
- Condition:
input.body.type - Cases:
payment_intent.succeeded,customer.subscription.deleted,invoice.payment_failed - Match Mode:
exact
import webhook from @tensorify/webhook-trigger:4.0.0
import route_event from @tensorify/switch:3.0.0
import transform from @tensorify/transform:3.0.0
import unhandled from @tensorify/stop:3.0.0
node stripe @tensorify/webhook-trigger:4.0.0 {
provider = "stripe"
path = "/stripe/events"
method = "POST"
}
node router @tensorify/switch:3.0.0 {
condition = "input.body.type"
cases = ["payment_intent.succeeded", "customer.subscription.deleted", "invoice.payment_failed"]
matchMode = "exact"
}
node charge @tensorify/transform:3.0.0 {
mode = "object"
}
node cancel @tensorify/transform:3.0.0 {
mode = "object"
}
node retry @tensorify/transform:3.0.0 {
mode = "object"
}
node fallback @tensorify/stop:3.0.0
stripe.payload -> router.input
router."payment_intent.succeeded" -> charge.input
router."customer.subscription.deleted" -> cancel.input
router."invoice.payment_failed" -> retry.input
router.default -> fallback.input
- Case labels are case-sensitive when
matchModeisexact. Uselower()in the condition for case-insensitive matching. - The
defaultbranch fires if no case label matches. If you leavedefaultunconnected, execution silently stops on no-match — which is usually fine. - Cases are evaluated in order. The first matching case wins.
- Case labels containing dots must be quoted in TSL:
router."checkout.session.completed" -> target.input - Old workflows with
{"{{ }}"}in conditions still work — the runtime strips them automatically. New workflows should use bare expressions.
- Expression Reference — full list of operators and helpers
- Expressions & Conditions Guide — workflow recipes
- If — binary true/false branch
- Stop — terminate the default branch explicitly
