{
  "name": "InquiryPilot - Gmail to Sheets and Draft",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {
          "labelIds": [
            "INBOX"
          ]
        }
      },
      "id": "gmail-trigger",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://host.docker.internal:8000/api/automation/inquiries",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Automation-Key",
              "value": "change-this-before-deployment"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"external_id\": $json.id, \"source\": \"gmail\", \"text\": ($json.textPlain || $json.snippet || $json.subject)}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "analyze",
      "name": "Analyze with InquiryPilot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "CONNECT_SPREADSHEET",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{$json.inquiry.contact_name}}",
            "Company": "={{$json.inquiry.company}}",
            "Email": "={{$json.inquiry.email}}",
            "Intent": "={{$json.inquiry.intent}}",
            "Priority": "={{$json.inquiry.priority}}",
            "Score": "={{$json.inquiry.lead_score}}",
            "Status": "={{$json.inquiry.status}}"
          }
        },
        "options": {}
      },
      "id": "sheets",
      "name": "Append Lead to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        520,
        -80
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{'Re: ' + ($node['Gmail Trigger'].json.subject || 'Your inquiry')}}",
        "message": "={{$node['Analyze with InquiryPilot'].json.inquiry.reply_draft}}",
        "options": {
          "sendTo": "={{$node['Analyze with InquiryPilot'].json.inquiry.email}}"
        }
      },
      "id": "draft",
      "name": "Create Gmail Draft",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        520,
        100
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Analyze with InquiryPilot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze with InquiryPilot": {
      "main": [
        [
          {
            "node": "Append Lead to Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Gmail Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "versionId": "00000000-0000-4000-8000-000000000001"
}