8
n8n 中文网amn8n.com

AI自动Gmail发票检测与Slack通知

中级

这是一个自动化工作流,包含 12 个节点。主要使用 If, Gmail, Slack, Agent, ScheduleTrigger 等节点。 使用GPT-4o从Gmail中提取发票数据并发送Slack通知

前置要求
  • Google 账号和 Gmail API 凭证
  • Slack Bot Token 或 Webhook URL
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "AI自动从Gmail检测发票并在Slack上通知",
  "nodes": [
    {
      "id": "df47f544-18a9-4eea-a02f-6e8618bdc903",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1488,
        -16
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fb69e703-7747-4862-8208-0d0803f5ce8f",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueRegularOutput",
      "position": [
        -1040,
        -16
      ],
      "parameters": {
        "text": "=You are an intelligent assistant that reads emails and determines whether the message is related to an invoice or a payment notification.\n\nYour tasks:\n1. Determine if the email is invoice-related.\n2. If yes, extract:\n   - Due date (in YYYY-MM-DD format, or null)\n   - Amount due (as a number, no currency symbols)\n\nAlways include these metadata values:\nId: {{ $json.id }}\nthreadId: {{ $json.threadId }}\nbody: {{ $json.text }}\nsubject: {{ $json.subject }}\nsender: {{ $json.from.value[0].name }}\n\nReturn only a valid JSON object in the format below:\n\n```json\n{\n  \"is_invoice\": true or false,\n  \"due_date\": \"YYYY-MM-DD\" or null,\n  \"amount_due\": number or null,\n  \"email_id\": \"string\",\n  \"thread_id\": \"string\",\n  \"sender\": \"string\",\n  \"subject\": \"string\"\n}\n\n\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "ff1adb6a-43d6-4b36-9c91-0046b0146565",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1024,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "acc58349-b51f-4623-9a23-f740791483fb",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -896,
        208
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"is_invoice\": {\n      \"type\": \"boolean\"\n    },\n    \"due_date\": {\n      \"type\": [\"string\", \"null\"],\n      \"format\": \"date\"\n    },\n    \"amount_due\": {\n      \"type\": [\"number\", \"null\"]\n    },\n    \"email_id\": {\n      \"type\": \"string\"\n    },\n    \"thread_id\": {\n      \"type\": \"string\"\n    },\n    \"sender\": {\n      \"type\": \"string\"\n    },\n    \"subject\": {\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"is_invoice\",\n    \"due_date\",\n    \"amount_due\",\n    \"email_id\",\n    \"thread_id\",\n    \"sender\",\n    \"subject\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "436dccba-2b62-4ee9-b2c3-0581bc836ed7",
      "name": "无操作,不执行任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -464,
        80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4c1eb726-1666-4f5c-b4e0-8f938f3ef791",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        208
      ],
      "parameters": {
        "width": 304,
        "height": 224,
        "content": "### ⚠️ 需要设置"
      },
      "typeVersion": 1
    },
    {
      "id": "17c6acfe-6074-43f9-af78-8a2f7104df5b",
      "name": "获取未读邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1264,
        -16
      ],
      "webhookId": "4259da3e-a2e2-41ea-aaac-50d8bf8a4bb7",
      "parameters": {
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {},
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "51725993-99b5-4d9e-a562-4e762ca6a0a2",
      "name": "检查邮件是否为发票",
      "type": "n8n-nodes-base.if",
      "position": [
        -688,
        -16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "dc8158a0-29aa-4c7f-9de3-994a5d827331",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.output.is_invoice }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ec14d8de-cfab-4b53-a3b5-9aae1c3b808d",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 272,
        "content": "### 💡 计划触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "3f7e75ec-5a03-4664-b1ff-91f57bee2d9d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -336
      ],
      "parameters": {
        "color": 5,
        "width": 272,
        "height": 400,
        "content": "### 💡 自定义通知格式"
      },
      "typeVersion": 1
    },
    {
      "id": "db70ae0c-794b-452e-b8cd-26574ff006a2",
      "name": "通知Slack用户",
      "type": "n8n-nodes-base.slack",
      "position": [
        -464,
        -112
      ],
      "webhookId": "a155a0c9-d84e-4937-b215-9d2920c45616",
      "parameters": {
        "text": "=Invoice from {{ $json.output.sender }} – ${{ $json.output.amount_due }} due {{ $json.output.due_date }}",
        "user": {
          "__rl": true,
          "mode": "username",
          "value": ""
        },
        "select": "user",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.3
    },
    {
      "id": "d9bc11f7-edb5-4521-9702-725c8fa736fc",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        -256
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 640,
        "content": "### 🤖 AI智能体"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Check If Email is Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Unread Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unread Emails": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check If Email is Invoice": {
      "main": [
        [
          {
            "node": "Notify Slack User",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级

需要付费吗?

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

工作流信息
难度等级
中级
节点数量12
分类-
节点类型9
难度说明

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

作者
Matt Chong | n8n Creator

Matt Chong | n8n Creator

@mattxchong

Automation nerd fueled by good coffee, deep curiosity, and clean flows.

外部链接
在 n8n.io 查看

分享此工作流