E-Lab Script Generator with Airtable Loop¶
An AI-powered workflow that generates WhatsApp-based mentor preparation scripts for Educate! programs. The system accepts PDF lesson content and user inputs, then creates structured educational scripts with visual assets, comprehensive metrics tracking, and automated logging to Airtable.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves educational content creators and mentor trainers who need to convert traditional lesson materials into interactive, audio-first WhatsApp scripts. It automates the creation of structured mentor preparation content that includes dialogue segments, knowledge checks, and visual assets while maintaining quality standards through validation and retry mechanisms.
How It Works¶
- Input Processing: The workflow receives a POST request with lesson details (name, objectives, duration, outline, characters) and a PDF file containing lesson content
- File Extraction: PDF content is extracted and processed to understand the lesson material
- Session Management: A unique session ID is generated for tracking and logging purposes
- Guidelines Retrieval: The system fetches formatting guidelines from a Google Docs document
- AI Script Generation: An AI agent (using Google Gemini) creates a structured script following specific educational format requirements
- Metrics Calculation: The generated script is analyzed for word count, segment count, dialogue count, and estimated duration
- Asset Generation: Visual assets are automatically created based on ASSET prompts embedded in the script
- File Management: Both the script and generated images are uploaded to Google Drive for storage
- Data Logging: All generation details, metrics, and file links are logged to Airtable for tracking
- Response Delivery: A comprehensive response is returned with the script content, download links, metrics, and tracking information
Workflow Diagram¶
graph TD
A[Webhook2 - POST /test] --> B[Validate Input2]
B --> C[Extract from File]
C --> D[Generate Session ID]
D --> E[Get a document1 - Google Docs]
E --> F[Prepare Agent Input1]
F --> G[Script Writer Agent1]
G --> H[Calculate Metrics]
H --> I[Extract Asset Prompts]
H --> J[Create Script File]
I --> K[Generate an image]
K --> L[Upload Images to Drive]
J --> M[Upload Script to Drive]
L --> N[Merge]
M --> N
N --> O[Final Response]
O --> P[Format Airtable Data]
O --> Q[Respond Success1]
P --> R[Create a record - Airtable]
Trigger¶
Webhook: POST request to /test endpoint
- Authentication: Header authentication required
- Content Type: multipart/form-data (for PDF upload)
- CORS: Configured for https://scriptsgeneration.netlify.app
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Webhook | Webhook2 | Receives POST requests with lesson data and PDF files |
| Code | Validate Input2 | Validates required fields and processes uploaded PDF |
| Extract from File | Extract from File | Extracts text content from uploaded PDF |
| Code | Generate Session ID | Creates unique session identifier for tracking |
| Google Docs | Get a document1 | Retrieves script formatting guidelines |
| Set | Prepare Agent Input1 | Combines guidelines, input data, and extracted content |
| LangChain Agent | Script Writer Agent1 | AI agent that generates educational scripts |
| LangChain Chat Model | OpenRouter Model1 | Google Gemini model for script generation |
| Code | Calculate Metrics | Analyzes generated script for various metrics |
| Code | Extract Asset Prompts | Identifies visual asset requirements from script |
| Google Gemini | Generate an image | Creates educational illustrations |
| Code | Create Script File | Prepares script file for upload |
| Google Drive | Upload Images to Drive | Stores generated images |
| Google Drive | Upload Script to Drive | Stores generated script file |
| Merge | Merge | Combines script and image data |
| Code | Final Response | Builds comprehensive response object |
| Code | Format Airtable Data | Prepares data for database logging |
| Airtable | Create a record | Logs generation session to database |
| Respond to Webhook | Respond Success1 | Returns final response to client |
External Services & Credentials Required¶
Required Credentials:¶
- OpenRouter API: For Google Gemini model access
- Google Docs OAuth2: For accessing formatting guidelines document
- Google Drive OAuth2: For file storage
- Google Palm API: For image generation
- Airtable Token: For logging and tracking
- HTTP Header Auth: For webhook authentication
External Services:¶
- OpenRouter: AI model hosting (Google Gemini 2.5 Pro)
- Google Docs: Guidelines document storage
- Google Drive: Generated file storage
- Airtable: Session and metrics logging
- Google AI: Image generation service
Environment Variables¶
No specific environment variables are documented in the workflow configuration. All external service access is managed through n8n credential system.
Data Flow¶
Input:¶
- Lesson Name: Title of the lesson
- Objectives: Learning objectives for the lesson
- Duration: Target duration in minutes
- Outline: Content structure outline
- Characters: Selected character types for dialogues
- Special Requirements: Additional formatting needs
- Tone: Conversational style preference
- PDF File: Source lesson content
Output:¶
- Script Content: Generated WhatsApp-ready script
- Script Download URL: Google Drive link to script file
- Visual Assets: Array of generated images with download links
- Metrics: Word counts, segment counts, estimated duration
- Session Data: Tracking ID and attempt information
- Airtable Record: Database logging confirmation
Error Handling¶
The workflow includes basic error handling: - Input Validation: Checks for required fields and proper file types - File Type Validation: Ensures only PDF files are processed - Missing Data Handling: Provides fallback values for optional fields
No retry mechanisms or advanced error recovery paths are implemented in the current version.
Known Limitations¶
Based on the workflow structure: - Only PDF files are supported for lesson content input - No validation or retry mechanism for failed script generation - Limited to Google Drive for file storage - Single AI model dependency (Google Gemini) - No content moderation or quality checks beyond basic metrics
Related Workflows¶
The workflow contains references to an alternative implementation with evaluation and retry logic (visible in disabled nodes), suggesting a more robust version may exist with: - Script quality validation - Multi-attempt generation with feedback loops - Enhanced error handling and recovery
Setup Instructions¶
-
Import Workflow: Import the JSON configuration into your n8n instance
-
Configure Credentials:
- Set up OpenRouter API credentials for AI model access
- Configure Google OAuth2 for Docs and Drive access
- Add Google Palm API credentials for image generation
- Set up Airtable API token
- Configure webhook header authentication
-
Update Document URLs:
- Update Google Docs URL in "Get a document1" node to point to your guidelines document
- Verify Google Drive folder IDs for file storage
-
Configure Webhook:
- Note the webhook URL for your frontend integration
- Update CORS settings if needed for your domain
-
Test Integration:
- Send a test POST request with sample lesson data and PDF
- Verify file uploads to Google Drive
- Check Airtable logging functionality
-
Frontend Integration:
- Configure your frontend to send multipart/form-data requests
- Include proper authentication headers
- Handle the comprehensive response object