{
  "name": "Invoice processing: Email to PostgreSQL database with GPT-4o & Discord alerts",
  "nodes": [
    {
      "id": "67a02659-4fe1-4394-89e8-03c4819dc1ff",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -3552,
        -144
      ]
    },
    {
      "id": "c3ebd896-96af-4c81-a916-aa19df57c8d3",
      "name": "Discord",
      "type": "n8n-nodes-base.discord",
      "position": [
        -832,
        -208
      ]
    },
    {
      "id": "e3754a1f-ea3b-4027-91ee-0d96c38270f2",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -2144,
        -272
      ]
    },
    {
      "id": "0e75a30b-b631-45c1-a957-71e8a20c9f9b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -2192,
        64
      ]
    },
    {
      "id": "c9555958-80ce-40d9-81f7-095f5fd59225",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -1920,
        64
      ]
    },
    {
      "id": "9444f054-ab31-4723-ad9b-43907f71d81a",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        -2928,
        -160
      ]
    },
    {
      "id": "42bf86b9-14f3-4ba1-b0f8-60ae8650e5f0",
      "name": "Extract from File1",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -2464,
        -176
      ]
    },
    {
      "id": "eeefc5f4-3c7f-49d7-8b21-3a98462c702e",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -3216,
        -144
      ]
    },
    {
      "id": "f7a051ed-f99a-4a5a-b6b7-b32f8e2f5fdf",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        -1584,
        -192
      ]
    },
    {
      "id": "7e57500b-1a8f-4854-8221-7edc2336a9dd",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        -2704,
        -160
      ]
    },
    {
      "id": "250cf1ac-90bc-4868-a8c6-7898c393d790",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        -1296,
        -192
      ]
    },
    {
      "id": "3406be94-e2e0-4a3d-af3d-d6c5c8cd1279",
      "name": "Prepare Company Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -1280,
        192
      ]
    },
    {
      "id": "7b540304-d0aa-40c9-b40b-6c6dc15ea557",
      "name": "Check Company",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -1072,
        192
      ]
    },
    {
      "id": "ee7ca336-4f6b-4f2e-94e6-7526896e5c52",
      "name": "IF Company Does Not Exist",
      "type": "n8n-nodes-base.if",
      "position": [
        -880,
        192
      ]
    },
    {
      "id": "180d3810-a537-447b-b6db-78fe01daebe7",
      "name": "Add Company",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -672,
        80
      ]
    },
    {
      "id": "e91420fb-0b15-4067-99e9-bf1f5c493bc6",
      "name": "Set Existing Company ID",
      "type": "n8n-nodes-base.set",
      "position": [
        -576,
        288
      ]
    },
    {
      "id": "4dfdc187-084e-4500-9249-fa2d0df5064c",
      "name": "Set New Company ID",
      "type": "n8n-nodes-base.set",
      "position": [
        -480,
        80
      ]
    },
    {
      "id": "a854c3c2-3375-4f80-84e1-fc327c30dce8",
      "name": "Merge Company ID",
      "type": "n8n-nodes-base.merge",
      "position": [
        -272,
        192
      ]
    },
    {
      "id": "76edc407-fac3-43f2-902e-c8e3de3031c8",
      "name": "Check Invoice",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -80,
        192
      ]
    },
    {
      "id": "e82706a5-0415-49d1-aa10-280d8b0ed9a9",
      "name": "IF Invoice Does Not Exist",
      "type": "n8n-nodes-base.if",
      "position": [
        144,
        192
      ]
    },
    {
      "id": "cf030538-7ab2-4199-979e-82fabc83a8a6",
      "name": "Add Invoice",
      "type": "n8n-nodes-base.postgres",
      "position": [
        416,
        80
      ]
    },
    {
      "id": "a25f62a0-4334-46aa-8ad7-fbcfb59b8910",
      "name": "Invoice Exists",
      "type": "n8n-nodes-base.set",
      "position": [
        416,
        288
      ]
    },
    {
      "id": "5e8aa135-8ee3-4ced-b239-f35aeb5eacbb",
      "name": "Merge End",
      "type": "n8n-nodes-base.merge",
      "position": [
        752,
        192
      ]
    },
    {
      "id": "d4dd9cd0-2ef9-4038-9cb8-8779edbf1887",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3712,
        -560
      ],
      "parameters": {
        "width": 432,
        "height": 672,
        "content": "### 📥 Email Trigger (IMAP)\n\nThis node listens for new emails in your inbox and fetches PDF attachments.\n\n**Setup Instructions:**\n- Go to **Credentials** and create new IMAP credentials  \n- Fill in: IM"
      }
    },
    {
      "id": "33a8dc7b-e181-495d-bfb3-f352ff883c17",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2256,
        -576
      ],
      "parameters": {
        "width": 816,
        "height": 800,
        "content": "### 🤖 AI Data Extraction (Basic LLM Chain)\n\nThis node sends the text from the PDF to an AI model (e.g. GPT-4o) to extract structured invoice data.\n\n**Setup Instructions:**\n- Provide a clear prompt des"
      }
    },
    {
      "id": "bacc660a-5fd2-463b-ba2e-54cb94a1bdde",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2256,
        256
      ],
      "parameters": {
        "width": 432,
        "height": 304,
        "content": "### 🔑 OpenAI API (LLM Provider)\n\nThis node connects to OpenAI (or another AI provider) and sends the invoice content for analysis.\n\n**Setup Instructions:**\n- Log in to [OpenAI](https://platform.openai"
      }
    },
    {
      "id": "970d4c31-8c78-482f-b10b-e3350bea6634",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1056,
        -576
      ],
      "parameters": {
        "width": 560,
        "height": 544,
        "content": "### 📤 Chat Notification (Discord Webhook)\n\nThis node sends a summary of the extracted invoice to your Discord channel.\n\n**Setup Instructions:**\n- In Discord:  \n  Go to Server Settings → Integrations →"
      }
    },
    {
      "id": "7f9798aa-bc2c-4653-9521-d2530e3917d9",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        384
      ],
      "parameters": {
        "width": 704,
        "height": 304,
        "content": "### ❗ Don't forget to set your PostgreSQL credentials\n\nIn every PostgreSQL-related node, you must manually select your own credentials from the dropdown.\n\n**Instructions:**\n- Click on the node  \n- Go "
      }
    },
    {
      "id": "27a3576a-2946-41ee-98af-be1e68a1011a",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        384
      ],
      "parameters": {
        "width": 544,
        "height": 320,
        "content": "### 🔀 Merge Node\n\nThis node merges metadata from the email (e.g., subject, sender) with the AI-extracted invoice content.\n\n**Setup Instructions:**\n- Input 1 → AI output  \n- Input 2 → Email data  \n- Se"
      }
    },
    {
      "id": "ccb75df0-4db9-40e1-ab87-11914e81d36f",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        384
      ],
      "parameters": {
        "width": 624,
        "height": 512,
        "content": "### 🗃️ PostgreSQL Insert\n\nThis node writes the extracted data into the `company` and `invoice` tables in your PostgreSQL database.\n\n**Setup Instructions:**\n- Ensure your database has the correct schem"
      }
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Extract from File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Discord",
            "type": "main",
            "index": 0
          },
          {
            "node": "Prepare Company Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Company": {
      "main": [
        [
          {
            "node": "Set New Company ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Invoice": {
      "main": [
        [
          {
            "node": "Merge End",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Company": {
      "main": [
        [
          {
            "node": "IF Company Does Not Exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Invoice": {
      "main": [
        [
          {
            "node": "IF Invoice Does Not Exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Exists": {
      "main": [
        [
          {
            "node": "Merge End",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Company ID": {
      "main": [
        [
          {
            "node": "Check Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File1": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Set New Company ID": {
      "main": [
        [
          {
            "node": "Merge Company ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Company Data": {
      "main": [
        [
          {
            "node": "Check Company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Existing Company ID": {
      "main": [
        [
          {
            "node": "Merge Company ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "IF Company Does Not Exist": {
      "main": [
        [
          {
            "node": "Add Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Existing Company ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Invoice Does Not Exist": {
      "main": [
        [
          {
            "node": "Add Invoice",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Invoice Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}