{
  "name": "تولید محتوای وردپرس با هوش مصنوعی (Gemini) — v2.0",
  "nodes": [
    {
      "parameters": {
        "content": "# 📘 تولید محتوای وردپرس با هوش مصنوعی — نسخه ساده\n\nیک فرم → **مقاله‌ی کوتاه** یا **توضیحات محصول ووکامرس** با Gemini → ثبت مستقیم در سایت.\n\n```\nفرم → پرامپت شما → Gemini → آماده‌سازی → مقاله؟\n                                    ├─ بله → ساخت نوشته در وردپرس\n                                    └─ نه  → ساخت محصول در ووکامرس\n                                         → صفحه‌ی نتیجه + لینک\n```\n\n## راه‌اندازی در ۴ قدم\n1. **Import** همین فایل در n8n\n2. گره **✏️ Your Prompts**: پرامپت دلخواه خود را بنویسید\n3. اعتبارنامه‌ها را بسازید (جدول پایین)\n4. ورکفلو را **Active** کنید و آدرس فرم را باز کنید\n\n## اعتبارنامه‌ها\n| نوع | کجا | مقدار |\n|---|---|---|\n| Header Auth «Gemini API Key» | Gemini – Write | `x-goog-api-key` = کلید Gemini |\n| WordPress API | Create Post | نام کاربری + **Application Password** |\n| WooCommerce API | Create Product | Consumer Key / Secret |\n\n💡 فقط مقاله لازم دارید؟ گره Create Product را حذف کنید (و برعکس).\n\n---\nطراحی و آموزش: **مرتضی عظیمی** — mortezaazimi.ir",
        "height": 1000,
        "width": 620,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1080,
        -460
      ],
      "id": "f26368f9-b718-4dc2-994c-0e67d0e076af",
      "name": "📘 راهنمای کلی"
    },
    {
      "parameters": {
        "content": "## 1️⃣ فرم و پرامپت شما\n\n**WordPress Content Form**\n- نوع محتوا: مقاله / محصول\n- موضوع یا نام محصول\n- کلمه‌ی کلیدی اصلی (اختیاری)\n- قیمت محصول (اختیاری، به واحد پول فروشگاه)\n- وضعیت: پیش‌نویس / انتشار\n\n**✏️ Your Prompts** ← ⭐ مهم‌ترین گره\n- `articlePrompt` — پرامپت مقاله\n- `productPrompt` — پرامپت محصول\n\nلحن، طول، ساختار و قواعد سئو را هر طور می‌خواهید بنویسید. قالب خروجی (JSON و HTML تمیز) خودکار اضافه می‌شود و لازم نیست درباره‌اش چیزی بنویسید.",
        "height": 780,
        "width": 460,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -460
      ],
      "id": "3cecbc70-2233-4464-983a-30167d7e579d",
      "name": "۱ — فرم و پرامپت"
    },
    {
      "parameters": {
        "content": "## 2️⃣ نوشتن با Gemini\n\n**Gemini – Write** پرامپت شما + موضوع فرم را می‌فرستد و خروجی را **حتماً** به شکل JSON می‌گیرد:\n`title` · `content` (HTML تمیز) · `summary` · `slug`\n\n**Parse Content** خروجی را می‌خواند، اسلاگ را تمیز می‌کند و قیمت فارسی را به عدد تبدیل می‌کند.\n\n💡 مدل: `gemini-3.5-flash-lite` — برای متن قوی‌تر در URL گره بنویسید `gemini-3.8-flash`.",
        "height": 780,
        "width": 460,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        80,
        -460
      ],
      "id": "ad7b6c72-adea-4546-8898-f29301abe185",
      "name": "۲ — نوشتن"
    },
    {
      "parameters": {
        "content": "## 3️⃣ ثبت در سایت\n\n- **Create Post** — عنوان، متن HTML، اسلاگ و وضعیت\n- **Create Product** — نام، توضیحات کامل، توضیح کوتاه، قیمت، اسلاگ و وضعیت\n- **Done Page** — نتیجه و لینک مشاهده\n\n⚠️ وردپرس: در **کاربران ← پروفایل ← Application Passwords** یک رمز بسازید (رمز اصلی کار نمی‌کند).\n⚠️ ووکامرس: **ووکامرس ← تنظیمات ← پیشرفته ← REST API** کلید با دسترسی **Read/Write** بسازید.",
        "height": 780,
        "width": 640,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        580,
        -460
      ],
      "id": "12b8675b-b7b7-43ac-8b63-3087ecad4ec3",
      "name": "۳ — ثبت در سایت"
    },
    {
      "parameters": {
        "formTitle": "تولید محتوای وردپرس",
        "formDescription": "موضوع مقاله یا نام محصول را بدهید؛ هوش مصنوعی متن را می‌نویسد و مستقیم در سایت ثبت می‌کند.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "نوع محتوا",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "مقاله"
                  },
                  {
                    "option": "محصول ووکامرس"
                  }
                ]
              }
            },
            {
              "fieldLabel": "موضوع یا نام محصول",
              "requiredField": true,
              "placeholder": "مثلاً: راهنمای انتخاب کفش کوهنوردی"
            },
            {
              "fieldLabel": "کلمه‌ی کلیدی اصلی",
              "placeholder": "اختیاری"
            },
            {
              "fieldLabel": "قیمت محصول",
              "placeholder": "اختیاری — فقط برای محصول"
            },
            {
              "fieldLabel": "وضعیت",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "پیش‌نویس"
                  },
                  {
                    "option": "انتشار"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "buttonLabel": "بنویس و ثبت کن ✨"
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -360,
        40
      ],
      "id": "be672c82-a0c1-4e73-b60b-b14d8e16a742",
      "name": "WordPress Content Form",
      "webhookId": "df3a58ea-c4c7-46ca-851a-26f8f4bd5538"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0ae90908-e7af-4ad3-9bef-b7cda290a623",
              "name": "articlePrompt",
              "value": "[پرامپت دلخواه خود را برای نوشتن مقاله اینجا بنویسید]",
              "type": "string"
            },
            {
              "id": "e1553c31-04ed-4f36-a878-cdc4a197702d",
              "name": "productPrompt",
              "value": "[پرامپت دلخواه خود را برای نوشتن توضیحات محصول اینجا بنویسید]",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -140,
        40
      ],
      "id": "f338e617-22ba-4c9e-aa9f-61110d2fd89c",
      "name": "✏️ Your Prompts"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash-lite:generateContent",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  systemInstruction: { parts: [{ text:\n    ($('WordPress Content Form').first().json['نوع محتوا'].includes('محصول') ? $('✏️ Your Prompts').first().json.productPrompt : $('✏️ Your Prompts').first().json.articlePrompt) + '\\n\\n' + \"Output rules (technical, do not ignore): Return JSON only. Write in Persian (fa-IR) with correct half-spaces. \\\"title\\\": the title. \\\"content\\\": the body as clean HTML using only <h2>, <h3>, <p>, <ul>, <ol>, <li>, <strong>, <em> (no <h1>, no markdown, no images). \\\"summary\\\": one or two sentence summary. \\\"slug\\\": a short Latin kebab-case slug.\"\n  }] },\n  contents: [{ role: 'user', parts: [{ text:\n    ($('WordPress Content Form').first().json['نوع محتوا'].includes('محصول') ? 'محصول: ' : 'موضوع مقاله: ') + $('WordPress Content Form').first().json['موضوع یا نام محصول'] +\n    ($('WordPress Content Form').first().json['کلمه‌ی کلیدی اصلی'] ? '\\nکلمه‌ی کلیدی اصلی: ' + $('WordPress Content Form').first().json['کلمه‌ی کلیدی اصلی'] : '')\n  }] }],\n  generationConfig: {\n    responseMimeType: 'application/json',\n    responseSchema: { type: 'OBJECT', properties: {\n      title: { type: 'STRING' }, content: { type: 'STRING' }, summary: { type: 'STRING' }, slug: { type: 'STRING' }\n    }, required: ['title', 'content', 'slug'] }\n  }\n}) }}",
        "options": {
          "timeout": 90000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        140,
        40
      ],
      "id": "2d619a89-6f53-4459-b2ce-372cfe04904a",
      "name": "Gemini – Write"
    },
    {
      "parameters": {
        "jsCode": "// خروجی Gemini را می‌خواند و برای وردپرس / ووکامرس آماده می‌کند\nconst f = $('WordPress Content Form').first().json;\nconst parts = $input.first().json.candidates?.[0]?.content?.parts || [];\nconst raw = parts.filter(p => p.text && !p.thought).map(p => p.text).join('').replace(/^```(?:json)?/i, '').replace(/```$/, '').trim();\nlet ai;\ntry { ai = JSON.parse(raw); } catch (e) { throw new Error('خروجی Gemini قابل خواندن نبود: ' + raw.slice(0, 200)); }\nif (!ai.title || !ai.content) throw new Error('Gemini عنوان یا متن برنگرداند.');\n\nconst slug = String(ai.slug || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 70);\nconst price = String(f['قیمت محصول'] ?? '').replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d)).replace(/[^\\d.]/g, '');\n\nreturn [{ json: {\n  isProduct: String(f['نوع محتوا'] || '').includes('محصول'),\n  status: String(f['وضعیت'] || '').includes('انتشار') ? 'publish' : 'draft',\n  title: ai.title.trim(),\n  content: ai.content.trim(),\n  summary: (ai.summary || '').trim(),\n  slug,\n  price,\n} }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        360,
        40
      ],
      "id": "6981024d-7fb2-44bd-9af6-4040862f55c1",
      "name": "Parse Content"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "9acc276a-da6a-43b0-9981-b60dd8942586",
              "leftValue": "={{ $json.isProduct }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        640,
        40
      ],
      "id": "0252db72-330a-4599-800e-0b5c59d31306",
      "name": "Article?"
    },
    {
      "parameters": {
        "title": "={{ $json.title }}",
        "additionalFields": {
          "content": "={{ $json.content }}",
          "slug": "={{ $json.slug }}",
          "status": "={{ $json.status }}"
        }
      },
      "type": "n8n-nodes-base.wordpress",
      "typeVersion": 1,
      "position": [
        880,
        -80
      ],
      "id": "35093a88-c356-4f15-b0d9-584f6ba6b2e5",
      "name": "Create Post"
    },
    {
      "parameters": {
        "resource": "product",
        "operation": "create",
        "name": "={{ $json.title }}",
        "additionalFields": {
          "description": "={{ $json.content }}",
          "shortDescription": "={{ $json.summary }}",
          "regularPrice": "={{ $json.price }}",
          "slug": "={{ $json.slug }}",
          "status": "={{ $json.status }}"
        },
        "dimensionsUi": {},
        "imagesUi": {},
        "metadataUi": {}
      },
      "type": "n8n-nodes-base.wooCommerce",
      "typeVersion": 1,
      "position": [
        880,
        160
      ],
      "id": "bdc71387-a168-4517-ab93-8a3ac3e18dc1",
      "name": "Create Product"
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div dir=\"rtl\" style=\"font-family:Tahoma,Vazirmatn,sans-serif;text-align:center;padding:24px;color:#1d2327\">\n<div style=\"font-size:52px;line-height:1\">✅</div>\n<h2 style=\"margin:10px 0 6px\">{{ $('Parse Content').first().json.isProduct ? 'محصول' : 'مقاله' }} ساخته شد</h2>\n<p style=\"color:#50575e;margin:0 0 6px\"><b>{{ $('Parse Content').first().json.title }}</b></p>\n<p style=\"color:#50575e;margin:0 0 18px\">وضعیت: {{ $('Parse Content').first().json.status === 'publish' ? 'منتشر شده' : 'پیش‌نویس' }}</p>\n<a href=\"{{ $json.permalink || $json.link }}\" target=\"_blank\" style=\"display:inline-block;padding:12px 28px;border-radius:999px;background:#2271b1;color:#fff;text-decoration:none;font-weight:bold\">مشاهده ↗</a>\n</div>"
      },
      "type": "n8n-nodes-base.form",
      "typeVersion": 1,
      "position": [
        1100,
        40
      ],
      "id": "8c434508-217a-40d3-8f77-5fac1034af7d",
      "name": "Done Page",
      "webhookId": "bbe60877-c7df-4521-b8ac-50baef1659b5"
    }
  ],
  "pinData": {},
  "connections": {
    "WordPress Content Form": {
      "main": [
        [
          {
            "node": "✏️ Your Prompts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "✏️ Your Prompts": {
      "main": [
        [
          {
            "node": "Gemini – Write",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini – Write": {
      "main": [
        [
          {
            "node": "Parse Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Content": {
      "main": [
        [
          {
            "node": "Article?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Article?": {
      "main": [
        [
          {
            "node": "Create Post",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Post": {
      "main": [
        [
          {
            "node": "Done Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Product": {
      "main": [
        [
          {
            "node": "Done Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}