Invoice Processing: Email to PostgreSQL Database with GPT-4o & Discord Alerts β€” n8n Workflow

High complexity▢️ Manual23 nodes🏷️ Invoice Processingby Halfbit πŸš€

Overview

AI-Powered Invoice Processing: from Email to Database & Chat Notifications

Automatically process PDF invoices directly from your email inbox. This workflow uses AI to extract key data, saves it to a PostgreSQL database, and instantly notifies you about the new document in your preferred chat application.

The workflow listens for new emails, fetches PDF attachments, and then passes their content to a Large Language Model (LLM) for intelligent recognition and data extraction. Finally, the inform

Nodes used

PostgresDiscordCodeBasic LLM ChainOpenAI Chat ModelStructured Output Parser

Workflow Preview

πŸ“₯ Email Trigger (IMAP)
This node listens for new emails in your inbox and fetc
Setup Instructions:
- Go to Credentials and create new IMAP credentials
- Fill in: IM
πŸ€– AI Data Extraction (Basic LLM Chain)
This node sends the text from the PDF to an AI model (e
Setup Instructions:
- Provide a clear prompt des
πŸ”‘ OpenAI API (LLM Provider)
This node connects to OpenAI (or another AI provider) a
Setup Instructions:
- Log in to [OpenAI](https://platform.openai
πŸ“€ Chat Notification (Discord Webhook)
This node sends a summary of the extracted invoice to y
Setup Instructions:
- In Discord:
Go to Server Settings β†’ Integrations β†’
❗ Don't forget to set your PostgreSQL credent
In every PostgreSQL-related node, you must manually sel
Instructions:
- Click on the node
- Go
πŸ”€ Merge Node
This node merges metadata from the email (e.g., subject
Setup Instructions:
- Input 1 β†’ AI output
- Input 2 β†’ Email data
- Se
πŸ—ƒοΈ PostgreSQL Insert
This node writes the extracted data into the `company`
Setup Instructions:
- Ensure your database has the correct schem
modelparser
E
Email Trigger (IMAP)
Discord
Basic LLM Chain
OpenAI Chat Model
Structured Output Parser
Code
E
Extract from File1
I
If
M
Merge
I
If1
I
If2
P
Prepare Company Data
Check Company
I
IF Company Does Not Exist
Add Company
S
Set Existing Company ID
S
Set New Company ID
M
Merge Company ID
Check Invoice
I
IF Invoice Does Not Exist
Add Invoice
I
Invoice Exists
M
Merge End
23 nodes25 edges

How it Works

  1. 1

    Trigger

    The workflow starts with a manual trigger.

  2. 2

    Process

    Data flows through 23 nodes, connecting chainllm, code, discord.

  3. 3

    Output

    The workflow completes its automation and delivers the result to the configured destination.

Node Details (23)

PO

Postgres

postgres

#1
DI

Discord

discord

#2
CO

Code

code

#3
BA

Basic LLM Chain

n8n-nodes-langchain.chainLlm

#4
OP

OpenAI Chat Model

n8n-nodes-langchain.lmChatOpenAi

#5
ST

Structured Output Parser

n8n-nodes-langchain.outputParserStructured

#6

How to Import This Workflow

  1. 1Click Download JSON button on the right to save the workflow file.
  2. 2Open your n8n instance. Go to Workflows β†’ New β†’ Import from file.
  3. 3Select the downloaded invoice-processing-email-to-postgresql-database-with-gpt-4o-discord-alerts file and click Import.
  4. 4Set up credentials for each service node (API keys, OAuth, etc.).
  5. 5Click Test Workflow to verify everything works, then activate it.

Or paste directly in n8n β†’ Import from JSON:

{ "name": "Invoice Processing: Email to PostgreSQL Database with GPT-4o & Discord Alerts", "nodes": [...], ...}

Integrations

chainllmcodediscordemailreadimapextractfromfileiflmchatopenaimergeoutputparserstructuredpostgresset

Get This Workflow

Download and import in one click

Download JSONView on n8n.io
Nodes23
Complexityhigh
Triggermanual

Created by

Halfbit πŸš€

Halfbit πŸš€

@halfbit

Tags

chainllmcodediscordemailreadimapextractfromfileiflmchatopenaimergeoutputparserstructuredpostgres
⚑

New to n8n?

n8n is a free, open-source workflow automation tool. Self-host it or use the cloud version.

Get n8n Free β†’

Related Invoice Processing Workflows

COCOEMEX+5
medium

Automate Custom QuickBooks Invoice PDFs & Email with n8n

Standard accounting templates often fail to reflect a premium brand identity. This sophisticated n8n workflow bridges the gap between financial record-keeping and professional client presentation. By moving beyond the native limitations of QuickBooks Online, this automation enables businesses to generate high-end, multi-page PDF invoices that align perfectly with their corporate styling. The process begins the moment a new invoice is generated in QuickBooks, triggering a webhook that captures real-time billing data. The workflow then utilizes advanced HTML-to-File conversion and custom Code nodes to structure data into a polished, branded layout. It handles complex logic such as line-item merging and multi-page formatting automatically. Once the document is rendered, the system bypasses generic 'no-reply' senders by routing the finalized PDF through your preferred email provider. This ensures a seamless, white-labeled experience for your clients while eliminating the manual overhead of exporting, styling, and attaching files. Ideal for agencies and service providers, this flow guarantees that your most frequent touchpointβ€”the billβ€”is as professional as your work. **Common Use Cases:** - High-end creative agencies requiring bespoke, white-labeled billing documents for premium clients. - Automated recurring subscription billing where custom tax disclosures or localized branding are required. - Service-based businesses needing to attach dynamic project reports or terms of service directly to QuickBooks invoices.

πŸ”— WebhookΒ·12 nodes