{
  "name": "P4 تأیید و ارسال — الگوی Gmail (زیرورک‌فلو)",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "id": "ef4f2492-8ee5-5598-88c3-8bd13b02e4a7",
      "name": "ورودی از ورک‌فلوی اصلی",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -200,
        100
      ]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "support-lead@example.com",
        "subject": "=تأیید پاسخ: {{ $json.subject }}",
        "message": "=پیش‌نویس کامل پاسخ به {{ $json.from }}:\n\n{{ $json.draft }}",
        "approvalOptions": {
          "values": {
            "approvalType": "double",
            "approveLabel": "تأیید",
            "disapproveLabel": "رد"
          }
        },
        "options": {
          "limitWaitTime": {
            "values": {
              "limitType": "afterTimeInterval",
              "resumeAmount": 4,
              "resumeUnit": "hours"
            }
          },
          "appendAttribution": false
        }
      },
      "id": "e746c6fb-5ddd-5231-b039-c732586f5a67",
      "name": "تأیید با ایمیل (Send and Wait)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        40,
        100
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "ac35411583c55124",
          "name": "Gmail (test account)"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "3d8e389e-5cac-5b82-81b7-f134ff6e15cb",
                    "leftValue": "={{ $json.data?.approved }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "تأیید"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "0234aca2-58b8-5bf3-b490-3e208328aa9e",
                    "leftValue": "={{ $json.data?.approved }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "رد"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "8a3afacc-1249-55c8-85df-bbd1aea7554f",
      "name": "نتیجه تأیید",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        260,
        100
      ]
    },
    {
      "parameters": {
        "action": "hash",
        "type": "SHA256",
        "value": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.draft }}",
        "dataPropertyName": "check_hash"
      },
      "id": "6419c9d2-b0a4-5099-b827-82f0375d2cfb",
      "name": "هش دوباره",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        480,
        -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": "1898182a-269d-517d-8d79-a60a80dca4f1",
      "name": "همان نسخه تأییدشده؟",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        700,
        -40
      ]
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "options": {
          "scope": "workflow"
        },
        "dedupeValue": "=reply-{{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}-{{ $('ورودی از ورک‌فلوی اصلی').item.json.draft_hash.slice(0, 16) }}"
      },
      "id": "87fa3bc4-778e-5c8b-9548-7d74d276f61c",
      "name": "فقط یک بار (کلید ارسال)",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        920,
        -120
      ]
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}",
        "emailType": "text",
        "message": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.draft }}",
        "options": {
          "appendAttribution": false,
          "replyToSenderOnly": true
        }
      },
      "id": "06a42a78-060a-5cba-95fa-52e3d6a210b4",
      "name": "پاسخ (Reply)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1140,
        -120
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "ac35411583c55124",
          "name": "Gmail (test account)"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}",
        "labelIds": [
          "REPLACE_WITH_LABEL_ID_replied"
        ]
      },
      "id": "e6b5119e-eb54-5f59-998a-ed817b79f689",
      "name": "برچسب: پاسخ داده شد",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1360,
        -120
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "ac35411583c55124",
          "name": "Gmail (test account)"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('ورودی از ورک‌فلوی اصلی').item.json.id }}",
        "labelIds": [
          "REPLACE_WITH_LABEL_ID_needs_human"
        ]
      },
      "id": "d2b8cf4a-ca31-54ab-8d68-f4dc66ab28b8",
      "name": "برچسب: نیاز به انسان",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        920,
        240
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "ac35411583c55124",
          "name": "Gmail (test account)"
        }
      }
    },
    {
      "parameters": {
        "content": "Gmail کلید ایدمپوتنسی ندارد؛ «فقط یک بار» با Remove Duplicates روی شناسه + هش، جلوی ارسال دوباره همان پاسخ را می‌گیرد. فاصله بین ارسال و ثبت را در سند تصمیم بنویس.",
        "height": 150,
        "width": 380,
        "color": 5
      },
      "id": "8c44b324-b873-560f-b51f-085d33e203b6",
      "name": "یادداشت 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        880,
        -360
      ]
    }
  ],
  "connections": {
    "ورودی از ورک‌فلوی اصلی": {
      "main": [
        [
          {
            "node": "تأیید با ایمیل (Send and Wait)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "تأیید با ایمیل (Send and Wait)": {
      "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": "پاسخ (Reply)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "پاسخ (Reply)": {
      "main": [
        [
          {
            "node": "برچسب: پاسخ داده شد",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "id": "LkyP4GmailAppr01",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lookiyar-academy-demo"
  },
  "tags": [
    {
      "name": "loOkiYar Academy"
    },
    {
      "name": "AUT-203"
    },
    {
      "name": "template"
    }
  ],
  "pinData": {}
}