{
  "name": "Ratifia: ask, then hand off to the protected send",
  "nodes": [
    {
      "parameters": {
        "content": "## Ask, then hand off\n\nAsks for approval of the draft, then passes the email and the `decisionId` to the protected send workflow. It never sends anything itself.\n\nAfter importing both, publish the child and point **Send it (protected)** at it.",
        "height": 200,
        "width": 520
      },
      "id": "4444d597-8841-4cd2-bb76-9071ed94d1a4",
      "name": "Note 26e489",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {},
      "id": "5b77c996-22e8-492f-bd24-94fb65c58a40",
      "name": "Run it",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "66c17be0-e26c-4424-95f1-e85e00344984",
              "name": "recipient",
              "value": "dana@acme.com",
              "type": "string"
            },
            {
              "id": "cfeefd52-7b9c-4a16-b781-25622592b148",
              "name": "subject",
              "value": "Your refund for invoice INV-2291",
              "type": "string"
            },
            {
              "id": "5d798c28-e10d-4074-9ed3-dfc41b1212f4",
              "name": "body",
              "value": "Hi Dana,\n\nWe've refunded the duplicate charge of $620.00 to the card ending 4242. It should appear within 5 business days.\n\nThanks for your patience,\nAcme Support",
              "type": "string"
            },
            {
              "id": "7137346d-3582-45d9-ad00-d9cabaa71f65",
              "name": "attachments",
              "value": "={{ [\"refund-receipt-INV-2291.pdf\"] }}",
              "type": "array"
            },
            {
              "id": "211f2e9f-a3fe-4b69-8630-c5908108c6d5",
              "name": "amount",
              "value": 620,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "123cf521-c27d-408f-82f3-0c611d6e6a49",
      "name": "Draft reply",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "type": "SHA256",
        "value": "={{ JSON.stringify({ attachments: $json.attachments, body: $json.body, recipient: $json.recipient, subject: $json.subject }) }}",
        "dataPropertyName": "factsHash"
      },
      "id": "5428deb5-1945-4437-8d94-e0d4a7184d03",
      "name": "Hash the draft",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.ratifia.com/v1/worker/decisions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  engine: \"api\",\n  externalRunId: \"n8n-\" + $execution.id,\n  stepRef: \"send-customer-reply\",\n  workflowRef: \"customer-replies\",\n  policy: { key: \"customer-replies\" },\n  required: true,\n  factsHash: $json.factsHash,\n  context: { title: \"Reply to \" + $json.recipient, prompt: \"Send this reply to \" + $json.recipient + \"?\", blocks: [{ kind: \"fields\", title: \"Email\", fields: [{ label: \"To\", value: $json.recipient }, { label: \"Subject\", value: $json.subject }, { label: \"Attachments\", value: $json.attachments.join(\", \") }] }, { kind: \"text\", title: \"Body\", text: $json.body }] }\n}) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "1b0c24fd-93f6-4bf5-9d49-70c7148849c5",
      "name": "Create decision",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "amount": 15
      },
      "id": "702a4b0d-35d4-4d42-87dc-202b70097a6d",
      "name": "Wait 15s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        880,
        300
      ],
      "webhookId": "ea5e5f28-b323-4c2e-a5d2-5d02117a9a17"
    },
    {
      "parameters": {
        "url": "=https://api.ratifia.com/v1/worker/decisions/{{ $(\"Create decision\").item.json.decisionId }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000
        }
      },
      "id": "ba492ffb-0f04-4920-a0b2-2aa40b549977",
      "name": "Check decision",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "7e4f6185-f9cc-44e9-8697-66925ab23466",
              "leftValue": "={{ $json.status }}",
              "rightValue": "PENDING",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "803e87da-ae72-42fb-98c6-8d325351d323",
      "name": "Still pending?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1320,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "f19b3a71-37c9-4d6a-b9a5-dbcc9c529119",
              "leftValue": "={{ $json.status }}",
              "rightValue": "APPROVED",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "fea42ee4-7ffa-44a6-b300-c441e5022132",
      "name": "Approved?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1540,
        420
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "78f11786-8c3c-4393-83a6-e7edd4cb63a5",
              "name": "recipient",
              "value": "={{ $(\"Draft reply\").item.json.recipient }}",
              "type": "string"
            },
            {
              "id": "8ef37416-f8f0-4ad6-9ae3-a78219ea9879",
              "name": "subject",
              "value": "={{ $(\"Draft reply\").item.json.subject }}",
              "type": "string"
            },
            {
              "id": "ca50a16a-b28e-433c-80d4-4b2fb486191f",
              "name": "body",
              "value": "={{ $(\"Draft reply\").item.json.body }}",
              "type": "string"
            },
            {
              "id": "25d3c7d0-f71d-4a3a-bf46-902557838ea0",
              "name": "attachments",
              "value": "={{ $(\"Draft reply\").item.json.attachments }}",
              "type": "array"
            },
            {
              "id": "ff017b8e-8693-4eb8-a4fb-5fd15aa94ebd",
              "name": "decisionId",
              "value": "={{ $json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "3b450118-e0bc-44ff-bad4-1e5c7c78bcdf",
      "name": "Email + decision",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1760,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "REPLACE_WITH_CHILD_WORKFLOW_ID",
          "mode": "id"
        },
        "options": {}
      },
      "id": "1e1bb470-ec84-451b-948b-d48cb365407a",
      "name": "Send it (protected)",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        1980,
        300
      ]
    },
    {
      "parameters": {},
      "id": "9126fc48-fd94-479e-992c-4d5adea1e7ef",
      "name": "Not approved",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1760,
        540
      ]
    }
  ],
  "connections": {
    "Run it": {
      "main": [
        [
          {
            "node": "Draft reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft reply": {
      "main": [
        [
          {
            "node": "Hash the draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hash the draft": {
      "main": [
        [
          {
            "node": "Create decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still pending?": {
      "main": [
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Approved?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approved?": {
      "main": [
        [
          {
            "node": "Email + decision",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not approved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email + decision": {
      "main": [
        [
          {
            "node": "Send it (protected)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create decision": {
      "main": [
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 15s": {
      "main": [
        [
          {
            "node": "Check decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check decision": {
      "main": [
        [
          {
            "node": "Still pending?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
