AITrainerDraft¶
An interactive WhatsApp-based AI coaching system that provides personalized educational content through conversational AI, supporting both text and voice interactions with intelligent mentor identification and course delivery.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Message Reception: The workflow receives WhatsApp messages via Twilio webhook, capturing text messages, voice notes, and media content
- Message Processing: Extracts key information including phone numbers, message content, and detects 6-digit mentor IDs from incoming messages
- AI Instruction: Processes the message through an AI agent configured as an interactive course instructor with access to educational content
- Content Retrieval: Uses vector search to find relevant course materials from a Supabase knowledge base
- Response Generation: Creates personalized educational responses with conversational memory to maintain context across interactions
- Audio Conversion: Converts AI text responses into natural-sounding audio using OpenAI's text-to-speech
- Message Delivery: Sends the audio response back to the user via WhatsApp through Twilio
Workflow Diagram¶
graph TD
A[WhatsApp Webhook] --> B[Extract Message Info]
B --> C[AI Agent]
D[OpenAI Chat Model] --> C
E[Simple Memory] --> C
F[Supabase Vector Store] --> C
G[Embeddings OpenAI] --> F
C --> H[Generate Audio]
H --> I[Send WhatsApp Message]
Trigger¶
WhatsApp Webhook - Activated when users send messages to the configured Twilio WhatsApp number at the endpoint /coaching-start
Nodes Used¶
| Node Type | Purpose |
|---|---|
| Webhook | Receives incoming WhatsApp messages from Twilio |
| Code (JavaScript) | Extracts and processes message data, detects mentor IDs |
| AI Agent | Core conversational AI instructor with educational prompts |
| OpenAI Chat Model | Language model for generating educational responses |
| Simple Memory | Maintains conversation context with 100-message window |
| Supabase Vector Store | Retrieves relevant educational content using semantic search |
| Embeddings OpenAI | Converts text to vectors for similarity search |
| OpenAI Audio | Converts AI responses to natural speech audio |
| Twilio | Sends audio responses back via WhatsApp |
External Services & Credentials Required¶
- Twilio: WhatsApp messaging service
- Account SID and Auth Token
- Configured WhatsApp sandbox or approved business number
- OpenAI: AI language model and text-to-speech
- API key with access to GPT-4 and TTS models
- Supabase: Vector database for educational content
- Project URL and service key
- Configured vector table for course materials
Environment Variables¶
This workflow uses credential-based authentication rather than environment variables. Ensure the following credentials are configured in n8n:
- twilioApi - Twilio account credentials
- openAiApi - OpenAI API access
- supabaseApi - Supabase database connection
Data Flow¶
Input: WhatsApp messages containing: - Text messages (potentially with 6-digit mentor IDs) - Voice notes and audio files - User profile information from WhatsApp
Processing: - Message content analysis and mentor ID detection - Conversation context retrieval from memory - Educational content search in vector database - AI-generated instructional responses
Output: - Audio responses delivered via WhatsApp - Conversation state maintained in memory - Session tracking by phone number
Error Handling¶
The JavaScript code node includes try-catch error handling for message processing failures. Errors are logged with descriptive messages and default values are provided to prevent workflow interruption.
Known Limitations¶
- Workflow is currently in draft status and not active
- Mentor ID detection is limited to 6-digit numeric patterns
- Memory window is capped at 100 messages per conversation
- Audio generation may have latency for longer responses
Related Workflows¶
No related workflows identified in the current configuration.
Setup Instructions¶
-
Import Workflow: Import the JSON configuration into your n8n instance
-
Configure Credentials:
- Set up Twilio API credentials with WhatsApp access
- Add OpenAI API key with GPT-4 and TTS permissions
- Configure Supabase credentials with vector database access
-
Prepare Vector Database:
- Set up Supabase vector table for educational content
- Populate with course materials and learning resources
- Ensure embeddings are generated for content search
-
Configure Webhook:
- Note the webhook URL from the WhatsApp Webhook node
- Configure Twilio WhatsApp webhook to point to this endpoint
- Test webhook connectivity
-
Customize AI Instructions:
- Review and modify the AI Agent system prompt for your educational content
- Adjust conversation memory settings if needed
- Configure appropriate OpenAI model settings
-
Test & Deploy:
- Send test messages to verify end-to-end functionality
- Activate the workflow when ready for production use
- Monitor conversation flows and adjust prompts as needed