Skip to content

Benchmarking Test for Self-hosted n8n

This workflow implements a comprehensive WhatsApp-based AI coaching system for entrepreneurship education. It processes incoming WhatsApp messages from coaches, validates their credentials, manages coaching sessions with youth participants, and provides AI-powered guidance through a 15-stage pedagogical model for business development.

Purpose

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

Based on the workflow structure, this system appears to serve: - Coaches who guide young entrepreneurs through WhatsApp - Youth participants learning to start and grow small businesses - Program coordinators managing entrepreneurship education programs

The workflow enables scalable, AI-assisted coaching sessions that track participant progress through defined business development stages, from initial psychological activation to advanced entrepreneurial skills.

How It Works

  1. Message Reception: WhatsApp messages arrive via Twilio webhook
  2. Coach Validation: System verifies the sender is a registered, active coach
  3. Command Processing: AI determines if message is a command (START, STATUS, DONE) or regular conversation
  4. Session Management:
    • START creates new coaching sessions with youth participants
    • STATUS provides progress reports
    • DONE closes active sessions
  5. Youth Profile Handling: Creates new profiles or retrieves existing ones
  6. AI Coaching: Sophisticated AI agent provides guidance using a 15-stage pedagogical model
  7. Progress Tracking: Records bottlenecks, micro-actions, and stage progression
  8. Response Delivery: Sends appropriate WhatsApp responses back to coaches

Workflow Diagram

graph TD
    A[WhatsApp Message] --> B[Clean Phone Number]
    B --> C[Get Coach Details]
    C --> D{Coach Exists & Active?}
    D -->|No| E[Send Error Message]
    D -->|Yes| F[AI Command Classification]
    F --> G{Command Type?}

    G -->|START| H[Normalize Phone Number]
    H --> I[Lookup Youth Profile]
    I --> J{Youth Exists?}
    J -->|No| K[Create New Youth Profile]
    J -->|Yes| L[Check Active Session]
    K --> M[Create Profile Collection Session]
    L --> N{Session Exists?}
    N -->|Yes| O[Close Old Session]
    N -->|No| P[Create Coaching Session]
    O --> P
    M --> Q[Send Welcome Message]
    P --> R[Fetch Bottleneck History]
    R --> S[Build Welcome Message]
    S --> T[Send Welcome Response]

    G -->|STATUS| U[Normalize Phone Number]
    U --> V[Get Youth Profile]
    V --> W{Youth Exists?}
    W -->|No| X[Send Error Message]
    W -->|Yes| Y[Load Bottleneck Data]
    Y --> Z[Build Status Response]
    Z --> AA[Send Status Message]

    G -->|DONE| BB[Lookup Active Session]
    BB --> CC{Session Active?}
    CC -->|No| DD[Send No Session Message]
    CC -->|Yes| EE[Close Session]
    EE --> FF[Send Closure Confirmation]

    G -->|MESSAGE| GG[Check Existing Session]
    GG --> HH{Session Exists?}
    HH -->|No| II[Send No Session Error]
    HH -->|Yes| JJ[Load Session Data]
    JJ --> KK[AI Agent Processing]
    KK --> LL[Send AI Response]

Trigger

Webhook Trigger: POST endpoint at /benchmarkingshn8n - Receives WhatsApp messages forwarded by Twilio - Processes incoming message data including sender, recipient, and message content

Nodes Used

Node Type Purpose
Webhook Receives incoming WhatsApp messages from Twilio
Code (JavaScript) Phone number normalization and data processing
Postgres Database operations for coaches, youth profiles, sessions, and bottlenecks
If (Conditional) Decision points for coach validation, session management
Switch Routes messages based on command classification
Twilio Sends WhatsApp responses back to users
AI Agent Provides sophisticated coaching using pedagogical model
LangChain LLM Powers AI classification and coaching responses
Postgres Chat Memory Maintains conversation history for AI context
Workflow Tools Calls sub-workflows for profile creation and bottleneck tracking
Set Prepares data for downstream processing
Respond to Webhook Returns HTTP responses to Twilio

External Services & Credentials Required

Twilio

  • Purpose: WhatsApp message sending/receiving
  • Credential: twilioApi (Account SID, Auth Token)
  • Configuration: WhatsApp sandbox or approved business account

PostgreSQL Database

  • Purpose: Data storage for all entities
  • Credential: postgres (Connection string, username, password)
  • Tables Required: coaches, youth_profiles, coaching_sessions, bottleneck_diagnoses, messages

OpenRouter API

  • Purpose: AI language model access
  • Credential: openRouterApi (API key)
  • Models Used: Google Gemini 2.0 Flash, Anthropic Claude Sonnet 4.5

Environment Variables

No explicit environment variables are defined in the workflow. Configuration is handled through: - n8n credential system for API keys and database connections - Workflow-level settings for webhook paths and response handling

Data Flow

Input

  • WhatsApp message data from Twilio webhook
  • Coach phone number (sender)
  • Youth phone number (extracted from commands)
  • Message content (commands or conversation)

Processing

  • Coach validation and authorization
  • Youth profile lookup/creation
  • Session state management
  • AI-powered coaching responses
  • Progress tracking and bottleneck diagnosis

Output

  • WhatsApp responses via Twilio
  • Database updates for sessions, profiles, and progress
  • HTTP responses to Twilio webhook
  • Conversation memory storage

Error Handling

The workflow includes comprehensive error handling:

  • Invalid Coach: Sends "not registered" message for unknown phone numbers
  • Inactive Coach: Rejects messages from deactivated coaches
  • Missing Youth: Creates new profiles or sends appropriate error messages
  • No Active Session: Guides coaches to start new sessions properly
  • Invalid Commands: AI classification handles malformed inputs gracefully
  • Database Errors: Always output data flags prevent workflow failures

Known Limitations

Based on the workflow structure: - Requires manual coach registration in database - WhatsApp rate limiting may affect high-volume usage - AI responses limited to 100 words for WhatsApp compatibility - Phone number normalization assumes Uganda format (+256) as default - Session management is coach-centric (one active session per coach)

The workflow calls several sub-workflows: - updatebottleneckdiagnoses (w7UrAZ6VdXuQZfPj): Records bottleneck analysis and micro-actions - youthProfileCreationTool (0Q4hboEGwXF7zn6P): Handles youth profile creation - Youth Stage (JWgXDOcZ8DQYJ3QX): Updates youth progression stages

Setup Instructions

  1. Import Workflow

    • Import the JSON into your n8n instance
    • Ensure all required nodes are available
  2. Configure Database

    • Set up PostgreSQL with required tables
    • Create credential for database connection
    • Populate coaches table with authorized phone numbers
  3. Set Up Twilio

    • Configure WhatsApp Business API or Sandbox
    • Set webhook URL to your n8n instance endpoint
    • Create Twilio credential with Account SID and Auth Token
  4. Configure AI Services

    • Obtain OpenRouter API key
    • Create credential for OpenRouter access
    • Verify model availability (Gemini 2.0 Flash, Claude Sonnet 4.5)
  5. Deploy Sub-workflows

    • Import and configure the three related workflows
    • Ensure proper workflow IDs are referenced
  6. Test Setup

    • Send test WhatsApp message from registered coach
    • Verify database connections and AI responses
    • Test all command types (START, STATUS, DONE, MESSAGE)
  7. Production Deployment

    • Activate the workflow
    • Monitor webhook endpoint health
    • Set up appropriate logging and monitoring