Execute custom JavaScript functions deployed on Cloudflare Workers or Supabase Functions. Functions can process data, integrate with external APIs, and update flow variables.

Configuration

  • id: Unique node identifier
  • function_id: ID of deployed function to execute
  • save_response_to: Variable name to store function response (optional)

Function context

Your function receives this data:
{
  execution_context: {
    vars: {},      // Flow variables
    system: {},    // System info (flow_id, started_at, etc)
    context: {}    // Channel info (phone_number, etc)
  },
  flow_events: [], // Recent flow events (last 10)
  flow_info: {
    id: "flow_123",
    name: "Customer Support",
    step_id: "current_step_456"
  },
  whatsapp_context: { // Only if WhatsApp flow
    conversation: {},
    messages: []
  }
}

Function response

Functions can return JSON to update the flow:
return new Response(JSON.stringify({
  vars: {
    user_score: 85,
    validated: true
  },
  next_edge: "success" // Optional: suggest next flow path
}))

Examples

Basic function execution
from kapso.builder.flows.nodes import FunctionNode

node = FunctionNode(
    id="validate_email",
    function_id="func_email_validator_123"
)
Save response to variable
node = FunctionNode(
    id="calculate_score",
    function_id="func_score_calculator_456",
    save_response_to="user_score"
)
Multiple functions in flow
# Calculate user score
score_node = FunctionNode(
    id="calc_score",
    function_id="func_calculate_user_score",
    save_response_to="score_data"
)

# Process payment based on score
payment_node = FunctionNode(
    id="process_payment",
    function_id="func_payment_processor",
    save_response_to="payment_result"
)

# Connect them
flow.add_edge("calc_score", "process_payment", "next")

How it works

  1. Invokes function: Calls your deployed function with flow context
  2. Processes response: Updates flow variables from function response
  3. Continues flow: Advances to next step via next edge
  4. Saves data: Optionally stores full response in specified variable

Usage patterns

Data validation API integration Conditional processing