{
  "name": "Turn new articles and videos into AI-written posts per network with PostDaily",
  "nodes": [
    {
      "parameters": {
        "content": "## Turn each new article or video into posts written for every network\n\n### How it works\nEvery hour this checks a blog's RSS feed or a YouTube channel's feed. For each new item, an AI model writes a separate post for every channel connected in [PostDaily](https://www.postdaily.app): short for X or Bluesky, longer for LinkedIn, a caption with hashtags for Instagram. Each post fits its channel's character limit. They are saved as one PostDaily **draft** with the image or thumbnail attached, for a person to check. Items already sent are skipped.\n\n### Requirements\n- A [PostDaily](https://www.postdaily.app) account with a connected channel (the free plan works).\n- The verified **PostDaily** community node, `n8n-nodes-postdaily` 0.2.1 or later ([how to add it](https://www.postdaily.app/help/connect-with-an-api-key#use-the-postdaily-node-in-n8n)). Tested on n8n 2.49.8 and imported on n8n Cloud.\n- An OpenAI API key, or another chat model.\n\n### Setup\n1. In PostDaily, open **Settings → AI agents → API key**, choose **Drafts only** and copy the key.\n2. In **Get PostDaily channels**, create a **PostDaily API** credential with it. **Save draft in PostDaily** uses it too.\n3. Add your OpenAI credential in **OpenAI Chat Model**.\n4. In **Settings**, set the feed URL. For YouTube: `https://www.youtube.com/feeds/videos.xml?channel_id=YOUR_CHANNEL_ID`.\n5. Run it once, then open **Drafts** in PostDaily.\n\n### Customization\n- **networks** in **Settings** picks channels, such as `instagram, linkedin` or an @handle. Empty means all.\n- **brandVoice** sets the tone; the system message in **Write one post per channel** holds the rules.\n- To skip drafts, set **Mode** to **Add to Queue** and use a **Full access** key.\n\n### Limitations\n- Instagram, TikTok, YouTube and Pinterest need media; TikTok and YouTube need a video. Drafts without it go to **Needs attention** with the reason.\n- An item counts as sent once read. To resend after a failed run, switch **Skip items already sent** to **Clear Deduplication History**, run it once, then switch it back.\n\n### The workflow\n![The PostDaily workflow](https://www.postdaily.app/n8n/ai-social-posts-to-postdaily-drafts.png)",
        "width": 700,
        "height": 1300,
        "color": 1
      },
      "id": "fe3c56b0-de37-56b7-8b52-e85dc890a437",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-140, -260]
    },
    {
      "parameters": {
        "content": "## 1. Settings and channels\nSet the feed and networks in **Settings**. PostDaily lists your channels with each one's character limit. A wrong key or network stops the run here, before any item is marked as sent.",
        "width": 900,
        "height": 360,
        "color": 7
      },
      "id": "ea18e940-7b56-5888-87fa-441dc7511d98",
      "name": "Section 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [600, 220]
    },
    {
      "parameters": {
        "content": "## 2. New articles and videos\nThe newest few feed items are kept, and any sent on an earlier run are dropped.",
        "width": 880,
        "height": 360,
        "color": 7
      },
      "id": "c7efd20f-bf5e-57d0-89c0-5b9435018f94",
      "name": "Section 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [1520, 220]
    },
    {
      "parameters": {
        "content": "## 3. AI writes one post per channel\nOne post for each channel, in its style and within its limit. The next step trims anything still too long.",
        "width": 560,
        "height": 560,
        "color": 7
      },
      "id": "745b640c-4178-527c-853f-ffc704170bae",
      "name": "Section 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [2420, 220]
    },
    {
      "parameters": {
        "content": "## 4. Save the draft and check it\nOne draft per item, with its own text for every channel. Drafts that break a network rule go to **Needs attention**.",
        "width": 760,
        "height": 360,
        "color": 7
      },
      "id": "a3281cbc-5d65-5b86-88b9-3e2fbde3324e",
      "name": "Section 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [3000, 220]
    },
    {
      "parameters": {
        "content": "### Use a Drafts only key\nAI-written posts should be read before they go out. With a Drafts only key, PostDaily refuses to schedule or publish from this workflow.",
        "width": 300,
        "height": 240,
        "color": 3
      },
      "id": "29157cb8-fda2-5eeb-822e-34eed7f277cd",
      "name": "Use a Drafts only key",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [3020, -60]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "id": "9e096a7f-7b94-599f-8b5f-4a2b413c7ebd",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [660, 400]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "feedUrl",
              "name": "feedUrl",
              "value": "https://example.com/rss.xml",
              "type": "string"
            },
            {
              "id": "networks",
              "name": "networks",
              "value": "",
              "type": "string"
            },
            {
              "id": "brandVoice",
              "name": "brandVoice",
              "value": "Clear, friendly and practical. Short sentences, no hype.",
              "type": "string"
            },
            {
              "id": "maxItemsPerRun",
              "name": "maxItemsPerRun",
              "value": 2,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "6c393fb4-182e-5008-8768-119a39b0377e",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [880, 400]
    },
    {
      "parameters": {
        "url": "={{ $('Settings').first().json.feedUrl }}",
        "options": {
          "customFields": "media:content, media:thumbnail, media:group, content:encoded"
        }
      },
      "id": "cfde76aa-7051-5757-8dcd-d08be1587e63",
      "name": "Read feed",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.2,
      "position": [1580, 400]
    },
    {
      "parameters": {
        "maxItems": "={{ $('Settings').first().json.maxItemsPerRun }}"
      },
      "id": "acfde5ba-48f2-5e87-88c9-286558e3aed8",
      "name": "Keep the newest few",
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [1800, 400]
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "logic": "removeItemsWithAlreadySeenKeyValues",
        "dedupeValue": "={{ $json.guid || $json.id || $json.link }}",
        "options": {}
      },
      "id": "018e03a3-37eb-51d0-8cf7-b20856a77baf",
      "name": "Skip items already sent",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [2020, 400]
    },
    {
      "parameters": {
        "resource": "channel",
        "operation": "getAll"
      },
      "id": "c045806e-3977-51df-84e1-047e2d87cf7f",
      "name": "Get PostDaily channels",
      "type": "n8n-nodes-postdaily.postDaily",
      "typeVersion": 1,
      "position": [1100, 400],
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Picks the PostDaily channels to write for. Runs before the feed is read, so a\n// wrong setting or key stops the run before any item is recorded as sent.\nconst settings = $('Settings').first().json;\n\nconst wanted = String(settings.networks ?? '')\n  .split(',')\n  .map((value) => value.trim().toLowerCase().replace(/^@/, ''))\n  .filter(Boolean);\n\n// Channels that can take a draft (a paused queue doesn't matter for drafts),\n// narrowed to the networks or @handles in Settings.\nconst channels = $input\n  .all()\n  .map((item) => item.json)\n  .filter((channel) => channel.status === 'ok' || channel.status === 'paused')\n  .filter(\n    (channel) =>\n      wanted.length === 0 ||\n      wanted.includes(String(channel.network).toLowerCase()) ||\n      wanted.includes(String(channel.handle ?? '').toLowerCase().replace(/^@/, '')),\n  )\n  .map((channel) => ({\n    id: channel.id,\n    network: channel.network,\n    networkName: channel.networkName,\n    handle: channel.handle,\n    maxCharacters: channel.limits?.maxCharacters ?? 500,\n  }));\n\nif (channels.length === 0) {\n  throw new Error(\n    `No PostDaily channel can take a draft for Settings → networks (\"${settings.networks}\"). Check the spelling, connect the channel in PostDaily or reconnect it, or leave networks empty to use every channel.`,\n  );\n}\n\nreturn [{ json: { channels } }];\n"
      },
      "id": "223b0ae1-edea-5373-843a-cd9e788b50d0",
      "name": "Pick channels",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1320, 400]
    },
    {
      "parameters": {
        "jsCode": "// Pairs each new article or video with the channels picked earlier.\nconst { channels } = $('Pick channels').first().json;\n\n// Plain text from HTML, with whitespace collapsed.\nfunction plain(value) {\n  return String(value ?? '')\n    .replace(/<[^>]*>/g, ' ')\n    .replace(/&nbsp;/g, ' ')\n    .replace(/&amp;/g, '&')\n    .replace(/\\s+/g, ' ')\n    .trim();\n}\n\n// The first value of an RSS custom field, which can be a string, an object or a list.\nfunction first(value) {\n  return Array.isArray(value) ? value[0] : value;\n}\n\nfunction urlOf(value) {\n  const entry = first(value);\n  return typeof entry === 'string' ? entry : (entry?.$?.url ?? entry?.url ?? null);\n}\n\n// The first image: enclosure, media tags (Ghost, WordPress, YouTube), then an <img> in the body.\nfunction findImage(item, group) {\n  const enclosure = item.enclosure;\n  if (enclosure?.url && (!enclosure.type || enclosure.type.startsWith('image/'))) {\n    return enclosure.url;\n  }\n  for (const value of [item['media:content'], item['media:thumbnail'], group?.['media:thumbnail']]) {\n    const entry = first(value);\n    const medium = entry?.$?.medium ?? entry?.$?.type ?? '';\n    const url = urlOf(value);\n    if (url && (!medium || medium === 'image' || String(medium).startsWith('image/'))) {\n      return url;\n    }\n  }\n  const html = String(item['content:encoded'] ?? item.content ?? '');\n  const match = html.match(/<img[^>]+src=[\"']([^\"']+)[\"']/i);\n  return match ? match[1] : null;\n}\n\nconst results = [];\nfor (const entry of $input.all()) {\n  const item = entry.json;\n  const group = first(item['media:group']);\n  const link = String(item.link ?? '').trim();\n  const title = plain(item.title ?? first(group?.['media:title']));\n  if (!title || !/^https?:\\/\\//.test(link)) continue;\n\n  const isVideo = /youtube\\.com|youtu\\.be|vimeo\\.com/.test(link) || Boolean(group);\n  const summary = plain(\n    first(group?.['media:description']) ??\n      item.contentSnippet ??\n      item['content:encoded'] ??\n      item.content ??\n      '',\n  ).slice(0, 3000);\n  const image = findImage(item, group);\n\n  results.push({\n    json: {\n      source: {\n        kind: isVideo ? 'video' : 'article',\n        title,\n        link,\n        summary,\n        image: image && /^https?:\\/\\//.test(image) ? image : null,\n        // The same article or video always gets the same key.\n        key: String(item.guid || item.id || link),\n      },\n      channels,\n    },\n  });\n}\n\nreturn results;\n"
      },
      "id": "f832e006-6622-558d-83b9-a07159dfe99d",
      "name": "Prepare article and channels",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2240, 400]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=New {{ $json.source.kind }}: {{ $json.source.title }}\nLink: {{ $json.source.link }}\nSummary: {{ $json.source.summary || 'No summary. Work from the title.' }}\n\nBrand voice: {{ $('Settings').first().json.brandVoice }}\n\nChannels:\n{{ $json.channels.map(c => '- channelId: ' + c.id + ' | network: ' + c.networkName + ' | account: ' + c.handle + ' | at most ' + c.maxCharacters + ' characters').join('\\n') }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "type": "SystemMessagePromptTemplate",
              "message": "You write social media posts that announce a new article or video. You get its title, link and summary, and a list of channels. Write exactly one post for each channel.\n\nRules:\n- Write for the network. X, Bluesky, Threads and Mastodon: one or two short sentences. LinkedIn: two or three short paragraphs for professionals. Facebook: friendly, two to four sentences. Instagram and TikTok: a caption with a hook in the first line and three to five relevant hashtags at the end. Pinterest: a descriptive sentence with search keywords. Any other network: two or three plain sentences.\n- Stay well under each channel's character limit, counting the link and hashtags.\n- Put the link in every post exactly once, at the end. On Instagram and TikTok links can't be clicked, so write \"Link in bio\" instead of the link.\n- Use only facts from the title and summary. Do not invent numbers, quotes, prices or dates.\n- Write in the language of the article or video.\n- No emojis unless the brand voice asks for them.\n- Copy each channelId exactly as given."
            }
          ]
        }
      },
      "id": "9077ddbc-ffcb-5755-810b-57bc49bdfb99",
      "name": "Write one post per channel",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [2480, 400]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "responsesApiEnabled": false,
        "options": {}
      },
      "id": "c6e4d8d1-78bb-543f-8095-478e1b6e606c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [2440, 620]
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"posts\": {\n      \"type\": \"array\",\n      \"description\": \"One post per channel\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"channelId\": {\n            \"type\": \"string\",\n            \"description\": \"The channelId exactly as given\"\n          },\n          \"text\": {\n            \"type\": \"string\",\n            \"description\": \"The post text for that channel\"\n          }\n        },\n        \"required\": [\n          \"channelId\",\n          \"text\"\n        ]\n      }\n    }\n  },\n  \"required\": [\n    \"posts\"\n  ]\n}"
      },
      "id": "8ff07d1b-582a-5394-8a5f-700dd6c129c2",
      "name": "One post per channel",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [2640, 620]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Turns the AI's posts into one PostDaily draft with its own text per channel.\nconst { source, channels } = $('Prepare article and channels').item.json;\nconst written = new Map(\n  ($json.output?.posts ?? []).map((post) => [String(post.channelId), String(post.text ?? '').trim()]),\n);\n\n// Shortens text at a word boundary and adds an ellipsis.\nfunction shorten(text, max) {\n  if (text.length <= max) return text;\n  const cut = text.slice(0, Math.max(0, max - 1));\n  const lastSpace = cut.lastIndexOf(' ');\n  return `${cut.slice(0, lastSpace > max * 0.6 ? lastSpace : cut.length).trim()}…`;\n}\n\n// Keeps the post within the channel's limit. When the link is in the post,\n// the words around it are shortened so the link survives whole.\nfunction fit(text, max) {\n  if (text.length <= max) return text;\n  if (!text.includes(source.link)) return shorten(text, max);\n  const rest = text.replace(source.link, '').replace(/\\s+\\n|\\n{3,}/g, '\\n\\n').trim();\n  return `${shorten(rest, max - source.link.length - 2)}\\n\\n${source.link}`;\n}\n\n// A short fingerprint of the channel set, so changing the channels in Settings\n// makes new drafts, while a retry for the same channels does not.\nfunction fingerprint(text) {\n  let hash = 0x811c9dc5;\n  for (let index = 0; index < text.length; index++) {\n    hash = Math.imul(hash ^ text.charCodeAt(index), 0x01000193) >>> 0;\n  }\n  return hash.toString(16).padStart(8, '0');\n}\n\nconst channelSettings = channels.map((channel) => {\n  // A channel the AI skipped still gets a plain post: the title and the link.\n  const text = written.get(channel.id) || `${source.title}\\n\\n${source.link}`;\n  return { channel: channel.id, text: fit(text, channel.maxCharacters) };\n});\n\nreturn {\n  json: {\n    source,\n    channels: channels.map((channel) => channel.id),\n    // The node needs a main text; each channel's own text below replaces it.\n    text: channelSettings[0].text,\n    channelSettings,\n    // The node splits Media URLs on commas, so commas inside the URL are encoded.\n    mediaUrls: source.image ? source.image.replace(/,/g, '%2C') : '',\n    title: shorten(source.title, 140),\n    idempotencyKey: `n8n-ai-${fingerprint(channels.map((channel) => channel.id).sort().join())}-${source.key}`.slice(0, 200),\n  },\n};\n"
      },
      "id": "a038745a-4108-595b-863a-b560207f7fbf",
      "name": "Fit posts to each channel",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2780, 400]
    },
    {
      "parameters": {
        "channels": "={{ $json.channels }}",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "channelSettings": "={{ $json.channelSettings }}",
          "idempotencyKey": "={{ $json.idempotencyKey }}",
          "mediaUrls": "={{ $json.mediaUrls }}",
          "title": "={{ $json.title }}"
        }
      },
      "id": "c33e02ab-4ec7-5ec1-8acc-f1e98e8b7032",
      "name": "Save draft in PostDaily",
      "type": "n8n-nodes-postdaily.postDaily",
      "typeVersion": 1,
      "position": [3060, 400],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "no-errors",
              "leftValue": "={{ ($json.validation?.errors ?? []).length }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "74750b9f-733a-50f1-8c0e-e887caf07f8b",
      "name": "Ready to review?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [3300, 400]
    },
    {
      "parameters": {},
      "id": "655efcce-8ea6-5252-8c0b-9aa66065df95",
      "name": "Done",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [3540, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "title",
              "name": "title",
              "value": "={{ $('Fit posts to each channel').item.json.source.title }}",
              "type": "string"
            },
            {
              "id": "link",
              "name": "link",
              "value": "={{ $('Fit posts to each channel').item.json.source.link }}",
              "type": "string"
            },
            {
              "id": "reason",
              "name": "reason",
              "value": "={{ String($json.error ?? '').startsWith('CONFLICT') ? 'An earlier run already saved a draft for this item and these channels.' : ($json.error ?? ((($json.validation?.errors ?? []).map(e => e.message).join(' ')) || 'PostDaily did not save this draft.')) }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "ea72c6cb-03eb-5d7f-858e-cf66935a71b8",
      "name": "Needs attention",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [3540, 500]
    }
  ],
  "connections": {
    "Every hour": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Get PostDaily channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get PostDaily channels": {
      "main": [
        [
          {
            "node": "Pick channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick channels": {
      "main": [
        [
          {
            "node": "Read feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read feed": {
      "main": [
        [
          {
            "node": "Keep the newest few",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep the newest few": {
      "main": [
        [
          {
            "node": "Skip items already sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip items already sent": {
      "main": [
        [
          {
            "node": "Prepare article and channels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare article and channels": {
      "main": [
        [
          {
            "node": "Write one post per channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Write one post per channel",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "One post per channel": {
      "ai_outputParser": [
        [
          {
            "node": "Write one post per channel",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Write one post per channel": {
      "main": [
        [
          {
            "node": "Fit posts to each channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fit posts to each channel": {
      "main": [
        [
          {
            "node": "Save draft in PostDaily",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save draft in PostDaily": {
      "main": [
        [
          {
            "node": "Ready to review?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Needs attention",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ready to review?": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Needs attention",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
