Skip to content

Course WhatsApp Chatbot

An AI-powered WhatsApp chatbot that delivers interactive educational courses through conversational learning. Students can engage with structured course content via text or voice messages, with the AI instructor guiding them through lessons, asking questions, and providing personalized feedback.

Purpose

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

How It Works

  1. Message Reception: The workflow receives WhatsApp messages through a Twilio webhook
  2. Message Type Detection: Determines if the incoming message is text or audio
  3. Audio Processing: For voice messages, downloads the audio file and transcribes it using OpenAI's Whisper
  4. Message Standardization: Converts both text and transcribed audio into a standard message format
  5. Reset Check: Checks if the user sent "reset" to clear conversation history
  6. AI Instruction: The main AI agent processes the message using OpenAI's language model with conversation memory
  7. Course Content Retrieval: The agent calls a specialized course content workflow to fetch lesson materials
  8. Response Generation: Creates educational responses that guide students through course sections
  9. WhatsApp Reply: Sends the AI-generated response back to the student via Twilio

The workflow also includes a separate process that periodically downloads and processes course content from Google Drive to keep the educational material up-to-date.

Workflow Diagram

graph TD
    A[Webhook] --> B[Switch]
    B -->|audio| C[HTTP Request]
    B -->|text| D[Edit Fields1]
    C --> E[Transcribe a recording]
    E --> F[Edit Fields]
    F --> G[Edit Fields2]
    D --> G
    G --> H[If]
    G --> I[Main agent]
    H -->|reset| J[Delete Messages1]
    I --> K[Send an SMS/MMS/WhatsApp message]
    L[OpenAI Chat Model] -.-> I
    M[Simple Memory] -.-> I
    N[Leadership_course_agent] -.-> I

    O[Schedule Trigger] --> P[HTTP Request1]
    P --> Q[Extract from File]
    Q --> R[Code]

    S[When clicking 'Execute workflow'] --> T[Delete Messages]
    T --> U[insert Messages1]

Trigger

  • Primary: Webhook endpoint /course-chatbot that receives POST requests from Twilio when WhatsApp messages are sent
  • Secondary: Schedule trigger for periodic course content updates
  • Testing: Manual trigger for conversation memory management

Nodes Used

Node Type Purpose
Webhook Receives WhatsApp messages from Twilio
Switch Routes messages based on type (audio/text)
HTTP Request Downloads audio files and course content
OpenAI (Transcribe) Converts voice messages to text
Set (Edit Fields) Standardizes message format
If Checks for reset command
LangChain Agent Main AI instructor logic
OpenAI Chat Model Language model for generating responses
Memory Buffer Window Maintains conversation context
Tool Workflow Connects to course content agent
Twilio Sends responses back to WhatsApp
Extract from File Processes PDF course materials
Code Parses course content structure
Memory Manager Manages conversation history
Schedule Trigger Automates content updates

External Services & Credentials Required

  • Twilio: WhatsApp Business API integration
    • Account SID and Auth Token
    • WhatsApp-enabled phone number
  • OpenAI: Language model and transcription services
    • API key for GPT models and Whisper
  • Google Drive: Course content storage
    • Public access to course PDF files

Environment Variables

No specific environment variables are configured in this workflow. All credentials are managed through n8n's credential system.

Data Flow

Input: - WhatsApp messages (text or audio) via Twilio webhook - Course content PDFs from Google Drive

Processing: - Audio transcription to text - Message routing and formatting - AI-powered educational conversation - Course content retrieval and parsing

Output: - Educational responses sent back to WhatsApp - Structured course data for the AI agent

Error Handling

The workflow includes basic error handling through: - Message type switching to handle different input formats - Conditional logic for reset commands - Memory management for conversation state

No explicit error nodes are present, so failures would stop execution and require manual intervention.

Known Limitations

Based on the workflow structure: - Limited to single course (Leadership Course) currently - Requires manual course content updates via schedule trigger - No explicit error recovery mechanisms - Memory is limited to 15 messages per conversation - Audio processing depends on Twilio's media URL availability

  • CourseContentAgent (I32PCLSspW3b6umC): Provides structured course lessons and content to the main chatbot

Setup Instructions

  1. Import the workflow into your n8n instance

  2. Configure Twilio credentials:

    • Create Twilio API credentials in n8n
    • Set up WhatsApp Business API with Twilio
    • Configure webhook URL pointing to your n8n instance
  3. Set up OpenAI credentials:

    • Add OpenAI API key to n8n credentials
    • Ensure access to both GPT models and Whisper API
  4. Configure course content:

    • Upload course PDF to Google Drive with public access
    • Update the Google Drive URL in the HTTP Request1 node
    • Ensure the CourseContentAgent workflow is available
  5. Test the webhook:

    • Send a test message to your WhatsApp number
    • Verify the webhook receives and processes messages correctly
  6. Activate the workflow to start receiving WhatsApp messages

  7. Optional: Configure the schedule trigger for automatic course content updates