{
  "name": "ساخت عکس حرفه‌ای فارسی با هوش مصنوعی + انتشار خودکار اینستاگرام — v3.1",
  "nodes": [
    {
      "parameters": {
        "content": "# 📘 ساخت عکس حرفه‌ای فارسی با هوش مصنوعی + انتشار خودکار اینستاگرام — نسخه 3.1\n\n## این ورکفلو چه می‌کند؟\n### بخش ۱ — انتشار فایل آماده\nبا **یک فرم** و فقط **لینک فایل + کپشن**، این‌ها را در اینستاگرام منتشر می‌کند:\n- 🖼 **پست عکس** — 🎬 **ریلز** — 📱 **استوری عکس** — 📱 **استوری ویدیو**\n\nلینک **Google Drive** و **Dropbox** خودکار به لینک مستقیم تبدیل می‌شود؛ لازم نیست فایل را جایی آپلود کنید.\n\n### بخش ۲ — ساخت عکس حرفه‌ای فارسی با هوش مصنوعی ✨\nفرم دوم (**AI Content Form**): موضوع و اطلاعات برند را می‌دهید؛ **GPT Image 2** از طریق **OpenRouter** یک تصویر حرفه‌ای با نوشته می‌سازد، کپشن هم نوشته می‌شود و پست یا استوری منتشر می‌شود (یا فقط پیش‌نمایش).\n\n\n### بخش ۳ — ویرایش عکس شما با هوش مصنوعی 🪄\nفرم سوم (**AI Edit Form**): یک عکس ساده می‌دهید و می‌گویید چه تغییری بخواهد؛ هوش مصنوعی آن را حرفه‌ای می‌کند، متن فارسی اضافه می‌کند، کپشن می‌نویسد و منتشر می‌کند.\n\nجزئیات بخش ۲ و ۳ در یادداشت‌های پایین 👇\n\n## مسیر کلی\n```\nفرم → ⚙️ تنظیمات → آماده‌سازی (تبدیل لینک + بررسی)\n   → ساخت کانتینر در اینستاگرام\n   → ⏳ صبر ۱۵ ثانیه → بررسی وضعیت ─┐\n        ↑   هنوز آماده نیست ───────────┘\n        آماده شد → انتشار → دریافت لینک پست ✅\n        خطا / بیش از ۱۰ دقیقه → پیام خطای فارسی ❌\n```\n\n## پیش‌نیازها\n- حساب اینستاگرام **Business** یا **Creator** متصل به یک **Facebook Page**\n- یک اپ در **developers.facebook.com** و یک **Access Token** با دسترسی‌های:\n  `instagram_basic` · `instagram_content_publish` · `pages_show_list` · `pages_read_engagement` · `business_management`\n\n## راه‌اندازی سریع\n1. اعتبارنامه‌ی **Facebook Graph API** بساز و Access Token را بگذار (در هر ۴ گره Graph انتخابش کن)\n2. در گره **⚙️ Settings** شناسه‌ی حساب اینستاگرام (`ig_user_id`) را وارد کن\n3. برای بخش هوش مصنوعی: اعتبارنامه‌ی **OpenRouter** (Header Auth) و **ImgBB** (Query Auth) را بساز\n4. ورکفلو را **Active** کن و **Production URL** هر سه فرم را بوکمارک کن\n\n---\nطراحی و آموزش: **مرتضی عظیمی** — mortezaazimi.ir",
        "height": 1300,
        "width": 640,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1240,
        -620
      ],
      "id": "a2fbb772-7863-45fd-a02f-04978f794a47",
      "name": "📘 راهنمای کلی"
    },
    {
      "parameters": {
        "content": "## 1️⃣ فرم و تنظیمات\n\n**Instagram Post Form** — سه فیلد:\n- **نوع محتوا** — پست عکس / ریلز / استوری عکس / استوری ویدیو\n- **لینک فایل** — لینک Drive، Dropbox یا هر لینک مستقیم\n- **کپشن** — برای استوری استفاده نمی‌شود\n\n**⚙️ Settings** — فقط یک بار:\n`ig_user_id` = شناسه‌ی عددی حساب اینستاگرام Business\n\n💡 پیدا کردن شناسه: در Graph API Explorer این را اجرا کن:\n`me/accounts?fields=instagram_business_account{id,username}`",
        "height": 760,
        "width": 440,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -500
      ],
      "id": "18d37017-3522-4185-94ee-7737da5973cc",
      "name": "۱ — فرم و تنظیمات"
    },
    {
      "parameters": {
        "content": "## 2️⃣ آماده‌سازی\n\n**Prepare Post** (کد):\n- لینک **Google Drive** را به لینک دانلود مستقیم تبدیل می‌کند\n- لینک **Dropbox** را به `raw=1` تبدیل می‌کند\n- کپشن را بررسی می‌کند: حداکثر ۲۲۰۰ کاراکتر و ۳۰ هشتگ\n- پارامترهای درست هر نوع محتوا را می‌سازد\n\n⚠️ فایل Drive باید روی **Anyone with the link** باشد.\n⚠️ عکس فقط **JPEG**؛ ویدیو **MP4/MOV**.",
        "height": 760,
        "width": 380,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -500
      ],
      "id": "b173a985-9a62-4a6e-835d-1e562a7c6f32",
      "name": "۲ — آماده‌سازی"
    },
    {
      "parameters": {
        "content": "## 3️⃣ ساخت کانتینر و صبر هوشمند\n\n1. **Create Container** — فایل را به اینستاگرام معرفی می‌کند؛ اینستاگرام خودش آن را از لینک دانلود می‌کند\n2. **Wait 15s** — ۱۵ ثانیه صبر\n3. **Check Status** — وضعیت پردازش را می‌پرسد\n4. **Ready?**\n   - `FINISHED` → انتشار\n   - `ERROR` / `EXPIRED` یا بیش از ۴۰ بار (حدود ۱۰ دقیقه) → پیام خطا\n   - در غیر این صورت → دوباره صبر\n\n💡 برخلاف صبر ثابت قبلی (۳۰ و ۶۰ ثانیه)، اینجا دقیقاً تا وقتی فایل آماده شود صبر می‌کند؛ نه کمتر (خطا) و نه بیشتر (اتلاف وقت).",
        "height": 520,
        "width": 900,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        340,
        -640
      ],
      "id": "aa264bd5-4f5a-46e0-9c79-0cef7dd30180",
      "name": "۳ — ساخت و انتظار"
    },
    {
      "parameters": {
        "content": "## 4️⃣ انتشار\n\n- **Publish** — کانتینر آماده را منتشر می‌کند\n- **Get Permalink** — لینک پست منتشرشده را برمی‌گرداند (در Executions می‌بینی)\n- **Show Error** — اگر اینستاگرام فایل را رد کرد، دلیلش را به فارسی نشان می‌دهد\n\n💡 اینستاگرام برای هر حساب در ۲۴ ساعت سقف تعداد انتشار از API دارد؛ برای استفاده‌ی معمول کسب‌وکار کافی است.",
        "height": 1000,
        "width": 640,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1280,
        -640
      ],
      "id": "1011452e-69e5-42a6-9aae-cdee7d6d351e",
      "name": "۴ — انتشار"
    },
    {
      "parameters": {
        "formTitle": "انتشار در اینستاگرام",
        "formDescription": "لینک فایل (Google Drive، Dropbox یا لینک مستقیم) و کپشن را وارد کنید. عکس باید JPEG و ویدیو MP4 یا MOV باشد.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "نوع محتوا",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "پست عکس"
                  },
                  {
                    "option": "ریلز (ویدیو)"
                  },
                  {
                    "option": "استوری عکس"
                  },
                  {
                    "option": "استوری ویدیو"
                  }
                ]
              }
            },
            {
              "fieldLabel": "لینک فایل",
              "requiredField": true,
              "placeholder": "https://drive.google.com/file/d/..."
            },
            {
              "fieldLabel": "کپشن",
              "fieldType": "textarea",
              "placeholder": "متن کپشن و هشتگ‌ها (برای استوری لازم نیست)"
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "buttonLabel": "انتشار در اینستاگرام"
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -500,
        -100
      ],
      "id": "d45134d2-9db2-487b-a502-836ce1b1f624",
      "name": "Instagram Post Form",
      "webhookId": "7e5a4ffc-833c-4aa2-8635-3ba7d6c34f75"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "26426ea0-fcb4-4432-bfad-e0cd1ce7df26",
              "name": "ig_user_id",
              "value": "YOUR_INSTAGRAM_BUSINESS_ID",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -280,
        -100
      ],
      "id": "5b952b27-efc1-4b03-99be-13595a9d036d",
      "name": "⚙️ Settings"
    },
    {
      "parameters": {
        "jsCode": "// ─────────────────────────────────────────────────────────────\n// آماده‌سازی انتشار: تبدیل لینک، بررسی خطاها و ساخت پارامترهای اینستاگرام\n// ─────────────────────────────────────────────────────────────\nconst f = $input.first().json;\n\n// ۱) شناسه‌ی حساب اینستاگرام از گره ⚙️ Settings\nconst igUserId = String(f.ig_user_id || '').trim();\nif (!/^\\d{5,}$/.test(igUserId)) {\n  throw new Error('شناسه‌ی حساب اینستاگرام (ig_user_id) را در گره «⚙️ Settings» وارد کنید. فقط عدد است.');\n}\n\n// ۲) تبدیل لینک اشتراک‌گذاری به لینک مستقیم دانلود\nlet url = String(f['لینک فایل'] || '').trim();\nconst drive = url.match(/drive\\.google\\.com\\/(?:file\\/d\\/|open\\?id=|uc\\?(?:[^#]*&)?id=)([\\w-]{10,})/);\nif (drive) {\n  url = `https://drive.usercontent.google.com/download?id=${drive[1]}&export=download&confirm=t`;\n} else if (/dropbox\\.com\\//.test(url)) {\n  url = url.replace(/([?&])dl=0\\b/, '$1raw=1');\n  if (!/[?&](raw|dl)=1\\b/.test(url)) url += (url.includes('?') ? '&' : '?') + 'raw=1';\n}\nif (!/^https:\\/\\/\\S+$/i.test(url)) {\n  throw new Error('لینک فایل باید با https:// شروع شود و برای همه قابل دانلود باشد (در Google Drive: Anyone with the link).');\n}\n\n// ۳) نوع محتوا\nconst type = String(f['نوع محتوا'] || '');\nconst TYPES = {\n  'پست عکس':      { urlParam: 'image_url' },\n  'ریلز (ویدیو)': { urlParam: 'video_url', media_type: 'REELS' },\n  'استوری عکس':   { urlParam: 'image_url', media_type: 'STORIES' },\n  'استوری ویدیو': { urlParam: 'video_url', media_type: 'STORIES' },\n};\nconst t = TYPES[type];\nif (!t) throw new Error('نوع محتوا نامعتبر است: ' + type);\n\n// ۴) کپشن (استوری کپشن ندارد)\nconst caption = String(f['کپشن'] || '').trim();\nconst isStory = t.media_type === 'STORIES';\nif (!isStory) {\n  if (caption.length > 2200) throw new Error(`کپشن ${caption.length} کاراکتر است؛ سقف اینستاگرام ۲۲۰۰ کاراکتر است.`);\n  const tags = (caption.match(/#[^\\s#]+/g) || []).length;\n  if (tags > 30) throw new Error(`کپشن ${tags} هشتگ دارد؛ اینستاگرام حداکثر ۳۰ هشتگ قبول می‌کند.`);\n}\n\n// ۵) پارامترهای ساخت کانتینر\nconst params = { [t.urlParam]: url };\nif (t.media_type) params.media_type = t.media_type;\nif (caption && !isStory) params.caption = caption;\nif (t.media_type === 'REELS') params.share_to_feed = 'true';\n\nreturn [{ json: { ig_user_id: igUserId, type, mediaUrl: url, params } }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        80,
        -100
      ],
      "id": "b869dc99-8646-44bb-8aed-3485bf4c9323",
      "name": "Prepare Post"
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "graphApiVersion": "v23.0",
        "node": "={{ $json.ig_user_id }}",
        "edge": "media",
        "options": {
          "queryParametersJson": "={{ JSON.stringify($json.params) }}"
        }
      },
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        400,
        -100
      ],
      "id": "2099e52f-edb0-4fe9-84f9-4c84d4a4030d",
      "name": "Create Container"
    },
    {
      "parameters": {
        "amount": 15,
        "unit": "seconds"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        620,
        -100
      ],
      "id": "73297708-f295-40fd-b2c6-9dbf13ced278",
      "name": "Wait 15s",
      "webhookId": "908c13cb-5058-4bed-b272-69e8821b0203"
    },
    {
      "parameters": {
        "httpRequestMethod": "GET",
        "graphApiVersion": "v23.0",
        "node": "={{ $('Create Container').item.json.id }}",
        "edge": "",
        "options": {
          "fields": {
            "field": [
              {
                "name": "status_code"
              },
              {
                "name": "status"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        840,
        -100
      ],
      "id": "c953e256-b2bb-4360-907a-819a6eae53e3",
      "name": "Check Status"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "5b264bf9-1206-4856-8814-5d8ebf24883d",
                    "leftValue": "={{ $json.status_code }}",
                    "rightValue": "FINISHED",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "or"
              },
              "renameOutput": true,
              "outputKey": "Ready"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d732f1ca-a7c9-4718-9ea1-1b9fabe5a42d",
                    "leftValue": "={{ $json.status_code }}",
                    "rightValue": "ERROR",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  },
                  {
                    "id": "963cefab-a48a-451d-98df-3ea376a6457b",
                    "leftValue": "={{ $json.status_code }}",
                    "rightValue": "EXPIRED",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  },
                  {
                    "id": "f0d8096e-3aed-44dc-adda-3a665ecf125e",
                    "leftValue": "={{ $runIndex >= 40 }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "or"
              },
              "renameOutput": true,
              "outputKey": "Failed"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Processing"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1060,
        -100
      ],
      "id": "bd665ee1-8897-4377-baba-3cc47e2527d6",
      "name": "Ready?"
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "graphApiVersion": "v23.0",
        "node": "={{ $('Prepare AI Post').isExecuted ? $('Prepare AI Post').item.json.ig_user_id : $('Prepare Post').item.json.ig_user_id }}",
        "edge": "media_publish",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "creation_id",
                "value": "={{ $('Create Container').item.json.id }}"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        1360,
        -260
      ],
      "id": "ce2bbfe0-e635-4ab5-b99b-4e781453e79c",
      "name": "Publish"
    },
    {
      "parameters": {
        "httpRequestMethod": "GET",
        "graphApiVersion": "v23.0",
        "node": "={{ $json.id }}",
        "edge": "",
        "options": {
          "fields": {
            "field": [
              {
                "name": "permalink"
              },
              {
                "name": "media_type"
              },
              {
                "name": "timestamp"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        1580,
        -260
      ],
      "id": "56e511c4-9d15-4890-871a-76474bedd6c1",
      "name": "Get Permalink"
    },
    {
      "parameters": {
        "errorMessage": "={{ ['ERROR','EXPIRED'].includes($json.status_code) ? 'اینستاگرام فایل را قبول نکرد (' + ($json.status || $json.status_code) + '). فرمت، حجم، ابعاد یا عمومی بودن لینک را بررسی کنید.' : 'آماده‌سازی فایل در اینستاگرام بیش از ۱۰ دقیقه طول کشید. چند دقیقه بعد دوباره امتحان کنید.' }}"
      },
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1360,
        0
      ],
      "id": "9f869ddd-4eab-41cf-9ca6-428d72b4fa83",
      "name": "Show Error"
    },
    {
      "parameters": {
        "content": "## 5️⃣ ساخت تصویر و کپشن با هوش مصنوعی (OpenRouter)\n\nفرم دوم: **AI Content Form** — موضوع و اطلاعات را می‌دهی، هوش مصنوعی تصویر حرفه‌ای با نوشته می‌سازد و (اگر بخواهی) منتشر می‌کند.\n\n1. **Route by Form** — تشخیص می‌دهد کدام فرم پر شده\n2. **AI – Write Brief** — مدل `openai/gpt-5.4-mini` یک بریف طراحی دقیق (انگلیسی)، تیتر روی تصویر و کپشن فارسی می‌نویسد\n3. **AI – Generate Image** — مدل **`openai/gpt-image-2`** با کیفیت `high` و خروجی **JPEG** تصویر را می‌سازد (پست ۱:۱، استوری ۹:۱۶)\n4. **Upload to ImgBB** — اینستاگرام فقط از **لینک عمومی** فایل برمی‌دارد؛ تصویر روی ImgBB می‌رود (بعد از ۲۴ ساعت خودکار پاک می‌شود)\n5. **Prepare AI Post** — پارامترهای انتشار را می‌سازد\n6. **Publish or Preview?**\n   - «منتشر شود» → همان مسیر انتشار بالا (کانتینر → صبر هوشمند → انتشار)\n   - «فقط پیش‌نمایش» → صفحه‌ی پیش‌نمایش با تصویر و کپشن، **بدون انتشار**\n\n🔑 اعتبارنامه‌ها:\n- **Header Auth «OpenRouter»**: Name `Authorization` / Value `Bearer sk-or-...`\n- **Query Auth «ImgBB»**: Name `key` / Value کلید رایگان از api.imgbb.com\n\n⚠️ متن فارسی روی تصویر گاهی ممکن است ایراد داشته باشد؛ متن کوتاه بدهید و اول با «فقط پیش‌نمایش» امتحان کنید.\n💰 هزینه‌ی هر تصویر در خروجی `AI – Generate Image` در فیلد `usage.cost` (دلار) دیده می‌شود.",
        "height": 1200,
        "width": 640,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1240,
        720
      ],
      "id": "47d4fed1-8d58-44ca-99c1-4d79f1b9bdd2",
      "name": "۵ — ساخت محتوا با هوش مصنوعی"
    },
    {
      "parameters": {
        "content": "## 🏁 صفحه‌ی نتیجه\n\nبعد از ارسال هر فرم، کاربر روی صفحه‌ی «در حال پردازش» می‌ماند و در آخر این‌ها را می‌بیند:\n- **Result Page** — «منتشر شد» + لینک پست (و تصویر، اگر با هوش مصنوعی ساخته شده باشد)\n- **Preview Page** — تصویر و کپشن ساخته‌شده، بدون انتشار",
        "height": 1000,
        "width": 380,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1940,
        -640
      ],
      "id": "ddfa6d25-f852-4978-bb07-ff13ebbfda8a",
      "name": "صفحه‌ی نتیجه"
    },
    {
      "parameters": {
        "formTitle": "ساخت محتوای اینستاگرام با هوش مصنوعی",
        "formDescription": "موضوع و اطلاعات را بنویسید؛ هوش مصنوعی یک تصویر حرفه‌ای با نوشته و کپشن می‌سازد. ساخت تصویر معمولاً ۳۰ تا ۹۰ ثانیه طول می‌کشد؛ این صفحه را نبندید.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "قالب",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "پست (مربع ۱:۱)"
                  },
                  {
                    "option": "استوری (عمودی ۹:۱۶)"
                  }
                ]
              }
            },
            {
              "fieldLabel": "موضوع و پیام اصلی",
              "fieldType": "textarea",
              "requiredField": true,
              "placeholder": "مثلاً: جشنواره ۳۰٪ تخفیف کفش‌های پاییزه تا پایان هفته، ارسال رایگان"
            },
            {
              "fieldLabel": "متن دقیق روی تصویر",
              "placeholder": "اختیاری — اگر خالی باشد، هوش مصنوعی یک تیتر کوتاه می‌نویسد"
            },
            {
              "fieldLabel": "اطلاعات برند",
              "fieldType": "textarea",
              "placeholder": "اختیاری — نام برند، رنگ‌های سازمانی، شماره تماس، سایت، حال‌وهوای برند"
            },
            {
              "fieldLabel": "سبک تصویر",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "مینیمال و مدرن"
                  },
                  {
                    "option": "عکس محصول واقعی"
                  },
                  {
                    "option": "تایپوگرافی پررنگ"
                  },
                  {
                    "option": "تصویرسازی رنگی"
                  },
                  {
                    "option": "لوکس و تیره"
                  }
                ]
              }
            },
            {
              "fieldLabel": "زبان متن تصویر",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "فارسی"
                  },
                  {
                    "option": "English"
                  }
                ]
              }
            },
            {
              "fieldLabel": "بعد از ساخت",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "فقط پیش‌نمایش (منتشر نشود)"
                  },
                  {
                    "option": "منتشر شود"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "buttonLabel": "ساخت تصویر ✨"
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -500,
        460
      ],
      "id": "f4b9946d-d10c-4126-abbc-a3e72521fdff",
      "name": "AI Content Form",
      "webhookId": "5497ff1a-52b9-4a4e-9126-ae30ae363e8a"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "a7155052-6b14-4eaf-a77e-27fc114e59db",
                    "leftValue": "={{ !!$json.photo_data_url }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "or"
              },
              "renameOutput": true,
              "outputKey": "Edit Photo"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "ebdfc5ba-d313-4d78-b271-df58a2d5e783",
                    "leftValue": "={{ !!$json['موضوع و پیام اصلی'] }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "or"
              },
              "renameOutput": true,
              "outputKey": "Create Image"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Publish File"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -150,
        -100
      ],
      "id": "c0c145a0-bf71-430d-ad5e-384af559944b",
      "name": "Route by Form"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Title",
              "value": "n8n Instagram AI"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  model: 'openai/gpt-5.4-mini',\n  response_format: { type: 'json_object' },\n  messages: [\n    { role: 'system', content: \"You are a senior art director and Instagram copywriter for small and medium businesses.\\nFrom the user's brief, return ONE JSON object with exactly these keys:\\n- \\\"headline\\\": the exact short text to render on the image (max 7 words). If the user gave exact text, use it unchanged.\\n- \\\"image_prompt\\\": a detailed ENGLISH prompt for an image model (gpt-image). Describe subject, composition, lighting, color palette, typography style and layout. Put the headline (and any phone/website the user gave) in double quotes and say exactly where and how it must appear. If the text language is Persian, say: \\\"render the quoted text in correct Persian (Farsi) script, right-to-left, with properly connected letters, large and perfectly legible\\\". Ask for clean, professional, high-end advertising design with strong hierarchy and generous margins. For a story (9:16) keep all text inside the central safe area, away from the top and bottom 15%. Never include brand logos of other companies.\\n- \\\"caption\\\": an Instagram caption in Persian for a feed post: a strong first-line hook, 2-4 short lines of value, a clear call to action, then 5-10 relevant Persian/English hashtags. For a story, return an empty string.\\nReturn JSON only.\" },\n    { role: 'user', content:\n      'Format: ' + ($json['قالب'].includes('استوری') ? 'Instagram STORY, vertical 9:16' : 'Instagram FEED POST, square 1:1') + '\\n' +\n      'Topic / main message: ' + $json['موضوع و پیام اصلی'] + '\\n' +\n      'Exact text on image (may be empty): ' + ($json['متن دقیق روی تصویر'] || '') + '\\n' +\n      'Brand info: ' + ($json['اطلاعات برند'] || '-') + '\\n' +\n      'Visual style: ' + $json['سبک تصویر'] + '\\n' +\n      'Language of text on image: ' + ($json['زبان متن تصویر'] === 'English' ? 'English' : 'Persian (Farsi)')\n    }\n  ]\n}) }}",
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -60,
        460
      ],
      "id": "ccaaa292-816f-4ee2-b0c5-c19623cc4813",
      "name": "AI – Write Brief"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://openrouter.ai/api/v1/images",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Title",
              "value": "n8n Instagram AI"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ (() => {\n  const b = JSON.parse(String($json.choices[0].message.content).replace(/^```(?:json)?/i, '').replace(/```$/, '').trim());\n  const story = $('⚙️ Settings').item.json['قالب'].includes('استوری');\n  return JSON.stringify({\n    model: 'openai/gpt-image-2',\n    prompt: b.image_prompt,\n    aspect_ratio: story ? '9:16' : '1:1',\n    quality: 'high',\n    output_format: 'jpeg',\n    n: 1\n  });\n})() }}",
        "options": {
          "timeout": 300000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        460
      ],
      "id": "4a780869-2ae9-4198-b395-bafa2c6c0902",
      "name": "AI – Generate Image"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.imgbb.com/1/upload",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "expiration",
              "value": "86400"
            }
          ]
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image",
              "value": "={{ $json.data[0].b64_json }}"
            },
            {
              "name": "name",
              "value": "={{ 'ig-ai-' + $now.toFormat('yyyyLLdd-HHmmss') }}"
            }
          ]
        },
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        380,
        460
      ],
      "id": "b05eb999-7450-4a74-b3c6-2ac0283fbe76",
      "name": "Upload to ImgBB"
    },
    {
      "parameters": {
        "jsCode": "// ─────────────────────────────────────────────────────────────\n// آماده‌سازی پست هوش مصنوعی: تصویر آپلودشده + کپشن → پارامترهای اینستاگرام\n// ─────────────────────────────────────────────────────────────\nconst s = $('⚙️ Settings').first().json;\nconst isStory = String(s['قالب'] || '').includes('استوری');\nconst publish = !String(s['بعد از ساخت'] || '').includes('پیش‌نمایش');\n\n// خروجی متن‌نویس (JSON)\nlet brief = {};\ntry {\n  const briefNode = $('AI – Write Edit Brief').isExecuted ? 'AI – Write Edit Brief' : 'AI – Write Brief';\n  const raw = $(briefNode).first().json.choices?.[0]?.message?.content || '{}';\n  brief = JSON.parse(String(raw).replace(/^```(?:json)?/i, '').replace(/```$/, '').trim());\n} catch (e) { brief = {}; }\n\n// لینک عمومی تصویر (ImgBB)\nconst up = $input.first().json;\nconst url = up?.data?.url || up?.data?.display_url;\nif (!url) throw new Error('آپلود تصویر در ImgBB ناموفق بود: ' + JSON.stringify(up).slice(0, 200));\n\nlet caption = String(brief.caption || '').trim();\nif (caption.length > 2200) caption = caption.slice(0, 2190).trim() + '…';\n\nconst igUserId = String(s.ig_user_id || '').trim();\nif (publish && !/^\\d{5,}$/.test(igUserId)) {\n  throw new Error('برای انتشار، شناسه‌ی حساب اینستاگرام (ig_user_id) را در گره «⚙️ Settings» وارد کنید. حالت «فقط پیش‌نمایش» به آن نیاز ندارد.');\n}\n\nconst params = { image_url: url };\nif (isStory) params.media_type = 'STORIES';\nelse if (caption) params.caption = caption;\n\nconst imgNode = $('AI – Edit Image').isExecuted ? 'AI – Edit Image' : 'AI – Generate Image';\nconst cost = $(imgNode).first().json.usage?.cost;\nreturn [{ json: {\n  ig_user_id: igUserId, type: isStory ? 'استوری عکس' : 'پست عکس', mediaUrl: url, params,\n  publish, headline: brief.headline || '', caption, imageCostUsd: cost ?? null\n} }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        600,
        460
      ],
      "id": "b6ec1374-c03a-4e1e-8725-0ee873e18d1e",
      "name": "Prepare AI Post"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "636c95ac-d8d5-48fb-b4d7-32a12f66683f",
              "leftValue": "={{ $json.publish }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        820,
        460
      ],
      "id": "1386c654-17a7-495a-aece-d44bff43de0f",
      "name": "Publish or Preview?"
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div dir=\"rtl\" style=\"font-family:Tahoma,Vazirmatn,sans-serif;text-align:center;padding:20px;color:#1b1530\">\n<h2 style=\"margin:0 0 6px\">🎨 پیش‌نمایش آماده است</h2>\n<p style=\"color:#6b6385;margin:0 0 16px\">این تصویر منتشر نشده. اگر پسندیدید، فرم را با «منتشر شود» دوباره بفرستید یا تصویر را دانلود کنید.</p>\n<img src=\"{{ $json.mediaUrl }}\" style=\"max-width:100%;max-height:62vh;border-radius:18px;box-shadow:0 10px 30px rgba(0,0,0,.15)\">\n<p style=\"margin:14px 0 6px\"><a href=\"{{ $json.mediaUrl }}\" target=\"_blank\" style=\"color:#d62976;font-weight:bold\">باز کردن / دانلود تصویر ↗</a></p>\n{{ $json.caption ? '<div style=\"text-align:right;white-space:pre-wrap;background:#faf6fd;border-radius:14px;padding:14px;margin-top:12px;font-size:14px;line-height:1.9\">' + $json.caption.replace(/</g,'&lt;') + '</div>' : '' }}\n</div>"
      },
      "type": "n8n-nodes-base.form",
      "typeVersion": 1,
      "position": [
        1060,
        620
      ],
      "id": "18c8b2c4-aea7-4d04-bbe3-c011a81149f8",
      "name": "Preview Page",
      "webhookId": "f99ae32d-3f49-4887-a038-23365426e803"
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div dir=\"rtl\" style=\"font-family:Tahoma,Vazirmatn,sans-serif;text-align:center;padding:20px;color:#1b1530\">\n<div style=\"font-size:52px;line-height:1\">✅</div>\n<h2 style=\"margin:10px 0 6px\">در اینستاگرام منتشر شد</h2>\n<p style=\"color:#6b6385;margin:0 0 16px\">{{ $json.media_type === 'STORY' ? 'استوری شما روی پیج است.' : 'پست شما روی پیج است.' }}</p>\n{{ $('Prepare AI Post').isExecuted ? '<img src=\"' + $('Prepare AI Post').item.json.mediaUrl + '\" style=\"max-width:100%;max-height:60vh;border-radius:18px;box-shadow:0 10px 30px rgba(0,0,0,.15)\">' : '' }}\n<p style=\"margin-top:18px\"><a href=\"{{ $json.permalink }}\" target=\"_blank\" style=\"display:inline-block;padding:12px 26px;border-radius:14px;background:linear-gradient(45deg,#fa7e1e,#d62976,#962fbf);color:#fff;text-decoration:none;font-weight:bold\">مشاهده در اینستاگرام ↗</a></p>\n</div>"
      },
      "type": "n8n-nodes-base.form",
      "typeVersion": 1,
      "position": [
        2000,
        -260
      ],
      "id": "1e651ddd-c163-423a-8607-3d8a48becaa9",
      "name": "Result Page",
      "webhookId": "b82a647c-5fa7-4631-87f2-c00237acf033"
    },
    {
      "parameters": {
        "content": "## 6️⃣ ویرایش عکس شما با هوش مصنوعی\n\nفرم سوم: **AI Edit Form** — یک عکس ساده (مثلاً عکس محصول با گوشی) می‌دهید و می‌گویید چه تغییری بخواهد؛ هوش مصنوعی آن را حرفه‌ای می‌کند، متن فارسی اضافه می‌کند، کپشن می‌نویسد و منتشر می‌کند.\n\n1. **Photo → Base64** — عکس فرم را برای ارسال به هوش مصنوعی آماده می‌کند (JPG/PNG/WEBP، حداکثر ۲۰ مگ)\n2. **Route by Form** — تشخیص می‌دهد کدام فرم پر شده\n3. **AI – Write Edit Brief** — `gpt-5.4-mini` **خود عکس را می‌بیند** و دستور ویرایش دقیق (چه چیزی ثابت بماند، چه چیزی عوض شود)، تیتر و کپشن فارسی می‌نویسد\n4. **AI – Edit Image** — `gpt-image-2` با `input_references` همان عکس را ویرایش می‌کند (high، JPEG، ۱:۱ یا ۹:۱۶)\n5. بعد از آن، همان مسیر بخش ۵: **ImgBB → پیش‌نمایش یا انتشار**\n\n💡 مثال دستور: «پس‌زمینه را استودیویی سفید کن، نور حرفه‌ای بده و بالای عکس بنویس ۲۰٪ تخفیف»\n💡 در دستور بگویید چه چیزی **نباید** عوض شود (مثلاً لوگو یا رنگ محصول).",
        "height": 860,
        "width": 640,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1240,
        1960
      ],
      "id": "f3128fa8-3098-4880-af71-56c1e439fd87",
      "name": "۶ — ویرایش عکس با هوش مصنوعی"
    },
    {
      "parameters": {
        "formTitle": "ویرایش حرفه‌ای عکس با هوش مصنوعی",
        "formDescription": "یک عکس ساده بدهید و بگویید چه تغییری می‌خواهید؛ هوش مصنوعی آن را حرفه‌ای می‌کند، متن و کپشن می‌نویسد و منتشر می‌کند. ساخت معمولاً ۳۰ تا ۹۰ ثانیه طول می‌کشد؛ این صفحه را نبندید.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "قالب",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "پست (مربع ۱:۱)"
                  },
                  {
                    "option": "استوری (عمودی ۹:۱۶)"
                  }
                ]
              }
            },
            {
              "fieldLabel": "عکس اولیه",
              "fieldType": "file",
              "requiredField": true,
              "multipleFiles": false,
              "acceptFileTypes": ".jpg, .jpeg, .png, .webp"
            },
            {
              "fieldLabel": "چه تغییری می‌خواهید؟",
              "fieldType": "textarea",
              "requiredField": true,
              "placeholder": "مثلاً: پس‌زمینه را استودیویی سفید کن، نور حرفه‌ای بده و بالای عکس با فونت درشت بنویس ۲۰٪ تخفیف"
            },
            {
              "fieldLabel": "متن دقیق روی تصویر",
              "placeholder": "اختیاری — اگر خالی باشد، طبق دستور بالا عمل می‌شود"
            },
            {
              "fieldLabel": "اطلاعات برند",
              "fieldType": "textarea",
              "placeholder": "اختیاری — نام برند، رنگ‌ها، شماره تماس، سایت"
            },
            {
              "fieldLabel": "زبان متن تصویر",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "فارسی"
                  },
                  {
                    "option": "English"
                  }
                ]
              }
            },
            {
              "fieldLabel": "بعد از ساخت",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "فقط پیش‌نمایش (منتشر نشود)"
                  },
                  {
                    "option": "منتشر شود"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "buttonLabel": "ویرایش عکس ✨"
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -560,
        760
      ],
      "id": "b4d4ff06-9be4-4302-84f2-84770de00f67",
      "name": "AI Edit Form",
      "webhookId": "e98a6452-ae3e-4cdd-9aaa-a841d250b17e"
    },
    {
      "parameters": {
        "jsCode": "// ─────────────────────────────────────────────────────────────\n// عکس آپلودشده در فرم → Data URL (برای ارسال به هوش مصنوعی)\n// ─────────────────────────────────────────────────────────────\nconst item = $input.first();\nconst key = Object.keys(item.binary || {})[0];\nif (!key) throw new Error('عکس اولیه آپلود نشده است.');\nconst meta = item.binary[key];\nif (!/^image\\/(jpeg|png|webp)$/.test(meta.mimeType || '')) {\n  throw new Error('فرمت عکس باید JPG، PNG یا WEBP باشد. فرمت فعلی: ' + meta.mimeType);\n}\nconst buf = await this.helpers.getBinaryDataBuffer(0, key);\nif (buf.length > 20 * 1024 * 1024) throw new Error('حجم عکس بیش از ۲۰ مگابایت است؛ عکس کوچک‌تری بفرستید.');\nreturn [{ json: { ...item.json, photo_data_url: `data:${meta.mimeType};base64,${buf.toString('base64')}` } }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -340,
        760
      ],
      "id": "8d974cb7-82c4-46e4-b077-d906a6a9469f",
      "name": "Photo → Base64"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Title",
              "value": "n8n Instagram AI"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  model: 'openai/gpt-5.4-mini',\n  response_format: { type: 'json_object' },\n  messages: [\n    { role: 'system', content: \"You are a senior retoucher, art director and Instagram copywriter for small and medium businesses.\\nYou receive the user's ORIGINAL PHOTO and their edit request. Return ONE JSON object with exactly these keys:\\n- \\\"headline\\\": the exact short text to place on the image (max 7 words). If the user gave exact text, use it unchanged. If the request needs no text, return \\\"\\\".\\n- \\\"edit_prompt\\\": precise ENGLISH instructions for an image-editing model (gpt-image) that receives the original photo. Start with \\\"Edit the provided photo.\\\" Say clearly what must stay IDENTICAL (the product's shape, colors, logo, label and details; people's faces and identity) and what must change (background, lighting, retouching, layout, added elements). Describe a clean, high-end, professional advertising result. If there is a headline (or a phone/website from the brand info), put it in double quotes and say exactly where and how it appears; if the text language is Persian, say: \\\"render the quoted text in correct Persian (Farsi) script, right-to-left, with properly connected letters, large and perfectly legible\\\". For a story (9:16) keep text inside the central safe area, away from the top and bottom 15%. Never add other companies' logos.\\n- \\\"caption\\\": an Instagram caption in Persian for a feed post, based on what you see in the photo and the request: a strong first-line hook, 2-4 short lines of value, a clear call to action, then 5-10 relevant hashtags. For a story, return \\\"\\\".\\nReturn JSON only.\" },\n    { role: 'user', content: [\n      { type: 'text', text:\n        'Format: ' + ($json['قالب'].includes('استوری') ? 'Instagram STORY, vertical 9:16' : 'Instagram FEED POST, square 1:1') + '\\n' +\n        'Edit request: ' + $json['چه تغییری می‌خواهید؟'] + '\\n' +\n        'Exact text on image (may be empty): ' + ($json['متن دقیق روی تصویر'] || '') + '\\n' +\n        'Brand info: ' + ($json['اطلاعات برند'] || '-') + '\\n' +\n        'Language of text on image: ' + ($json['زبان متن تصویر'] === 'English' ? 'English' : 'Persian (Farsi)') },\n      { type: 'image_url', image_url: { url: $json.photo_data_url } }\n    ] }\n  ]\n}) }}",
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -60,
        760
      ],
      "id": "086eb5ba-b7c2-4623-8e2f-a36888b9ecfa",
      "name": "AI – Write Edit Brief"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://openrouter.ai/api/v1/images",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Title",
              "value": "n8n Instagram AI"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ (() => {\n  const b = JSON.parse(String($json.choices[0].message.content).replace(/^```(?:json)?/i, '').replace(/```$/, '').trim());\n  const s = $('⚙️ Settings').item.json;\n  return JSON.stringify({\n    model: 'openai/gpt-image-2',\n    prompt: b.edit_prompt,\n    input_references: [{ type: 'image_url', image_url: { url: s.photo_data_url } }],\n    aspect_ratio: s['قالب'].includes('استوری') ? '9:16' : '1:1',\n    quality: 'high',\n    output_format: 'jpeg',\n    n: 1\n  });\n})() }}",
        "options": {
          "timeout": 300000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        760
      ],
      "id": "9b502ee0-3483-401f-abb8-62974c61038d",
      "name": "AI – Edit Image"
    }
  ],
  "pinData": {},
  "connections": {
    "Instagram Post Form": {
      "main": [
        [
          {
            "node": "⚙️ Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Content Form": {
      "main": [
        [
          {
            "node": "⚙️ Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Edit Form": {
      "main": [
        [
          {
            "node": "Photo → Base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Photo → Base64": {
      "main": [
        [
          {
            "node": "⚙️ Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "⚙️ Settings": {
      "main": [
        [
          {
            "node": "Route by Form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Form": {
      "main": [
        [
          {
            "node": "AI – Write Edit Brief",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI – Write Brief",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI – Write Edit Brief": {
      "main": [
        [
          {
            "node": "AI – Edit Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI – Edit Image": {
      "main": [
        [
          {
            "node": "Upload to ImgBB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Post": {
      "main": [
        [
          {
            "node": "Create Container",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI – Write Brief": {
      "main": [
        [
          {
            "node": "AI – Generate Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI – Generate Image": {
      "main": [
        [
          {
            "node": "Upload to ImgBB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to ImgBB": {
      "main": [
        [
          {
            "node": "Prepare AI Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare AI Post": {
      "main": [
        [
          {
            "node": "Publish or Preview?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Publish or Preview?": {
      "main": [
        [
          {
            "node": "Create Container",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Preview Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Permalink": {
      "main": [
        [
          {
            "node": "Result Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Container": {
      "main": [
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 15s": {
      "main": [
        [
          {
            "node": "Check Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Status": {
      "main": [
        [
          {
            "node": "Ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ready?": {
      "main": [
        [
          {
            "node": "Publish",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Show Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Publish": {
      "main": [
        [
          {
            "node": "Get Permalink",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}