This commit is contained in:
nusquama
2025-11-20 09:19:25 +01:00
parent 2209065634
commit 21116e9e88
@@ -0,0 +1,298 @@
Email-to-Thread Generator: Auto-Post to X, Threads & Bluesky with ChatGPT
https://n8nworkflows.xyz/workflows/email-to-thread-generator--auto-post-to-x--threads---bluesky-with-chatgpt-8538
# Email-to-Thread Generator: Auto-Post to X, Threads & Bluesky with ChatGPT
### 1. Workflow Overview
This workflow automates the process of converting email content into long-form social media threads and posts them automatically to multiple platforms: Twitter, Threads, and Bluesky. It targets users who want to efficiently transform brief email ideas into fully developed, viral-style threads using AI (ChatGPT), then distribute the content via Blotatos API to different social networks.
The workflow is logically divided into these blocks:
- **1.1 Input Reception:** Detect incoming emails with a specific subject filter ("thread") from Gmail.
- **1.2 AI Processing:** Use OpenAI GPT models to generate a structured long-form thread from the email snippet, including fallback and output parsing.
- **1.3 Post-Processing:** Mark the processed email as read to avoid duplication.
- **1.4 Posting to Social Platforms:** Post the generated thread content to Twitter, Threads, and Bluesky via Blotato nodes.
- **1.5 Error Handling & Reporting:** Collect errors from posting nodes and the email marking node for consolidated reporting.
- **1.6 Documentation & Setup Notes:** Multiple sticky notes provide setup guidance, usage instructions, platform-specific tips, and troubleshooting links.
---
### 2. Block-by-Block Analysis
#### Block 1.1: Input Reception
- **Overview:** Listens for new unread Gmail messages with the subject containing "thread" to trigger the workflow.
- **Nodes Involved:**
- `New Email Subject "Thread"`
- **Node Details:**
- **Type:** Gmail Trigger node
- **Role:** Watches Gmail inbox for new emails matching criteria.
- **Configuration:**
- Filter: subject contains "thread", unread emails only, no sender restrictions.
- Poll frequency: hourly.
- **Inputs:** External trigger from Gmail inbox.
- **Outputs:** Email metadata and snippet to downstream nodes.
- **Potential Failures:** Authentication failures (Gmail OAuth token expired), Gmail API rate limits, network issues.
- **Notes:** Requires Gmail OAuth2 credential setup (brown sticky note 1).
#### Block 1.2: AI Processing
- **Overview:** Takes the email snippet and instructs OpenAI GPT to write a multi-post long-form thread in a viral Twitter style, then parses the structured JSON output for content and media URLs.
- **Nodes Involved:**
- `AI Writes Thread`
- `OpenAI Model`
- `OpenAI Backup`
- `Structured Output Parser`
- `OpenAI Fixer`
- **Node Details:**
- **OpenAI Model**
- Type: ChatGPT (LangChain OpenAI node)
- Role: Primary language model (GPT-4.1) for generating thread content.
- Config: Model set to "gpt-4.1".
- Inputs: Receives trigger from email node indirectly (via AI Writes Thread).
- Outputs: Generated thread JSON to `AI Writes Thread`.
- Failures: API quota, network timeouts, rate limiting.
- Credentials: OpenAI API key required (sticky note 4).
- **OpenAI Backup**
- Type: ChatGPT (LangChain OpenAI node)
- Role: Backup model (chatgpt-4o-latest) if primary fails, connected as fallback to `AI Writes Thread`.
- Failures: Same as primary, fallback if primary fails.
- **AI Writes Thread**
- Type: LangChain agent node
- Role: Core node that uses GPT output and example viral thread templates with strict writing style instructions to generate the thread.
- Config: Detailed prompt embedding writing style, examples, and task instruction to produce valid JSON output with fields: `text`, `mediaUrls`, `additionalPosts`.
- Inputs: Email snippet from trigger node, OpenAI model responses.
- Outputs: JSON thread structure for social media posting.
- Failures: Misformatted JSON output, model errors, parsing errors.
- Notes: Uses fallback from both OpenAI nodes.
- **Structured Output Parser**
- Type: LangChain Output Parser
- Role: Validates and auto-corrects AI-generated JSON output according to a strict schema.
- Config: Schema requires `text` (string), `mediaUrls` (array of strings), `additionalPosts` (array of objects each with text and mediaUrls).
- Inputs: AI Writes Threads output.
- Outputs: Clean structured JSON to AI Writes Thread (feedback loop to ensure valid output).
- Failures: Schema mismatches, auto-fix failures.
- **OpenAI Fixer**
- Type: ChatGPT (LangChain OpenAI node)
- Role: Attempts to fix malformed JSON or output that does not conform to the schema.
- Config: Uses smaller "gpt-4.1-mini" model for quick fixes.
- Inputs: Output parsers error feedback.
- Outputs: Corrected output back to Structured Output Parser.
- Failures: Same as other OpenAI nodes.
#### Block 1.3: Post-Processing
- **Overview:** Marks the processed email as read in Gmail to prevent re-processing.
- **Nodes Involved:**
- `Mark email as read`
- **Node Details:**
- Type: Gmail node
- Role: Changes email status to read using the message ID from the trigger node.
- Config: Uses Gmail OAuth2 credential.
- Inputs: Message ID from the email trigger node.
- Outputs: Passes errors to error report node if marking fails.
- Failures: Auth errors, message ID invalid, Gmail API limits.
#### Block 1.4: Posting to Social Platforms
- **Overview:** Posts the generated thread content to three social platforms via Blotato API nodes, enabling multi-platform distribution.
- **Nodes Involved:**
- `Twitter [BLOTATO]`
- `Threads [BLOTATO]`
- `Bluesky [BLOTATO]`
- **Node Details:**
- **All three nodes:**
- Type: Blotato community node for n8n
- Role: Post contents to respective social media platforms using Blotato API.
- Config:
- Platform parameter set (`twitter`, `threads`, `bluesky`).
- Account ID selected per platform.
- Post content text, thread array, and media URLs passed from AI Writes Thread output.
- Thread input method: array (posts split as array of tweets/posts).
- Inputs: Structured output from AI Writes Thread.
- Outputs: Errors flow to consolidated `Error Report` node.
- Failures: API key invalid, network issues, platform-specific posting errors, media URL restrictions.
- Credentials: Blotato API key required (sticky note 9).
- Notes: Platform-specific posting tips and troubleshooting links in sticky note 5.
#### Block 1.5: Error Handling & Reporting
- **Overview:** Consolidates errors from all posting nodes and the email marking node for centralized error reporting.
- **Nodes Involved:**
- `Error Report` (Merge node)
- **Node Details:**
- Type: Merge node
- Role: Collect errors from Twitter, Threads, Bluesky nodes and Gmail marking node.
- Config: Set up for 4 input streams (one from each posting node and one from email marking node).
- Outputs: Error data for monitoring or further handling.
- Failures: N/A (merging only).
- Notes: Sticky note 7 provides links to Blotato API dashboard and logs.
#### Block 1.6: Documentation & Setup Notes
- **Overview:** Several sticky notes provide user instructions, setup guidance, platform-specific posting notes, and troubleshooting resources.
- **Nodes Involved:**
- Multiple Sticky Notes (`Sticky Note`, `Sticky Note1`, `Sticky Note2`, `Sticky Note4`, `Sticky Note5`, `Sticky Note7`, `Sticky Note8`, `Sticky Note9`)
- **Node Details:**
- Type: Sticky Note nodes
- Role:
- Main workflow explanation and user instructions.
- Setup steps for Gmail, OpenAI, and Blotato credentials.
- Platform-specific notes with links to Blotato help pages for Twitter, Threads, Bluesky.
- Error report and troubleshooting help links.
- Inputs/Outputs: None (informational only).
---
### 3. Summary Table
| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note |
|-------------------------|----------------------------------|---------------------------------------|------------------------------------|--------------------------------------------------|----------------------------------------------------------------------------------------------|
| New Email Subject "Thread" | Gmail Trigger | Detect new emails with subject "thread" | External (Gmail inbox) | AI Writes Thread | # Setup 1 Select your Gmail credential |
| AI Writes Thread | LangChain Agent | Generate viral long-form thread JSON from email snippet | New Email Subject "Thread", OpenAI Model, OpenAI Backup | Mark email as read, Twitter, Threads, Bluesky | |
| OpenAI Model | LangChain ChatGPT (GPT-4.1) | Primary AI model for thread generation | - | AI Writes Thread | # Setup 2 Select your OpenAI credential |
| OpenAI Backup | LangChain ChatGPT (chatgpt-4o) | Backup AI model fallback | - | AI Writes Thread | # Setup 2 Select your OpenAI credential |
| Structured Output Parser | LangChain Output Parser | Validate and auto-fix AI JSON output | OpenAI Fixer | AI Writes Thread | # Don't Touch |
| OpenAI Fixer | LangChain ChatGPT (GPT-4.1-mini) | Fix malformed AI output | Structured Output Parser | Structured Output Parser | # Don't Touch |
| Mark email as read | Gmail Node | Mark processed email as read | AI Writes Thread | Error Report | |
| Twitter [BLOTATO] | Blotato API Node | Post thread to Twitter | AI Writes Thread | Error Report | # Platform Specific Notes with best practices and FAQs for Twitter, Threads, Bluesky |
| Threads [BLOTATO] | Blotato API Node | Post thread to Threads | AI Writes Thread | Error Report | # Platform Specific Notes with best practices and FAQs for Twitter, Threads, Bluesky |
| Bluesky [BLOTATO] | Blotato API Node | Post thread to Bluesky | AI Writes Thread | Error Report | # Platform Specific Notes with best practices and FAQs for Twitter, Threads, Bluesky |
| Error Report | Merge Node | Consolidate errors from posting & email marking | Twitter [BLOTATO], Threads [BLOTATO], Bluesky [BLOTATO], Mark email as read | - | # Error Report with links to API dashboard and run logs |
| Sticky Note | Sticky Note Node | Workflow overview and usage instructions | - | - | # Email to Long-Form Thread detailed instructions and setup |
| Sticky Note1 | Sticky Note Node | Setup step 1 - Gmail credential | - | - | # Setup 1 Select your Gmail credential |
| Sticky Note2 | Sticky Note Node | Setup step 3 - Social account selection | - | - | # Setup 3 Guide to select social accounts and deactivate unneeded platforms |
| Sticky Note4 | Sticky Note Node | Setup step 2 - OpenAI credential | - | - | # Setup 2 Select your OpenAI credential |
| Sticky Note5 | Sticky Note Node | Platform-specific posting notes & help | - | - | # Platform Specific Notes with links to Blotato help pages |
| Sticky Note7 | Sticky Note Node | Error reporting & API dashboard links | - | - | # Error Report with links to API dashboard and logs |
| Sticky Note8 | Sticky Note Node | Post Long-Form Threads instructions & best practices | - | - | # Post Long-Form Threads with media and AI disclosure instructions |
| Sticky Note9 | Sticky Note Node | Setup step 3 instructions for social accounts | - | - | # Setup 3 Guide to select social accounts and deactivate unneeded platforms |
---
### 4. Reproducing the Workflow from Scratch
1. **Create Gmail Trigger node**
- Type: Gmail Trigger
- Set filter to: Subject contains "thread", unread only, no sender filter
- Poll interval: Every hour
- Connect Gmail OAuth2 credential (create if not already done)
- Name node: `New Email Subject "Thread"`
2. **Create OpenAI Model node (Primary)**
- Type: LangChain ChatGPT (OpenAI)
- Model: Select "gpt-4.1"
- Connect OpenAI API credential
- Name node: `OpenAI Model`
3. **Create OpenAI Backup node**
- Type: LangChain ChatGPT (OpenAI)
- Model: Select "chatgpt-4o-latest"
- Connect same OpenAI API credential
- Name node: `OpenAI Backup`
4. **Create AI Writes Thread node**
- Type: LangChain Agent
- Prompt: Include detailed writing style, example viral thread template, and task description as per original prompt.
- Set fallback to `OpenAI Backup` if `OpenAI Model` fails.
- Connect input from `New Email Subject "Thread"` (email snippet)
- Connect input from `OpenAI Model` (primary AI output) and `OpenAI Backup` (fallback)
- Enable output parser for valid JSON response.
5. **Create Structured Output Parser node**
- Type: LangChain Output Parser Structured
- Schema: JSON schema requiring `text` (string), `mediaUrls` (array of strings), `additionalPosts` (array of objects with `text` and `mediaUrls`)
- Set autoFix to true
- Connect input from `OpenAI Fixer` (step 6)
- Connect output back to `AI Writes Thread` as feedback loop
6. **Create OpenAI Fixer node**
- Type: LangChain ChatGPT (OpenAI)
- Model: "gpt-4.1-mini" for quick fixes
- Connect OpenAI API credential
- Connect input from `Structured Output Parser` error output
- Connect output to `Structured Output Parser` input
7. **Connect AI Writes Thread output to:**
- `Mark email as read` node
- Social posting nodes (steps 8-10)
8. **Create Mark email as read node**
- Type: Gmail Node
- Operation: Mark as read
- Use message ID from `New Email Subject "Thread"` node
- Connect Gmail OAuth2 credential
- Name node: `Mark email as read`
9. **Create Twitter [BLOTATO] node**
- Type: Blotato node
- Platform: Twitter
- Select Twitter account ID
- Post content text: Bind to `AI Writes Thread` output `text` field
- Thread posts array: Bind to `additionalPosts` from AI output
- Media URLs: Bind to `mediaUrls` from AI output
- Connect Blotato API credential
- Name node: `Twitter [BLOTATO]`
10. **Create Threads [BLOTATO] node**
- Same setup as Twitter node but platform: Threads
- Use appropriate account ID
- Name node: `Threads [BLOTATO]`
11. **Create Bluesky [BLOTATO] node**
- Same setup as Twitter node but platform: Bluesky
- Use appropriate account ID
- Name node: `Bluesky [BLOTATO]`
12. **Create Error Report node**
- Type: Merge node
- Number of inputs: 4 (Twitter, Threads, Bluesky, Mark email as read)
- Connect error outputs from these nodes to merge inputs
- Name node: `Error Report`
13. **Add Sticky Notes for user instructions and setup guidance**
- Add notes describing workflow usage, credentials setup, platform posting notes, troubleshooting links, and best practices.
14. **Connect all nodes according to the following flow:**
- `New Email Subject "Thread"``AI Writes Thread`
- `OpenAI Model` and `OpenAI Backup``AI Writes Thread` (fallback)
- `AI Writes Thread``Mark email as read` and all three Blotato nodes
- All four output nodes (Mark email as read + 3 Blotato nodes) send errors to `Error Report`
- `OpenAI Fixer` and `Structured Output Parser` connected in feedback loop to ensure valid AI output
15. **Verify all credentials:** Gmail OAuth2, OpenAI API key, Blotato API key are correctly configured.
16. **Test workflow with a sample email titled "thread" and verify posting to all platforms and marking email as read.**
---
### 5. General Notes & Resources
| Note Content | Context or Link |
|-------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| You can post text, images, and videos embedded within your long-form thread by filling `mediaUrls` with public URLs. | Sticky Note main overview |
| Sign up for Blotato, generate API key under paid plan, enable "Verified Community Nodes" in n8n Admin Panel for Blotato node usage. | Setup instructions |
| Twitter, Threads, Bluesky support long-form threads with media; see best practices and FAQs at https://help.blotato.com/platforms/ | Platform-specific posting notes (Sticky Note 5) |
| Avoid posting same image/video repeatedly to prevent spam flags. Disclose AI-generated content if using avatars. | Posting best practices (Sticky Note 8) |
| View run logs and API dashboard for troubleshooting: https://my.blotato.com/api-dashboard | Error Report sticky note (Sticky Note 7) |
| Connect Gmail to n8n via OAuth2: https://docs.n8n.io/integrations/builtin/credentials/google/oauth-single-service | Credential setup guidance |
| Contact Blotato support via website chat for help; Sabrina Ramonov replies within 24 hours most weekdays. | Support contact info in Sticky Note 5 |
---
This documentation provides a complete, stepwise breakdown and reference for the "Email-to-Thread Generator: Auto-Post to X, Threads & Bluesky with ChatGPT" workflow, enabling advanced users and AI agents to understand, reproduce, or extend the workflow confidently.