{
  "id": "oW2pSjFU5zCRH0ps",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true,
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram Invoice OCR Processor with AI and Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "df5b0e04-5512-42e0-a667-65cef4c452c3",
      "name": "Sticky Note 8c54e987",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -896
      ],
      "parameters": {
        "width": 1360,
        "height": 416,
        "content": "## Configure here first\n\nSet your three required values in the node below before activating the workflow:\n\n- **googleSheetId** \u2014 ID from your Google Sheets URL\n- **googleDriveFolderId** \u2014 ID of the Drive folder for archived invoices\n- **invoiceDatabaseLink** \u2014 Link shared with users in the Telegram confirmation"
      },
      "typeVersion": 1
    },
    {
      "id": "e52d50f8-27e7-4d86-a0af-120ea4bdb13a",
      "name": "Sticky Note e29290ec",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -304
      ],
      "parameters": {
        "width": 880,
        "height": 1232,
        "content": "## Telegram Invoice OCR Processor with AI and Google Sheets\n\n### How it works\n\n1. A user sends a JPG, PNG, or PDF invoice to a Telegram bot.\n2. The workflow downloads the file and detects the file type.\n3. OCR.space extracts readable text from the invoice.\n4. OpenAI converts the OCR text into structured invoice fields.\n5. The invoice data is saved to Google Sheets.\n6. The original invoice file is uploaded to Google Drive.\n7. The user receives a short Telegram confirmation message.\n\n### Setup steps\n\n- [ ] Connect Telegram credentials.\n- [ ] Add OCR.space API key as HTTP Header Auth.\n- [ ] Connect OpenAI credentials.\n- [ ] Connect Google Sheets and Google Drive credentials.\n- [ ] Create the required Google Sheets columns.\n- [ ] Set your Sheet ID, Drive folder ID, and database link in the Configure Workflow Variables node.\n- [ ] Test with JPG, PNG, and PDF invoices before using it live.\n\n### Required Google Sheets columns\n\nInvoice Number, Invoice Date, Due Date, Delivery Date, Vendor Name, Customer Name, Customer Address, Currency, Subtotal, Tax, Total, Item Descriptions, Item Quantities, Item Unit Prices, Item Amounts\n\n### Customization\n\n- Add a Slack or email alert for invoices above a set total amount.\n- Replace Google Sheets with Airtable or Notion for richer querying.\n- Add a duplicate-check step using the invoice number before appending."
      },
      "typeVersion": 1
    },
    {
      "id": "50c0367b-4edb-4fa3-bec6-462d2525484e",
      "name": "Configure Workflow Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        416,
        -736
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "config-001",
              "name": "googleSheetId",
              "type": "string",
              "value": "REPLACE_WITH_YOUR_GOOGLE_SHEET_ID"
            },
            {
              "id": "config-002",
              "name": "googleDriveFolderId",
              "type": "string",
              "value": "REPLACE_WITH_YOUR_GOOGLE_DRIVE_FOLDER_ID"
            },
            {
              "id": "config-003",
              "name": "invoiceDatabaseLink",
              "type": "string",
              "value": "REPLACE_WITH_YOUR_INVOICE_DATABASE_LINK"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "86a8c83f-71ec-47a9-997e-d50066617b1f",
      "name": "Receive Invoice in Telegram",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        528,
        480
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ea8bc778-48db-49db-8d11-4f2c77949411",
      "name": "Download Telegram Invoice File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        800,
        480
      ],
      "parameters": {
        "fileId": "={{ $json.message.photo ? $json.message.photo[$json.message.photo.length-1].file_id : $json.message.document ? $json.message.document.file_id : null }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "579a26af-fd8b-4ccd-8a15-b7b03e7f073c",
      "name": "Detect File Type",
      "type": "n8n-nodes-base.code",
      "position": [
        1104,
        480
      ],
      "parameters": {
        "jsCode": "const item = items[0];\n\nif (!item.binary || !item.binary.data) {\n  throw new Error(\"No binary file found\");\n}\n\nconst binary = item.binary.data;\nconst mime = binary.mimeType || \"\";\n\nlet fileType = \"unknown\";\n\nif (mime.includes(\"pdf\")) {\n  fileType = \"pdf\";\n} else if (mime.includes(\"png\")) {\n  fileType = \"png\";\n} else if (mime.includes(\"jpeg\") || mime.includes(\"jpg\")) {\n  fileType = \"jpg\";\n}\n\nreturn [\n  {\n    json: { fileType },\n    binary: { data: binary }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "485649aa-7402-4fb0-960c-a33574453d06",
      "name": "Route Supported File Types",
      "type": "n8n-nodes-base.switch",
      "position": [
        1328,
        352
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "jpg",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "53d5306b-c8a2-4a12-ba8f-ccdfde7b0dd3",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileType }}",
                    "rightValue": "jpg"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "png",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c5b79e25-be95-4db1-9953-5a05793c8e12",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileType }}",
                    "rightValue": "png"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "pdf",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c476580a-563b-44f9-80a6-ddc4f02d6b5c",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileType }}",
                    "rightValue": "pdf"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "53578c01-bd12-4fc3-9343-83aaecce76f5",
      "name": "Extract Invoice Text with OCR.space",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1552,
        368
      ],
      "parameters": {
        "url": "https://api.ocr.space/parse/image",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            },
            {
              "name": "OCREngine",
              "value": "2"
            },
            {
              "name": "filetype",
              "value": "={{ $json.fileType.toUpperCase() }}"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "d41ee19e-e60d-4468-b91e-8933fa5e5959",
      "name": "Extract Structured Invoice Data",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1840,
        368
      ],
      "parameters": {
        "text": "=Extract structured invoice data from the OCR text below.\n\nReturn ONLY this JSON format:\n\n{\n  \"invoiceNumber\": string|null,\n  \"invoiceDate\": string|null,\n  \"dueDate\": string|null,\n  \"deliveryDate\": string|null,\n  \"vendorName\": string|null,\n  \"customerName\": string|null,\n  \"customerAddress\": string|null,\n  \"currency\": string|null,\n  \"subtotal\": number|null,\n  \"tax\": number|null,\n  \"total\": number|null,\n  \"items\": [\n    {\n      \"description\": string,\n      \"quantity\": number|null,\n      \"unitPrice\": number|null,\n      \"amount\": number|null\n    }\n  ]\n}\n\nRules:\n- Return only valid JSON.\n- Do not include markdown or explanation.\n- Infer currency from symbols like \u20ac, $, \u00a3 or labels like EUR, USD, GBP.\n- Extract total from labels like TOTAL, TOTAL DUE, AMOUNT DUE.\n- Use recipient block as customerAddress.\n- Do not invent values.\n\nOCR TEXT:\n{{ $json.ParsedResults[0].ParsedText }}\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "f6129b28-d4e2-4e4e-9010-13e4b01542a3",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1792,
        592
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "156b41f3-dd1c-4741-a94c-8cad67749629",
      "name": "Validate Invoice JSON Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1920,
        592
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"invoiceNumber\": { \"type\": [\"string\", \"null\"] },\n    \"invoiceDate\": { \"type\": [\"string\", \"null\"] },\n    \"dueDate\": { \"type\": [\"string\", \"null\"] },\n    \"deliveryDate\": { \"type\": [\"string\", \"null\"] },\n    \"vendorName\": { \"type\": [\"string\", \"null\"] },\n    \"customerName\": { \"type\": [\"string\", \"null\"] },\n    \"customerAddress\": { \"type\": [\"string\", \"null\"] },\n    \"currency\": { \"type\": [\"string\", \"null\"] },\n    \"subtotal\": { \"type\": [\"number\", \"null\"] },\n    \"tax\": { \"type\": [\"number\", \"null\"] },\n    \"total\": { \"type\": [\"number\", \"null\"] },\n    \"items\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"description\": { \"type\": \"string\" },\n          \"quantity\": { \"type\": [\"number\", \"null\"] },\n          \"unitPrice\": { \"type\": [\"number\", \"null\"] },\n          \"amount\": { \"type\": [\"number\", \"null\"] }\n        }\n      }\n    }\n  }\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e8daead6-7cd6-417e-b8f5-2046381e726f",
      "name": "Format Invoice Fields for Sheets",
      "type": "n8n-nodes-base.code",
      "position": [
        2224,
        368
      ],
      "parameters": {
        "jsCode": "const d = $json.output ?? {};\n\nreturn [\n  {\n    json: {\n      invoiceNumber: d.invoiceNumber ?? null,\n      invoiceDate: d.invoiceDate ?? null,\n      dueDate: d.dueDate ?? null,\n      deliveryDate: d.deliveryDate ?? null,\n      vendorName: d.vendorName ?? null,\n      customerName: d.customerName ?? null,\n      customerAddress: d.customerAddress ?? null,\n      currency: d.currency ?? null,\n      subtotal: d.subtotal ?? null,\n      tax: d.tax ?? null,\n      total: d.total ?? null,\n      items: Array.isArray(d.items) ? d.items : [],\n      itemDescriptions: Array.isArray(d.items) ? d.items.map(i => i.description).join(\"\\n\") : \"\",\n      itemQuantities: Array.isArray(d.items) ? d.items.map(i => i.quantity ?? \"\").join(\"\\n\") : \"\",\n      itemUnitPrices: Array.isArray(d.items) ? d.items.map(i => i.unitPrice ?? \"\").join(\"\\n\") : \"\",\n      itemAmounts: Array.isArray(d.items) ? d.items.map(i => i.amount ?? \"\").join(\"\\n\") : \"\"\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "2a6a0416-57ab-4d15-8d41-c6105ce185d4",
      "name": "Save Invoice Data to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2560,
        368
      ],
      "parameters": {
        "columns": {
          "value": {
            "Tax": "={{ $json.tax }}",
            "Total": "={{ $json.total }}",
            "Currency": "={{ $json.currency }}",
            "Due Date": "={{ $json.dueDate }}",
            "Subtotal": "={{ $json.subtotal }}",
            "Vendor Name": "={{ $json.vendorName }}",
            "Invoice Date": "={{ $json.invoiceDate }}",
            "Item Amounts": "={{ $json.itemAmounts }}",
            "Customer Name": "={{ $json.customerName }}",
            "Delivery Date": "={{ $json.deliveryDate }}",
            "Invoice Number": "={{ $json.invoiceNumber }}",
            "Item Quantities": "={{ $json.itemQuantities }}",
            "Customer Address": "={{ $json.customerAddress }}",
            "Item Unit Prices": "={{ $json.itemUnitPrices }}",
            "Item Descriptions": "={{ $json.itemDescriptions }}"
          },
          "schema": [
            {
              "id": "Invoice Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Due Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Due Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Delivery Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Delivery Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Vendor Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Vendor Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Customer Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Customer Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subtotal",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Subtotal",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tax",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tax",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Total",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Descriptions",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Item Descriptions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Quantities",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Item Quantities",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Unit Prices",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Item Unit Prices",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Amounts",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Item Amounts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configure Workflow Variables').item.json.googleSheetId }}"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "14677a80-45aa-4d9a-94f4-d8daadc86198",
      "name": "Merge Invoice Data with Original File",
      "type": "n8n-nodes-base.merge",
      "position": [
        2752,
        464
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "7d41a90f-8e3d-4161-ae36-091e06d5b957",
      "name": "Upload Original Invoice to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2976,
        464
      ],
      "parameters": {
        "name": "=Invoice {{ $json.invoiceNumber || Math.floor(Math.random() * 10000) }} [{{ $now.format('dd-MMMM-yyyy') }} | {{ $now.format('hh:mm a').toUpperCase() }}]",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configure Workflow Variables').item.json.googleDriveFolderId }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "36d958b2-23d0-4f6f-9042-982eb72c4952",
      "name": "Prepare Confirmation Message Data",
      "type": "n8n-nodes-base.set",
      "position": [
        3184,
        464
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ae811e48-0cc7-4feb-8399-01388b73a610",
              "name": "Invoice Detail",
              "type": "string",
              "value": "={{ JSON.stringify($json, null, 2) }}"
            },
            {
              "id": "19d8ee22-c298-48a8-a2c3-4bf6faca9476",
              "name": "file",
              "type": "string",
              "value": "={{ $json.name }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "23940cca-a438-4def-936c-d51549e5b089",
      "name": "Write Telegram Confirmation Message",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3392,
        464
      ],
      "parameters": {
        "text": "=User Message:\n\nInvoice Details\n{{ $json['Invoice Detail'] }}\n\nFile Name\n{{ $json.file }}\n\nInvoice Database Link\n{{ $('Configure Workflow Variables').item.json.invoiceDatabaseLink }}",
        "options": {
          "systemMessage": "You are an efficient invoice assistant.\n\nYou will receive cleaned structured invoice data in JSON format.\nYour job is to generate a short, clear user-facing confirmation message.\n\nRequirements:\n- Thank the user for submitting the invoice.\n- Mention the invoice number if available.\n- Mention the total amount and currency if available.\n- Mention the due date if available.\n- Mention the uploaded file name.\n- Tell the user the invoice has been added to Google Drive.\n- Include that they can access the invoice database using the provided link.\n- Keep the response concise and easy to read.\n- Do not mention fields that are null or missing."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "f7f7991a-e48a-47bb-919c-a61a3896d4b5",
      "name": "Send Confirmation to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3760,
        464
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Receive Invoice in Telegram').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d529226b-acd6-4464-a130-3efdc3ec650b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -48
      ],
      "parameters": {
        "color": "#FFFFFF",
        "width": 1008,
        "height": 1008,
        "content": "## Receive and route invoice files\n\nTelegram receives the invoice from the user and downloads the original file.\n\nThe Code node checks the file MIME type, and the Switch node routes only supported invoice formats: JPG, PNG, and PDF."
      },
      "typeVersion": 1
    },
    {
      "id": "7db8ceb5-23af-4bf3-88e1-1fa93e134a1a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1552,
        -64
      ],
      "parameters": {
        "color": "#FFFFFF",
        "width": 496,
        "height": 1024,
        "content": "## Extract invoice text and fields\n\nOCR.space extracts raw text from the uploaded invoice.\n\nOpenAI reads the OCR text and returns structured invoice data. The output parser keeps the result predictable before it moves to Google Sheets."
      },
      "typeVersion": 1
    },
    {
      "id": "63c5fe79-e635-49ac-b037-d02a791196ca",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2112,
        -48
      ],
      "parameters": {
        "color": "#FFFFFF",
        "width": 560,
        "height": 1008,
        "content": "## Save invoice data\n\nThe formatted invoice fields are appended to Google Sheets.\n\nMake sure the destination sheet contains the required column headers before activating the workflow.\n\nRequired columns:\nInvoice Number, Invoice Date, Due Date, Delivery Date, Vendor Name, Customer Name, Customer Address, Currency, Subtotal, Tax, Total, Item Descriptions, Item Quantities, Item Unit Prices, Item Amounts"
      },
      "typeVersion": 1
    },
    {
      "id": "445d0a2d-e921-4201-9ca5-d2aa4f629037",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2752,
        16
      ],
      "parameters": {
        "color": "#FFFFFF",
        "width": 1104,
        "height": 960,
        "content": "## Archive file and confirm user\n\nThe original invoice file is uploaded to Google Drive.\n\nThe workflow prepares a short confirmation message, then sends it back to the same Telegram chat with key invoice details and the database link."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "timeSavedMode": "fixed",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "468e575d-2005-40f1-9d30-64de72338330",
  "connections": {
    "Detect File Type": {
      "main": [
        [
          {
            "node": "Route Supported File Types",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Invoice Data with Original File",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Structured Invoice Data",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Write Telegram Confirmation Message",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Route Supported File Types": {
      "main": [
        [
          {
            "node": "Extract Invoice Text with OCR.space",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Invoice Text with OCR.space",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Invoice Text with OCR.space",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Invoice in Telegram": {
      "main": [
        [
          {
            "node": "Download Telegram Invoice File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Invoice JSON Output": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Structured Invoice Data",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Download Telegram Invoice File": {
      "main": [
        [
          {
            "node": "Detect File Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Structured Invoice Data": {
      "main": [
        [
          {
            "node": "Format Invoice Fields for Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Invoice Fields for Sheets": {
      "main": [
        [
          {
            "node": "Save Invoice Data to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Confirmation Message Data": {
      "main": [
        [
          {
            "node": "Write Telegram Confirmation Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Invoice Data to Google Sheets": {
      "main": [
        [
          {
            "node": "Merge Invoice Data with Original File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoice Text with OCR.space": {
      "main": [
        [
          {
            "node": "Extract Structured Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Telegram Confirmation Message": {
      "main": [
        [
          {
            "node": "Send Confirmation to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Invoice Data with Original File": {
      "main": [
        [
          {
            "node": "Upload Original Invoice to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Original Invoice to Google Drive": {
      "main": [
        [
          {
            "node": "Prepare Confirmation Message Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}