{
  "name": "Document Intelligence Workflow",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {},
        "options": {
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        -1920,
        -60
      ],
      "id": "f2d9bbf8-c9ed-477c-b144-38e642709e1c",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "id": "eEcIcDm0Eq5KA5F2",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.0-flash-exp",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        -1340,
        120
      ],
      "id": "969715c7-da5f-4369-a257-bee3d7d4e3ef",
      "name": "Google Gemini Chat Model1",
      "credentials": {
        "googlePalmApi": {
          "id": "rqm9WHlcHVNKIX6K",
          "name": "Google Gemini(PaLM) Api account 2"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are an email classifier that determines whether an email is invoice or bill-related. Analyze the email subject and content to identify if it contains billing information, payment requests, invoices, receipts, or financial obligations.\n\nYour task: Read the provided email subject and content, then respond with only \"YES\" if it's an invoice/bill-related email, or \"NO\" if it's not.\n\nInvoice/Bill indicators include:\n- Invoice numbers, billing statements, payment due dates\n- Words like: invoice, bill, payment, due, amount owed, receipt, statement, charge\n- Financial amounts, payment methods, account balances\n- Vendor/company billing communications\n- Purchase confirmations with payment details\n- Subscription/service fee notifications\n- Late payment notices, overdue reminders\n\nNOT invoice/bill emails:\n- Marketing emails, newsletters, promotions\n- General business communications\n- Social notifications, personal messages\n- Appointment confirmations without payment\n- Product information without billing\n\nInput Format\n\nEmail Subject: {{ $('Field Extraction').item.json.email_subject }}\n\nEmail Content: {{ $('Field Extraction').item.json.email_content }}\n\nOutput Format \n\nRespond with only one word: YES or NO\n ",
        "hasOutputParser": true,
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        -1360,
        -60
      ],
      "id": "0760926f-70e4-4651-8476-482f72cdc3b1",
      "name": "Basic LLM Chain1"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"is_invoice\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"description\": \"Whether the email is invoice/bill related\"\n\t\t}\n\t},\n\t\"required\": [\"is_invoice\"]\n}\n"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        -1200,
        120
      ],
      "id": "8f1d0a20-4a76-4c04-8286-10234554820a",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a1279300-a8b8-4e18-bc2c-7792b2a1d72b",
              "leftValue": "={{ $json.status }}",
              "rightValue": "running",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "1bcea415-c462-46f3-a198-68f71ef92860",
              "leftValue": "",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        380,
        -60
      ],
      "id": "f03a7d99-b4b5-42ee-9c11-aa9de5bc435f",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        320,
        140
      ],
      "id": "9ffc6e12-e5df-4adc-923c-13d4ba69501d",
      "name": "Wait",
      "webhookId": "518e20fd-1087-4704-8127-4c744b8a0ebd"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1we5B_Lxm1Ez5XvvHJ4ZQUDwW8TPg6PyDwCA3ku0LQcs",
          "mode": "list",
          "cachedResultName": "test n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1we5B_Lxm1Ez5XvvHJ4ZQUDwW8TPg6PyDwCA3ku0LQcs/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1we5B_Lxm1Ez5XvvHJ4ZQUDwW8TPg6PyDwCA3ku0LQcs/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "VendorName": "={{ $json.Invoice_1.VendorName.content }}",
            "VendorAddress": "={{ $json.Invoice_1.VendorAddress.content }}",
            "PaymentTerm": "={{ $json.Invoice_1.PaymentTerm.content }}",
            "CustomerName": "={{ $json.Invoice_1.CustomerName.content }}",
            "CustomerId": "={{ $json.Invoice_1.CustomerId.content }}",
            "CustomerAddress": "={{ $json.Invoice_1.CustomerAddress.content }}",
            "CustomerAddressRecipient": "={{ $json.Invoice_1.CustomerAddressRecipient.content }}",
            "InvoiceId": "={{ $json.Invoice_1.InvoiceId.content }}",
            "InvoiceDate": "={{ $json.Invoice_1.InvoiceDate.content }}",
            "InvoiceTotal": "={{ $json.Invoice_1.InvoiceTotal.content }}",
            "Items": "={{ $json.Invoice_1.Items }}",
            "ServiceEndDate": "={{ $json.Invoice_1.ServiceEndDate.content }}",
            "ServiceStartDate": "={{ $json.Invoice_1.ServiceStartDate.content }}",
            "TotalTax": "={{ $json.Invoice_1.TotalTax.content }}",
            "SubTotal": "={{ $json.Invoice_1.SubTotal.content }}",
            "DueDate": "={{ $json.Invoice_1.DueDate.content }}",
            "PurchaseOrder": "={{ $json.Invoice_1.PurchaseOrder.content }}",
            "BillingAddress": "={{ $json.Invoice_1.BillingAddress.content }}",
            "BillingAddressRecipient": "={{ $json.Invoice_1.BillingAddressRecipient.content }}",
            "ShippingAddress": "={{ $json.Invoice_1.ShippingAddress.content }}",
            "ShippingAddressRecipient": "={{ $json.Invoice_1.ShippingAddressRecipient.content }}",
            "PreviousUnpaidBalance": "={{ $json.Invoice_1.PreviousUnpaidBalance.content }}",
            "AmountDue": "={{ $json.Invoice_1.AmountDue.content }}",
            "ServiceAddress": "={{ $json.Invoice_1.ServiceAddress.content }}",
            "ServiceAddressRecipient": "={{ $json.Invoice_1.ServiceAddressRecipient.content }}",
            "Email From": "={{ $('Field Extraction').item.json.email_from }}",
            "id": "={{ $('Field Extraction').item.json.email_message_id }}",
            "Status": "Success"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "Email From",
              "displayName": "Email From",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "VendorName",
              "displayName": "VendorName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "VendorAddress",
              "displayName": "VendorAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "PaymentTerm",
              "displayName": "PaymentTerm",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "CustomerName",
              "displayName": "CustomerName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "CustomerId",
              "displayName": "CustomerId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "CustomerAddress",
              "displayName": "CustomerAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "CustomerAddressRecipient",
              "displayName": "CustomerAddressRecipient",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "InvoiceId",
              "displayName": "InvoiceId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "InvoiceDate",
              "displayName": "InvoiceDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "InvoiceTotal",
              "displayName": "InvoiceTotal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "DueDate",
              "displayName": "DueDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "PurchaseOrder",
              "displayName": "PurchaseOrder",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "BillingAddress",
              "displayName": "BillingAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "BillingAddressRecipient",
              "displayName": "BillingAddressRecipient",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ShippingAddress",
              "displayName": "ShippingAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ShippingAddressRecipient",
              "displayName": "ShippingAddressRecipient",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "SubTotal",
              "displayName": "SubTotal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "TotalTax",
              "displayName": "TotalTax",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "PreviousUnpaidBalance",
              "displayName": "PreviousUnpaidBalance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "AmountDue",
              "displayName": "AmountDue",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ServiceStartDate",
              "displayName": "ServiceStartDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ServiceEndDate",
              "displayName": "ServiceEndDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ServiceAddress",
              "displayName": "ServiceAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "ServiceAddressRecipient",
              "displayName": "ServiceAddressRecipient",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Items",
              "displayName": "Items",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        820,
        -60
      ],
      "id": "3efdecf0-aa81-4c2e-a9b5-0dc3c1bd5f1b",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "5PXqxUvuLMrnoxCm",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e5957902-8418-4101-8477-7bfb487ffffb",
              "name": "email_message_id",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "09938dd0-f557-40dd-8adb-6d9d2aff0d33",
              "name": "email_from",
              "value": "={{ $json.from.value[0].address }}",
              "type": "string"
            },
            {
              "id": "9239a754-e04e-447e-af3a-b64cf6396643",
              "name": "email_subject",
              "value": "={{ $json.subject }}",
              "type": "string"
            },
            {
              "id": "201d7932-63e4-4b46-ab73-80e5979e9f17",
              "name": "email_content",
              "value": "={{ $json.text }}",
              "type": "string"
            },
            {
              "id": "324bbb05-1ccd-42bf-8870-e17564c7da4c",
              "name": "email_attachment",
              "value": "={{ $binary }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1740,
        -60
      ],
      "id": "de42236e-a711-47c2-a28d-5574d248c06b",
      "name": "Field Extraction"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c2a51bb2-0f09-41f2-92f5-9ebd58937ad0",
              "leftValue": "={{ $json.output.is_invoice }}",
              "rightValue": "true",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -1040,
        -60
      ],
      "id": "3ce99ca4-bbb9-4df5-bec6-e3aa878d8138",
      "name": "Check for Mail related to Invoice"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "indexes = [\n    itm.get('pairedItem', {}).get('item', pos)      \n    for pos, itm in enumerate(items)                \n]\n\ngmail_items = _(\"Gmail Trigger\").all()\n\nout_items = []\nfor idx in indexes:\n    if idx >= len(gmail_items):             \n        continue\n\n    email_item = gmail_items[idx]\n    for key, blob in (email_item.get(\"binary\") or {}).items():\n        out_items.append({\n            \"json\": {\n                \"sourceEmailIndex\": idx,\n                \"originalKey\": key,\n            },\n            \"binary\": {\n                \"data\": blob,               \n            },\n            \"pairedItem\": { \"item\": idx }   \n        })\n\nreturn out_items\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -860,
        -60
      ],
      "id": "f609e623-b642-435f-a0be-6d11e0216152",
      "name": "extract the attachment from email"
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {
          "keepSource": "json"
        }
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        -440,
        -60
      ],
      "id": "8d5c0293-a24f-440d-9804-2b406cd49328",
      "name": "Convert file to Base64"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('setting').item.json.document_intelligence_endpoint }}documentintelligence/documentModels/prebuilt-invoice:analyze",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "_overload",
              "value": "analyzeDocument"
            },
            {
              "name": "api-version",
              "value": "={{ $('setting').item.json.document_intelligence_api_version }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Ocp-Apim-Subscription-Key",
              "value": "={{ $('setting').item.json.document_intelligence_key }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "base64Source",
              "value": "={{ $json.data }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -260,
        -60
      ],
      "id": "5742ca4c-f879-4c70-ab0f-ede1fcda3c73",
      "name": "Add file to Document Intelligence"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -60,
        -60
      ],
      "id": "80988a14-e389-48c4-addd-f6f373e1d24f",
      "name": "Wait_",
      "webhookId": "1af13890-806a-46bf-a95f-2750ecdeaa11"
    },
    {
      "parameters": {
        "url": "={{ $('setting').item.json.document_intelligence_endpoint }}documentintelligence/documentModels/prebuilt-invoice/analyzeResults/{{ $('Add file to Document Intelligence').item.json.headers['apim-request-id'] }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "api-version",
              "value": "={{ $('setting').item.json.document_intelligence_api_version }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Ocp-Apim-Subscription-Key",
              "value": "={{ $('setting').item.json.document_intelligence_key }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        180,
        -60
      ],
      "id": "fe016bef-da53-4c4c-b1e1-e57e17fb789a",
      "name": "Check for Execution completion"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "from typing import List, Dict, Any\n\nitems: List[Any] = _input.all()\noutput_items: List[Dict[str, Any]] = []\n\nFIELDS_TO_EXTRACT = [\n    \"VendorName\", \"VendorAddress\", \"PaymentTerm\",\n    \"CustomerName\", \"CustomerId\", \"CustomerAddress\",\n    \"CustomerAddressRecipient\", \"InvoiceId\", \"InvoiceDate\",\n    \"InvoiceTotal\", \"DueDate\", \"PurchaseOrder\", \"BillingAddress\",\n    \"BillingAddressRecipient\", \"ShippingAddress\", \"ShippingAddressRecipient\",\n    \"SubTotal\", \"TotalTax\", \"PreviousUnpaidBalance\", \"AmountDue\",\n    \"ServiceStartDate\", \"ServiceEndDate\", \"ServiceAddress\",\n    \"ServiceAddressRecipient\", \"RemittanceAddress\", \"RemittanceAddressRecipient\",\n]\n\ndef one_line(txt: str) -> str:\n    return \" \".join(txt.splitlines()).strip()\n\ndef safe_categorise(path: str) -> Dict[str, str]:\n    try:\n        from helpers import categorize_invoice\n        return categorize_invoice(path) or {}\n    except Exception:\n        return {}\n\nfor n8n_item in items:\n\n    analyze_result = n8n_item.json.get(\"analyzeResult\", {})\n    documents = analyze_result.get(\"documents\", [])\n\n    file_path = n8n_item.json.get(\"filePath\") or n8n_item.json.get(\"file_path\", \"\")\n\n    result_data: Dict[str, Any] = {}\n    confidence_scores: List[float] = []\n\n    for idx, invoice in enumerate(documents, start=1):\n        invoice_data: Dict[str, Any] = {}\n        fields = invoice.get(\"fields\", {})\n\n        for name in FIELDS_TO_EXTRACT:\n            fld = fields.get(name)\n            if fld and fld.get(\"content\") and \"confidence\" in fld:\n                content = one_line(fld[\"content\"])\n                conf    = fld[\"confidence\"]\n                invoice_data[name] = {\"content\": content, \"confidence\": conf}\n                confidence_scores.append(conf)\n\n        items_field = fields.get(\"Items\")\n        if items_field:\n            value_array = (\n                items_field.get(\"values\")\n                or items_field.get(\"valueArray\")\n                or items_field.get(\"value\")\n                or []\n            )\n\n            invoice_items = []\n            for entry in value_array:\n                obj = entry.get(\"valueObject\") or entry.get(\"value\") or {}\n                if not obj:\n                    continue\n\n                item_row = {}\n                for key, val in obj.items():\n                    if not val:\n                        continue\n                    field_content = (\n                        val.get(\"content\")\n                        or val.get(\"valueString\")\n                        or val.get(\"text\")\n                    )\n                    field_confidence = val.get(\"confidence\")\n                    if field_content and field_confidence is not None:\n                        \n                        item_row[key] = one_line(field_content)\n                        confidence_scores.append(field_confidence)\n                if item_row:\n                    invoice_items.append(item_row)\n\n            if invoice_items:\n                invoice_data[\"Items\"] = invoice_items\n\n        result_data[f\"Invoice_{idx}\"] = invoice_data\n\n  \n\n    output_items.append({\"json\": result_data})\n\nreturn output_items\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        -60
      ],
      "id": "9febc1de-4786-42ef-a973-f4c9456d33c0",
      "name": "Extract data from Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "48711eae-2372-4abc-9faf-a8fd907538e2",
              "name": "document_intelligence_endpoint",
              "value": "https://invouce-details-test.cognitiveservices.azure.com/",
              "type": "string"
            },
            {
              "id": "61e39a8d-0ea0-4d13-9d2e-8be2f9383baa",
              "name": "document_intelligence_api_version",
              "value": "2024-11-30",
              "type": "string"
            },
            {
              "id": "343f4022-714b-4303-b024-843b40ba001c",
              "name": "document_intelligence_key",
              "value": "7NpmkhQQtwYxLx2pZXf2YIPUMi54j0iI5qkmFP8hcFouPaZVBpKlJQQJ99ALACYeBjFXJ3w3AAALACOGf14c",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1560,
        -60
      ],
      "id": "b7282dca-f1f8-4992-b4a9-d124dad9c1b5",
      "name": "setting"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1947db73-18a9-4ccb-bfed-422e3ece840d",
              "leftValue": "={{ $('extract the attachment from email').item.binary.data.mimeType }}",
              "rightValue": "pdf",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -640,
        -60
      ],
      "id": "3d7c7776-b31c-4f17-a6e8-ff333b83d6ed",
      "name": "check Attachment Type PDF"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "C08VD6ES598",
          "mode": "list",
          "cachedResultName": "invoice"
        },
        "text": "=You have received an invoice from {{ $json.VendorName }} for a total amount of {{ $json.InvoiceTotal }}.",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1000,
        -60
      ],
      "id": "cfe6dd67-1130-4ba9-b7b1-25ce7e16b579",
      "name": "Slack",
      "webhookId": "ab6c8bc4-aed3-4a2b-bf2e-e1833ffaa24d",
      "credentials": {
        "slackOAuth2Api": {
          "id": "qGHKbDkv4rcjLoPw",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "file",
        "options": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1560,
        40
      ],
      "id": "76f69bfb-d411-482d-bc8c-31ce6a35d2e6",
      "name": "Slack1",
      "webhookId": "4d2ef4a5-b43d-4e7c-af59-70128cdd4391",
      "credentials": {
        "slackOAuth2Api": {
          "id": "qGHKbDkv4rcjLoPw",
          "name": "Slack account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Field Extraction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain1": {
      "main": [
        [
          {
            "node": "Check for Mail related to Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract data from Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Check for Execution completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Field Extraction": {
      "main": [
        [
          {
            "node": "setting",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Mail related to Invoice": {
      "main": [
        [
          {
            "node": "extract the attachment from email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract the attachment from email": {
      "main": [
        [
          {
            "node": "check Attachment Type PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert file to Base64": {
      "main": [
        [
          {
            "node": "Add file to Document Intelligence",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add file to Document Intelligence": {
      "main": [
        [
          {
            "node": "Wait_",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait_": {
      "main": [
        [
          {
            "node": "Check for Execution completion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Execution completion": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract data from Response": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setting": {
      "main": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check Attachment Type PDF": {
      "main": [
        [
          {
            "node": "Convert file to Base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack": {
      "main": [
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8ab7faff-9cf5-404a-a8f6-7f0b98c68de9",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "bcc5aa223adeac3da47e936526154a79cb834b3cfdc4f3d8f2a97c53bcd91c02"
  },
  "id": "xaBcoK1N2t6EsesW",
  "tags": []
}