Opening Problem Statement
Meet Omar, a digital marketing assistant who drowns daily in a flood of promotional emails labeled “CATEGORY_PROMOTIONS” in his Gmail inbox. Every day, he wastes hours sifting through these promotional messages to extract key offers and interesting deals, often missing out on vital information amidst the clutter. The tedious reading process leads to lost productivity, eye strain, and repeated failures to retain important content — a problem many professionals face who want to stay updated but lack the time to read it all.
Omar’s specific pain? Approximately 2 hours wasted daily deciphering the promotional deluge, and the inability to keep track of relevant promotions means lost opportunities worth potentially hundreds of dollars over time.
What This Automation Does
This tailor-made n8n workflow transforms those overwhelming Gmail CATEGORY_PROMOTIONS emails into concise audio podcasts that Omar, or anyone, can listen to on the go. Here’s what happens step-by-step when the automation runs:
- Monitors Gmail inbox every minute for new promotional emails filtered by the “CATEGORY_PROMOTIONS” label.
- Fetches full email content effortlessly for processing.
- Cleans unnecessary email metadata like headers, HTML, reply info to focus on key text content.
- Generates crisp, emoji-enhanced summaries of promotional content using advanced AI summarization with OpenAI and LangChain nodes.
- Converts those summaries into natural-sounding speech audio using a dedicated Free Text-to-Speech HTTP API.
- Packages the audio file and text summary together for final sending.
- Delivers the podcast-style promotional audio directly to a special Telegram chat for immediate listening.
Benefits: Saves Omar about 10+ hours weekly by switching reading to listening, reduces eye strain, and keeps him updated with vital marketing promotions clearly and quickly.
Prerequisites ⚙️
- n8n account for designing and executing automation workflows
- Gmail account with configured OAuth2 credentials to access CATEGORY_PROMOTIONS labeled emails 📧
- OpenAI account API key to power the summarization AI nodes 🔑
- HTTP endpoint access to use Free Text-to-Speech conversion 🔌
- Telegram bot token and chat ID to send the final audio message 💬
Step-by-Step Guide to Build This Automation
Step 1: Set Up Gmail Trigger Node to Poll Promotions
Navigate to the n8n editor. Add a Gmail Trigger node. Configure it:
- Under “Poll Times,” set it to “Every Minute” to keep checking for new emails regularly.
- In “Filters,” enter the label ID for
CATEGORY_PROMOTIONS. This ensures only promotional emails trigger the workflow. - Link it with your Gmail OAuth2 credentials (e.g., “Gmail Omar”).
Save and execute. The node now fires whenever new relevant emails arrive.
Watch out: Incorrect label ID will stop triggering. Double-check label ID from your Gmail labels.
Step 2: Fetch Full Email Content with Gmail Node
Drag a Gmail node and connect it to the Gmail Trigger’s output.
Configure to get details for each new email by setting messageId={{ $json.id }}.
This pulls the entire email, including body text, subject, and metadata for processing.
Common error: Not using dynamic ID reference leads to fetching wrong email or no data.
Step 3: Clean Email Data with Code Node
Add a Code node named “Delete the unnecessary items” after the Gmail node.
Paste this JavaScript code to remove clutter fields:
for (const item of $input.all()) {
delete item.json.threadId;
delete item.json.labelIds;
delete item.json.sizeEstimate;
delete item.json.headers;
delete item.json.html;
delete item.json.to;
delete item.json.cc;
delete item.json.replyTo;
delete item.json.messageId;
delete item.json.id;
delete item.json.textAsHtml;
delete item.json.date;
}
return $input.all();
This focuses subsequent processing only on essential text.
Tip: Skipping this slows NLP summarization with excessive data.
Step 4: Summarize Text Using LangChain Summarization Node
Add the Summarization Chain3 node and connect from the Code node.
This AI node uses OpenAI behind the scenes to craft concise, emoji-rich summaries under 247 characters, perfect for audio clarity.
The prompt used is:
Craft a concise newsletter using the given content. Include emojis, avoid starting with the subject word, summarize linked articles briefly, and ensure it's under 247 characters for easy TTS readability.
Important: Customize prompt for your tone and style.
Step 5: Convert Summary Text to Audio Using HTTP Request TTS Node
Add the Text to TTS node which is an HTTP Request node configured to POST to https://tiktok-tts.weilnet.workers.dev/api/generation.
Configure body JSON parameters:
text = {{ $json.response.text }}to pass summary textvoice = "en_us_001"to select the preferred TTS voice
Make sure to add header Content-Type: application/json.
Note: This node might generate base64 encoded audio.
Step 6: Convert Base64 Audio to File Binary
Use the Convert from base64 to File node next. Set it to convert the data property to a binary file suitable for Telegram.
This step is essential to attach audio files correctly in messaging apps.
Step 7: Merge Text and Audio Data
Add a Merge node named “Merge Text with Audio.” Connect from both the Summarization Chain and the Convert to File nodes to combine text summary with audio binary.
This dual-input structure prepares data for final aggregation.
Step 8: Aggregate Data in a Single Cell
Next, add the Aggregate node to compile all combined data within one output set for smooth delivery.
Step 9: Send Audio Podcast to Telegram
Add the Send Message to Telegram node configured for sendAudio operation:
- Set
chatIdto your Telegram channel or chat ID, e.g.,53739339. - Attach the binary audio file from the earlier node.
- Add a caption with summary text for context.
Connect this node last to deliver the finished audio podcast to your desired chat.
Customizations ✏️
- Change Gmail Label Filter: In the Gmail Trigger node, modify the label ID to target other Gmail categories like “Social” or “Updates” to create different podcast streams.
- Adjust Text Summarization Prompt: In the Summarization Chain node, edit the AI prompt to focus summaries on deals only, or add a formal tone.
- Select Different TTS Voice: In the HTTP Request node, change the
voiceparameter to other supported voices from the TTS API for varied audio styles. - Send to Multiple Telegram Chats: Duplicate and customize the Telegram node to send final audio podcasts to multiple groups or users.
- Add Email Subject to Caption: Modify the final Telegram caption field to dynamically include the email subject along with the summary.
Troubleshooting 🔧
- Problem: “No new emails trigger detected”
- Cause: Incorrect Gmail label filter or no recent emails with the specified label.
- Solution: Verify label IDs in Gmail settings. Test by manually labeling a test email “CATEGORY_PROMOTIONS” and triggering the workflow.
- Problem: “Text to Speech API returns error”
- Cause: Server or API endpoint downtime, or malformed request parameters.
- Solution: Check the API endpoint URL, confirm headers and body parameters, retry after some time.
- Problem: “Audio file not sent to Telegram”
- Cause: Incorrect binary property mapping or unsupported audio format.
- Solution: Confirm in “Convert from base64 to File” node that binary property is correctly set. Validate file format compatibility with Telegram.
Pre-Production Checklist ✅
- Confirm Gmail OAuth2 credentials are authorized and token is active.
- Test Gmail Trigger for exactly one email labeled “CATEGORY_PROMOTIONS”.
- Run the Code node alone to verify email metadata is cleaned properly.
- Test OpenAI summarization with sample text to ensure the prompt yields correct output.
- Verify HTTP Request node correctly receives audio data and converts it.
- Send a test audio message to Telegram channel before full deployment.
Deployment Guide
Once testing is complete and your workflow runs smoothly, activate the workflow in n8n. It will start polling Gmail every minute automatically. Monitor the executions in the n8n dashboard for errors. Logs help debug if the podcast doesn’t deliver correctly.
FAQs
- Q: Can I use Outlook instead of Gmail?
A: You can substitute the Gmail Trigger and Gmail nodes with Outlook equivalents, but the labeling and filtering might differ. - Q: Does this consume OpenAI API credits?
A: Yes, each summarization call counts against your OpenAI quota. - Q: Is my email data secure using this workflow?
A: The data is processed within your n8n setup. Ensure secure credentials and network settings. - Q: Can this handle high volumes of emails?
A: It can scale, but consider API rate limits on Gmail and OpenAI.
Conclusion
You’ve just built a powerful, n8n-driven automation that converts Gmail promotional emails into audio podcasts you can listen to anywhere. By doing so, you save hours weekly and gain an engaging new way to consume offers and promotions without screen strain.
Next automation ideas to explore include:
- Creating separate podcast workflows for other Gmail categories like “Social” or “Updates”.
- Enhancing audio output with background music or voice modulation.
- Extending this to other messaging platforms such as WhatsApp or Slack.
Keep exploring the power of n8n and automation to make your digital life easier! ⚙️