{
  "name": "Nodbot - Gmail inbox triage with draft reply",
  "nodes": [
    {
      "parameters": {
        "path": "integration-gmail-n8n-triage",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "c25a0d52-ff87-4e4d-856d-d3a5f01c785b",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const msg = $json.body ?? $json;\nconst from = String(msg.from ?? msg.headers?.from ?? '').trim().toLowerCase();\nconst subject = String(msg.subject ?? '').replace(/\\s+/g, ' ').trim();\nconst text = String(msg.text ?? msg.snippet ?? '').replace(/\\s+/g, ' ').trim();\nconst attachments = Array.isArray(msg.attachments) ? msg.attachments : [];\nconst hasPdf = attachments.some(a => /pdf/i.test(a.mimeType ?? a.filename ?? ''));\nconst route = /счет|счёт|акт|закрывающ/i.test(subject + ' ' + text) ? 'documents' :\n  /ошибка|не работает|срочно|проблем/i.test(subject + ' ' + text) ? 'support' :\n  /резюме|ваканси/i.test(subject + ' ' + text) ? 'hr' : 'general';\nreturn [{ json: {\n  message_id: msg.id,\n  thread_id: msg.threadId,\n  from,\n  subject,\n  text_preview: text.slice(0, 700),\n  route,\n  has_attachments: attachments.length > 0,\n  has_pdf: hasPdf,\n  labels_to_add: route === 'support' ? ['needs-human','sla-risk'] : ['triaged'],\n  draft_allowed: Boolean(msg.threadId) && !/unsubscribe|noreply|no-reply/.test(from)\n}}];"
      },
      "id": "8158c014-1940-4c46-9222-171c1f599389",
      "name": "Normalize email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const msg = $json.body ?? $json;\nconst from = String(msg.from ?? msg.headers?.from ?? '').trim().toLowerCase();\nconst subject = String(msg.subject ?? '').replace(/\\s+/g, ' ').trim();\nconst text = String(msg.text ?? msg.snippet ?? '').replace(/\\s+/g, ' ').trim();\nconst attachments = Array.isArray(msg.attachments) ? msg.attachments : [];\nconst hasPdf = attachments.some(a => /pdf/i.test(a.mimeType ?? a.filename ?? ''));\nconst route = /счет|счёт|акт|закрывающ/i.test(subject + ' ' + text) ? 'documents' :\n  /ошибка|не работает|срочно|проблем/i.test(subject + ' ' + text) ? 'support' :\n  /резюме|ваканси/i.test(subject + ' ' + text) ? 'hr' : 'general';\nreturn [{ json: {\n  message_id: msg.id,\n  thread_id: msg.threadId,\n  from,\n  subject,\n  text_preview: text.slice(0, 700),\n  route,\n  has_attachments: attachments.length > 0,\n  has_pdf: hasPdf,\n  labels_to_add: route === 'support' ? ['needs-human','sla-risk'] : ['triaged'],\n  draft_allowed: Boolean(msg.threadId) && !/unsubscribe|noreply|no-reply/.test(from)\n}}];"
      },
      "id": "be0ea901-fb6b-4a6e-9181-8a44a607d824",
      "name": "Classify route",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "99419d03-ea76-41ce-a52c-789fe35faef1",
      "name": "Check draft allowed",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {
        "path": "integration-gmail-n8n-triage",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "5f35ebc4-e43f-43ad-829f-901a25b9ff54",
      "name": "Create Gmail draft",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "c4c3e2eb-fb5d-49ca-85c8-f5120fa09d00",
      "name": "Apply labels",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Normalize email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize email": {
      "main": [
        [
          {
            "node": "Classify route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify route": {
      "main": [
        [
          {
            "node": "Check draft allowed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check draft allowed": {
      "main": [
        [
          {
            "node": "Create Gmail draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Gmail draft": {
      "main": [
        [
          {
            "node": "Apply labels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "e18c83a9-941c-46ec-902c-771551a3b3fe",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}