{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "60012318-0c2b-4bfa-ae56-f84f9b56cd53",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        16
      ],
      "parameters": {
        "path": "6dc2aea4-38c8-4d0e-8e8c-6bf231f50056",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "9ba8a0de-54b8-4a9b-96ff-a40c8e97624a",
      "name": "HTML To Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        448,
        16
      ],
      "parameters": {
        "html": "={{ $('Webhook').item.json.body.post.post_content }}",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "91670d70-7be8-43a8-a3ec-c7f865c5f2a1",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        224,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e0bda018-2dd1-4c65-bc2d-77d219981ad5",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.post.post_type }}",
              "rightValue": "post"
            },
            {
              "id": "9be02a9a-ae8c-4ce4-8dea-dfadd7a630cd",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.post.post_status }}",
              "rightValue": "publish"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "c9deca50-1d77-48cb-90c2-8abea2baeba8",
      "name": "Clean Data",
      "type": "n8n-nodes-base.set",
      "position": [
        672,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ac7c00ef-8f72-4898-b78b-2bbf5b62ea11",
              "name": "post_title",
              "type": "string",
              "value": "={{ $json.body.post.post_title }}"
            },
            {
              "id": "3ba2adcd-b031-418b-a739-dd93b6ada23b",
              "name": "post_content",
              "type": "string",
              "value": "={{ $json.data }}"
            },
            {
              "id": "a8c96599-d650-4cdb-91c5-8a94872d42de",
              "name": "post_link",
              "type": "string",
              "value": "={{ $('Webhook').item.json.body.post_permalink }}"
            },
            {
              "id": "e6a65c63-deff-4aaa-b5c6-c323f8b10069",
              "name": "post_thumbnail",
              "type": "string",
              "value": "={{ $('Webhook').item.json.body.post_thumbnail }}"
            },
            {
              "id": "f849fd26-fbc3-4b6f-af75-c3896d9dba87",
              "name": "facebook_page_id",
              "type": "string",
              "value": "788563884350153"
            },
            {
              "id": "ed237fa5-3ab4-4815-a120-36a1ed4e2e04",
              "name": "instagram_id",
              "type": "string",
              "value": "17841478701285041"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c99c8c5e-6172-4f4f-8090-180932fa07c0",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        896,
        16
      ],
      "parameters": {
        "text": "=Post Title: {{ $json.post_title }}\nPost Link: {{ $json.post_link }}\nPost Content: {{ $json.post_content.slice(0, 800) }}\n\nGenerate platform-specific social media captions for this blog post now.",
        "options": {
          "systemMessage": "# Role\nYou are a professional social media content writer.\nYou write platform-specific captions when a new blog \npost is published on a WordPress website.\n\n# Your Job\nRead the post title, link, and content.\nThen write one caption for each platform below.\nEach caption must match that platform's style, \ntone, length, and best practices.\n\n# Platform Guidelines\n\nTWITTER:\n- Max 220 characters including the link\n- One punchy insight or hook from the post\n- 1 to 2 relevant hashtags only\n- End with the post link\n- Tone: short, direct, conversational\n\nFACEBOOK:\n- Max 300 characters for the hook line\n- Start with a bold question or statement\n- 2 to 3 bullet points of what readers will learn\n- End with the post link\n- Tone: friendly, conversational\n- No more than 3 hashtags\n\nINSTAGRAM:\n- Start with a bold hook in the first 125 characters\n- 3 to 5 key takeaways as short bullet points\n- End with: Link in bio to read the full guide\n- Add 3 to 5 relevant hashtags at the bottom\n- Tone: engaging, direct, value-driven\n- Do NOT include the link in the caption body\n\nLINKEDIN:\n- Professional tone\n- Start with a bold insight or surprising statement\n- Write 3 to 4 short paragraphs:\n  Paragraph 1: the hook or problem\n  Paragraph 2: what the post covers\n  Paragraph 3: key takeaway or insight\n  Paragraph 4: call to action with the link\n- 2 to 3 professional hashtags at the end\n- Between 800 and 1200 characters total\n\n# Output Format\nReturn ONLY a valid JSON object.\nNo explanation. No markdown. No extra text.\nJust the raw JSON like this:\n\n{\n  \"twitter\": \"your twitter caption here\",\n  \"facebook\": \"your facebook caption here\",\n  \"instagram\": \"your instagram caption here\",\n  \"linkedin\": \"your linkedin caption here\"\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "66af76e5-3bbb-4f00-afca-aaf471ea68cf",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1040,
        240
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"twitter\": \"string\",\n  \"facebook\": \"string\",\n  \"instagram\": \"string\",\n  \"linkedin\": \"string\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "8c6f0b78-541a-4072-a70e-1e98ee6b3823",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        912,
        240
      ],
      "parameters": {
        "model": "openai/gpt-4o",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b1961efd-2123-44fe-b85c-55666c5a5446",
      "name": "Create Tweet",
      "type": "n8n-nodes-base.twitter",
      "position": [
        1408,
        -272
      ],
      "parameters": {
        "text": "={{ $json.output.twitter }}",
        "additionalFields": {}
      },
      "credentials": {
        "twitterOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c2f0c3db-a8b0-459e-921c-fdcb63dcdc63",
      "name": "Create a post",
      "type": "n8n-nodes-base.linkedIn",
      "position": [
        1600,
        400
      ],
      "parameters": {
        "text": "={{ $json.output.linkedin }}",
        "postAs": "organization",
        "organization": "your_org_URN",
        "additionalFields": {},
        "shareMediaCategory": "IMAGE"
      },
      "credentials": {
        "linkedInOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "991f738a-894e-4dcd-890b-3b808de9659d",
      "name": "Post on FB",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1392,
        -80
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v25.0/{{ $('Clean Data').item.json.facebook_page_id }}/photos",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "={{ $json.output.facebook }}"
            },
            {
              "name": "url",
              "value": "={{ $('Clean Data').item.json.post_thumbnail }}"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "c5855820-3179-46b8-95e7-c188b12ddfba",
      "name": "Create Media Container",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1392,
        96
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v25.0/{{ $('Clean Data').item.json.instagram_id }}/media",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "caption",
              "value": "={{ $json.output.instagram }}"
            },
            {
              "name": "image_url",
              "value": "={{ $('Clean Data').item.json.post_thumbnail }}"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "92ead471-dfcc-45c7-8b77-b2c8032f98a3",
      "name": "Post On IG",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1600,
        96
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v25.0/{{ $('Clean Data').item.json.instagram_id }}/media_publish",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "creation_id",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "bb161802-79a5-4459-9ca5-fcc0b3b06c6b",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1376,
        400
      ],
      "parameters": {
        "url": "={{ $('Clean Data').item.json.post_thumbnail }}",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "50912aa0-9900-45f8-b43c-b1904fa2b258",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -336
      ],
      "parameters": {
        "width": 480,
        "height": 608,
        "content": "## AI Agent for Auto Posting WordPress Blogs to Social Media\n\n### How it works\n\n1. The workflow starts with a webhook trigger. \n2. If conditions are met, HTML is converted to Markdown. \n3. Cleansed data is processed by an AI agent. \n4. Outputs are distributed to various social media platforms. \n5. HTTP Requests manage additional media handling for posts.\n\n### Setup steps\n\n- [ ] Set up the webhook trigger URL.\n- [ ] Configure conditional logic in the 'If' node.\n- [ ] Connect API credentials for AI, Twitter, Facebook, Instagram, and LinkedIn.\n- [ ] Ensure correct endpoint and data formatting in HTTP Request nodes.\n\n### Customization\n\nConsider modifying API endpoints or authentication methods for different platforms."
      },
      "typeVersion": 1
    },
    {
      "id": "d4aa1839-ff0b-4810-a41e-1d46d09d2336",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## Webhook Trigger and Condition\n\nInitial trigger through a webhook and conditional branching."
      },
      "typeVersion": 1
    },
    {
      "id": "cf53d3f0-6682-44ad-bf84-f9e9087fc539",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## Markdown Conversion and Clean Data\n\nConverts HTML content to markdown format and cleans up the data for AI processing."
      },
      "typeVersion": 1
    },
    {
      "id": "54c6939c-e695-4434-87d6-59334f2148fd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 512,
        "content": "## AI Processing\n\nProcesses cleansed data with an AI agent and generates structured output."
      },
      "typeVersion": 1
    },
    {
      "id": "787f2c8a-8de2-4f1b-9adb-0bcb7cd3702e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1328,
        -432
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 688,
        "content": "## Social Media Publishing\n\nPublishes content to various social media platforms including Twitter, Facebook, and Instagram."
      },
      "typeVersion": 1
    },
    {
      "id": "89ae2c2f-7101-4a89-80ce-5fe87ea7d467",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1328,
        288
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## LinkedIn Posting\n\nHandles the creation and management of LinkedIn posts."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "HTML To Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Create Tweet",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post on FB",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Media Container",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Data": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Tweet": {
      "main": [
        []
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Create a post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML To Markdown": {
      "main": [
        [
          {
            "node": "Clean Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create Media Container": {
      "main": [
        [
          {
            "node": "Post On IG",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}