Skip to content

Test User Clear

This workflow provides a web-based interface for managing test user data in the SIFA system, allowing administrators to either reset existing user data back to initial state or add new test users to the database for testing purposes.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. Initial Form: Users access a web form where they select either "Reset" or "Add" from a dropdown menu
  2. Branch Selection: Based on the selection, the workflow routes to different paths:
    • Reset Path: Collects phone number to reset an existing user's data
    • Add Path: Collects first name, phone number, and business name to create a new test user
  3. Phone Validation: Both paths validate that the phone number is exactly 13 characters long (Kenyan format: +254XXXXXXXXX)
  4. Data Operations:
    • For reset: Deletes chat logs, chat history, and credit-related data, then resets all user profile fields to initial state
    • For add: Inserts a new user record with provided details and default values
  5. Success/Error Feedback: Shows appropriate completion messages based on operation success or failure

Mermaid Diagram

graph TD
    A[On form submission] --> B[If3: Check Reason]
    B -->|Reset| C[Form3: Phone Input]
    B -->|Add| D[Form4: User Details]

    C --> E[Edit Fields]
    E --> F[If: Phone Validation]
    F -->|Valid| G[delete_chat]
    F -->|Invalid| H[Form: Error]

    G --> I[If6: Check Success]
    I -->|Success| J[delete_chat_history]
    I -->|Failure| K[Form1: Error]

    J --> L[If1: Check Success]
    J --> M[delete_extra_tables]
    L -->|Success| N[update_user_data]
    L -->|Failure| K

    N --> O[If2: Check Success]
    O -->|Success| P[Form2: Success]
    O -->|Failure| K

    D --> Q[Edit Fields1]
    Q --> R[If4: Phone Validation]
    R -->|Valid| S[upsert_user_records]
    R -->|Invalid| T[Form5: Error]

    S --> U[If5: Check Success]
    U -->|Success| V[Form7: Success]
    U -->|Failure| W[Form6: Error]

Trigger

Form Trigger: A web form accessible at the /reset-user path with: - Title: "Test Users - v4" - Description: "Enter Your Phone Number to clear the test data or add your phone number to beginning testing." - Single dropdown field labeled "Reason" with options "Reset" and "Add"

Nodes Used

Node Type Node Name Purpose
Form Trigger On form submission Initial form to select reset or add operation
If If3 Routes workflow based on selected reason
Form Form3 Collects phone number for reset operation
Form Form4 Collects user details for add operation
Set Edit Fields Extracts phone number from reset form
Set Edit Fields1 Extracts user details from add form
If If, If4 Validates phone number format (13 characters)
Postgres delete_chat Removes chat log entries for user
Postgres delete_chat_history Removes chat history entries
Postgres delete_extra_tables Removes credit-related data
Postgres update_user_data Resets user profile to initial state
Postgres upsert_user_records Creates new user record
If If1, If2, If5, If6 Checks database operation success
Form Form, Form5 Shows phone format error
Form Form1, Form6 Shows general error message
Form Form2 Shows reset success message
Form Form7 Shows add success message

External Services & Credentials Required

  • PostgreSQL Database: Requires credential named "sifaV4Dev"
    • Used for all database operations (DELETE, UPDATE, INSERT)
    • Must have access to tables: v4_chatLog, v4_youthEntrepreneurs, n8n_chat_histories, v4_creditpathFollowup, v4_creditpathHistory, v4_credit_n8n_chat_history

Environment Variables

No environment variables are used in this workflow. All configuration is handled through node parameters and database credentials.

Data Flow

Input (Reset Path): - Phone number in format +254XXXXXXXXX (13 characters)

Input (Add Path): - First Name (string) - Phone number in format +254XXXXXXXXX (13 characters)
- Business name (string)

Output: - Success/error completion pages with appropriate messages - Database modifications (deletions, updates, or inserts)

Data Transformations: - Phone number validation (length check) - Field mapping from form inputs to database columns - Default value assignment for new users (secondName: 'Doe', channel: 'Whatsapp', gender: 'Male', age: 24, county: 'Nairobi', sifa_points: 0)

Error Handling

The workflow includes comprehensive error handling:

  1. Phone Format Validation: Shows "Wrong Number Format" error if phone number isn't exactly 13 characters
  2. Database Operation Failures: Each database operation is followed by success validation
  3. Graceful Error Recovery: The delete_chat_history node is configured with "continueRegularOutput" on error
  4. User-Friendly Messages: All error states show appropriate completion forms with guidance

Known Limitations

  • Phone number validation only checks length (13 characters), not actual format validity
  • Hard-coded default values for new users (gender, age, county)
  • No duplicate phone number checking when adding new users
  • Reset operation affects multiple database tables and may not be fully atomic

No related workflows identified from the provided information.

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named "sifaV4Dev"
    • Ensure it has read/write access to all required tables
  3. Database Schema: Verify the following tables exist with proper structure:
    • v4_chatLog (with userPhone column)
    • v4_youthEntrepreneurs (with all profile columns)
    • n8n_chat_histories (with session_id column)
    • v4_creditpathFollowup (with phoneNumber column)
    • v4_creditpathHistory (with phoneNumber column)
    • v4_credit_n8n_chat_history (with session_id column)
  4. Activate Workflow: Enable the workflow to make the form accessible
  5. Test Access: Navigate to [your-n8n-url]/form/reset-user to access the form
  6. Verify Operations: Test both reset and add operations with valid phone numbers