Terminal.skills
Use Cases/Build an AI Content Engine That Runs Your Social Media

Build an AI Content Engine That Runs Your Social Media

Automate social media by turning one long-form piece into 30+ platform-optimized posts across LinkedIn, Twitter, and Instagram using OpenAI and n8n orchestration.

Automation#n8n#workflow#automation#integration#low-code
Works with:claude-codeopenai-codexgemini-clicursor
$

Leo is the solo marketer at a 15-person developer tools startup, responsible for LinkedIn, Twitter, Instagram, and a newsletter. He spends 20 hours per week creating and scheduling content. His insight: most social content is derived from the same core ideas, just reformatted per platform.

The Problem

A single blog post contains enough material for 10 LinkedIn posts, 15 tweets, and 5 Instagram carousels. But manually reformatting, optimizing for each platform's algorithm, and scheduling across channels eats 20 hours a week. The CEO wants Leo to also manage the company blog and YouTube. Content ideas aren't the bottleneck — the manual labor of repurposing and scheduling is.

The Solution

Build an automated pipeline where Leo drops one long-form piece (blog post, podcast transcript, or video script) into a webhook. n8n orchestrates the flow: extract content atoms, generate platform-specific posts via OpenAI, and schedule everything through Buffer.

bash
terminal-skills install n8n openai-sdk twitter-x-marketing linkedin-marketing instagram-marketing

Step-by-Step Walkthrough

1. Content Atomization Pipeline in n8n

The pipeline starts when Leo drops long-form content into a webhook. An n8n Function Node calls OpenAI to extract atomic content pieces — each with a core insight, hook, supporting evidence, and target platforms.

javascript
// n8n Function Node: atomize-content
const content = $input.first().json.content;
const contentType = $input.first().json.type;

const response = await $http.request({
  method: "POST",
  url: "https://api.openai.com/v1/chat/completions",
  headers: {
    "Authorization": `Bearer ${$env.OPENAI_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: {
    model: "gpt-4o",
    response_format: { type: "json_object" },
    messages: [
      {
        role: "system",
        content: `Extract atomic content pieces. For each: core insight, hook,
supporting evidence, target platforms, content_type (thought_leadership,
how_to, data_point, story, controversial_take). Return as JSON array.`
      },
      { role: "user", content: `Content type: ${contentType}\n\n${content}` }
    ],
  },
});

const atoms = JSON.parse(response.choices[0].message.content).atoms;
return atoms.map(atom => ({ json: atom }));

2. Platform-Specific Content Generation

Each atom is transformed into platform-native posts. LinkedIn gets professional storytelling with formatting. Twitter gets punchy threads (4-7 tweets, each under 280 chars). Instagram gets carousel slide text with captions.

python
from openai import OpenAI
from pydantic import BaseModel

client = OpenAI()

class LinkedInPost(BaseModel):
    hook: str           # First line — the scroll-stopper
    body: str           # Main content with line breaks
    cta: str            # Call-to-action
    hashtags: list[str] # 3-5 relevant hashtags

class TwitterThread(BaseModel):
    tweets: list[str]   # Each tweet <= 280 chars

def generate_linkedin(atom: dict) -> LinkedInPost:
    response = client.beta.chat.completions.parse(
        model="gpt-4o",
        response_format=LinkedInPost,
        messages=[
            {"role": "system", "content": "Write a LinkedIn post. Bold first line, "
             "short paragraphs, end with a question. 800-1200 chars."},
            {"role": "user", "content": f"Content atom:\n{atom}"}
        ],
    )
    return response.choices[0].message.parsed

3. Scheduling and Performance Feedback

Approved posts are pushed to Buffer at optimal times per platform. Each week, the system pulls engagement metrics and feeds them back into generation prompts — top-performing post patterns influence future content style.

typescript
const optimalTimes: Record<string, string[]> = {
  linkedin: ["08:00", "12:00", "17:30"],
  twitter: ["09:00", "12:30", "15:00", "18:00"],
  instagram: ["11:00", "19:00"],
};

for (const post of posts) {
  const scheduledAt = getNextOptimalSlot(post.platform, optimalTimes);
  await fetch("https://api.bufferapp.com/1/updates/create.json", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams({
      access_token: bufferToken,
      text: post.content,
      "profile_ids[]": getProfileId(post.platform),
      scheduled_at: scheduledAt.toISOString(),
    }),
  });
}

Real-World Example

Leo, solo marketer at DevToolsCo (15 people), records a 30-minute podcast about their migration from REST to GraphQL.

  1. He pastes the transcript into the n8n webhook
  2. The pipeline extracts 12 content atoms (performance wins, developer experience insights, migration pitfalls)
  3. OpenAI generates 12 LinkedIn posts, 8 Twitter threads, and 5 Instagram carousels
  4. Leo reviews in Notion, tweaks 3 posts, approves the rest (30 minutes)
  5. Buffer schedules everything across the week at optimal times

After 8 weeks: Content volume went from 8 to 32 posts/week. Time dropped from 20 hours to 4 hours/week. LinkedIn followers grew 340%. Twitter impressions jumped from 12K to 89K/week. Inbound leads from social increased from 3/month to 14/month. Cost: $0.12 per generated post.

Related Skills