¿Tiene factura adjunta?

Avanzado

Este es unautomatización que contiene 22 nodos.Utiliza principalmente nodos como If, Code, Gmail, Slack, Quickbooks. Usar detección de fraude de GPT-4o y QuickBooks para extraer y aprobar facturas automáticamente

Requisitos previos
  • Cuenta de Google y credenciales de API de Gmail
  • Bot Token de Slack o URL de Webhook
  • Credenciales de API de Google Sheets
  • Clave de API de OpenAI

Categoría

-
Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "id": "KMgt49BPco6oE5Xj",
  "meta": {
    "instanceId": "277842713620d9f5554de3b1518b865a152c8c4db680008bd8aec536fc18b4a8"
  },
  "name": "AI Invoice Approval & Fraud Detection",
  "tags": [
    {
      "id": "CWardZYJBmejoyC4",
      "name": "under review",
      "createdAt": "2025-10-09T18:43:37.031Z",
      "updatedAt": "2025-10-09T18:43:37.031Z"
    }
  ],
  "nodes": [
    {
      "id": "2855123e-800d-426d-9adc-35b4fcbbbd65",
      "name": "¿Tiene adjunto de factura?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1264,
        256
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "caseSensitive": false
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "has-attachment",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.attachments?.length > 0 }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6177f958-e010-426b-8d7a-1d9f2966eaed",
      "name": "Extraer adjuntos de facturas",
      "type": "n8n-nodes-base.code",
      "position": [
        -736,
        192
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const attachments = item.json.attachments || [];\n  \n  // Filter for PDF and image attachments (common invoice formats)\n  const invoiceAttachments = attachments.filter(att => {\n    const name = att.filename?.toLowerCase() || '';\n    return name.endsWith('.pdf') || \n           name.endsWith('.png') || \n           name.endsWith('.jpg') || \n           name.endsWith('.jpeg');\n  });\n  \n  // Process each invoice attachment\n  for (const attachment of invoiceAttachments) {\n    results.push({\n      json: {\n        email_from: item.json.from,\n        email_subject: item.json.subject,\n        email_date: item.json.date,\n        email_id: item.json.id,\n        attachment_name: attachment.filename,\n        attachment_id: attachment.attachmentId,\n        attachment_size: attachment.size,\n        invoice_id: `INV-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`\n      },\n      binary: {\n        data: item.binary[attachment.attachmentId]\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "49036c5c-fdc0-47d0-8885-63dcd931f2e2",
      "name": "IA - OCR y extracción de facturas",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -576,
        192
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "temperature": 0.1
        },
        "messages": {
          "values": [
            {
              "content": "=You are an expert invoice processing AI. Extract ALL information from this invoice document with perfect accuracy.\n\n**Email Context:**\nFrom: {{ $json.email_from }}\nSubject: {{ $json.email_subject }}\nDate: {{ $json.email_date }}\n\nAnalyze the attached invoice image/PDF and extract complete structured information. Return ONLY valid JSON with this exact structure:\n\n{\n  \"vendor_name\": \"Company Name\",\n  \"vendor_email\": \"vendor@email.com\",\n  \"vendor_address\": \"Full address\",\n  \"vendor_tax_id\": \"Tax/VAT ID if present\",\n  \"invoice_number\": \"INV-12345\",\n  \"invoice_date\": \"YYYY-MM-DD\",\n  \"due_date\": \"YYYY-MM-DD\",\n  \"po_number\": \"PO number if referenced\",\n  \"currency\": \"USD\",\n  \"line_items\": [\n    {\n      \"description\": \"Item description\",\n      \"quantity\": 1,\n      \"unit_price\": 100.00,\n      \"total\": 100.00\n    }\n  ],\n  \"subtotal\": 100.00,\n  \"tax_amount\": 8.00,\n  \"tax_rate\": 8.0,\n  \"shipping\": 0.00,\n  \"total_amount\": 108.00,\n  \"payment_terms\": \"Net 30\",\n  \"notes\": \"Any special notes or terms\",\n  \"bank_details\": \"Bank account information if present\",\n  \"invoice_category\": \"software|hardware|services|consulting|office_supplies|utilities|marketing|travel|other\",\n  \"confidence_score\": 0.95\n}\n\nIMPORTANT:\n- Extract exact amounts with 2 decimal places\n- Use YYYY-MM-DD format for dates\n- If information is missing, use null\n- Be extremely accurate with numbers\n- Classify invoice into appropriate category\n- Confidence score 0-1 based on document clarity"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "8IkhtT3EbXygnvcr",
          "name": "Klinsman OpenAI"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "e82f7d85-e1d2-408b-a3ce-b5e12993763d",
      "name": "Analizar datos de la factura",
      "type": "n8n-nodes-base.code",
      "position": [
        -288,
        192
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  try {\n    // Parse AI response\n    const aiText = item.json.message?.content || item.json.output || '{}';\n    \n    // Clean JSON\n    let cleanJson = aiText.replace(/```json\\n?/g, '').replace(/```\\n?/g, '').trim();\n    const jsonMatch = cleanJson.match(/\\{[\\s\\S]*\\}/);\n    if (jsonMatch) {\n      cleanJson = jsonMatch[0];\n    }\n    \n    const invoiceData = JSON.parse(cleanJson);\n    \n    // Get original email data\n    const originalData = $('Extract Invoice Attachments').item(0).json;\n    \n    results.push({\n      json: {\n        ...originalData,\n        ...invoiceData,\n        parsed_at: new Date().toISOString(),\n        processing_status: 'extracted'\n      }\n    });\n  } catch (error) {\n    results.push({\n      json: {\n        ...item.json,\n        parsing_error: error.message,\n        processing_status: 'failed'\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "2aedc6f8-75f4-4ae3-a562-39f270728a28",
      "name": "Agente de detección de fraude con IA",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        16,
        144
      ],
      "parameters": {
        "text": "=You are a financial fraud detection AI with expertise in identifying invoice anomalies, duplicate submissions, and fraudulent patterns.\n\nAnalyze this invoice for potential fraud, anomalies, or issues:\n\n## INVOICE DETAILS\n**Vendor:** {{ $json.vendor_name }}\n**Invoice Number:** {{ $json.invoice_number }}\n**Date:** {{ $json.invoice_date }}\n**Due Date:** {{ $json.due_date }}\n**Amount:** {{ $json.currency }} {{ $json.total_amount }}\n**Category:** {{ $json.invoice_category }}\n**PO Number:** {{ $json.po_number || 'None' }}\n**Email From:** {{ $json.email_from }}\n\n**Line Items:**\n{{ $json.line_items.map(item => `- ${item.description}: ${item.quantity} × $${item.unit_price} = $${item.total}`).join('\\n') }}\n\n**Payment Terms:** {{ $json.payment_terms }}\n\n---\n\n## FRAUD DETECTION CRITERIA\n\n### Red Flags to Check:\n1. **Duplicate Invoice Detection**\n   - Similar amounts recently processed\n   - Same invoice number from this vendor\n   - Duplicate line item descriptions\n\n2. **Amount Anomalies**\n   - Unusually high amount for vendor/category\n   - Round numbers (possible fake invoices)\n   - Amount just under approval threshold (splitting)\n\n3. **Vendor Verification**\n   - New/unknown vendor\n   - Mismatched email domain vs vendor name\n   - Missing tax ID or business details\n   - Suspicious bank details\n\n4. **Document Quality Issues**\n   - Low confidence score from OCR\n   - Missing critical information\n   - Unprofessional formatting\n   - Mismatched totals or calculations\n\n5. **Timing Anomalies**\n   - Invoice date in future\n   - Very old invoice\n   - Due date already passed\n   - Weekend/holiday invoice dates\n\n6. **Pattern Detection**\n   - Frequent small invoices (just under approval limit)\n   - Vague descriptions (\"consulting services\")\n   - No PO number for large amounts\n   - Rush payment requests\n\n### Category-Specific Checks:\n- **Software/SaaS:** Check if subscription-based, verify renewal dates\n- **Consulting:** Verify hourly rates are reasonable\n- **Travel:** Check dates align with known business trips\n- **Office Supplies:** Verify quantities are reasonable\n\n---\n\n## YOUR ANALYSIS TASK\n\nProvide detailed fraud risk assessment covering:\n\n1. **Overall Risk Level** - critical/high/medium/low with clear reasoning\n\n2. **Specific Red Flags Found** - List all anomalies detected\n\n3. **Vendor Trust Score** - Rate vendor legitimacy (0-100)\n\n4. **Amount Validation** - Is the amount reasonable for this category?\n\n5. **Document Quality Score** - Rate invoice professionalism (0-100)\n\n6. **Duplicate Risk** - Likelihood this is a duplicate submission\n\n7. **Recommended Action** - auto_approve / manager_review / fraud_investigation / reject\n\n8. **Required Verifications** - What should be manually verified\n\n9. **Approval Workflow** - Who should approve based on amount/risk\n\n10. **Priority Level** - urgent / high / normal / low\n\nBe thorough and err on the side of caution. Flag anything suspicious for human review.",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "d79e193d-8f8e-4f63-bc5d-87af7ebd3e42",
      "name": "Modelo de chat OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -16,
        416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "temperature": 0.2
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "8IkhtT3EbXygnvcr",
          "name": "Klinsman OpenAI"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b07f6e14-d650-4da4-845f-191d76249aa6",
      "name": "Analizador de salida estructurada",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        176,
        416
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"required\": [\n    \"risk_level\",\n    \"risk_score\",\n    \"red_flags\",\n    \"vendor_trust_score\",\n    \"amount_validation\",\n    \"document_quality_score\",\n    \"duplicate_risk\",\n    \"recommended_action\",\n    \"required_verifications\",\n    \"approval_workflow\",\n    \"priority_level\",\n    \"detailed_analysis_markdown\"\n  ],\n  \"properties\": {\n    \"risk_level\": {\n      \"type\": \"string\",\n      \"enum\": [\"critical\", \"high\", \"medium\", \"low\"]\n    },\n    \"risk_score\": {\n      \"type\": \"integer\",\n      \"minimum\": 0,\n      \"maximum\": 100,\n      \"description\": \"Overall fraud risk score\"\n    },\n    \"red_flags\": {\n      \"type\": \"array\",\n      \"items\": {\"type\": \"string\"},\n      \"description\": \"List of specific concerns found\"\n    },\n    \"vendor_trust_score\": {\n      \"type\": \"integer\",\n      \"minimum\": 0,\n      \"maximum\": 100\n    },\n    \"amount_validation\": {\n      \"type\": \"string\",\n      \"description\": \"Is amount reasonable? Details\"\n    },\n    \"document_quality_score\": {\n      \"type\": \"integer\",\n      \"minimum\": 0,\n      \"maximum\": 100\n    },\n    \"duplicate_risk\": {\n      \"type\": \"string\",\n      \"enum\": [\"none\", \"low\", \"medium\", \"high\", \"confirmed\"]\n    },\n    \"recommended_action\": {\n      \"type\": \"string\",\n      \"enum\": [\"auto_approve\", \"manager_review\", \"cfo_approval\", \"fraud_investigation\", \"reject\"]\n    },\n    \"required_verifications\": {\n      \"type\": \"array\",\n      \"items\": {\"type\": \"string\"}\n    },\n    \"approval_workflow\": {\n      \"type\": \"string\",\n      \"description\": \"Who should approve\"\n    },\n    \"priority_level\": {\n      \"type\": \"string\",\n      \"enum\": [\"urgent\", \"high\", \"normal\", \"low\"]\n    },\n    \"detailed_analysis_markdown\": {\n      \"type\": \"string\",\n      \"description\": \"Full analysis in markdown\"\n    }\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "5f940f8a-f146-4438-b87d-e85b294095bb",
      "name": "¿Riesgo crítico de fraude?",
      "type": "n8n-nodes-base.if",
      "position": [
        400,
        96
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {},
          "combinator": "or",
          "conditions": [
            {
              "id": "critical-risk",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.risk_level }}",
              "rightValue": "critical"
            },
            {
              "id": "fraud-investigation",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.recommended_action }}",
              "rightValue": "fraud_investigation"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7ca0fa2f-183d-41fb-b654-bd39481ffc99",
      "name": "¿Aprobación automática elegible?",
      "type": "n8n-nodes-base.if",
      "position": [
        416,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {},
          "combinator": "and",
          "conditions": [
            {
              "id": "auto-approve",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.recommended_action }}",
              "rightValue": "auto_approve"
            },
            {
              "id": "low-risk-and-small",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.risk_level }}",
              "rightValue": "low"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7f4ffb88-3c0a-4ee2-90bf-f6139eeb62e2",
      "name": "Solicitar investigación de fraude",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1296,
        -16
      ],
      "webhookId": "fraud-investigation-webhook",
      "parameters": {
        "sendTo": "finance-manager@yourcompany.com",
        "message": "=<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody{font-family:Arial,sans-serif;line-height:1.6;color:#333;max-width:700px;margin:0 auto;padding:20px}\n.alert-banner{background:#dc3545;color:#fff;padding:20px;text-align:center;border-radius:8px 8px 0 0;font-size:20px;font-weight:bold}\n.content{background:#fff;padding:30px;border:3px solid #dc3545}\n.risk-grid{display:grid;grid-template-columns:1fr 1fr 1fr;gap:15px;margin:20px 0}\n.risk-box{background:#fff3cd;padding:15px;text-align:center;border-radius:5px;border:2px solid #ffc107}\n.risk-box.critical{background:#f8d7da;border-color:#dc3545}\n.risk-box strong{display:block;font-size:28px;color:#dc3545;margin-bottom:5px}\n.red-flags{background:#f8d7da;padding:15px;border-left:4px solid #dc3545;margin:20px 0}\n.invoice-details{background:#f8f9fa;padding:15px;border-radius:5px;margin:20px 0}\n</style>\n</head>\n<body>\n<div class=\"alert-banner\">🚨 CRITICAL FRAUD ALERT 🚨</div>\n<div class=\"content\">\n<p><strong>A potentially fraudulent invoice has been detected and requires immediate investigation.</strong></p>\n\n<div class=\"invoice-details\">\n<h3 style=\"margin-top:0;color:#dc3545\">Invoice Information</h3>\n<p><strong>Vendor:</strong> {{ $('Parse Invoice Data').item.json.vendor_name }}<br>\n<strong>Invoice Number:</strong> {{ $('Parse Invoice Data').item.json.invoice_number }}<br>\n<strong>Amount:</strong> {{ $('Parse Invoice Data').item.json.currency }} {{ $('Parse Invoice Data').item.json.total_amount }}<br>\n<strong>Date:</strong> {{ $('Parse Invoice Data').item.json.invoice_date }}<br>\n<strong>Due Date:</strong> {{ $('Parse Invoice Data').item.json.due_date }}<br>\n<strong>Category:</strong> {{ $('Parse Invoice Data').item.json.invoice_category }}<br>\n<strong>PO Number:</strong> {{ $('Parse Invoice Data').item.json.po_number || 'None provided' }}</p>\n</div>\n\n<div class=\"risk-grid\">\n<div class=\"risk-box critical\"><strong>{{ $json.output.risk_score }}</strong>Risk Score</div>\n<div class=\"risk-box\"><strong>{{ $json.output.vendor_trust_score }}</strong>Vendor Trust</div>\n<div class=\"risk-box\"><strong>{{ $json.output.document_quality_score }}</strong>Doc Quality</div>\n</div>\n\n<div class=\"red-flags\">\n<h3 style=\"margin-top:0;color:#dc3545\">⚠️ Red Flags Detected</h3>\n<ul style=\"margin:0;padding-left:20px\">\n{{ $json.output.red_flags.map(flag => '<li><strong>' + flag + '</strong></li>').join('') }}\n</ul>\n</div>\n\n<h3>Required Verifications:</h3>\n<ul>\n{{ $json.output.required_verifications.map(ver => '<li>' + ver + '</li>').join('') }}\n</ul>\n\n<h3>AI Recommendation:</h3>\n<p style=\"font-size:18px;color:#dc3545\"><strong>{{ $json.output.recommended_action.toUpperCase().replace('_', ' ') }}</strong></p>\n\n<p><strong>⏰ This invoice has been BLOCKED from payment pending your investigation.</strong></p>\n\n<p>Please review immediately and take appropriate action.</p>\n\n<p style=\"margin-top:30px;padding-top:20px;border-top:1px solid #ddd;font-size:12px;color:#666\">\n<strong>Invoice ID:</strong> {{ $('Parse Invoice Data').item.json.invoice_id }}<br>\n<strong>Detected:</strong> {{ $('Parse Invoice Data').item.json.parsed_at }}\n</p>\n</div>\n</body>\n</html>",
        "options": {},
        "subject": "=⚠️ URGENT: Suspicious Invoice Requires Investigation - {{ $('Parse Invoice Data').item.json.vendor_name }}",
        "operation": "sendAndWait"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PIMDNhXNj8Zyiz3G",
          "name": "Gmail account - Deepanshi"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "4de0ce06-d062-4c0d-a006-3dda68257db0",
      "name": "¿Monto > $5000?",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {},
          "conditions": [
            {
              "id": "amount-check",
              "operator": {
                "type": "number",
                "operation": "larger"
              },
              "leftValue": "={{ $('Parse Invoice Data').item.json.total_amount }}",
              "rightValue": "5000"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8b3d632f-fb06-4f4c-bbe7-00012fe7581e",
      "name": "Solicitar aprobación del gerente",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1312,
        176
      ],
      "webhookId": "manager-approval-webhook",
      "parameters": {
        "sendTo": "finance-manager@yourcompany.com",
        "message": "=<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody{font-family:Arial,sans-serif;line-height:1.6;color:#333;max-width:700px;margin:0 auto;padding:20px}\n.header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:#fff;padding:25px;text-align:center;border-radius:8px 8px 0 0}\n.content{background:#fff;padding:30px;border:1px solid #ddd}\n.info-grid{display:grid;grid-template-columns:1fr 1fr;gap:15px;margin:20px 0}\n.info-box{background:#f8f9fa;padding:15px;border-radius:5px}\n.score-box{background:#d4edda;padding:15px;text-align:center;border-radius:5px;border:2px solid #28a745}\n.score-box strong{display:block;font-size:24px;color:#28a745}\n.line-items{background:#f8f9fa;padding:15px;border-radius:5px;margin:20px 0}\ntable{width:100%;border-collapse:collapse}\ntable th{background:#667eea;color:#fff;padding:10px;text-align:left}\ntable td{padding:10px;border-bottom:1px solid #ddd}\n</style>\n</head>\n<body>\n<div class=\"header\">\n<h2 style=\"margin:0\">📄 Invoice Approval Required</h2>\n<p style=\"margin:5px 0 0 0\">{{ $('Parse Invoice Data').item.json.vendor_name }}</p>\n</div>\n<div class=\"content\">\n<div class=\"info-grid\">\n<div class=\"info-box\">\n<strong>Invoice Number:</strong> {{ $('Parse Invoice Data').item.json.invoice_number }}<br>\n<strong>Date:</strong> {{ $('Parse Invoice Data').item.json.invoice_date }}<br>\n<strong>Due Date:</strong> {{ $('Parse Invoice Data').item.json.due_date }}\n</div>\n<div class=\"info-box\">\n<strong>Amount:</strong> {{ $('Parse Invoice Data').item.json.currency }} {{ $('Parse Invoice Data').item.json.total_amount }}<br>\n<strong>Category:</strong> {{ $('Parse Invoice Data').item.json.invoice_category }}<br>\n<strong>PO #:</strong> {{ $('Parse Invoice Data').item.json.po_number || 'N/A' }}\n</div>\n</div>\n\n<div class=\"score-box\">\n<strong>{{ $json.output.vendor_trust_score }}</strong>\nVendor Trust Score (Low Risk)\n</div>\n\n<div class=\"line-items\">\n<h3 style=\"margin-top:0\">Line Items</h3>\n<table>\n<thead>\n<tr><th>Description</th><th>Qty</th><th>Unit Price</th><th>Total</th></tr>\n</thead>\n<tbody>\n{{ $('Parse Invoice Data').item.json.line_items.map(item => '<tr><td>' + item.description + '</td><td>' + item.quantity + '</td><td>$' + item.unit_price.toFixed(2) + '</td><td>$' + item.total.toFixed(2) + '</td></tr>').join('') }}\n<tr style=\"font-weight:bold;background:#f8f9fa\"><td colspan=\"3\">Subtotal</td><td>${{ $('Parse Invoice Data').item.json.subtotal.toFixed(2) }}</td></tr>\n<tr><td colspan=\"3\">Tax ({{ $('Parse Invoice Data').item.json.tax_rate }}%)</td><td>${{ $('Parse Invoice Data').item.json.tax_amount.toFixed(2) }}</td></tr>\n<tr style=\"font-weight:bold;font-size:18px;background:#667eea;color:#fff\"><td colspan=\"3\">TOTAL</td><td>${{ $('Parse Invoice Data').item.json.total_amount.toFixed(2) }}</td></tr>\n</tbody>\n</table>\n</div>\n\n<h3>AI Analysis Summary:</h3>\n<p><strong>Risk Level:</strong> {{ $json.output.risk_level.toUpperCase() }}<br>\n<strong>Recommendation:</strong> {{ $json.output.recommended_action.replace('_', ' ').toUpperCase() }}</p>\n\n{{ $json.output.red_flags.length > 0 ? '<h3>⚠️ Items to Verify:</h3><ul>' + $json.output.red_flags.map(flag => '<li>' + flag + '</li>').join('') + '</ul>' : '<p>✅ No issues detected</p>' }}\n\n<p><strong>Payment Terms:</strong> {{ $('Parse Invoice Data').item.json.payment_terms }}</p>\n\n<p style=\"margin-top:30px\"><strong>Please approve or reject this invoice.</strong></p>\n</div>\n</body>\n</html>",
        "options": {},
        "subject": "=Invoice Approval Required - {{ $('Parse Invoice Data').item.json.vendor_name }} - ${{ $('Parse Invoice Data').item.json.total_amount }}",
        "operation": "sendAndWait"
      },
      "typeVersion": 2.1
    },
    {
      "id": "e7d4d4b9-f1a7-49c2-acb2-bf66d102fe29",
      "name": "Notificar al proveedor - Aprobada",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1328,
        368
      ],
      "webhookId": "c9c97d37-6231-4e60-8d68-252db4f5399f",
      "parameters": {
        "sendTo": "={{ $('Parse Invoice Data').item.json.email_from }}",
        "message": "=<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody{font-family:Arial,sans-serif;line-height:1.6;color:#333;max-width:600px;margin:0 auto;padding:20px}\n.header{background:#28a745;color:#fff;padding:20px;text-align:center;border-radius:8px 8px 0 0}\n.content{background:#fff;padding:30px;border:1px solid #ddd}\n.info-box{background:#f8f9fa;padding:15px;border-radius:5px;margin:20px 0}\n</style>\n</head>\n<body>\n<div class=\"header\"><h2 style=\"margin:0\">✅ Invoice Approved</h2></div>\n<div class=\"content\">\n<p>Dear {{ $('Parse Invoice Data').item.json.vendor_name }},</p>\n<p>Thank you for your invoice. We've received and automatically processed it.</p>\n<div class=\"info-box\">\n<strong>Invoice Number:</strong> {{ $('Parse Invoice Data').item.json.invoice_number }}<br>\n<strong>Amount:</strong> {{ $('Parse Invoice Data').item.json.currency }} {{ $('Parse Invoice Data').item.json.total_amount }}<br>\n<strong>Due Date:</strong> {{ $('Parse Invoice Data').item.json.due_date }}<br>\n<strong>Status:</strong> Approved for Payment\n</div>\n<p>Payment will be processed according to terms: <strong>{{ $('Parse Invoice Data').item.json.payment_terms }}</strong></p>\n<p>Expected payment date: <strong>{{ $('Parse Invoice Data').item.json.due_date }}</strong></p>\n<p>If you have questions, please reply to this email.</p>\n<p>Best regards,<br><strong>Accounts Payable</strong><br>[Your Company]</p>\n</div>\n</body>\n</html>",
        "options": {},
        "subject": "=Invoice Received & Processing - {{ $('Parse Invoice Data').item.json.invoice_number }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "33787ce5-b0ef-46f2-9687-6d88d4effb55",
      "name": "Registrar en base de datos de facturas",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1840,
        272
      ],
      "parameters": {
        "columns": {
          "value": {
            "amount": "={{ $('Parse Invoice Data').item.json.total_amount }}",
            "status": "={{ $json.status || 'Processed' }}",
            "category": "={{ $('Parse Invoice Data').item.json.invoice_category }}",
            "currency": "={{ $('Parse Invoice Data').item.json.currency }}",
            "due_date": "={{ $('Parse Invoice Data').item.json.due_date }}",
            "po_number": "={{ $('Parse Invoice Data').item.json.po_number }}",
            "red_flags": "={{ $json.output.red_flags.join('; ') }}",
            "invoice_id": "={{ $('Parse Invoice Data').item.json.invoice_id }}",
            "risk_level": "={{ $json.output.risk_level }}",
            "risk_score": "={{ $json.output.risk_score }}",
            "vendor_name": "={{ $('Parse Invoice Data').item.json.vendor_name }}",
            "invoice_date": "={{ $('Parse Invoice Data').item.json.invoice_date }}",
            "vendor_email": "={{ $('Parse Invoice Data').item.json.vendor_email }}",
            "vendor_trust": "={{ $json.output.vendor_trust_score }}",
            "duplicate_risk": "={{ $json.output.duplicate_risk }}",
            "invoice_number": "={{ $('Parse Invoice Data').item.json.invoice_number }}",
            "processed_date": "={{ $('Parse Invoice Data').item.json.parsed_at }}",
            "recommended_action": "={{ $json.output.recommended_action }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "e510ac2c-183f-4f6b-bea0-1573cb6af792",
      "name": "Nota adhesiva - Recepción",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1568,
        64
      ],
      "parameters": {
        "color": 5,
        "width": 674,
        "height": 388,
        "content": "## 📧 Smart Invoice Intake\n\nMonitors new invoice submitted via a **Jotform**\n\nCreate your form for free on [JotForm using this link](https://www.jotform.com/?partner=mediajade)\n\n**Output:** Invoice attachments ready for AI processing"
      },
      "typeVersion": 1
    },
    {
      "id": "e03f3fdf-80c2-4c87-9e05-58f499853191",
      "name": "Nota adhesiva - OCR",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 674,
        "height": 444,
        "content": "## 🤖 AI-Powered OCR & Data Extraction\n\nUses GPT-4o-mini with vision to read invoices and extract ALL structured data with high accuracy.\n\n**Result:** 95%+ accuracy on invoice data extraction"
      },
      "typeVersion": 1
    },
    {
      "id": "69a627b2-fc15-440b-9668-f7cead11c022",
      "name": "Nota adhesiva - Fraude",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        -48
      ],
      "parameters": {
        "color": 6,
        "width": 756,
        "height": 692,
        "content": "## 🚨 AI Fraud Detection & Risk Analysis\n\nAdvanced fraud detection AI analyzes every invoice for anomalies, duplicates, and suspicious patterns.\n\n**Result:** Catch fraud before payment, protect company assets"
      },
      "typeVersion": 1
    },
    {
      "id": "8a173f21-6a0a-4428-916e-801b83eb1dda",
      "name": "Nota adhesiva - Enrutamiento",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        -176
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 772,
        "content": "## 🚦 Intelligent Routing & Approval Workflows\n\nAutomatically routes invoices based on risk level, amount, and fraud analysis.\n\n**Result:** Fast processing for legitimate invoices, rigorous checks for suspicious ones"
      },
      "typeVersion": 1
    },
    {
      "id": "30f7ee03-153b-4ab6-86ce-f01e014e42d1",
      "name": "Nota adhesiva - Análisis",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1632,
        96
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 364,
        "content": "## 📊 Financial Analytics & Audit Trail\n\nComprehensive logging of all invoices for analytics, compliance, and audit purposes.\n\n**Result:** Data-driven financial operations with full transparency"
      },
      "typeVersion": 1
    },
    {
      "id": "399c8b7f-a346-4cab-a49f-337b8b1605f4",
      "name": "Enviar un mensaje",
      "type": "n8n-nodes-base.slack",
      "position": [
        992,
        0
      ],
      "webhookId": "9d823dcf-d08f-4c87-aef9-d9cb2b4b542a",
      "parameters": {
        "text": "=:rotating_light: *CRITICAL FRAUD ALERT* :rotating_light:\\n\\n*Invoice Details:*\\nVendor: {{ $('Parse Invoice Data').item.json.vendor_name }}\\nAmount: {{ $('Parse Invoice Data').item.json.currency }} {{ $('Parse Invoice Data').item.json.total_amount }}\\nInvoice #: {{ $('Parse Invoice Data').item.json.invoice_number }}\\n\\n*Risk Assessment:*\\nRisk Level: {{ $json.output.risk_level.toUpperCase() }}\\nRisk Score: {{ $json.output.risk_score }}/100\\nVendor Trust: {{ $json.output.vendor_trust_score }}/100\\n\\n*Red Flags:*\\n{{ $json.output.red_flags.map(flag => '• ' + flag).join('\\\\n') }}\\n\\n*Recommended Action:* {{ $json.output.recommended_action.toUpperCase().replace('_', ' ') }}\\n\\n:warning: *IMMEDIATE ACTION REQUIRED* - Do NOT process this invoice until investigated!",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "otherOptions": {}
      },
      "typeVersion": 2.3
    },
    {
      "id": "87e7a15b-abbc-4fbc-b1ba-fe987c2740c8",
      "name": "Actualizar una factura",
      "type": "n8n-nodes-base.quickbooks",
      "position": [
        1104,
        368
      ],
      "parameters": {
        "resource": "invoice",
        "operation": "update",
        "updateFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "8faf07af-b384-43d9-910e-ad4991bddd87",
      "name": "Activador de JotForm",
      "type": "n8n-nodes-base.jotFormTrigger",
      "position": [
        -1488,
        256
      ],
      "webhookId": "209c111c-5573-466c-8602-b4d6e2f44659",
      "parameters": {
        "form": "252815253377461"
      },
      "credentials": {
        "jotFormApi": {
          "id": "cOSh16Q5l4e0EB1A",
          "name": "Jotform jitesh@mediajade.com"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6b6c692c-9156-400b-938a-66f0ae41f11c",
  "connections": {
    "399c8b7f-a346-4cab-a49f-337b8b1605f4": {
      "main": [
        [
          {
            "node": "7f4ffb88-3c0a-4ee2-90bf-f6139eeb62e2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4de0ce06-d062-4c0d-a006-3dda68257db0": {
      "main": [
        [
          {
            "node": "8b3d632f-fb06-4f4c-bbe7-00012fe7581e",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "87e7a15b-abbc-4fbc-b1ba-fe987c2740c8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8faf07af-b384-43d9-910e-ad4991bddd87": {
      "main": [
        [
          {
            "node": "2855123e-800d-426d-9adc-35b4fcbbbd65",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d79e193d-8f8e-4f63-bc5d-87af7ebd3e42": {
      "ai_languageModel": [
        [
          {
            "node": "2aedc6f8-75f4-4ae3-a562-39f270728a28",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "87e7a15b-abbc-4fbc-b1ba-fe987c2740c8": {
      "main": [
        [
          {
            "node": "e7d4d4b9-f1a7-49c2-acb2-bf66d102fe29",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e82f7d85-e1d2-408b-a3ce-b5e12993763d": {
      "main": [
        [
          {
            "node": "2aedc6f8-75f4-4ae3-a562-39f270728a28",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5f940f8a-f146-4438-b87d-e85b294095bb": {
      "main": [
        [
          {
            "node": "399c8b7f-a346-4cab-a49f-337b8b1605f4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "4de0ce06-d062-4c0d-a006-3dda68257db0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7ca0fa2f-183d-41fb-b654-bd39481ffc99": {
      "main": [
        [
          {
            "node": "87e7a15b-abbc-4fbc-b1ba-fe987c2740c8",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "4de0ce06-d062-4c0d-a006-3dda68257db0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2855123e-800d-426d-9adc-35b4fcbbbd65": {
      "main": [
        [
          {
            "node": "6177f958-e010-426b-8d7a-1d9f2966eaed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2aedc6f8-75f4-4ae3-a562-39f270728a28": {
      "main": [
        [
          {
            "node": "5f940f8a-f146-4438-b87d-e85b294095bb",
            "type": "main",
            "index": 0
          },
          {
            "node": "7ca0fa2f-183d-41fb-b654-bd39481ffc99",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e7d4d4b9-f1a7-49c2-acb2-bf66d102fe29": {
      "main": [
        [
          {
            "node": "33787ce5-b0ef-46f2-9687-6d88d4effb55",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8b3d632f-fb06-4f4c-bbe7-00012fe7581e": {
      "main": [
        [
          {
            "node": "33787ce5-b0ef-46f2-9687-6d88d4effb55",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b07f6e14-d650-4da4-845f-191d76249aa6": {
      "ai_outputParser": [
        [
          {
            "node": "2aedc6f8-75f4-4ae3-a562-39f270728a28",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "49036c5c-fdc0-47d0-8885-63dcd931f2e2": {
      "main": [
        [
          {
            "node": "e82f7d85-e1d2-408b-a3ce-b5e12993763d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6177f958-e010-426b-8d7a-1d9f2966eaed": {
      "main": [
        [
          {
            "node": "49036c5c-fdc0-47d0-8885-63dcd931f2e2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7f4ffb88-3c0a-4ee2-90bf-f6139eeb62e2": {
      "main": [
        [
          {
            "node": "33787ce5-b0ef-46f2-9687-6d88d4effb55",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿Cómo usar este flujo de trabajo?

Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.

¿En qué escenarios es adecuado este flujo de trabajo?

Avanzado

¿Es de pago?

Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.

Información del flujo de trabajo
Nivel de dificultad
Avanzado
Número de nodos22
Categoría-
Tipos de nodos12
Descripción de la dificultad

Adecuado para usuarios avanzados, flujos de trabajo complejos con 16+ nodos

Autor
Jitesh Dugar

Jitesh Dugar

@jiteshdugar

AI Automation Specialist - OpenAI, CRM & Automation Expert with a solid understanding of various tools that include Zapier, Make, Zoho CRM, Hubspot, Google Sheets, Airtable, Pipedrive, Google Analytics, and more.

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34