8
n8n 中文网amn8n.com

Telegram支出追踪器到Google Sheets(使用GPT-4.1)

高级

这是一个Personal Productivity, AI Summarization领域的自动化工作流,包含 23 个节点。主要使用 If, Code, Telegram, GoogleSheets, Agent 等节点。 使用GPT-4.1 Mini从Telegram追踪支出到Google Sheets

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "RYrAtaZopeMoGvwC",
  "meta": {
    "instanceId": "4a2e6764ba7a6bc9890d9225f4b21d570ce88fc9bd57549c89057fcee58fed0f",
    "templateId": "2465",
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram支出追踪器到Google Sheets(使用GPT-4.1)",
  "tags": [
    {
      "id": "5HqPDYxcmr92h5gG",
      "name": "Finance Workflow",
      "createdAt": "2025-08-02T13:47:30.790Z",
      "updatedAt": "2025-08-02T13:47:30.790Z"
    }
  ],
  "nodes": [
    {
      "id": "528b33c9-b3d7-4fc2-ad0c-8112b09377b2",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        864,
        2512
      ],
      "webhookId": "4fa0d5df-5d63-4197-a5ba-add4fb4205ba",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "download": true
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "paNoPvnV5Wzt4Lhv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "73e405fd-1906-4970-9bfd-034663753371",
      "name": "OpenAI 聊天模型2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1376,
        2436
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "PPSwAKeLQYgAPobT",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0923ce77-3410-4f8d-b8ca-19f1912bdb43",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1504,
        2436
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"relevant\": true,\n  \"expense_record\": {\n    \"date\": \"2025-08-04\",\n    \"amount\": 120000,\n    \"currency\": \"VND\",\n    \"category\": \"Food\",\n    \"description\": \"Lunch at Phở Hòa with Linh\"\n  },\n  \"message\": \"\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e61ee81e-b66a-4df9-a2d1-ad6b181fa009",
      "name": "支持场景?",
      "type": "n8n-nodes-base.if",
      "position": [
        1744,
        2316
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "430e6d22-2ff8-42bf-8f0e-940c0378ad30",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.output.relevant }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "bcf6f9b4-23aa-4ddb-8b80-c7bbf54bf681",
      "name": "确认支出",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1968,
        2176
      ],
      "webhookId": "da2178e4-f6e4-4c45-b8de-b810d65f580a",
      "parameters": {
        "text": "={{ $json.output.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "paNoPvnV5Wzt4Lhv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5a98d5eb-c402-4473-bd1c-5d1c4a9406be",
      "name": "发送不支持场景消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1968,
        2560
      ],
      "webhookId": "4e8e4674-5b05-458b-818a-f46a0254d344",
      "parameters": {
        "text": "={{ $json.output.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "paNoPvnV5Wzt4Lhv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b0377606-2f20-4329-9a11-7e710eea221e",
      "name": "转换输出为支出记录",
      "type": "n8n-nodes-base.code",
      "position": [
        1968,
        2368
      ],
      "parameters": {
        "jsCode": "const record = $input.first().json.output.expense_record;\n\nreturn {\n  Date: record.date.toString(),\n  Amount: record.amount,\n  Currency: record.currency,\n  Category: record.category,\n  Description: record.description,\n  MessageID: $('Telegram Trigger').first().json.message.message_id,\n  ChatID: $('Telegram Trigger').first().json.message.chat.id\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "f5f1845c-02b3-4f9c-8e8f-5e98dda19dda",
      "name": "记录支出到Google表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2192,
        2368
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Amount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Source",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Source",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "File ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "File ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CDLvqjsCPlNvHqZo-TyqVJ3yjkcL-WJyj1OdVw90YOs/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1CDLvqjsCPlNvHqZo-TyqVJ3yjkcL-WJyj1OdVw90YOs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CDLvqjsCPlNvHqZo-TyqVJ3yjkcL-WJyj1OdVw90YOs/edit?usp=drivesdk",
          "cachedResultName": "Expense Tracking"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "L670Nly6gZGo71br",
          "name": "Google Sheets account 2"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "2fb66558-eae4-4a25-ad99-86c7e02e3a77",
      "name": "预算助手Telegram代理文本",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1344,
        2212
      ],
      "parameters": {
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "You are Budget Buddy, a helpful and funny personal finance assistant that helps users track their spending via Telegram chat.\nThe input you receive is a plain text message sent by the user in chat. It may describe a recent expense such as a purchase, bill payment, or money transfer. Your job is to analyze this message and determine whether it contains a valid personal expense.\nIf the content clearly describes a financial transaction (such as a purchase, payment, or transfer), extract the structured details:\n- date: The date of the transaction (use today’s date if not mentioned)\n- amount: The total amount paid\n- currency: The currency used (default to “VND” unless another is clearly shown)\n- category: Choose the most appropriate category\n- description: A short summary of what the expense was for\nOnly return an expense if key information like amount and description is present. Do not assume details that are not clearly found in the input.\nYou must always respond with a single valid JSON object in the following format:\n- \"relevant\": true if the user chat contains a valid expense, false otherwise\n- \"expense_record\": An object with the extracted expense details (only include if relevant is true, otherwise leave empty for all fields)\n- \"message\": A friendly, human-like response that confirms the tracked expense (if relevant), or a polite fallback message if not\n\nYour tone should be casual, friendly, and supportive. If the content is not clearly an expense (e.g., unclear message , unrelated info), respond with message sorry and politely as user to tell user that you only able to suport expense tracking\n\nWhen classifying the expense, choose one appropriate category from the list below:\n\nFood, Transportation, Utilities, Shopping, Entertainment, Health, Education, Housing, Travel, Groceries, Subscriptions, Gifts, Insurance, Investment, Phone & Internet, Bank Fees, Charity, Childcare, Pets, Other\n\nIf no category fits, use \"Other\".\n\nOnly return the final JSON object. Do not include explanations or extra text."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "ea33d919-65ea-4337-b386-a37a0999d006",
      "name": "是文本消息吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        1120,
        2516
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "069b1c3b-d683-46f2-b7d6-9dbcdde41445",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.message.toJsonString() }}",
              "rightValue": "text"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8227ca3e-9e42-4be6-942e-7febe923d4d8",
      "name": "不支持的消息类型",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1432,
        2612
      ],
      "webhookId": "4e8e4674-5b05-458b-818a-f46a0254d344",
      "parameters": {
        "text": "=Sorry, I can’t read files or images right now. Just send me a message describing what you spent, and I’ll help you track it! 💬💸",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "paNoPvnV5Wzt4Lhv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8672c0fe-ff15-4dd2-a7fc-40f70539ad51",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1024,
        1520
      ],
      "parameters": {
        "width": 1024,
        "height": 2000,
        "content": "# 📒 Telegram支出追踪器到Google Sheets(使用GPT-4.1)"
      },
      "typeVersion": 1
    },
    {
      "id": "6dd2be31-9532-4cc9-b42a-6c7e55db816f",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2720,
        2224
      ],
      "parameters": {
        "width": 960,
        "height": 320,
        "content": "![替代文本](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-04+at+9.32.37%E2%80%AFPM.png \"可选标题\")"
      },
      "typeVersion": 1
    },
    {
      "id": "1b56c157-8f4d-4b8b-8b54-6a1993c20b25",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1952,
        1760
      ],
      "parameters": {
        "width": 960,
        "height": 272,
        "content": "![替代文本](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-04+at+9.32.13%E2%80%AFPM.png \"可选标题\")"
      },
      "typeVersion": 1
    },
    {
      "id": "6496a7e8-4c4d-4264-8e72-371a7457e415",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        2752
      ],
      "parameters": {
        "width": 960,
        "height": 288,
        "content": "![替代文本](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-04+at+9.28.40%E2%80%AFPM.png \"可选标题\")"
      },
      "typeVersion": 1
    },
    {
      "id": "083253a0-bc79-4acc-816b-bc3d0a5e8f4c",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        2816
      ],
      "parameters": {
        "width": 960,
        "height": 208,
        "content": "![替代文本](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-04+at+9.37.48%E2%80%AFPM.png \"可选标题\")"
      },
      "typeVersion": 1
    },
    {
      "id": "a3959a72-29f4-4947-b20a-d088781674dc",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        2512
      ],
      "parameters": {
        "width": 304,
        "height": 128,
        "content": "### 1. 📩 Telegram触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "5cd98929-68d9-42fe-bf55-354efebe8dbc",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        2336
      ],
      "parameters": {
        "width": 272,
        "height": 144,
        "content": "### 2. 是文本消息吗?"
      },
      "typeVersion": 1
    },
    {
      "id": "93216e1c-1d56-4b52-b81f-0cc10186549c",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        2064
      ],
      "parameters": {
        "width": 512,
        "height": 112,
        "content": "### 3. 💬 预算助手Telegram代理(GPT-4.1 Mini)"
      },
      "typeVersion": 1
    },
    {
      "id": "81c17aea-3f22-4c29-b220-17bc14f6512e",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1968,
        2048
      ],
      "parameters": {
        "width": 640,
        "height": 96,
        "content": "### 4.1. ✅ 确认支出"
      },
      "typeVersion": 1
    },
    {
      "id": "147c9089-8fed-44a7-86a5-350d9a5e56f5",
      "name": "### 替换 Airtable 连接",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2144,
        2240
      ],
      "parameters": {
        "width": 512,
        "height": 96,
        "content": "### 4.2 转换并记录支出"
      },
      "typeVersion": 1
    },
    {
      "id": "f453b718-dc12-41e5-8d6c-90323d546744",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2208,
        2576
      ],
      "parameters": {
        "width": 512,
        "height": 96,
        "content": "### 5 告知用户不支持该场景"
      },
      "typeVersion": 1
    },
    {
      "id": "42f1955f-ba2e-466f-b3ed-ab2226b353a6",
      "name": "便签11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        1520
      ],
      "parameters": {
        "width": 1136,
        "height": 752,
        "content": "![替代文本](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-04+at+9.49.43%E2%80%AFPM.png \"可选标题\")"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "34a0a999-731f-4321-a74f-75412e341b7b",
  "connections": {
    "Is text message?": {
      "main": [
        [
          {
            "node": "Budget Buddy Telegram Agent Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Un-supported message type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Is text message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Budget Buddy Telegram Agent Text",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Supported scenario?": {
      "main": [
        [
          {
            "node": "Acknowledge the expense",
            "type": "main",
            "index": 0
          },
          {
            "node": "Transform the output to expense record",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send un-supported scenario message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Budget Buddy Telegram Agent Text",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Budget Buddy Telegram Agent Text": {
      "main": [
        [
          {
            "node": "Supported scenario?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transform the output to expense record": {
      "main": [
        [
          {
            "node": "Log expense record to google sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 个人效率, AI 摘要总结

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量23
分类2
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Trung Tran

Trung Tran

@trungtran

Empowering small and medium businesses with smart automation and practical AI, no big tech team required. Reach out: lets@automatewith.me

外部链接
在 n8n.io 查看

分享此工作流