An automated n8n workflow that generates and delivers comprehensive weekly English masterclasses via email, powered by Google Gemini AI.
This project provides a complete end-to-end automation system that:
- Reads your lesson history from Google Sheets to provide context
- Generates comprehensive weekly lessons using Google Gemini AI
- Creates structured JSON content with vocabulary, grammar, exercises, and solutions
- Transforms content into premium HTML emails with beautiful design
- Delivers automated weekly emails with Gmail integration
- Archives lesson content back to Google Sheets for tracking
Perfect for: Language teachers, self-learners, educational content creators, or anyone building AI-powered learning systems with n8n.
Here's what your weekly masterclass emails will look like:
Beautiful gradient header with dynamic title and emoji based on the week's theme
✨ Weekly Schedule Automation - Set-and-forget Sunday delivery (customizable) ✨ AI-Powered Content Generation - Google Gemini creates contextual lessons ✨ Structured Educational Content - Vocabulary, grammar, dialogues, exercises, and solutions ✨ Premium HTML Email Design - Beautiful, responsive email templates with color-coded sections ✨ Exercise Validation - Includes complete solutions for self-assessment ✨ Historical Context Awareness - AI references previous lessons for continuity ✨ Robust Error Handling - Parser validation with fallback values ✨ Production-Ready - Retry logic, error emails, and comprehensive logging
┌─────────────────────────────────────────────────────────────────────────┐
│ Weekly Masterclass Workflow │
└─────────────────────────────────────────────────────────────────────────┘
Schedule Trigger (Weekly - Sunday 9 AM)
│
↓
Read History from Google Sheets (Last 6 lessons)
│
↓
Prepare Context (JavaScript - Build AI input)
│
↓
Generate Lesson (Google Gemini AI)
│
├─→ Returns structured JSON with:
│ • Weekly emoji & title
│ • Intro & vocabulary (5-7 words)
│ • Grammar focus with exercises
│ • Dialogue practice (6-8 lines)
│ • Translation & word scramble exercises
│ • Weekly challenge
│ • Complete solutions
│ • Closing motivational quote
│
↓
Parser & Validation (JavaScript)
│
├─→ Validates JSON structure
├─→ Ensures all required fields
└─→ Provides fallback values
│
↓
Formatters (JavaScript - Convert to HTML)
│
├─→ Format vocabulary with pronunciation
├─→ Format grammar with examples
├─→ Format dialogue with translations
├─→ Format exercises & solutions
└─→ Apply color scheme & styling
│
↓
HTML Generator (JavaScript - Assemble email)
│
├─→ Create header with gradient
├─→ Build content sections
├─→ Add footer with attribution
└─→ Generate complete HTML document
│
↓
Send Email (Gmail)
│
├─→ Send to main recipient
└─→ BCC to additional recipients
│
↓
Save to Google Sheets (Archive lesson)
│
└─→ Log: Date, Intro, Vocab, Grammar, Dialogue, Challenge
Before using this workflow, ensure you have:
- Self-hosted n8n or n8n Cloud account
- n8n version 1.0+ recommended
You'll need to enable these APIs and create credentials:
-
Google Sheets API
- For reading lesson history and saving new lessons
- Requires OAuth2 credentials
-
Gmail API
- For sending weekly emails
- Requires OAuth2 credentials
-
Google Gemini API
- For AI content generation
- Requires API key (Gemini 3 Flash Preview recommended)
- Create a Google Sheet with two sheets:
- Sheet 1 (History): Columns:
Fecha,Cita,Autor,Contenido Email - Sheet 2 (Weekly Lessons): Columns:
Fecha,Introduccion,Vocabulario,Grammar Focus,Dialogo,Desafio
- Sheet 1 (History): Columns:
git clone <repository-url>
cd weekly-masterclass- Open your n8n instance
- Click Workflows → Import
- Select
weekly-masterclass.json - Click Import
You'll need to set up three credentials in n8n:
- Go to Credentials → Add Credential
- Select Google Sheets OAuth2 API
- Enter your Google Cloud OAuth2 credentials
- Authorize access to Google Sheets
- Copy the credential ID
- Go to Credentials → Add Credential
- Select Google PaLM API (used for Gemini)
- Enter your Gemini API key from Google AI Studio
- Save the credential
- Go to Credentials → Add Credential
- Select Gmail OAuth2 API
- Enter your Google Cloud OAuth2 credentials
- Authorize access to Gmail
- Copy the credential ID
Open the workflow and update these nodes:
- Replace
YOUR_GOOGLE_SHEET_DOCUMENT_IDwith your Google Sheet ID - Update credential to your Google Sheets OAuth2 credential
- CRITICAL: Replace the
[PLACEHOLDER: YOUR CUSTOM LLM PROMPT]with your custom AI prompt - Update credential to your Google Gemini API credential
- See "Customization" section for prompt engineering guidance
- Replace
your-email@example.comwith your email address - Update
bccListwith additional recipients (or remove if not needed) - Update credential to your Gmail OAuth2 credential
- Replace
YOUR_GOOGLE_SHEET_DOCUMENT_IDwith your Google Sheet ID - Ensure the sheet name matches your Sheet 2 name
- Update credential to your Google Sheets OAuth2 credential
- Adjust the trigger time if you want a different schedule
- Currently set to weekly on Sundays at 9 AM
- Click Execute Workflow to run a test
- Check each node for successful execution (green checkmarks)
- Verify:
- History was read correctly
- AI generated valid JSON content
- Email was sent successfully
- Lesson was saved to Google Sheets
- Check your email inbox for the masterclass email
Once testing is successful:
- Toggle the Active switch in the top right
- The workflow will now run automatically on schedule
This sheet should contain your daily lesson history:
| Fecha | Cita | Autor | Contenido Email |
|---|---|---|---|
| 2024-01-15 | "The only way to do great work..." | Steve Jobs | [Full lesson content] |
| 2024-01-16 | "Success is not final..." | Winston Churchill | [Full lesson content] |
The workflow automatically populates this:
| Fecha | Introduccion | Vocabulario | Grammar Focus | Dialogo | Desafio |
|---|---|---|---|---|---|
| 2024-01-21 | ¡Buen domingo! Esta semana... | [JSON array] | [JSON object] | [JSON array] | Challenge text |
Your prompt should define:
1. Role & Persona
- Define the AI's role (e.g., English teacher, motivator, curriculum designer)
- Specify teaching style and tone
- Set language level expectations (e.g., A1-A2 beginner)
2. Task Description
- Clearly state what the AI should produce (weekly masterclass content)
- Define inputs (last 6 lessons from context)
- Specify output requirements (JSON structure)
3. Content Strategy
- Define pedagogical approach (grammar-focused, communicative, etc.)
- Specify curriculum or syllabus to follow (optional)
- Provide topic selection guidance
4. Output Structure
- Specify exact JSON schema with all required fields
- Provide examples for each field
- Define validation rules (e.g., "translation array must have exactly 3 items")
5. Quality Guidelines
- Specify content quality expectations
- Provide examples of good vs. bad outputs
- Define edge case handling
Example prompt structure:
You are an expert English teacher creating weekly masterclasses.
INPUT: You'll receive the last 6 daily lessons with quotes and content.
OUTPUT: Respond with ONLY valid JSON (no markdown) in this exact structure:
{
"weeklyEmoji": "🚀",
"weeklyTitle": "Your Adventure with Present Simple",
"intro": "...",
"vocab": [...],
"grammar": {...},
"dialogue": [...],
"exercises": {...},
"challenge": "...",
"solutions": {...},
"closingQuote": {...}
}
RULES:
- Keep language simple (A1-A2 level)
- Provide exactly 3 translation exercises
- Include complete solutions for all exercises
- Choose the best quote from the week for closingQuote
See the "Generar Lección Semanal" node comments for the full expected JSON structure.
The email design is fully customizable through the Formatadores (Formatters) node. Here's how to modify the visual appearance:
All colors are defined in the colors object in the Formateadores node (line ~259):
const colors = {
// Background & Text
bg: "#FFFDF9", // Email background (warm white)
text: "#1a202c", // Primary text color (dark)
textLight: "#555555", // Secondary text (gray)
textMuted: "#888888", // Tertiary text (light gray)
pronunciation: "#FF6B6B", // Pronunciation guide (red)
// Section Badges
vocabBadgeBg: "#E3F2FD", // Vocabulary badge background (light blue)
vocabBadgeText: "#1565C0", // Vocabulary badge text (blue)
grammarBadgeBg: "#F3E5F5", // Grammar badge background (light purple)
grammarBadgeText: "#7B1FA2", // Grammar badge text (purple)
talkBadgeBg: "#E8F5E9", // Dialogue badge background (light green)
talkBadgeText: "#2E7D32", // Dialogue badge text (green)
exercisesBadgeBg: "#FFF3E0", // Exercises badge background (light orange)
exercisesBadgeText: "#EF6C00", // Exercises badge text (orange)
challengeBadgeBg: "#FFE0F0", // Challenge badge background (light pink)
challengeBadgeText: "#C2185B", // Challenge badge text (pink)
solutionsBadgeBg: "#FFF9C4", // Solutions badge background (light yellow)
solutionsBadgeText: "#F57F17", // Solutions badge text (gold)
quoteBadgeBg: "#E0F2F1", // Quote badge background (light teal)
quoteBadgeText: "#00695C", // Quote badge text (teal)
// Header Gradient
gradientStart: "#f6d365", // Gradient left (gold)
gradientEnd: "#fda085", // Gradient right (coral)
// Section Backgrounds
vocabBg: "#FFFFFF", // Vocabulary section (white)
grammarBg: "#F8FAFC", // Grammar section (light gray)
dialogueBg: "#F0FFF4", // Dialogue section (very light green)
exercisesBg: "#FFFBF0", // Exercises section (light cream)
solutionsBg: "#FFFFF0", // Solutions section (ivory)
quoteBg: "#F0FFFF", // Quote section (light cyan)
// Accents
accentBlue: "#2C7BE5", // Link and highlight blue
accentBorder: "#D0E6FF", // Border accent (light blue)
accentGold: "#FFD700" // Border accent for special sections (gold)
};Modify font families, sizes, and weights throughout the formatters:
Primary Fonts:
- Headers:
Georgia, serif(classic, elegant) - Body text:
'Trebuchet MS', sans-serif(modern, readable) - Code/Pronunciation:
'Courier New', monospace(fixed-width for clarity)
Font Sizes:
- Main title (header):
36px - Section titles:
20px - Body text:
16px - Small text (hints, meta):
13-14px
To change fonts, search for font-family in the Formateadores node and replace with your preferred web-safe fonts.
Card Padding:
// In createCard function (~line 285)
<td style=\"padding: 32px;\"> // Increase/decrease for more/less spacingSection Margins:
// Between sections
style=\"margin: 24px 0;\" // Vertical spacing between cardsBorder Radius:
border-radius: 20px; // Roundness of cards
border-radius: 50px; // Roundness of badgesThe header uses a linear gradient. Modify in Generador HTML node (~line 320):
style=\"background:linear-gradient(135deg,${colors.gradientStart} 0%,${colors.gradientEnd} 100%);\"
// Change angle: 135deg → 90deg (vertical) or 180deg (horizontal)
// Change colors: Update gradientStart and gradientEnd in colors objectBadge Style:
// In createBadge function (~line 275)
padding: 6px 14px; // Horizontal and vertical padding
border-radius: 50px; // Pill shape
font-size: 11px; // Text size
letter-spacing: 1px; // Character spacing
text-transform: uppercase; // ALL CAPS styleEmoji Icons: Update emoji icons in each section badge:
- Vocabulary: 🧩
- Grammar: 💡
- Dialogue: 🗣️
- Exercises: 📚
- Challenge: 🎯
- Solutions: 🔑
- Quote: 📜
Change these in the Generador HTML node where createBadge() is called.
The email template uses table-based layout for maximum email client compatibility. The max-width is set to 600px:
<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"
style=\"max-width:600px; ...\">To adjust for mobile, consider media queries (though support varies by email client).
The weekly masterclass email includes the following sections:
- Dynamic Emoji Badge: Changes based on weekly theme (e.g., 🚀 ⭐ 💪 🎯 🔥)
- Personalized Title: AI-generated title matching the week's grammar focus
- Gradient Background: Eye-catching gold-to-coral gradient
1. Introduction
- Warm greeting and weekly theme overview
- Connection to previous lessons
- Grammar topic preview
2. 🧩 Vocabulario (Vocabulary)
- 5-7 carefully selected words from the week's quotes
- Pronunciation guide in IPA format:
/pronunciación/ - Spanish translation
- Example sentence at A1-A2 level
Each word includes pronunciation, translation, and a practical example sentence
3. 💡 Grammar Focus
- Clear grammar topic title (e.g., "Present Simple", "Past Tense")
- Simple explanation (max 3 sentences)
- 3 practical examples
- Fill-in-the-blank exercise
Grammar explanation with examples and an interactive fill-in exercise
4. 🗣️ Let's Talk (Dialogue)
- 6-8 lines of natural conversation
- Speaker labels (A/B format)
- Pronunciation for each line
- Spanish translation
5. 📚 Ejercicios Prácticos (Practice Exercises)
Translation Practice:
- 3 sentences to translate from English to Spanish
- Helpful hints for each (e.g., "Use the verb 'to be'")
- Color-coded boxes
Word Scramble:
- 2 scrambled sentences to put in correct order
- Structure hints (e.g., "Subject + Verb + Object")
- Monospace font for clarity
Translation exercises and word scramble challenges with helpful hints
6. 🎯 Desafío Semanal (Weekly Challenge)
- Practical, achievable task
- Related to the week's grammar topic
- Example: "Write 3 sentences about your day using Present Simple"
7. 🔑 Soluciones (Solutions)
- Complete answers to all exercises
- Grammar exercise solution
- All 3 translations
- Both word scrambles solved
- Example challenge response
8. 📜 Cita de la Semana (Quote of the Week)
- Best quote from the week's lessons
- Original author attribution
- Spanish translation
- Centered, elegant typography
- Motivational message: "Keep learning, keep growing 🌱"
- Attribution link (customizable)
Here's a snippet showing the vocabulary section HTML:
<div style="margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px dashed #EEF2F7;">
<div style="margin-bottom: 6px;">
<span style="color: #2C7BE5; font-weight: 700; font-size: 18px; font-family: Georgia, serif;">
PRACTICE
</span>
<span style="color: #FF6B6B; font-family: 'Courier New', monospace; font-weight: 600; font-size: 15px; margin-left: 10px;">
/práctis/
</span>
</div>
<div style="color: #555555; font-size: 16px; line-height: 1.8; font-family: 'Trebuchet MS', sans-serif;">
práctica
</div>
<div style="margin-top: 8px; padding-left: 12px; border-left: 3px solid #D0E6FF; color: #556677; font-style: italic; font-size: 15px;">
Practice makes perfect (La práctica hace al maestro)
</div>
</div>Detailed breakdown of each node in the workflow:
- Type: Schedule Trigger
- Function: Executes the workflow weekly on Sundays at 9 AM
- Customizable: Change day, time, and frequency in node settings
- Output: Trigger signal (no data)
- Type: Google Sheets
- Function: Fetches all rows from the daily quotes history sheet
- Configuration:
- Document ID: Your Google Sheet
- Sheet: Sheet 1 (gid=0)
- Operation: Read
- Output: Array of all lesson rows with columns: Fecha, Cita, Autor, Contenido Email
- Type: Code (JavaScript)
- Function: Takes the last 6 lessons and formats them as AI input context
- Logic:
- Slices last 6 rows from history
- Builds formatted text with lesson date, quote, and full content
- Creates context string for AI
- Output: Object with
context(formatted text) andlessonCount(number)
- Type: Google Gemini (LangChain)
- Function: Sends context to AI and receives structured JSON lesson
- Configuration:
- Model:
gemini-3-flash-preview - Messages: System prompt + user context
- Model:
- Critical: Requires custom prompt (see Customization section)
- Output: AI response with
content.parts[0].textcontaining JSON
- Type: Code (JavaScript)
- Function: Validates and cleans AI output
- Validation Steps:
- Checks for content existence
- Removes markdown code blocks if present
- Parses JSON
- Validates all required fields exist
- Checks array lengths (translation = 3, wordScramble = 2)
- Provides fallback values for missing/empty fields
- Error Handling: Returns error object if parsing fails
- Output: Validated JSON object with all required fields
- Type: Code (JavaScript)
- Function: Converts JSON data into formatted HTML strings
- Includes:
- Color system definition
- Formatter functions for each content type
- HTML generation for vocab, grammar, dialogue, exercises, etc.
- Output: Object with formatted HTML strings for each section
- Type: Code (JavaScript)
- Function: Assembles complete HTML email document
- Components:
- Header with gradient and title
- Content sections (intro, vocab, grammar, etc.)
- Footer with attribution
- Error Handling: Generates error email if previous nodes failed
- Output: Complete HTML email in
htmlContentfield
- Type: Gmail
- Function: Sends the formatted email
- Configuration:
- To: Main recipient
- BCC: Additional recipients (optional)
- Subject: "🎓 Tu Masterclass Semanal de Inglés"
- Body: HTML content from previous node
- Retry Logic: 3 attempts with 5-second delays
- Type: Google Sheets
- Function: Archives the lesson content to Sheet 2
- Columns Saved:
- Fecha: Current date
- Introduccion: Intro text
- Vocabulario: Vocab JSON array (stringified)
- Grammar Focus: Grammar object (stringified)
- Dialogo: Dialogue array (stringified)
- Desafio: Challenge text
- Retry Logic: 3 attempts with 5-second delays
Cause: Gemini API returned empty response Solutions:
- Check your Gemini API credentials
- Verify API key is valid and has quota remaining
- Check if Gemini API is experiencing outages
- Review the AI prompt - it might be too complex or malformed
Cause: AI returned invalid JSON or included markdown Solutions:
- Review your prompt - ensure it explicitly says "NO markdown" and "ONLY JSON"
- Add examples of correct JSON format in your prompt
- Check if the model you're using supports JSON mode
- Inspect the
rawContentin error output to see what AI actually returned
Cause: Gmail credentials invalid or quota exceeded Solutions:
- Re-authorize Gmail OAuth2 credentials
- Check Gmail sending limits (500/day for regular accounts)
- Verify the email address in "sendTo" is correct
- Check spam folder
Cause: Sheets credentials invalid or Sheet structure mismatch Solutions:
- Re-authorize Google Sheets OAuth2 credentials
- Verify Sheet ID in both nodes matches your actual Google Sheet
- Ensure Sheet 1 has columns: Fecha, Cita, Autor, Contenido Email
- Ensure Sheet 2 has columns: Fecha, Introduccion, Vocabulario, Grammar Focus, Dialogo, Desafio
- Check that gid values match your sheet structure
Cause: AI generated wrong number of translation exercises Solutions:
- Make your prompt more explicit: "EXACTLY 3 translation exercises"
- Add validation rules to your prompt
- Provide examples in your prompt showing arrays with 3 items
- Consider adding retry logic to regenerate if validation fails
Cause: AI taking too long to generate content Solutions:
- Increase timeout in Gemini node settings
- Simplify your AI prompt to reduce processing time
- Switch to a faster Gemini model (e.g., flash instead of pro)
- Check n8n execution timeout settings
Cause: Email client doesn't support certain CSS Solutions:
- Test email in multiple clients (Gmail, Outlook, Apple Mail)
- Use inline styles only (already implemented)
- Avoid advanced CSS features
- Use table-based layout (already implemented)
- Check for unclosed HTML tags in custom content
Cause: Parser fallback values being used due to AI output issues Solutions:
- Review AI prompt for clarity on required content
- Check if context from history is being passed correctly
- Inspect "Preparar Contexto" node output to verify lesson data
- Add more specific instructions for each content type
- n8n - Workflow automation platform
- Google Gemini (3 Flash Preview) - AI content generation
- Google Sheets API - Data storage and retrieval
- Gmail API - Email delivery
- JavaScript (ES6+) - Custom code nodes for data transformation
- HTML5 & CSS3 - Email template design
- OAuth2 - Secure API authentication
This workflow uses a placeholder prompt for the AI content generation. The original project uses proprietary prompt engineering techniques developed specifically for language teaching, including:
- Detailed pedagogical strategies
- Specific curriculum syllabus (Headway Beginner units)
- Advanced prompt optimization
- Custom JSON structure validation rules
You must replace the placeholder with your own custom prompt that matches your:
- Teaching methodology
- Target audience and language level
- Content goals and structure
- Quality standards
The JSON structure and workflow architecture are provided as-is, but the quality and effectiveness of your lessons will depend entirely on your prompt engineering skills.
Contributions are welcome! Here's how you can help:
-
Report Bugs: Open an issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs. actual behavior
- n8n version and environment details
-
Suggest Features: Open an issue with:
- Feature description
- Use case and benefits
- Possible implementation approach
-
Submit Pull Requests:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit PR with clear description
- Multi-language support - Adapt for other languages
- Alternative AI models - Integration with OpenAI, Claude, etc.
- Enhanced email designs - New templates and themes
- Advanced exercises - New exercise types and formats
- Mobile app integration - Push notifications instead of email
- Progress tracking - Dashboard for learning analytics
- A/B testing - Experiment with different teaching approaches
MIT License - See LICENSE file for details.
This means you can:
- ✅ Use commercially
- ✅ Modify and distribute
- ✅ Use privately
- ✅ Sublicense
Requirements:
- Include original license and copyright notice
- No liability or warranty provided
- Full workflow walkthrough in this README
- Inline comments in all Code nodes
- Detailed node descriptions
- Issues: Report bugs or request features via GitHub Issues
- Discussions: Share tips and ask questions
Built with ❤️ for language learners everywhere
Transform your English learning with AI-powered weekly masterclasses 🚀



