Telegram和Google Sheets费用记录:周度汇总与预算提醒

中级

这是一个Personal Productivity、Miscellaneous、Multimodal AI领域的自动化工作流,包含 15 个节点。主要使用 Code、Telegram、GoogleSheets、ScheduleTrigger、TelegramTrigger 等节点。 Telegram和Google Sheets费用记录:周度汇总与预算提醒

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "19e5bdcaace8da818cec75a5b6c7d27485bb3218a7ba566cbf475ddfd436a339",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ce1bf9d0-73d3-44d7-89e6-7a255be132f2",
      "name": "便签 - 概述",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        112
      ],
      "parameters": {
        "width": 640,
        "height": 308,
        "content": "# 💸 Telegram 费用追踪器与 Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "8a39a922-2230-4d47-896e-722009ffcf61",
      "name": "便签 - 每日记录",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        400
      ],
      "parameters": {
        "color": 4,
        "width": 1232,
        "height": 304,
        "content": "## 表格中的每日记录开支"
      },
      "typeVersion": 1
    },
    {
      "id": "d25a775e-f537-4e28-851d-ebf02dc67531",
      "name": "便签 - 每周总计",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        704
      ],
      "parameters": {
        "color": 5,
        "width": 1056,
        "height": 272,
        "content": "## 每周总计"
      },
      "typeVersion": 1
    },
    {
      "id": "e8295340-df45-4f59-a79c-d34284171769",
      "name": "Telegram - 获取费用命令",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        624,
        496
      ],
      "webhookId": "b794fd0e-d6fa-442c-b916-0eb73f65f448",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "qFp0dReFa2R5lsei",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "424fbab2-7a0d-4752-87cf-c678af551858",
      "name": "解析 Telegram 消息",
      "type": "n8n-nodes-base.code",
      "position": [
        816,
        496
      ],
      "parameters": {
        "jsCode": "const msg = $json.message.text;   // e.g. \"/spent 4 coffee\"\nconst parts = msg.split(\" \");     // [\"/spent\", \"4\", \"coffee\"]\nreturn [{\n  json: {\n    amount: parseFloat(parts[1]),\n    description: parts.slice(2).join(\" \"),\n    date: new Date().toISOString().split(\"T\")[0] // YYYY-MM-DD\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "fe60d073-a130-40c4-b44c-d9f7047d6432",
      "name": "Google Sheets - 记录开支",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1008,
        496
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date ": "={{ $json.date }}",
            "Amount ": "={{ $json.amount }}",
            "Description": "={{ $json.description }}"
          },
          "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": "Description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "<YOUR_SHEET_ID>"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ktGp50kJq6nhFH5q",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "89969a35-a406-46a2-80b9-68b91d06eee3",
      "name": "每周摘要触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        640,
        800
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 11
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "538c8dec-9443-429f-830f-964af2e09092",
      "name": "计算每周总计",
      "type": "n8n-nodes-base.code",
      "position": [
        1056,
        800
      ],
      "parameters": {
        "jsCode": "const rows = items.map(item => item.json);\n\nconst now = new Date();\nconst weekAgo = new Date();\nweekAgo.setDate(now.getDate() - 7);\n\nlet total = 0;\nfor (let r of rows) {\n  // Handle column name issues (trim spaces in keys)\n  const dateStr = r[\"Date\"] || r[\"Date \"] || r[\"date\"];\n  const amountStr = r[\"Amount\"] || r[\"Amount \"] || r[\"amount\"];\n\n  // Try parsing date safely (Google Sheets often gives YYYY-MM-DD if set to ISO)\n  const d = new Date(dateStr);\n\n  if (!isNaN(d)) {\n    if (d >= weekAgo && d <= now) {\n      total += parseFloat(amountStr) || 0;\n    }\n  }\n}\n\nreturn [{\n  json: { summary: `💰 Your total expenses this week: €${total.toFixed(2)}` }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "f2fb125e-a966-4e4b-ac87-729eee25771f",
      "name": "Telegram - 发送每周摘要",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1264,
        800
      ],
      "webhookId": "cd477ad5-32ee-4d4f-a864-694323cdf656",
      "parameters": {
        "text": "={{$json[\"summary\"]}}",
        "chatId": "<YOUR_CHAT_ID>",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "qFp0dReFa2R5lsei",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "de30a959-b686-4868-b526-008cfad554e8",
      "name": "便签 - 设置指南",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        416
      ],
      "parameters": {
        "color": 6,
        "width": 528,
        "height": 496,
        "content": "# 🛠️ 设置指南"
      },
      "typeVersion": 1
    },
    {
      "id": "2f11e041-b267-4ee3-b097-13b64250acfc",
      "name": "Google Sheets - 清理(可选)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1472,
        800
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "<YOUR_SHEET_ID>"
        },
        "numberToDelete": 30
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ktGp50kJq6nhFH5q",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "77d677fc-5c20-4d6a-934f-6c11b03d2b62",
      "name": "Google Sheets - 获取每周开支",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        848,
        800
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "<YOUR_SHEET_ID>"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ktGp50kJq6nhFH5q",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "1a7dd79f-cfe3-4612-9efc-3995ad521e5e",
      "name": "Google Sheets - 获取开支(实时)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1232,
        496
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "<YOUR_SHEET_ID>"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ktGp50kJq6nhFH5q",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d3a25a1b-e05a-4984-8ab3-8c22d90b8a1b",
      "name": "检查每周预算",
      "type": "n8n-nodes-base.code",
      "position": [
        1440,
        496
      ],
      "parameters": {
        "jsCode": "const rows = items.map(item => item.json);\n\nlet total = 0;\nfor (let r of rows) {\n  const amountStr = r[\"Amount\"] || r[\"Amount \"] || r[\"amount\"];\n  total += parseFloat(amountStr) || 0;\n}\n\nif (total > 100) {\n  return [{\n    json: {\n      alert: `⚠️ Warning Giorgos! You have exceeded your weekly budget of 100€ (€${total.toFixed(2)})`\n    }\n  }];\n} else {\n  return [];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "6b30f059-d3d0-4117-bb06-0d027f0d95eb",
      "name": "Telegram - 发送预算警报",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1632,
        496
      ],
      "webhookId": "5d273b13-40db-441d-8dc5-f753e7b8256e",
      "parameters": {
        "text": "={{$json[\"alert\"]}}",
        "chatId": "<YOUR_CHAT_ID>",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "qFp0dReFa2R5lsei",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "pinData": {},
  "connections": {
    "Check Weekly Budget": {
      "main": [
        [
          {
            "node": "Telegram - Send Budget Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Weekly Total": {
      "main": [
        [
          {
            "node": "Telegram - Send Weekly Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Telegram Message": {
      "main": [
        [
          {
            "node": "Google Sheets - Log Expense",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Summary Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets - Get Weekly Expenses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Log Expense": {
      "main": [
        [
          {
            "node": "Google Sheets - Get Expenses (Realtime)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram - Get Expense Command": {
      "main": [
        [
          {
            "node": "Parse Telegram Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram - Send Weekly Summary": {
      "main": [
        [
          {
            "node": "Google Sheets - Clean Up (Optional)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Get Weekly Expenses": {
      "main": [
        [
          {
            "node": "Calculate Weekly Total",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Get Expenses (Realtime)": {
      "main": [
        [
          {
            "node": "Check Weekly Budget",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

这是一个中级难度的工作流,适用于Personal Productivity、Miscellaneous、Multimodal AI等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

需要付费吗?

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

工作流信息
难度等级
中级
节点数量15
分类3
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 上查看 →

分享此工作流