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.

When to Use

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 type or action field

For exactly two outcomes (true/false), use If instead.

Inputs

HandleTypeDescription
inputanyThe value used for case matching. Required.

Outputs

None. Switch has no data output handles. Execution continues through one of these control branch handles:

HandleTypeDescription
[case label]controlOne handle per case you define. Execution flows down the matching branch.
defaultcontrolExecution flows here when no case matches.

Settings

SettingTypeDefaultDescription
conditionexpressionExpression evaluated against input. Supports template bindings. Example: input.body.type
casesdynamic listOrdered list of case labels. Each label creates one control output handle.
matchModeenumexactHow 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.

Example

Canvas

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

TSL

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

Common Gotchas

  • Case labels are case-sensitive when matchMode is exact. Use lower() in the condition for case-insensitive matching.
  • The default branch fires if no case label matches. If you leave default unconnected, 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.

See Also

On this page