Condition Node
The condition node is a core control component in FlowAI that allows you to split the workflow into different execution paths based on specified conditions. By using condition checks effectively, you can build complex business logic.
Node Configuration
Basic Settings
-
Node Name
- Set a descriptive name for the condition node.
- It is recommended to use a name that reflects the purpose of the check, such as “Check Age” or “Verify Permissions.”
- Naming convention: use a verb+noun format, e.g., “Verify User Permissions” or “Check Order Status.”
-
Condition Content
- Only variable references are supported; ensure that a variable has been output from a preceding node.
-
Condition Options
The following string comparison methods are supported:
- Equal / Not Equal: Exact string matching.
- Contains / Does Not Contain: Checks if the string contains a substring; even a partial match is considered successful.
- Starts With / Does Not Start With: Checks the prefix of the string.
- Ends With / Does Not End With: Checks the suffix of the string.
Usage Examples
1. User Type Determination
Let’s create a simple workflow to determine user type—one of the most common scenarios in FlowAI:
-
Input Node Configuration
-
Condition Check Configuration
Node Name: User Type CheckCondition Content: $input.userTypeCondition 1: Equal to "VIP"Condition 2: Equal to "Regular User"Condition 3: Contains "" // Using an empty string in the 'Contains' condition to represent all other cases; it will match anything not matched earlier.Note: Conditions are evaluated in sequence, so Condition 3 must be placed last to avoid prematurely matching other cases!
-
Output Node Configuration
Use different branches to handle different user types.
2. Message Type Classification
A practical example—processing messages with different responses, suitable for chatbots, customer service systems, etc.:
-
Input Node Configuration
-
Condition Check Configuration
Condition Content: $input.messageCondition 1: Starts With "/help" // Help commandCondition 2: Starts With "/search" // Search commandCondition 3: Contains "Order Number:" // Order inquiryCondition 4: Contains empty string // Regular message -
Processing Node Configuration (for each branch)
For example, you can:
- Help Command Branch: Return a list of help information.
- Search Command Branch: Execute a search operation.
- Order Inquiry Branch: Query the order status.
- Regular Message Branch: Return a default reply.
3. File Name Matching Example
This example showcases how to use string-related condition checks, applicable for file processing, automated workflows, and similar scenarios:
Node Name: File ClassificationCondition Content: $input.filenameCondition 1: Ends With ".jpg" or Ends With ".png" (Image Files)Condition 2: Ends With ".pdf" (PDF Document)Condition 3: Ends With ".zip" (Compressed Archive)Condition 4: Other cases (Unknown Type)
Advanced Usage
1. Nested Conditions
You can implement complex logic by connecting multiple condition nodes, which is useful in scenarios such as multi-level approvals or complex business rules:
[Age Check] --> [Identity Check] --> [Permission Check]
2. Combined Condition Example
Using multiple conditions in a single condition node is suitable for scenarios requiring several conditions to be met simultaneously:
Condition 1: Equal to "premium" and Contains "plus" // Matches "premium plus"Condition 2: Starts With "basic" // Matches all entries beginning with "basic"Condition 3: Other cases
Best Practices
-
Principles of Condition Design
- All comparisons are based on strings.
- Conditions should be mutually exclusive.
- Conditions should comprehensively cover all possible cases.
- Special cases should be handled with priority.
- Use comments to explain the business meaning behind each condition.
- Keep the condition logic simple and maintainable.
-
Variable Handling
- Ensure that the variable exists before performing condition checks.
- Consider consistency in data types.
- Be mindful of case sensitivity.
-
Error Handling
- Add a default branch to handle exceptional cases.
- Include logging in critical branches.
- Consider the necessity of data validation.