{
  "name": "Do4U – reply drafts for incoming emails (template)",
  "nodes": [
    {
      "parameters": { "mailbox": "INBOX", "postProcessAction": "nothing", "options": {} },
      "name": "New email (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [0, 0],
      "notes": "Your own IMAP credentials stay in n8n. Do4U never sees them."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://do4u.eu/api/v1/jobs",
        "sendHeaders": true,
        "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Bearer YOUR_DO4U_API_KEY" } ] },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ tool: 'support_reply', text: ($json.textPlain || '').slice(0, 30000), no_store: true, language: 'en', options: { tone: 'friendly' } }) }}",
        "options": {}
      },
      "name": "Do4U: create reply job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [240, 0]
    },
    {
      "parameters": { "amount": 5, "unit": "seconds" },
      "name": "Wait 5 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [480, 0]
    },
    {
      "parameters": {
        "url": "={{ 'https://do4u.eu/api/v1/jobs/' + $('Do4U: create reply job').item.json.id }}",
        "sendHeaders": true,
        "headerParameters": { "parameters": [ { "name": "Authorization", "value": "Bearer YOUR_DO4U_API_KEY" } ] },
        "options": {}
      },
      "name": "Do4U: get result",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [720, 0]
    },
    {
      "parameters": {
        "conditions": { "string": [ { "value1": "={{ $json.status }}", "operation": "equal", "value2": "done" } ] }
      },
      "name": "Done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [960, 0]
    },
    {
      "parameters": {},
      "name": "Create draft in your mailbox (replace with Gmail/Outlook node)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [1200, -100],
      "notes": "The reply text is in {{ $json.result.reply }}. Use the Gmail or Microsoft Outlook node with the operation 'Create draft'. Do4U does not send emails."
    }
  ],
  "connections": {
    "New email (IMAP)": { "main": [ [ { "node": "Do4U: create reply job", "type": "main", "index": 0 } ] ] },
    "Do4U: create reply job": { "main": [ [ { "node": "Wait 5 s", "type": "main", "index": 0 } ] ] },
    "Wait 5 s": { "main": [ [ { "node": "Do4U: get result", "type": "main", "index": 0 } ] ] },
    "Do4U: get result": { "main": [ [ { "node": "Done?", "type": "main", "index": 0 } ] ] },
    "Done?": { "main": [
      [ { "node": "Create draft in your mailbox (replace with Gmail/Outlook node)", "type": "main", "index": 0 } ],
      [ { "node": "Wait 5 s", "type": "main", "index": 0 } ]
    ] }
  },
  "settings": {},
  "meta": { "templateCreatedBy": "Do4U", "note": "Template: check node versions in your n8n. Replace YOUR_DO4U_API_KEY (better: an n8n credential of type Header Auth)." }
}
