Skip to content

AITrainerV0.1

An automated WhatsApp-based course delivery system that provides interactive learning experiences through multiple content types including text, audio, dialogs, knowledge checks, and media. The workflow intelligently routes user messages to either deliver structured course content or provide AI-powered assistance.

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 a platform most users already have. It supports multiple learning formats and includes an AI assistant to answer questions and provide personalized help during the learning journey.

How It Works

  1. Message Reception: The workflow receives WhatsApp messages through Twilio webhooks
  2. Message Parsing: Incoming messages are parsed to extract user phone numbers, commands, and course IDs
  3. Content Retrieval: The system fetches appropriate course content from a Supabase backend based on user requests
  4. Content Type Routing: Messages are routed to different formatters based on content type (text, audio, dialog, knowledge check, media, or learning objectives)
  5. Message Formatting: Each content type is formatted appropriately for WhatsApp delivery with relevant emojis and structure
  6. AI Integration: User questions or help requests are routed to an AI assistant for personalized responses
  7. Message Delivery: Formatted content is sent back to users via Twilio's WhatsApp API
  8. Error Handling: Failed operations trigger error messages to keep users informed

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]
    D --> J[Format Learning Objectives]

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

    M[WhatsApp Message Trigger2] --> N[Parse WhatsApp Message2]
    N --> O[Route to AI or Content]
    O --> P[Invoke AI Assistant]
    O --> Q[Get Course Content2]
    P --> R[Format AI Response]
    Q --> S[Format Content Message]
    R --> T[Send WhatsApp Text2]
    S --> T

    U[Error Handler] --> V[Send Error Message]
    W[Webhook Response] --> X[End]

Trigger

Webhook Trigger: The workflow is triggered by incoming WhatsApp messages sent to configured Twilio phone numbers. Multiple webhook endpoints are configured: - whatsapp-content-delivery - Main content delivery endpoint - Additional webhook endpoints for different message routing paths

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 and invokes AI assistant via Supabase functions
Switch/If Routes messages based on content type and user intent
Twilio Sends WhatsApp messages (text and media) back to users
Respond to Webhook Provides HTTP responses to webhook calls

External Services & Credentials Required

Twilio

  • Purpose: WhatsApp message sending and receiving
  • Credentials: Account SID, Auth Token, WhatsApp-enabled phone number
  • Configuration: Set up WhatsApp sandbox or approved business account

Supabase

  • Purpose: Course content storage and AI assistant backend
  • Credentials: Project URL, Anonymous API key
  • Endpoints Used:
    • /functions/v1/n8n-course-delivery - Course content retrieval
    • /functions/v1/ai-course-assistant - AI-powered assistance

Environment Variables

1
2
3
4
SUPABASE_ANON_KEY=your_supabase_anonymous_key
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
YOUR_TWILIO_WHATSAPP_NUMBER=whatsapp:+1234567890

Data Flow

Input

  • WhatsApp Messages: User commands, course requests, questions
  • Message Format: Text messages containing commands like "START course_id", "NEXT", or questions

Processing

  • Course Content: Retrieved from Supabase based on user progress and course ID
  • Content Types: Text, audio, dialog, knowledge checks, media, learning objectives
  • AI Responses: Generated responses for user questions and help requests

Output

  • Formatted WhatsApp Messages: Structured content with emojis and clear formatting
  • Media Messages: Audio, images, and videos when applicable
  • Progress Tracking: Progress indicators and navigation prompts

Error Handling

The workflow includes comprehensive error handling:

  1. Error Handler Nodes: Catch failures in content retrieval and message processing
  2. Fallback Messages: Send user-friendly error messages when operations fail
  3. Default Responses: Provide helpful guidance when content is unavailable
  4. Timeout Handling: 30-second timeout on HTTP requests to prevent hanging

Error messages are sent via WhatsApp to keep users informed and maintain engagement.

Known Limitations

  • Workflow is currently inactive (status: false)
  • Multiple similar node implementations suggest this may be a development/testing version
  • Hardcoded placeholder values need to be replaced with actual credentials
  • No explicit rate limiting or user session management visible in the workflow

This workflow is tagged with: - Course Delivery: Suggests integration with other course management workflows - AI Assistant: May work alongside other AI-powered educational tools

Setup Instructions

  1. Import Workflow

    • Import the JSON into your n8n instance
    • Activate the workflow after configuration
  2. Configure Twilio

    • Set up Twilio account with WhatsApp capabilities
    • Configure webhook URLs to point to your n8n instance
    • Update Twilio credentials in all Twilio nodes
  3. Configure Supabase

    • Set up Supabase project with required functions
    • Update SUPABASE_ANON_KEY environment variable
    • Ensure course content database is properly structured
  4. Update Credentials

    • Replace all placeholder values (YOUR_TWILIO_WHATSAPP_NUMBER, etc.)
    • Configure proper authentication headers
    • Test webhook endpoints
  5. Test the Workflow

    • Send test messages to your WhatsApp number
    • Verify content delivery and AI responses
    • Monitor error handling and user experience
  6. Deploy

    • Activate the workflow
    • Monitor logs for any issues
    • Set up proper monitoring and alerting