{
 "name": "Check a social post before publishing (Postifuse preflight)",
 "nodes": [
  {
   "parameters": {},
   "name": "When clicking 'Test workflow'",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    0
   ]
  },
  {
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "a1",
       "name": "text",
       "type": "string",
       "value": "New reel is live #running #pace #marathon #training #run #10k #tips"
      },
      {
       "id": "a2",
       "name": "networks",
       "type": "array",
       "value": "[\"instagram\",\"x\",\"bluesky\",\"linkedin\"]"
      },
      {
       "id": "a3",
       "name": "media",
       "type": "array",
       "value": "[]"
      }
     ]
    },
    "options": {}
   },
   "name": "Your post",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    220,
    0
   ]
  },
  {
   "parameters": {
    "method": "POST",
    "url": "https://postifuse.com/v1/preflight",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify({ text: $json.text, networks: $json.networks, media: $json.media }) }}",
    "options": {}
   },
   "name": "Preflight (free, no key)",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    440,
    0
   ]
  },
  {
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "strict"
     },
     "conditions": [
      {
       "id": "c1",
       "leftValue": "={{ $json.ready }}",
       "rightValue": true,
       "operator": {
        "type": "boolean",
        "operation": "true",
        "singleValue": true
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   },
   "name": "Ready, as is or fixed?",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2,
   "position": [
    660,
    0
   ]
  },
  {
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "f1",
       "name": "posts",
       "type": "object",
       "value": "={{ Object.fromEntries(Object.entries($json.results).map(([n, r]) => [n, r.fixed ? r.fixed.text : $('Your post').item.json.text])) }}"
      },
      {
       "id": "f2",
       "name": "corrected",
       "type": "string",
       "value": "={{ $json.summary }}"
      }
     ]
    },
    "options": {}
   },
   "name": "Final text per network",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    880,
    -100
   ]
  },
  {
   "parameters": {},
   "name": "Publish here (your nodes)",
   "type": "n8n-nodes-base.noOp",
   "typeVersion": 1,
   "position": [
    1120,
    -100
   ]
  },
  {
   "parameters": {
    "errorMessage": "={{ $json.summary }}"
   },
   "name": "Stop: needs a person",
   "type": "n8n-nodes-base.stopAndError",
   "typeVersion": 1,
   "position": [
    1120,
    100
   ]
  }
 ],
 "connections": {
  "When clicking 'Test workflow'": {
   "main": [
    [
     {
      "node": "Your post",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Your post": {
   "main": [
    [
     {
      "node": "Preflight (free, no key)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Preflight (free, no key)": {
   "main": [
    [
     {
      "node": "Ready, as is or fixed?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Ready, as is or fixed?": {
   "main": [
    [
     {
      "node": "Final text per network",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Stop: needs a person",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Final text per network": {
   "main": [
    [
     {
      "node": "Publish here (your nodes)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 }
}
