Switch Node

Documentation for the Switch node in the SMSPort Visual Bot Builder. Learn how to route conversations across multiple pathways based on discrete values, customer choices, triage priority, or departments.

While a Condition card splits a flow into 2 paths (True or False), a Switch card routes conversations into multiple custom pathways (e.g. 3, 5, or 10 branches) based on the exact value of a variable.


Operations & Logic Flow

graph TD
    PrevNode[User Selects Department] --> SwitchNode[Switch: variable {{department}}]
    SwitchNode -->|case 'cardiology'| CardioCard[Send Text: Welcome to Cardiology Center]
    SwitchNode -->|case 'pediatrics'| PediaCard[Send Text: Welcome to Children's Clinic]
    SwitchNode -->|case 'dermatology'| DermaCard[Send Text: Welcome to Skin Care Clinic]
    SwitchNode -->|fallback| DefaultCard[Send Text: Connecting you to General Helpdesk]

Inspector Screen: Field-by-Field Guide

When you click on a Switch card in the Visual Builder canvas, the inspector presents:

1. Variable Key (`variableKey`)

  • Label on Screen: Variable to Inspect
  • Required: Yes
  • What to Fill: The variable whose value you want to test (e.g. selected_department, lead_grade, payment_status). Do not include {{}} brackets here—just the variable key name (e.g. selected_department).

2. Matching Mode (`matchingMode`)

  • Options:
    • exact_match (Default): Value must match the case string exactly.
    • case_insensitive: Matches Cardio, cardio, or CARDIO.
    • contains: Checks if the variable contains the case keyword.
    • regex: Evaluates regular expression patterns.

3. Cases (`options[]`)

Click + Add Case to define each branch:

  • Case 1: cardiology -> Generates canvas output handle case_cardiology
  • Case 2: pediatrics -> Generates canvas output handle case_pediatrics
  • Case 3: dermatology -> Generates canvas output handle case_dermatology

4. Fallback Default Handle

  • Generates the default handle on the canvas. If the incoming variable does not match any of the defined cases, the bot will safely follow this branch.

Step-by-Step Tutorial: Department Routing Bot

Here is how to build a multi-department triage flow:

  1. Add Ask Button Card:
    • Message: "Welcome to Apollo Clinic. Please choose a department:"
    • Options: Cardiology, Pediatrics, Dermatology
    • Output Variable: selected_dept
  2. Add Switch Card:
    • Variable Key: selected_dept
    • Matching Mode: case_insensitive
    • Add Case: Cardiology
    • Add Case: Pediatrics
    • Add Case: Dermatology
  3. Wire Canvas Outputs:
    • Connect case_cardiology -> Send WhatsApp Flow (Cardiology Intake Form).
    • Connect case_pediatrics -> Send Text (Pediatrician available slots).
    • Connect case_dermatology -> Send Media (Skin clinic consultation brochure).
    • Connect default -> Human Handoff (Transfer to front desk receptionist).

Common Issues & Troubleshooting

1. "Variable is routed to default branch even though it looks identical"

  • Cause: Leading or trailing whitespace in the customer's answer (e.g. "Cardiology " with a space).
  • Fix: Enable case_insensitive mode in the Switch card inspector, or use the trim({{selected_dept}}) helper function before the switch.

2. "All branches execute simultaneously"

  • Clarification: The Switch card is deterministic. Only one single branch executes per execution step. Once a match is found, subsequent cases are ignored.