Skip to content

Course WhatsApp Chatbot

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

Purpose

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

This workflow creates an intelligent tutoring system accessible through WhatsApp, making educational content available to students wherever they are. The chatbot acts as a virtual instructor, breaking down complex course materials into digestible conversations, supporting both text and audio interactions, and maintaining conversation history to provide personalized learning experiences.

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 speech-to-text
  4. Message Standardization: Converts both text and transcribed audio into a standard message format
  5. Reset Detection: Checks if the user sent "reset" to clear conversation history
  6. AI Processing: The main agent processes the message using OpenAI's language model with conversation memory
  7. Course Content Retrieval: Accesses structured course materials through a specialized course agent tool
  8. Response Generation: Creates educational responses that explain concepts, ask questions, and guide learning
  9. Response Delivery: Sends the AI-generated response back to the user via WhatsApp

The system also includes a separate process that periodically downloads and processes course content from Google Drive, parsing PDF materials into structured lessons and sections.

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 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[Manual Trigger] --> T[Delete Messages]
    T --> U[insert Messages1]
    M -.-> T
    M -.-> U
    M -.-> J

Trigger

Primary Trigger: Webhook endpoint (/course-chatbot) that receives POST requests from Twilio when WhatsApp messages are sent to the bot.

Secondary Triggers: - Schedule Trigger for periodic course content updates - Manual Trigger for testing conversation scenarios

Nodes Used

Node Type Purpose
Webhook Receives incoming WhatsApp messages from Twilio
Switch Routes messages based on type (audio vs text)
HTTP Request Downloads audio files from Twilio
OpenAI (Transcribe) Converts voice messages to text
Set (Edit Fields) Standardizes message format across different input types
If Checks for reset command to clear conversation
AI Agent Main conversational AI that processes messages and generates responses
OpenAI Chat Model Language model for generating educational responses
Memory Buffer Window Maintains conversation history per user
Tool Workflow Accesses course content through specialized agent
Twilio Sends responses back via WhatsApp
Memory Manager Manages conversation history (delete/insert operations)
Extract from File Parses PDF course materials
Code Processes and structures course content
Schedule Trigger Triggers periodic content updates
Manual Trigger Enables testing scenarios

External Services & Credentials Required

Twilio: - Account for WhatsApp Business API - Credentials: twilioApi and httpBasicAuth for media downloads

OpenAI: - API access for chat completions and audio transcription - Credentials: openAiApi

Google Drive: - Access to course content PDFs (public download links)

Environment Variables

No explicit environment variables are defined in this workflow. All configuration is handled through n8n credentials and node parameters.

Data Flow

Input: - WhatsApp messages (text or audio) via Twilio webhook - Message metadata (sender ID, message type, media URLs)

Processing: - Audio transcription to text - Message standardization - AI-powered conversation with course content integration - Conversation memory management

Output: - Educational responses sent via WhatsApp - Structured course content delivery - Interactive learning experiences with questions and feedback

Error Handling

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

No explicit error nodes are present, so errors would be handled by n8n's default error handling mechanisms.

Known Limitations

Based on the workflow structure: - Depends on external services (Twilio, OpenAI, Google Drive) availability - Course content is limited to what's available in the connected course agent - Audio processing requires clear speech for accurate transcription - Memory is limited to 15 messages per conversation window - Reset functionality requires exact "reset" command match

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

Setup Instructions

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

  2. Configure Credentials:

    • Set up Twilio API credentials for WhatsApp messaging
    • Configure OpenAI API credentials for chat and transcription
    • Set up HTTP Basic Auth for Twilio media downloads
  3. Configure Webhook:

    • Note the webhook URL generated by n8n
    • Configure your Twilio WhatsApp number to send messages to this webhook
  4. Set Up Course Content:

    • Ensure the CourseContentAgent workflow is imported and configured
    • Update the Google Drive link in the HTTP Request1 node if needed
    • Test the course content parsing by running the Schedule Trigger manually
  5. Test the System:

    • Send a test message to your WhatsApp number
    • Verify audio transcription works by sending a voice message
    • Test the reset functionality by sending "reset"
    • Use the manual trigger to test conversation scenarios
  6. Activate the Workflow: Enable the workflow to start receiving messages

  7. Monitor Performance: Check execution logs and adjust memory settings or course content as needed