Skip to main content

Event Examples: Multi Mode

Complete JSON examples for Multi branching events - switch-like routing with 3+ distinct paths.

Overview

Multi mode routes to different branches based on a variable value. Perfect for switch-like routing with multiple distinct paths.

Use Cases

  • Route by user role (admin/user/guest)
  • Route by event type (touchdown/field_goal/interception)
  • Route by region (us/ca/eu/intl)
  • Route by priority level (high/medium/low)
  • Dynamic routing based on computed values

Basic Multi Event

Route by NFL event type:

{
"organizationId": "550e8400-e29b-41d4-a716-446655440000",
"environmentId": "660e8400-e29b-41d4-a716-446655440001",
"name": "Route by Play Type",
"description": "Routes NFL events to different handlers based on play type",
"workflowEntityTypeId": "event-type-uuid",
"condition": {
"type": "rule",
"field": "message.payload.metadata.league",
"comparison": "equals",
"value": "nfl"
},
"tfCondition": "Multi",
"logicField": "playType",
"script": "var playType = message.payload.event.event_type || 'unknown'; print('Routing play type:', playType);",
"arguments": [],
"logic": [
{ "name": "Touchdown", "value": "touchdown" },
{ "name": "Field Goal", "value": "field_goal" },
{ "name": "Interception", "value": "interception" },
{ "name": "Timeout", "value": "timeout" },
{ "name": "Other", "value": "*" }
]
}

Example Messages:

Touchdown message:

{
"organizationId": "550e8400-e29b-41d4-a716-446655440000",
"environmentId": "660e8400-e29b-41d4-a716-446655440001",
"type": "nfl_event",
"payload": {
"event": {
"event_type": "touchdown",
"description": "Touchdown by NE"
},
"metadata": {
"league": "nfl",
"event_type": "touchdown"
}
}
}

→ Routes to "Touchdown" branch

Field goal message:

{
"type": "nfl_event",
"payload": {
"event": {
"event_type": "field_goal",
"description": "Field goal good by NE - 42 yards"
},
"metadata": {
"league": "nfl"
}
}
}

→ Routes to "Field Goal" branch

Unknown event:

{
"type": "nfl_event",
"payload": {
"event": {
"event_type": "penalty",
"description": "Holding on offense"
}
}
}

→ Routes to "Other" branch (wildcard *)

Workflow JSON Structure

{
"nodes": {
"n1": {
"entityId": "event-entity-uuid",
"name": "Route by Play Type",
"entityType": "event",
"tfCondition": "Multi",
"logicField": "playType",
"presentation": {
"type": "circle",
"position": { "x": 100, "y": 200 }
}
},
"n2": {
"name": "Touchdown",
"entityType": "logic-branch",
"branchValue": "touchdown",
"presentation": {
"type": "logic-branch",
"position": { "x": 300, "y": 50 }
}
},
"n3": {
"name": "Field Goal",
"entityType": "logic-branch",
"branchValue": "field_goal",
"presentation": {
"type": "logic-branch",
"position": { "x": 300, "y": 150 }
}
},
"n4": {
"name": "Other",
"entityType": "logic-branch",
"branchValue": "*",
"presentation": {
"type": "logic-branch",
"position": { "x": 300, "y": 250 }
}
}
}
}

Multi Mode - Route by User Role

{
"organizationId": "550e8400-e29b-41d4-a716-446655440000",
"environmentId": "660e8400-e29b-41d4-a716-446655440001",
"name": "Route by User Role",
"description": "Routes users to role-specific workflows",
"workflowEntityTypeId": "event-type-uuid",
"condition": {
"type": "rule",
"field": "message.type",
"comparison": "equals",
"value": "user.action"
},
"tfCondition": "Multi",
"logicField": "userRole",
"script": "var userRole = message.user.role || 'guest'; if (message.user.isAdmin) { userRole = 'admin'; } print('User role:', userRole);",
"arguments": [],
"logic": [
{ "name": "Admin", "value": "admin" },
{ "name": "User", "value": "user" },
{ "name": "Guest", "value": "guest" },
{ "name": "Default", "value": "*" }
]
}

Example Message:

{
"type": "user.action",
"user": {
"id": "user-456",
"email": "admin@example.com",
"role": "admin",
"isAdmin": true
},
"action": "view_dashboard"
}

Multi Mode - Route by Region

{
"organizationId": "550e8400-e29b-41d4-a716-446655440000",
"environmentId": "660e8400-e29b-41d4-a716-446655440001",
"name": "Route by Shipping Region",
"description": "Routes orders to regional fulfillment centers",
"workflowEntityTypeId": "event-type-uuid",
"condition": {
"type": "rule",
"field": "message.type",
"comparison": "equals",
"value": "order.created"
},
"tfCondition": "Multi",
"logicField": "region",
"script": "var country = message.shipping.country || 'unknown'; var region = 'intl'; if (country === 'US') { region = 'us'; } else if (country === 'CA') { region = 'ca'; } else if (country === 'GB' || country === 'DE' || country === 'FR') { region = 'eu'; } print('Routing to region:', region);",
"arguments": [],
"logic": [
{ "name": "United States", "value": "us" },
{ "name": "Canada", "value": "ca" },
{ "name": "Europe", "value": "eu" },
{ "name": "International", "value": "intl" }
]
}

Wildcard Catch-All (*)

The wildcard * branch catches any value not matched by other branches:

{
"organizationId": "550e8400-e29b-41d4-a716-446655440000",
"environmentId": "660e8400-e29b-41d4-a716-446655440001",
"name": "Priority Router",
"description": "Routes messages by priority with default handler",
"workflowEntityTypeId": "event-type-uuid",
"condition": {
"type": "rule",
"field": "message.type",
"comparison": "equals",
"value": "notification"
},
"tfCondition": "Multi",
"logicField": "priority",
"script": "var priority = message.priority || 'normal'; print('Message priority:', priority);",
"arguments": [],
"logic": [
{ "name": "Critical", "value": "critical" },
{ "name": "High", "value": "high" },
{ "name": "Normal", "value": "normal" },
{ "name": "Low", "value": "low" },
{ "name": "Default Handler", "value": "*" }
]
}

Wildcard Behavior:

  • priority = "critical" → Routes to "Critical" branch
  • priority = "high" → Routes to "High" branch
  • priority = "unknown" → Routes to "Default Handler" branch (wildcard)
  • priority = undefined → Routes to "Default Handler" branch (wildcard)

API Endpoint

POST /api/workflow-entities
Content-Type: application/json

Key Requirements

  1. logicField: Must be set in the script before branching evaluation
  2. logic array: Defines the available branch values
  3. Workflow branches: Must create logic-branch nodes for each value
  4. Wildcard recommended: Always include a * branch for unmatched values

Best Practices

  1. Use Multi mode for 3+ distinct paths
  2. Always include a wildcard * branch for unmatched values
  3. Set the logic field variable early in the script
  4. Use clear, descriptive branch names
  5. Handle missing/null values with defaults in script
  6. Test with messages that match each branch