{
  "name": "P4 تأیید و ارسال — نسخه آزمایشی (زیرورک‌فلو)",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "id": "3926020d-710f-5c3c-af46-abe412231869",
      "name": "ورودی از ورک‌فلوی اصلی",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -400,
        100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8b3d55ab-aa77-5f8f-8c30-3d94945aea93",
              "name": "mail_base",
              "value": "http://127.0.0.1:8787",
              "type": "string"
            },
            {
              "id": "0c799d42-8301-5869-84d1-1f41d5d327c9",
              "name": "approver",
              "value": "support_lead",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "f168044a-53c1-5344-9954-8cc654eb5575",
      "name": "تنظیمات",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -180,
        100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.mail_base }}/botDEMO/sendMessage",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: $json.approver, text: 'پیش‌نویس پاسخ به ' + $('ورودی از ورک‌فلوی اصلی').item.json.from + ':\\n\\n' + $('ورودی از ورک‌فلوی اصلی').item.json.draft + '\\n\\nتأیید یا رد: ' + $execution.resumeFormUrl }) }}"
      },
      "id": "e9a771fb-e16b-57e4-9745-f9e31543ff4b",
      "name": "اطلاع به تأییدکننده",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        40,
        100
      ]
    },
    {
      "parameters": {
        "resume": "form",
        "formTitle": "تأیید پاسخ برگ سبز",
        "formDescription": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.draft }}",
        "formFields": {
          "values": [
            {
              "fieldLabel": "تصمیم",
              "fieldType": "dropdown",
              "requiredField": true,
              "fieldOptions": {
                "values": [
                  {
                    "option": "تأیید"
                  },
                  {
                    "option": "رد"
                  }
                ]
              }
            },
            {
              "fieldLabel": "دلیل",
              "fieldType": "textarea"
            }
          ]
        },
        "limitWaitTime": true,
        "limitType": "afterTimeInterval",
        "resumeAmount": 4,
        "resumeUnit": "hours",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "083071ed-8380-5c26-98a5-8233b74c5b35",
      "name": "انتظار تأیید (فرم)",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        260,
        100
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "38403955-a3be-599a-af04-d9e5cce982fd",
                    "leftValue": "={{ $json['تصمیم'] }}",
                    "rightValue": "تأیید",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "تأیید"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "3e0ef21a-89dc-5b75-a2cc-a4b00f29558d",
                    "leftValue": "={{ $json['تصمیم'] }}",
                    "rightValue": "رد",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "رد"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "bb786310-e50e-55c4-b759-d07f69453695",
      "name": "نتیجه تأیید",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        480,
        100
      ]
    },
    {
      "parameters": {
        "action": "hash",
        "type": "SHA256",
        "value": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.draft }}",
        "dataPropertyName": "check_hash"
      },
      "id": "e414ee40-12b5-5e85-82a7-cfe8b6bf118f",
      "name": "هش دوباره",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        700,
        -40
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "40b4250d-ca44-51a5-8a5e-a23ddb3bfa3f",
              "leftValue": "={{ $json.check_hash }}",
              "rightValue": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.draft_hash }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "ea41de14-1473-5bbe-b8d1-533e098536ee",
      "name": "همان نسخه تأییدشده؟",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        920,
        -40
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('تنظیمات').first().json.mail_base }}/mail/messages/{{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}/reply",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=reply-{{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}-{{ $('ورودی از ورک‌فلوی اصلی').item.json.draft_hash.slice(0, 16) }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ body: $('ورودی از ورک‌فلوی اصلی').item.json.draft }) }}"
      },
      "id": "f78eac3f-6765-5369-bc64-6657f162e4f0",
      "name": "ارسال پاسخ (یک بار)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1140,
        -120
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "aa05db4bc8085d30",
          "name": "Barg Sabz mock API (Header Auth)"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('تنظیمات').first().json.mail_base }}/mail/messages/{{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}/labels",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={ \"add\": [\"replied\"] }"
      },
      "id": "28bbebf7-5374-55b7-a65b-9e88a4f4ace9",
      "name": "برچسب: پاسخ داده شد",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1360,
        -120
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "aa05db4bc8085d30",
          "name": "Barg Sabz mock API (Header Auth)"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('تنظیمات').first().json.mail_base }}/mail/messages/{{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}/labels",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={ \"add\": [\"needs-human\"] }"
      },
      "id": "d92b7184-6f2c-5640-ae34-0fd079ac5933",
      "name": "برچسب: نیاز به انسان",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1140,
        220
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "aa05db4bc8085d30",
          "name": "Barg Sabz mock API (Header Auth)"
        }
      }
    },
    {
      "parameters": {
        "content": "سه نتیجه: **تأیید** (فقط همان متن، با Idempotency-Key)، **رد**، و **پایان مهلت ۴ ساعته** (شاخه Fallback). رد و پایان مهلت هر دو به صف انسانی می‌روند.",
        "height": 150,
        "width": 380,
        "color": 5
      },
      "id": "07483635-7d64-58e2-a6d1-80ee1489b9e8",
      "name": "یادداشت 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        420,
        -220
      ]
    }
  ],
  "connections": {
    "ورودی از ورک‌فلوی اصلی": {
      "main": [
        [
          {
            "node": "تنظیمات",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "تنظیمات": {
      "main": [
        [
          {
            "node": "اطلاع به تأییدکننده",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "اطلاع به تأییدکننده": {
      "main": [
        [
          {
            "node": "انتظار تأیید (فرم)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "انتظار تأیید (فرم)": {
      "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
          }
        ]
      ]
    },
    "همان نسخه تأییدشده؟": {
      "main": [
        [
          {
            "node": "ارسال پاسخ (یک بار)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "برچسب: نیاز به انسان",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ارسال پاسخ (یک بار)": {
      "main": [
        [
          {
            "node": "برچسب: پاسخ داده شد",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": "LkyP4ErrAlert001"
  },
  "id": "LkyP4ApproveMk01",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lookiyar-academy-demo"
  },
  "tags": [
    {
      "name": "loOkiYar Academy"
    },
    {
      "name": "AUT-203"
    }
  ],
  "pinData": {}
}