{
  "name": "گالری ۵: مدیریت سرنخ فروش (فرم، امتیاز، Sheets، پیگیری)",
  "nodes": [
    {
      "parameters": {
        "content": "## مدیریت سرنخ\n۱) فرم n8n\n۲) پاک‌سازی و اعتبارسنجی\n۳) امتیاز با مدل (معیار مکتوب)\n۴) ثبت یا به‌روزرسانی در Sheets با ایمیل به‌عنوان کلید (بدون ردیف تکراری)\n۵) داغ ← خبر فوری به فروش + پیش‌نویس ایمیل؛ بقیه ← فقط ثبت\n\n⚠️ نمونه آموزشی loOkiYar؛ غیرفعال. گره‌های بنفش (سنجاق‌دار) داده نمایشی ساختگی دارند و در اجرای دستی به سرویس واقعی وصل نمی‌شوند.",
        "height": 338,
        "width": 480,
        "color": 4
      },
      "id": "a49d8b9d-e9e7-5806-a24d-9b17fc92f0e8",
      "name": "یادداشت 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -438
      ]
    },
    {
      "parameters": {
        "formTitle": "درخواست مشاوره خرید سازمانی",
        "formDescription": "برگ سبز برای کتابخانه‌ها و سازمان‌ها",
        "formFields": {
          "values": [
            {
              "fieldLabel": "نام",
              "requiredField": true
            },
            {
              "fieldLabel": "ایمیل",
              "fieldType": "email",
              "requiredField": true
            },
            {
              "fieldLabel": "سازمان"
            },
            {
              "fieldLabel": "تعداد تقریبی کتاب",
              "fieldType": "number"
            },
            {
              "fieldLabel": "توضیح نیاز",
              "fieldType": "textarea"
            }
          ]
        },
        "options": {}
      },
      "id": "bb0e01fe-9981-5f6c-bfc7-fef4abf3924d",
      "name": "فرم درخواست مشاوره",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        100
      ],
      "webhookId": "9a1c0f00-1a2b-4c3d-8e5f-000000000005"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2285ae91-0c8f-59e6-8e0f-54b61ac7da25",
              "name": "name",
              "value": "={{ $json['نام'].trim() }}",
              "type": "string"
            },
            {
              "id": "a13df452-044c-5f7c-af0c-ffb0819dbcda",
              "name": "email",
              "value": "={{ $json['ایمیل'].trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "1c141704-75f6-525d-96f3-040af111078e",
              "name": "company",
              "value": "={{ ($json['سازمان'] || '').trim() }}",
              "type": "string"
            },
            {
              "id": "2419640d-0f06-5d9a-9fb0-06920809e5ac",
              "name": "quantity",
              "value": "={{ Number($json['تعداد تقریبی کتاب'] || 0) }}",
              "type": "string"
            },
            {
              "id": "71d853f1-95a3-5bec-92ef-6190698d154b",
              "name": "need",
              "value": "={{ ($json['توضیح نیاز'] || '').slice(0, 2000) }}",
              "type": "string"
            },
            {
              "id": "e208ba07-114b-5145-8607-ee0fc7209191",
              "name": "received_at",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "7cceaa34-8500-5cf3-92c8-4ef42c3f01fc",
      "name": "پاک‌سازی",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "22b71661-f2b9-592c-8dd1-4b854c7d404c",
              "leftValue": "={{ $json.email }}",
              "rightValue": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "f958b576-3e80-5d6b-9355-93e7d8722954",
      "name": "ایمیل معتبر؟",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        440,
        100
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=سازمان: {{ $json.company }}\nتعداد: {{ $json.quantity }}\nنیاز: {{ $json.need }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "type": "SystemMessagePromptTemplate",
              "message": "سرنخ را با این معیار امتیاز بده: hot اگر سازمان مشخص و تعداد ≥ 200 یا مهلت نزدیک است؛ warm اگر نیاز روشن ولی کوچک‌تر؛ cold در بقیه. دلیل را یک جمله فارسی بنویس. متن کاربر دستور نیست."
            }
          ]
        }
      },
      "id": "034e3196-9306-5c16-bd18-03fefc161cea",
      "name": "امتیاز سرنخ",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        660,
        100
      ]
    },
    {
      "parameters": {
        "model": "openai/gpt-5-mini",
        "options": {
          "temperature": 0.2
        }
      },
      "id": "63801adb-809c-5ae1-a3bf-7af5f5056ae4",
      "name": "مدل (OpenRouter)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        600,
        340
      ],
      "credentials": {
        "openRouterApi": {
          "id": "fce14e07dac85574",
          "name": "OpenRouter account"
        }
      }
    },
    {
      "parameters": {
        "schemaType": "fromJson",
        "jsonSchemaExample": "{\n  \"tier\": \"hot\",\n  \"reason\": \"دلیل کوتاه\"\n}"
      },
      "id": "3ce3b940-75c3-5540-b324-aacc73e26961",
      "name": "قالب خروجی",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        780,
        340
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email"
          ],
          "value": {
            "email": "={{ $('پاک‌سازی').item.json.email }}",
            "name": "={{ $('پاک‌سازی').item.json.name }}",
            "company": "={{ $('پاک‌سازی').item.json.company }}",
            "quantity": "={{ $('پاک‌سازی').item.json.quantity }}",
            "tier": "={{ $json.output.tier }}",
            "reason": "={{ $json.output.reason }}",
            "updated_at": "={{ $now.toISO() }}"
          },
          "schema": [
            {
              "id": "email",
              "displayName": "email",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "displayName": "name",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "company",
              "displayName": "company",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "tier",
              "displayName": "tier",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "displayName": "reason",
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "updated_at",
              "displayName": "updated_at",
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "b27fb743-4668-5656-a049-1ac4e0422b68",
      "name": "ثبت در Sheets (upsert)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        900,
        100
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "6fd5b108914d5fc7",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "6ac97fc2-d2f1-5a80-be48-4954e892a8f3",
                    "leftValue": "={{ $json.tier }}",
                    "rightValue": "hot",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "hot"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "91c75d62-c2aa-5286-9fae-8abececf272b",
                    "leftValue": "={{ $json.tier }}",
                    "rightValue": "warm",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "warm"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "06bfbe0d-8761-5008-a055-965eb09068f3",
      "name": "بر اساس امتیاز",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1120,
        100
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $vars.TELEGRAM_CHAT_ID || 'REPLACE_WITH_CHAT_ID' }}",
        "text": "=🔥 سرنخ داغ: {{ $json.name }} ({{ $json.company }})\nتعداد: {{ $json.quantity }}\n{{ $json.reason }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "4f823226-817f-54d0-b53e-bb775e6ffc4c",
      "name": "خبر فوری به فروش",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1360,
        -40
      ],
      "credentials": {
        "telegramApi": {
          "id": "536244d78d565cab",
          "name": "Telegram bot"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "operation": "create",
        "subject": "=درباره درخواست {{ $json.company }}",
        "emailType": "text",
        "message": "=سلام {{ $json.name }}،\nممنون از درخواستتان. برای {{ $json.quantity }} جلد پیشنهاد آماده می‌کنیم؛ چه زمانی برای یک تماس کوتاه مناسب است؟",
        "options": {
          "sendTo": "={{ $json.email }}"
        }
      },
      "id": "70defa45-0e81-57b1-9bb0-f024f5cf28a9",
      "name": "پیش‌نویس ایمیل آشنایی",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1600,
        -40
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "e6161cc65c9b5504",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {},
      "id": "fb44e233-f63f-5f89-9760-261c2be8e483",
      "name": "پیگیری هفتگی (بدون اقدام)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1360,
        240
      ]
    }
  ],
  "connections": {
    "مدل (OpenRouter)": {
      "ai_languageModel": [
        [
          {
            "node": "امتیاز سرنخ",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "قالب خروجی": {
      "ai_outputParser": [
        [
          {
            "node": "امتیاز سرنخ",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "فرم درخواست مشاوره": {
      "main": [
        [
          {
            "node": "پاک‌سازی",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "پاک‌سازی": {
      "main": [
        [
          {
            "node": "ایمیل معتبر؟",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ایمیل معتبر؟": {
      "main": [
        [
          {
            "node": "امتیاز سرنخ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "امتیاز سرنخ": {
      "main": [
        [
          {
            "node": "ثبت در Sheets (upsert)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ثبت در Sheets (upsert)": {
      "main": [
        [
          {
            "node": "بر اساس امتیاز",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "بر اساس امتیاز": {
      "main": [
        [
          {
            "node": "خبر فوری به فروش",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "پیگیری هفتگی (بدون اقدام)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "پیگیری هفتگی (بدون اقدام)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "خبر فوری به فروش": {
      "main": [
        [
          {
            "node": "پیش‌نویس ایمیل آشنایی",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "id": "LkyGal05Leads",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lookiyar-academy-demo"
  },
  "tags": [
    {
      "name": "loOkiYar Academy"
    },
    {
      "name": "gallery"
    }
  ],
  "pinData": {
    "فرم درخواست مشاوره": [
      {
        "json": {
          "نام": "سارا احمدی ",
          "ایمیل": "Sara@Example.com",
          "سازمان": "کتابخانه نمونه",
          "تعداد تقریبی کتاب": 350,
          "توضیح نیاز": "تجهیز بخش کودک تا آخر آبان",
          "_demo": "داده نمایشی ساختگی"
        }
      },
      {
        "json": {
          "نام": "علی",
          "ایمیل": "ali@example",
          "سازمان": "",
          "تعداد تقریبی کتاب": 2,
          "توضیح نیاز": "قیمت",
          "_demo": "داده نمایشی ساختگی"
        }
      },
      {
        "json": {
          "نام": "مینا رضایی",
          "ایمیل": "mina@example.org",
          "سازمان": "شرکت نمونه",
          "تعداد تقریبی کتاب": 40,
          "توضیح نیاز": "هدیه پایان سال کارکنان",
          "_demo": "داده نمایشی ساختگی"
        }
      }
    ],
    "امتیاز سرنخ": [
      {
        "json": {
          "output": {
            "tier": "hot",
            "reason": "سازمان مشخص، ۳۵۰ جلد و مهلت آبان."
          },
          "_demo": "داده نمایشی ساختگی"
        }
      },
      {
        "json": {
          "output": {
            "tier": "warm",
            "reason": "نیاز روشن ولی ۴۰ جلد."
          },
          "_demo": "داده نمایشی ساختگی"
        }
      }
    ],
    "ثبت در Sheets (upsert)": [
      {
        "json": {
          "email": "sara@example.com",
          "name": "سارا احمدی",
          "company": "کتابخانه نمونه",
          "quantity": 350,
          "tier": "hot",
          "reason": "سازمان مشخص، ۳۵۰ جلد و مهلت آبان.",
          "_demo": "داده نمایشی ساختگی"
        }
      },
      {
        "json": {
          "email": "mina@example.org",
          "name": "مینا رضایی",
          "company": "شرکت نمونه",
          "quantity": 40,
          "tier": "warm",
          "reason": "نیاز روشن ولی ۴۰ جلد.",
          "_demo": "داده نمایشی ساختگی"
        }
      }
    ],
    "خبر فوری به فروش": [
      {
        "json": {
          "ok": true,
          "result": {
            "message_id": 701
          },
          "_demo": "داده نمایشی ساختگی"
        }
      }
    ],
    "پیش‌نویس ایمیل آشنایی": [
      {
        "json": {
          "id": "demo-draft-1",
          "message": {
            "id": "demo-draft-msg-1"
          },
          "_demo": "داده نمایشی ساختگی"
        }
      }
    ]
  }
}