Suivi de receipts piloté par l'IA avec stockage multiplateforme via un bot Telegram

Intermédiaire

Ceci est unMiscellaneous, AI Summarization, Multimodal AIworkflow d'automatisation du domainecontenant 14 nœuds.Utilise principalement des nœuds comme Notion, Switch, Function, Telegram, GoogleDrive. Extraire et stocker les données des reçus via un robot Telegram avec GPT-4, OCR, Google Sheets et Notion

Prérequis
  • Clé API Notion
  • Token Bot Telegram
  • Informations d'identification Google Drive API
  • Peut nécessiter les informations d'identification d'authentification de l'API cible
  • Informations d'identification Google Sheets API
  • Clé API OpenAI
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
  "id": "YGDpr1ZwlWwPwpsD",
  "meta": {
    "instanceId": "d226d4f84a040d022e5981c2ad7340a0fd39f59c8ca44d7b13a48fbd5f93342f"
  },
  "name": "AI-Powered Receipt Tracker with Multi-Platform Storage via Telegram Bot",
  "tags": [],
  "nodes": [
    {
      "id": "1ab8188b-b92f-4e84-9d49-1baf01e999cc",
      "name": "Telegram Bot Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -512,
        160
      ],
      "webhookId": "003163f1-4653-4a49-a57a-fd04d78b2d62",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "telegram_bot_credentials",
          "name": "telegram_bot_credentials"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "50cecf34-87c8-4fa6-9599-30f656a4b593",
      "name": "Message Type Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        -272,
        160
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "exists"
                    },
                    "leftValue": "={{ $json.message.photo }}",
                    "rightValue": ""
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "exists"
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "32cc964e-d4b2-4072-b3d2-3d41c3f2925f",
      "name": "Download Telegram Image",
      "type": "n8n-nodes-base.telegram",
      "position": [
        0,
        0
      ],
      "webhookId": "59d7a7bc-efca-458a-a8b4-a2d59aad70a4",
      "parameters": {
        "fileId": "={{ $json.message.photo[$json.message.photo.length - 1].file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "telegram_bot_credentials",
          "name": "telegram_bot_credentials"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e4c88939-58a3-4dea-b754-d6e542edd530",
      "name": "OCR Receipt Processing",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        176,
        80
      ],
      "parameters": {
        "url": "https://api.ocr.space/parse/image",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "https://api.telegram.org/file/bot{{ $credentials.telegramApi.accessToken }}/{{ $('Download Telegram Image').item.json.file_path }}"
            },
            {
              "name": "language",
              "value": "eng"
            },
            {
              "name": "detectOrientation",
              "value": "true"
            },
            {
              "name": "isTable",
              "value": "true"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $credentials.ocrSpaceApi.apiKey }}"
            }
          ]
        }
      },
      "credentials": {
        "ocrSpaceApi": {
          "id": "ocr_space_credentials",
          "name": "OCR Space API"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3ae3a207-260f-440f-a06d-956aeb675244",
      "name": "Handle Text Message",
      "type": "n8n-nodes-base.function",
      "position": [
        0,
        272
      ],
      "parameters": {
        "functionCode": "// Handle text messages - could be manual transaction entry\nconst text = $input.first().json.message.text;\n\n// Simple text parsing for manual entries like: \"McDonald's $12.50 lunch food\"\nconst parts = text.split(' ');\nif (parts.length >= 3) {\n  const vendor = parts[0];\n  const amountMatch = text.match(/\\$?([0-9]+\\.?[0-9]*)/); \n  const amount = amountMatch ? parseFloat(amountMatch[1]) : 0;\n\n  return {\n    json: {\n      ParsedResults: [{\n        ParsedText: `Vendor: ${vendor}\\nAmount: $${amount}\\nDate: ${new Date().toISOString().split('T')[0]}\\nType: purchase`\n      }]\n    }\n  };\n} else {\n  throw new Error('Invalid text format. Use: \"Vendor $amount description\"');\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "0d04b8c2-27c7-45a4-9175-43705b0bf9cd",
      "name": "AI Purchase Data Extractor",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        320,
        208
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4"
        },
        "options": {
          "maxTokens": 500,
          "temperature": 0.1
        },
        "messages": {
          "values": [
            {
              "role": "user",
              "content": "You are an expert receipt and transaction data extractor. Extract transaction data from the provided text and return ONLY a JSON object with these exact fields:\n\n{\n  \"vendor\": \"vendor/store name\",\n  \"amount\": \"numeric amount (without currency symbol)\",\n  \"currency\": \"USD\",\n  \"date\": \"YYYY-MM-DD format\",\n  \"transaction_type\": \"purchase/refund/payment\",\n  \"category\": \"food/shopping/transport/entertainment/other\"\n}\n\nInput text: {{ $json.ParsedResults[0].ParsedText || $json.message.text }}\n\nReturn only the JSON object, no additional text or explanation."
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "openai_credentials",
          "name": "openai_credentials"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "ff76dcfc-40d3-469b-9308-7dec5dcfe4a2",
      "name": "Transaction Data Validator",
      "type": "n8n-nodes-base.function",
      "position": [
        608,
        176
      ],
      "parameters": {
        "functionCode": "try {\n  // Parse AI response\n  let aiResponse = $input.first().json.content || $input.first().json.response || $input.first().json;\n\n  // Handle if response is string\n  if (typeof aiResponse === 'string') {\n    // Try to extract JSON from string response\n    const jsonMatch = aiResponse.match(/\\{[\\s\\S]*\\}/);\n    if (jsonMatch) {\n      aiResponse = jsonMatch[0];\n    }\n    aiResponse = JSON.parse(aiResponse);\n  }\n\n  // Validate required fields\n  const requiredFields = ['vendor', 'amount', 'date', 'transaction_type'];\n  const missingFields = requiredFields.filter(field => !aiResponse[field]);\n\n  if (missingFields.length > 0) {\n    throw new Error(`Missing required fields: ${missingFields.join(', ')}`);\n  }\n\n  // Generate UUID alternative\n  const generateId = () => {\n    return 'txn_' + Math.random().toString(36).substring(2) + Date.now().toString(36);\n  };\n\n  // Standardize and clean data\n  const transaction = {\n    id: generateId(),\n    vendor: String(aiResponse.vendor).trim(),\n    amount: parseFloat(aiResponse.amount),\n    currency: aiResponse.currency || 'USD',\n    date: aiResponse.date,\n    transaction_type: aiResponse.transaction_type,\n    category: aiResponse.category || 'uncategorized',\n    processed_date: new Date().toISOString(),\n    user_id: $('Telegram Bot Trigger').item.json.message.from.id,\n    username: $('Telegram Bot Trigger').item.json.message.from.username || 'unknown'\n  };\n\n  // Validate amount is a valid number\n  if (isNaN(transaction.amount) || transaction.amount <= 0) {\n    throw new Error('Invalid amount detected');\n  }\n\n  // Validate date format\n  if (!transaction.date.match(/^\\d{4}-\\d{2}-\\d{2}$/)) {\n    transaction.date = new Date().toISOString().split('T')[0];\n  }\n\n  return { json: transaction };\n\n} catch (error) {\n  // Pass error info for error handler\n  return {\n    json: {\n      error: true,\n      message: error.message,\n      user_id: $('Telegram Bot Trigger').item.json.message.from.id,\n      original_data: $input.first().json\n    }\n  };\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "7c57c8da-7156-48d2-936c-33f33c31f797",
      "name": "Check for Errors",
      "type": "n8n-nodes-base.switch",
      "position": [
        800,
        176
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "boolean",
                      "operation": "true"
                    },
                    "leftValue": "={{ $json.error }}",
                    "rightValue": ""
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "06af3c07-0613-4990-95ae-2395aeda7725",
      "name": "Send Error Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        960,
        176
      ],
      "webhookId": "74df7c52-973d-4789-9f31-2a1f8dcddbc5",
      "parameters": {
        "text": "❌ Error processing your receipt:\\n\\n{{ $json.message }}\\n\\nPlease try again or send a clearer image of your receipt.\\n\\nFor text input, use format: \"Vendor $amount description\"",
        "chatId": "={{ $json.user_id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "telegram_bot_credentials",
          "name": "telegram_bot_credentials"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9fb86db3-19dd-4dab-9309-69151fffd0d1",
      "name": "Record to Database",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1184,
        96
      ],
      "parameters": {
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Transactions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "google_sheets_credentials",
          "name": "google_sheets_credentials"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "181ea179-c278-422a-934e-4d5ec899ba3f",
      "name": "Store Receipt Image",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1184,
        -32
      ],
      "parameters": {
        "name": "receipt_{{ $json.id }}_{{ $json.date }}.jpg",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "google_drive_credentials",
          "name": "google_drive_credentials"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "4249d4f3-e394-4d03-9ee9-d608ba94082f",
      "name": "Save to Notion Database",
      "type": "n8n-nodes-base.notion",
      "position": [
        1184,
        240
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "databaseId": "YOUR_NOTION_DATABASE_ID_HERE"
      },
      "credentials": {
        "notionApi": {
          "id": "notion_api_credentials",
          "name": "notion_api_credentials"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "96f32d63-a79b-4154-a223-76d00336f76e",
      "name": "Send to Website API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1248,
        384
      ],
      "parameters": {
        "url": "https://yourwebsite.com/api/transactions",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {}
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_API_KEY_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c4e931b6-5988-4cd4-ae38-48650d523213",
      "name": "Send Confirmation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1424,
        176
      ],
      "webhookId": "3200b803-5c0e-41bf-8c1e-002447596408",
      "parameters": {
        "text": "✅ Transaction Recorded Successfully!\\n\\n📊 Details:\\n• Vendor: {{ $json.vendor }}\\n• Amount: {{ $json.currency || 'USD' }} {{ $json.amount }}\\n• Type: {{ $json.transaction_type }}\\n• Category: {{ $json.category }}\\n• Date: {{ $json.date }}\\n• ID: {{ $json.id }}\\n\\n💾 Receipt stored and data recorded in all systems.",
        "chatId": "={{ $json.user_id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "telegram_bot_credentials",
          "name": "telegram_bot_credentials"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1d2c44d6-1f06-4c6e-a25d-87c7d8c5e894",
  "connections": {
    "7c57c8da-7156-48d2-936c-33f33c31f797": {
      "main": [
        [
          {
            "node": "06af3c07-0613-4990-95ae-2395aeda7725",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9fb86db3-19dd-4dab-9309-69151fffd0d1": {
      "main": [
        [
          {
            "node": "c4e931b6-5988-4cd4-ae38-48650d523213",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "06af3c07-0613-4990-95ae-2395aeda7725": {
      "main": [
        [
          {
            "node": "4249d4f3-e394-4d03-9ee9-d608ba94082f",
            "type": "main",
            "index": 0
          },
          {
            "node": "96f32d63-a79b-4154-a223-76d00336f76e",
            "type": "main",
            "index": 0
          },
          {
            "node": "9fb86db3-19dd-4dab-9309-69151fffd0d1",
            "type": "main",
            "index": 0
          },
          {
            "node": "181ea179-c278-422a-934e-4d5ec899ba3f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3ae3a207-260f-440f-a06d-956aeb675244": {
      "main": [
        [
          {
            "node": "0d04b8c2-27c7-45a4-9175-43705b0bf9cd",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "50cecf34-87c8-4fa6-9599-30f656a4b593": {
      "main": [
        [
          {
            "node": "32cc964e-d4b2-4072-b3d2-3d41c3f2925f",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "3ae3a207-260f-440f-a06d-956aeb675244",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "96f32d63-a79b-4154-a223-76d00336f76e": {
      "main": [
        [
          {
            "node": "c4e931b6-5988-4cd4-ae38-48650d523213",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "181ea179-c278-422a-934e-4d5ec899ba3f": {
      "main": [
        [
          {
            "node": "c4e931b6-5988-4cd4-ae38-48650d523213",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1ab8188b-b92f-4e84-9d49-1baf01e999cc": {
      "main": [
        [
          {
            "node": "50cecf34-87c8-4fa6-9599-30f656a4b593",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e4c88939-58a3-4dea-b754-d6e542edd530": {
      "main": [
        [
          {
            "node": "0d04b8c2-27c7-45a4-9175-43705b0bf9cd",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "32cc964e-d4b2-4072-b3d2-3d41c3f2925f": {
      "main": [
        [
          {
            "node": "e4c88939-58a3-4dea-b754-d6e542edd530",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4249d4f3-e394-4d03-9ee9-d608ba94082f": {
      "main": [
        [
          {
            "node": "c4e931b6-5988-4cd4-ae38-48650d523213",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "0d04b8c2-27c7-45a4-9175-43705b0bf9cd": {
      "main": [
        [
          {
            "node": "ff76dcfc-40d3-469b-9308-7dec5dcfe4a2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ff76dcfc-40d3-469b-9308-7dec5dcfe4a2": {
      "main": [
        [
          {
            "node": "7c57c8da-7156-48d2-936c-33f33c31f797",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Foire aux questions

Comment utiliser ce workflow ?

Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.

Dans quelles scénarios ce workflow est-il adapté ?

Intermédiaire - Divers, Résumé IA, IA Multimodale

Est-ce payant ?

Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.

Informations sur le workflow
Niveau de difficulté
Intermédiaire
Nombre de nœuds14
Catégorie3
Types de nœuds9
Description de la difficulté

Adapté aux utilisateurs expérimentés, avec des workflows de complexité moyenne contenant 6-15 nœuds

Auteur
Tegar karunia ilham

Tegar karunia ilham

@tegarkaruniailham

Helping business owners & marketers automate their processes with n8n. Specialist in custom workflows, API integrations, and template development. 📈 100+ successful automation projects 🔧 Premium n8n templates available 💡 Free consultation for custom automation Book a consultation for your business digital transformation!"

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34