Skip to content

WhatsApp Coaching Bot for Youth Entrepreneurship

A comprehensive WhatsApp-based coaching system that guides young entrepreneurs through a 15-stage pedagogical model, from initial business idea to advanced operations. The bot validates coaches, manages sessions, collects youth profiles, and provides AI-powered coaching using a structured entrepreneurship curriculum.

Purpose

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

This workflow serves as the main entry point for a WhatsApp-based entrepreneurship coaching program. It enables registered coaches to start coaching sessions with youth via WhatsApp, guiding them through a structured 15-stage business development program. The system handles coach authentication, youth profile creation, session management, and AI-powered coaching conversations that diagnose bottlenecks and recommend micro-actions based on the youth's current stage.

How It Works

  1. Message Reception: WhatsApp messages are received via Twilio webhook
  2. Coach Validation: The system checks if the sender is a registered, active coach
  3. Command Processing: AI determines if the message is a command (START, STATUS, DONE) or regular message
  4. Session Management:
    • START creates new coaching sessions with youth
    • STATUS provides youth progress reports
    • DONE closes active sessions
    • Regular messages continue coaching conversations
  5. Youth Profile Handling: New youth get profile creation flow, existing youth continue coaching
  6. AI Coaching: Advanced AI agent provides stage-appropriate coaching using the pedagogical model
  7. Response Delivery: All responses are sent back via WhatsApp through Twilio

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 Session]
    L --> N{Session Exists?}
    N -->|Yes| O[Close Old Session]
    N -->|No| P[Create Coaching Session]
    O --> Q[Create New Session]
    M --> R[Send Welcome Message]
    P --> S[Fetch Youth History]
    Q --> S
    S --> T[Build Welcome Message]
    T --> U[Send WhatsApp Response]

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

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

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

Trigger

Webhook: POST endpoint /benchmarkingshn8ntesting that receives WhatsApp messages from Twilio. The webhook expects Twilio's standard WhatsApp message format with fields like From, To, Body, etc.

Nodes Used

Node Type Purpose
Webhook Receives incoming WhatsApp messages from Twilio
Code (JavaScript) Cleans phone numbers, normalizes formats, builds messages
Postgres Database operations for coaches, youth profiles, sessions, bottlenecks
If (Conditional) Decision points for coach validation, session existence, etc.
Switch Routes messages based on command type (START/STATUS/DONE/MESSAGE)
Basic LLM Chain AI classification of incoming messages as commands vs. regular messages
AI Agent Advanced coaching conversations using the 15-stage pedagogical model
OpenRouter Chat Models AI language models (Gemini 2.0 Flash, Claude Sonnet 4.5)
Postgres Chat Memory Conversation memory storage for coaching sessions
Workflow Tools External workflow calls for profile creation, stage setting, bottleneck diagnosis
Twilio Sends WhatsApp responses back to users
Respond to Webhook Returns HTTP responses to Twilio

External Services & Credentials Required

  • Twilio: WhatsApp messaging service
    • Account SID and Auth Token
    • WhatsApp-enabled phone number
  • OpenRouter: AI model access
    • API key for Gemini 2.0 Flash and Claude Sonnet 4.5
  • PostgreSQL Database: Data storage
    • Connection credentials for database with tables: coaches, youth_profiles, coaching_sessions, bottleneck_diagnoses, messages

Environment Variables

The workflow uses stored credentials rather than environment variables. Required credential sets: - Twilio account 3: Twilio API credentials - OpenRouter account: OpenRouter API key - Postgres account 2: Database connection details

Data Flow

Input: Twilio WhatsApp webhook payload containing: - From: Sender's WhatsApp number - To: Bot's WhatsApp number
- Body: Message text - WaId: WhatsApp ID for responses

Output: WhatsApp messages sent via Twilio containing: - Coaching responses and questions - Session status updates - Error messages for invalid operations - Profile creation confirmations

Database Updates: - Coach validation lookups - Youth profile creation/updates - Coaching session management - Bottleneck diagnosis records - Conversation message history

Error Handling

The workflow includes several error handling paths:

  1. Invalid Coach: Non-registered coaches receive "not registered" messages
  2. Inactive Coach: Inactive coaches are blocked from using the system
  3. No Active Session: Commands requiring sessions show appropriate error messages
  4. Youth Not Found: STATUS commands for non-existent youth return error messages
  5. Session Conflicts: Existing active sessions are properly closed before creating new ones
  6. Database Errors: All database operations use alwaysOutputData to handle empty results gracefully

Known Limitations

No specific limitations documented in the provided context. The workflow appears to be a comprehensive implementation with extensive error handling and validation.

The workflow calls several external sub-workflows: - youthProfileCreationTool (ID: 0Q4hboEGwXF7zn6P): Creates youth profiles - Youth Stage (ID: JWgXDOcZ8DQYJ3QX): Sets youth development stages - updatebottleneckdiagnoses (ID: w7UrAZ6VdXuQZfPj): Records bottleneck diagnoses

Setup Instructions

  1. Import Workflow: Import the JSON workflow into your n8n instance

  2. Configure Database:

    • Set up PostgreSQL with required tables: coaches, youth_profiles, coaching_sessions, bottleneck_diagnoses, messages
    • Create credential "Postgres account 2" with connection details
  3. Configure Twilio:

    • Set up Twilio account with WhatsApp messaging enabled
    • Create credential "Twilio account 3" with Account SID and Auth Token
    • Configure webhook URL pointing to your n8n instance
  4. Configure AI Services:

    • Set up OpenRouter account
    • Create credential "OpenRouter account" with API key
    • Ensure access to Gemini 2.0 Flash and Claude Sonnet 4.5 models
  5. Set Up Sub-workflows:

    • Import and configure the three related workflows mentioned above
    • Ensure they're accessible to this main workflow
  6. Test the Setup:

    • Register test coaches in the database
    • Send test WhatsApp messages to verify end-to-end functionality
    • Verify all command types (START, STATUS, DONE, MESSAGE) work correctly
  7. Activate Workflow: Enable the workflow to start processing WhatsApp messages