Skip to content

AITrainerV0.1

An automated WhatsApp-based course delivery system that provides interactive learning content through messaging, including text lessons, audio content, dialogs, knowledge checks, and AI-powered assistance for learners.

Purpose

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

This workflow enables educational content delivery through WhatsApp, making learning accessible via mobile messaging. It supports multiple content types and includes an AI assistant to help learners with questions and provide personalized support throughout their learning journey.

How It Works

  1. Message Reception: The workflow receives WhatsApp messages through a webhook endpoint
  2. Message Parsing: Incoming messages are parsed to extract the sender's number, course ID, and user action
  3. Content Retrieval: The system calls a Supabase function to fetch appropriate course content based on the user's progress
  4. Content Type Routing: Different content types (text, audio, dialog, knowledge checks, media, learning objectives) are routed to specialized formatting nodes
  5. Message Formatting: Each content type is formatted appropriately for WhatsApp delivery with relevant emojis and structure
  6. AI Integration: For questions or help requests, the system routes to an AI assistant that provides contextual support
  7. Message Delivery: Formatted content is sent back to the user via Twilio's WhatsApp API
  8. Error Handling: Failed operations trigger error messages to keep users informed

The workflow includes three separate trigger paths for different versions of the message processing logic, suggesting an iterative development approach.

Workflow Diagram

graph TD
    A[WhatsApp Message Trigger] --> B[Parse WhatsApp Message]
    B --> C[Get Course Content]
    C --> D[Route by Content Type]

    D --> E[Format Text Message]
    D --> F[Format Audio Message]
    D --> G[Format Dialog Message]
    D --> H[Format Knowledge Check]
    D --> I[Format Media Message]

    E --> J[Send WhatsApp Text]
    F --> K[Send WhatsApp Media]
    G --> J
    H --> J
    I --> K

    L[Error Handler] --> M[Send Error Message]

    N[WhatsApp Message Trigger1] --> O[Parse WhatsApp Message1]
    O --> P[Get Course Content1]
    P --> Q[Route by Content Type1]

    Q --> R[Format Text Message1]
    Q --> S[Format Audio Message1]
    Q --> T[Format Dialog Message1]
    Q --> U[Format Knowledge Check1]
    Q --> V[Format Media Message1]
    Q --> W[Format Learning Objectives]

    R --> X[Send WhatsApp Text1]
    S --> Y[Send WhatsApp Media1]
    T --> X
    U --> X
    V --> Y
    W --> X

    X --> Z[Webhook Response]
    Y --> Z

    AA[Error Handler1] --> BB[Send Error Message1]

    CC[WhatsApp Message Trigger2] --> DD[Parse WhatsApp Message2]
    DD --> EE[Route to AI or Content]

    EE --> FF[Invoke AI Assistant]
    EE --> GG[Get Course Content2]

    FF --> HH[Format AI Response]
    GG --> II[Format Content Message]

    HH --> JJ[Send WhatsApp Text2]
    II --> JJ

Trigger

Webhook Trigger: The workflow is triggered by HTTP POST requests to the /whatsapp-content-delivery endpoint. This is typically called by Twilio when a WhatsApp message is received.

Expected Payload: Twilio webhook format containing: - From: WhatsApp number (format: whatsapp:+1234567890) - Body: Message content from the user

Nodes Used

Node Type Purpose
Webhook Receives incoming WhatsApp messages from Twilio
Code Parses messages, formats responses, and handles data transformation
HTTP Request Fetches course content from Supabase and invokes AI assistant
Switch/If Routes content based on type and determines AI vs content flow
Twilio Sends WhatsApp messages (text and media) back to users
Respond to Webhook Returns success response to Twilio

External Services & Credentials Required

Twilio

  • Purpose: WhatsApp message sending and receiving
  • Credentials: Account SID, Auth Token
  • Configuration: WhatsApp-enabled phone number

Supabase

  • Purpose: Course content storage and AI assistant functions
  • Credentials: Anonymous API key, Project URL
  • Endpoints:
    • /functions/v1/n8n-course-delivery (content retrieval)
    • /functions/v1/ai-course-assistant (AI responses)

Environment Variables

Variable Description Example
SUPABASE_ANON_KEY Supabase anonymous API key eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
YOUR_TWILIO_WHATSAPP_NUMBER Twilio WhatsApp business number +14155238886
YOUR_SUPABASE_ANON_KEY Alternative reference to Supabase key Same as above

Data Flow

Input

  • WhatsApp Message: User's message content and phone number
  • Commands: NEXT (continue course), START [course_id] (begin course), questions/help requests

Processing

  • Course Progress Tracking: System maintains user progress through course content
  • Content Type Detection: Identifies whether to serve text, audio, dialog, quiz, or media content
  • AI Request Detection: Recognizes when users need assistance vs. course progression

Output

  • Formatted Messages: Course content with appropriate formatting and emojis
  • Media Messages: Audio, images, or videos when applicable
  • AI Responses: Contextual help and answers to user questions
  • Progress Updates: Visual progress indicators for learners

Error Handling

The workflow includes comprehensive error handling:

  1. Error Handler Nodes: Catch failures in content retrieval or formatting
  2. Fallback Messages: Send user-friendly error messages when issues occur
  3. Default Routing: Unrecognized content types trigger error responses
  4. Timeout Protection: HTTP requests include timeout settings to prevent hanging

Error messages inform users to try again or contact support, maintaining a good user experience even when technical issues arise.

Known Limitations

  • Multiple webhook triggers suggest the workflow is in active development with different versions
  • Hard-coded placeholder values (YOUR_TWILIO_WHATSAPP_NUMBER) need configuration
  • No explicit user authentication or session management visible
  • Limited error context provided to users (generic error messages)

Based on the tags, this workflow is part of a larger "Course Delivery" system and integrates with "AI Assistant" functionality. Other related workflows may handle user enrollment, progress tracking, or content management.

Setup Instructions

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

  2. Configure Twilio:

    • Set up Twilio account with WhatsApp Business API
    • Configure webhook URL to point to your n8n webhook endpoint
    • Update Twilio credentials in n8n
  3. Configure Supabase:

    • Set up Supabase project with course content database
    • Deploy the required edge functions (n8n-course-delivery, ai-course-assistant)
    • Add Supabase credentials to n8n
  4. Environment Variables:

    • Set SUPABASE_ANON_KEY in n8n environment
    • Replace placeholder phone numbers with actual Twilio WhatsApp number
  5. Test Setup:

    • Send a test message to your Twilio WhatsApp number
    • Verify webhook receives the message
    • Check that content is retrieved from Supabase
    • Confirm response is sent back via WhatsApp
  6. Activate Workflow: Enable the workflow to start processing live messages

  7. Monitor: Check execution logs to ensure proper operation and troubleshoot any issues