{
  "name": "Gmail AI reply drafts (TestedFlows)",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "in:inbox -category:promotions -category:social -category:updates",
          "readStatus": "unread"
        },
        "options": {}
      },
      "name": "New email in Gmail",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        300
      ],
      "id": "d972bc12-55ab-41f4-8ebf-e41ba26c340e"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "f1",
              "leftValue": "={{ $json.from.value[0].address }}",
              "rightValue": "noreply",
              "operator": {
                "type": "string",
                "operation": "notContains"
              }
            },
            {
              "id": "f2",
              "leftValue": "={{ $json.from.value[0].address }}",
              "rightValue": "no-reply",
              "operator": {
                "type": "string",
                "operation": "notContains"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "name": "Skip no-reply senders",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        240,
        300
      ],
      "id": "8be64157-73a3-4f58-a9ad-92b6e3a29e44"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Write a reply to this email.\n\nFrom: {{ $json.from.value[0].name }} <{{ $json.from.value[0].address }}>\nSubject: {{ $json.subject }}\n\n{{ $json.text }}",
        "messages": {
          "messageValues": [
            {
              "message": "You draft email replies for a busy professional. Write in plain, friendly English, under 150 words. Answer the sender's actual question. If something needs a decision or information you do not have, write [CHECK: what is needed] instead of guessing. Do not invent prices, dates or commitments. Return only the reply body, with no subject line and no signature."
            }
          ]
        }
      },
      "name": "Write reply with AI",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        480,
        300
      ],
      "id": "bb0daf68-ee30-433c-9a24-68d0cc128e9b"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "options": {}
      },
      "name": "OpenAI model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        480,
        520
      ],
      "id": "2de8fdb4-4681-4498-a45a-fd4cd16142d2"
    },
    {
      "parameters": {
        "url": "https://gmail.googleapis.com/gmail/v1/users/me/settings/sendAs",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "gmailOAuth2",
        "options": {}
      },
      "name": "Get Gmail signature",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        800,
        300
      ],
      "id": "9374487b-c65d-49a0-813f-36904ec17207"
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "=Re: {{ $('New email in Gmail').item.json.subject }}",
        "message": "={{ $('Write reply with AI').item.json.text }}{{ (() => { const s = ($json.sendAs || []).find(a => a.isDefault)?.signature || ''; const t = s.replace(/<br\\s*\\/?>/gi, '\\n').replace(/<\\/(div|p)>/gi, '\\n').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').trim(); return t ? '\\n\\n' + t : ''; })() }}",
        "options": {
          "threadId": "={{ $('New email in Gmail').item.json.threadId }}",
          "sendTo": "={{ $('New email in Gmail').item.json.from.value[0].address }}"
        }
      },
      "name": "Save as Gmail draft",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1040,
        300
      ],
      "webhookId": "0b1ff50a-9c04-4cc1-b170-23d14087b226",
      "id": "7877d448-5339-457b-8d24-ef6601b3750a"
    }
  ],
  "connections": {
    "New email in Gmail": {
      "main": [
        [
          {
            "node": "Skip no-reply senders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip no-reply senders": {
      "main": [
        [
          {
            "node": "Write reply with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI model": {
      "ai_languageModel": [
        [
          {
            "node": "Write reply with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Write reply with AI": {
      "main": [
        [
          {
            "node": "Get Gmail signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Gmail signature": {
      "main": [
        [
          {
            "node": "Save as Gmail draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://testedflows.com/templates/"
  }
}