8
n8n 中文网amn8n.com

Gmail→GPT→Supabase任务提取器

中级

这是一个Personal Productivity, AI Summarization领域的自动化工作流,包含 9 个节点。主要使用 If, Code, Gmail, Supabase, HttpRequest 等节点。 使用Gmail、ChatGPT-4o和Supabase提取邮件任务

前置要求
  • Google 账号和 Gmail API 凭证
  • Supabase URL 和 API Key
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "8mU5BDEPNPCBrcNG",
  "meta": {
    "instanceId": "05cd306a73f97150c796adf49d28dcc97084b722b0b212b8c228ea8b71d87571",
    "templateCredsSetupCompleted": true
  },
  "name": "Gmail → GPT → Supabase | 任务提取器",
  "tags": [],
  "nodes": [
    {
      "id": "60d16e90-4a70-4aca-9643-997141a65cdf",
      "name": "触发工作流",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "Runs the workflow on a schedule (every X minutes) to check for new unread emails.",
      "position": [
        -580,
        -430
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "id": "501a117f-93ff-43e9-8a49-5f0c58c4e496",
      "name": "准备ChatGPT提示",
      "type": "n8n-nodes-base.code",
      "notes": "Formats the email content into a prompt for GPT, asking it to extract a structured task in JSON format.",
      "position": [
        520,
        -580
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return {\n  prompt: `You are an AI productivity assistant. Given the email below, extract any actionable task(s). Respond in this format:\n  {\n    \"task\": \"Brief title of the task\",\n    \"description\": \"Expanded detail if needed\",\n    \"due_date\": \"2025-07-01\" or null,\n    \"estimated_minutes\": 30,\n    \"deep_work\": true\n  }\n  If no actionable task exists, respond with null.\\n\\nEmail:\\n${$('Loop Over Items').item.json.snippet}`\n};\n"
      },
      "executeOnce": false,
      "notesInFlow": true,
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "cec2c062-7333-499a-b5c3-5f7831022d34",
      "name": "从邮件提取任务详情",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Sends the email to ChatGPT-4o to extract task details like title, description, due date, duration, and focus level.",
      "position": [
        740,
        -580
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "chatgpt-4o-latest",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "={{ $json.prompt }}"
            }
          ]
        },
        "jsonOutput": true
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "d708c9c3-d5ec-4b2a-8f8a-b5b123fa44ea",
      "name": "将邮件详情插入Supabase",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Inserts the processed email and GPT-extracted task into the Supabase emails table. Uses upsert to avoid duplicates.",
      "position": [
        1116,
        -505
      ],
      "parameters": {
        "url": "={{ $vars.Supabase_TaskManagement_URI + '/rest/v1/emails?on_conflict=email_id' }}",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"email_id\": {{ JSON.stringify( $('Get Unread Emails from Inbox').item.json.id) }},\n  \"subject\": {{ JSON.stringify($('Get Unread Emails from Inbox').item.json.Subject) }},\n  \"sender\": {{ JSON.stringify($('Get Unread Emails from Inbox').item.json.From) }},\n  \"received_at\": {{ JSON.stringify(new Date(Number($('Get Unread Emails from Inbox').item.json.internalDate)).toISOString()) }},\n  \"body\": {{ JSON.stringify($('Get Unread Emails from Inbox').item.json.snippet) }},\n  \"gpt_summary\": {{ JSON.stringify($json.message.content) }},\n  \"requires_deep_work\": {{ JSON.stringify($json.message.content.deep_work) }},\n  \"deleted\": false\n}",
        "sendBody": true,
        "jsonHeaders": "={\n  \"apikey\": \"{{ $vars.Supabase_TaskManagement_ANON_KEY }}\",\n  \"Authorization\": \"Bearer {{ $vars.Supabase_TaskManagement_ANON_KEY }}\",\n  \"Content-Type\": \"application/json\",\n  \"Prefer\": \"resolution=ignore-conflict\"\n}",
        "sendHeaders": true,
        "specifyBody": "json",
        "specifyHeaders": "json"
      },
      "notesInFlow": true,
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "5b774acc-8e19-4576-9970-91a060d25d87",
      "name": "从收件箱获取未读邮件",
      "type": "n8n-nodes-base.gmail",
      "notes": "Fetches all unread emails from the inbox using Gmail API. These are the raw email inputs for analysis.",
      "position": [
        -360,
        -430
      ],
      "webhookId": "b6105761-5356-4ba7-828d-6efe96e244ba",
      "parameters": {
        "filters": {
          "labelIds": [
            "INBOX"
          ],
          "readStatus": "unread"
        },
        "operation": "getAll",
        "returnAll": true
      },
      "notesInFlow": true,
      "typeVersion": 2.1,
      "alwaysOutputData": false
    },
    {
      "id": "5d856e76-d335-4a72-8807-556417a35d2d",
      "name": "从数据库获取邮件",
      "type": "n8n-nodes-base.supabase",
      "notes": "Checks Supabase to see if this email has already been processed (by matching on email_id). Prevents duplicate GPT calls.",
      "position": [
        80,
        -580
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "email_id",
              "keyValue": "={{ $json.id }}"
            }
          ]
        },
        "tableId": "emails",
        "operation": "get"
      },
      "executeOnce": false,
      "notesInFlow": true,
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "4d1d53a4-14c4-4d53-b9cb-1f29d425060b",
      "name": "检查邮件是否在数据库中",
      "type": "n8n-nodes-base.if",
      "notes": "If the email does not exist in Supabase, continue with GPT processing. Otherwise, skip this email.",
      "position": [
        300,
        -580
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5969f38d-31d4-4ed0-ad6c-d8bb522db40f",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{ $json.isEmpty() }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "notesInFlow": true,
      "typeVersion": 2.2,
      "alwaysOutputData": false
    },
    {
      "id": "9ff6b95c-9d19-4925-a718-15ca5774d81d",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "notes": "Loops through each unread email individually, allowing per-item processing (dedup, GPT, insert).",
      "position": [
        -140,
        -430
      ],
      "parameters": {
        "options": {}
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "a46fc69d-9711-4846-b6ff-e77394f518b5",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1680,
        -640
      ],
      "parameters": {
        "width": 1000,
        "height": 1840,
        "content": "## 📩 Gmail → GPT → Supabase | 任务提取器"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a7ad1235-9417-4c86-a3fd-cd72849f51dc",
  "connections": {
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Get Email from Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Workflow": {
      "main": [
        [
          {
            "node": "Get Unread Emails from Inbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare ChatGPT Prompt": {
      "main": [
        [
          {
            "node": "Extract Task Detail from Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Email from Database": {
      "main": [
        [
          {
            "node": "Check if Email in Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Email in Database": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare ChatGPT Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unread Emails from Inbox": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Task Detail from Email": {
      "main": [
        [
          {
            "node": "Insert Email Detail to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Email Detail to Supabase": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Paul Taylor

Paul Taylor

@ptylr

Senior product and solutions leader with deep technical expertise, commercial acumen, and proven leadership across VC- and PE-backed firms. I specialize in unifying product strategy, scaling cross-functional models, and incubating new opportunities. Skilled at crafting compelling narratives, driving GTM execution, and engaging externally with impact. I thrive on building teams and turning vision into value across the full product lifecycle.

外部链接
在 n8n.io 查看

分享此工作流