使用GPT-4整理Gmail并通过Telegram和WhatsApp发送紧急通知
高级
这是一个Ticket Management, Multimodal AI领域的自动化工作流,包含 28 个节点。主要使用 If, Code, Wait, Gmail, Filter 等节点。 通过GPT-4整理Gmail,并使用Telegram和WhatsApp发送紧急通知
前置要求
- •Google 账号和 Gmail API 凭证
- •Telegram Bot Token
- •OpenAI API Key
- •Google Gemini API Key
使用的节点 (28)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "67849de66331aaa2dca6a4f3cbf793b274f923d94e4d9cdaae2e5d9aebaff626",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "d94e086d-1845-420c-a8d0-659f2985dfb4",
"name": "Gmail 触发器1",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-2848,
1440
],
"parameters": {
"filters": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "923af877-ba1b-4765-b297-93fb9ffcbda1",
"name": "结构化输出解析器1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-1760,
1664
],
"parameters": {
"autoFix": true,
"jsonSchemaExample": "{\n\t\"label\": \"Label name\", \n\"label ID\": \"label ID\" \n}"
},
"typeVersion": 1.2
},
{
"id": "a289e623-df2d-4e2d-b324-544e2d350535",
"name": "检查已发送2",
"type": "n8n-nodes-base.gmailTool",
"position": [
-2016,
1664
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"filters": {
"q": "=to:{{ $fromAI('email') }}",
"labelIds": [
"SENT"
]
},
"operation": "getAll"
},
"typeVersion": 2.1
},
{
"id": "019e8526-436c-4619-9da1-d9f958905e54",
"name": "如果不存在则创建标签1",
"type": "n8n-nodes-base.gmail",
"onError": "continueRegularOutput",
"position": [
-1056,
1440
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"name": "={{ $json.output.label }}",
"options": {},
"resource": "label",
"operation": "create"
},
"typeVersion": 2.1
},
{
"id": "cc545b7e-f5ae-44f0-98ab-6de8161905b2",
"name": "获取现有标签1",
"type": "n8n-nodes-base.gmail",
"position": [
-704,
1440
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"resource": "label",
"returnAll": true
},
"typeVersion": 2.1
},
{
"id": "ead0e438-b7df-4432-a241-a5acfe85c550",
"name": "遍历项目1",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-1392,
1440
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "708905c5-51de-49a4-9955-04bda21371de",
"name": "过滤器1",
"type": "n8n-nodes-base.filter",
"position": [
-480,
1440
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "e36a5069-09dd-424d-a2b8-096cefa059d7",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.name }}",
"rightValue": "={{ $('Loop Over Items1').item.json.output.label }}"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "3f784595-5df0-4809-8bfc-fbb613f26493",
"name": "检查已发送3",
"type": "n8n-nodes-base.gmailTool",
"position": [
-1888,
1664
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"resource": "label"
},
"typeVersion": 2.1
},
{
"id": "44cd8d9e-4a22-4dc1-aff7-83cdda5743d8",
"name": "向会话添加标签1",
"type": "n8n-nodes-base.gmail",
"position": [
-256,
1504
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"labelIds": "={{ $json.id }}",
"resource": "thread",
"threadId": "={{ $('Get a message1').item.json.threadId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "11bf73c9-645b-4166-a1bf-b21daf52b443",
"name": "代码1",
"type": "n8n-nodes-base.code",
"onError": "continueErrorOutput",
"position": [
-768,
784
],
"parameters": {
"jsCode": "const raw = $json.output;\n\n// Fully remove any Markdown code block wrapping\nconst clean = raw\n .replace(/^\\s*```json\\s*/i, '') // Remove opening ```json\n .replace(/^\\s*```\\s*/i, '') // Remove opening ``` if no json\n .replace(/\\s*```$/, '') // Remove trailing ```\n .trim();\n\nlet parsed;\n\ntry {\n parsed = JSON.parse(clean);\n} catch (e) {\n throw new Error('Failed to parse JSON: ' + e.message + '\\nContent: ' + clean);\n}\n\nreturn [\n {\n json: {\n urgency: parsed.urgency || 'normal',\n summary: parsed.summary || ''\n }\n }\n];\n"
},
"typeVersion": 2
},
{
"id": "bcd51860-5e8c-4a25-a138-8c716c71843e",
"name": "条件判断1",
"type": "n8n-nodes-base.if",
"position": [
-544,
736
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "08d94b28-1974-422c-ab84-5fe541b6be22",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.urgency }}",
"rightValue": "urgent"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "5853e3f7-fd73-442f-8c78-f7ac05903495",
"name": "发送消息1",
"type": "n8n-nodes-base.whatsApp",
"position": [
-320,
640
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"textBody": "=\nto :{{ $('Gmail Trigger1').first().json.To }}\n\n{{ $json.summary }}\n\n\n{{ $('Gmail Trigger1').item.json.snippet }}\n",
"operation": "send",
"phoneNumberId": "[REDACTED_PHONE_NUMBER_ID]",
"additionalFields": {
"previewUrl": false
},
"recipientPhoneNumber": "[REDACTED_RECIPIENT_PHONE_NUMBER]"
},
"typeVersion": 1
},
{
"id": "c985b440-5e29-4441-beec-ebf85d64367d",
"name": "发送文本消息1",
"type": "n8n-nodes-base.telegram",
"position": [
-320,
864
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"text": "=\nto :{{ $('Gmail Trigger1').first().json.To }}\n\n{{ $json.summary }}\n\n\n{{ $('Gmail Trigger1').item.json.snippet }}\n",
"chatId": "[REDACTED_CHAT_ID]",
"additionalFields": {
"appendAttribution": false
}
},
"retryOnFail": true,
"typeVersion": 1.2
},
{
"id": "6fd66034-4fd6-49f7-87c0-f254b2eb1a3c",
"name": "OpenRouter Chat Model2",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
-2144,
1664
],
"parameters": {
"model": "deepseek/deepseek-chat-v3-0324:free",
"options": {}
},
"typeVersion": 1
},
{
"id": "7f49e491-2774-4ecf-9cb0-8fca4c1a799d",
"name": "等待1",
"type": "n8n-nodes-base.wait",
"position": [
-544,
960
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"amount": 15
},
"typeVersion": 1.1
},
{
"id": "992e1bb0-b068-4e72-8509-eceede49581c",
"name": "AI代理3",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-2112,
1440
],
"parameters": {
"text": "Run the task.",
"options": {
"systemMessage": "=Objective:\nClassify the given email into the most appropriate domain-specific label by analyzing the sender, subject, content, metadata, and prior engagement history. Return only the corresponding Label ID based on the classification criteria. Use unsubscribe headers, auto-submission flags, and sender reputation to improve accuracy.\n\n📧 Input Email Metadata\nSender: {{ $json.from.value[0].name }} <{{ $json.from.value[0].address }}>\n\nTo: {{ $json.to.value.map(r => r.address).join(', ') }}\n\nSubject: {{ $json.subject }}\n\nBody (Text): {{ $json.text }}\n\nGmail Labels: {{ $json.labelIds.join(', ') }}\n\nHeaders:\n\nAuto-Submitted: {{ $json.headers['auto-submitted'] }}\n\nList-Unsubscribe: {{ $json.headers['list-unsubscribe'] }}\n\nPrecedence: {{ $json.headers['precedence'] }}\n\nIn-Reply-To: {{ $json.headers['in-reply-to'] }}\n\nReferences: {{ $json.headers['references'] }}\n\nPrior Email History with Sender: (from user logs or database)\n\n🧠 Label Classification Criteria\nLabel Name\tLabel ID\tDescription\nFinance\tLabel_FIN_90210\tStatements, invoices, bank alerts, credit cards, UPI summaries.\nEducation\tLabel_EDU_90211\tCourses, admissions, certifications, university updates.\nMarketing\tLabel_MKT_90212\tPromotions, upsells, newsletters selling something.\nNotification\tLabel_NOTIFY_90213\tBilling, system alerts, policy changes, service updates.\nTo Respond\tLabel_ACTION_90214\tRequires user's reply, task-based, follow-up needed.\nFYI\tLabel_FYI_90215\tInformational only, no reply needed.\nComment/Feedback\tLabel_COMMENT_90216\tComments on docs, feedback, inline annotations.\nMeeting Update\tLabel_MEETING_90217\tInvites, schedule changes, meeting summaries.\nCloud Services\tLabel_CLOUD_90218\tEmails from AWS, Azure, GCP, Cloudflare, etc.\nDev Tools\tLabel_DEV_90219\tGitHub, GitLab, Docker, CI/CD pipelines, webhooks, etc.\nTech Updates\tLabel_TECH_90220\tProduct launches, changelogs, software feature rollouts.\nCommunity/Forum\tLabel_COMM_90221\tThreads from Reddit, StackOverflow, Discord, forums.\nSecurity Alert\tLabel_SEC_90222\tLogin attempts, MFA alerts, password resets.\n\n⚙️ Classification Rules (Heuristics)\nAuto-Submitted = yes OR Precedence = bulk: Likely Notification, FYI, or Marketing.\n\nList-Unsubscribe exists AND No prior history: Prefer Marketing.\n\nSender is GitHub, CI/CD, or version control tool → Dev Tools.\n\nSubject/body mentions login attempt, MFA, password reset → Security Alert.\n\nFrom AWS, Cloudflare, or similar → Cloud Services.\n\nRelease notes, update logs, patch info → Tech Updates.\n\nCommunity replies, thread responses → Community/Forum.\n\nDirect task requests or questions → To Respond.\n\nInvoices/statements with no promo → Finance.\n\nSchool/university address or edu domain → Education.\n\n✅ Final Instruction:\nReturn ONLY the Label ID that best matches the email based on the above logic. No extra output, just the correct ID.\n\n📌 Sample Email Analysis (Example)\nFrom: GitHub noreply@github.com\nSubject: [your-repo] New pull request opened\nContent: Contributor opened PR with description and change log. No reply needed unless assigned.\nHeaders: auto-submitted: yes\nPrior history: Yes (developer account)\n\n👉 Result:\nLabel_DEV_90219"
},
"promptType": "define",
"needsFallback": true,
"hasOutputParser": true
},
"executeOnce": false,
"typeVersion": 2.1
},
{
"id": "ea93f6d2-14ed-44ae-a13d-e283aedea9b6",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1680,
1872
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-nano",
"cachedResultName": "gpt-4.1-nano"
},
"options": {}
},
"typeVersion": 1.2
},
{
"id": "48d11f0f-6f8d-43ff-baa7-6676e338d68c",
"name": "AI Agent1",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-1184,
752
],
"parameters": {
"text": "=You are an intelligent email assistant.\n\nYour task is to:\n1. Analyze the following email.\n2. Decide whether it is **urgent** or **normal**.\n3. Provide a **short summary** of what the email is about (max 2 sentences).\n\nUse urgency judgment based on:\n- Urgent = Requires immediate action (e.g., OTP, payment due, failed transaction, security alert, verification, deadline)\n- Normal = Informational emails like statements, newsletters, general notifications, or promotions\n\n\n---\n\nEmail Details:\n\nFrom: {{ $('Get a message1').item.json.from.value[0].address }}\nSubject: {{ $('Get a message1').item.json.subject }}\nBody:{{ $('Get a message1').item.json.text }}\n\n---\n\nRespond in the following JSON format:\n{\n \"urgency\": \"urgent\" | \"normal\",\n \"summary\": \"[short explanation of the email]\"\n}\n",
"options": {},
"promptType": "define",
"needsFallback": true
},
"executeOnce": true,
"typeVersion": 2.1,
"alwaysOutputData": true
},
{
"id": "730c73a2-3058-4149-ae56-7636c4c18612",
"name": "Google Gemini 聊天模型2",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
-2272,
1664
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "9d73b218-17ea-4d59-8bfd-ce03c7ceed56",
"name": "Google Gemini Chat Model3",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
-1232,
976
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "022c035e-793d-44ec-a797-c928fcef0cc4",
"name": "简单记忆1",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
-976,
976
],
"parameters": {
"sessionKey": "={{ $('Get Existing Labels1').first().json.id }}",
"sessionIdType": "customKey"
},
"typeVersion": 1.3
},
{
"id": "b466f7b4-a0e5-4d08-870d-bc33d4760667",
"name": "OpenRouter 聊天模型3",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
-1104,
976
],
"parameters": {
"model": "deepseek/deepseek-chat-v3-0324:free",
"options": {}
},
"typeVersion": 1
},
{
"id": "4d33199c-a9d7-47aa-adc0-8920d23fe982",
"name": "获取消息1",
"type": "n8n-nodes-base.gmail",
"position": [
-2624,
1440
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"simple": false,
"options": {},
"messageId": "={{ $json.id }}",
"operation": "get"
},
"typeVersion": 2.1
},
{
"id": "bde50502-712e-4761-b1ea-cc7861a825ae",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2944,
1328
],
"parameters": {
"color": 4,
"width": 256,
"height": 272,
"content": "## 触发器:收到新邮件"
},
"typeVersion": 1
},
{
"id": "8b8451df-b8d5-40ec-875b-52de0ab37460",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2672,
1248
],
"parameters": {
"color": 4,
"width": 256,
"height": 352,
"content": "## 获取完整邮件内容"
},
"typeVersion": 1
},
{
"id": "5d08f0c3-d647-4c51-8c9f-0a36e0132d39",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2384,
1248
],
"parameters": {
"color": 4,
"width": 960,
"height": 752,
"content": "## AI 驱动的分类"
},
"typeVersion": 1
},
{
"id": "faceff2c-c767-411e-b7ad-389bf59c1d0a",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1408,
1248
],
"parameters": {
"color": 4,
"width": 1392,
"height": 560,
"content": "## 标签管理和应用"
},
"typeVersion": 1
},
{
"id": "ed965f5c-7f2d-44a1-a893-96c2de3a6616",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1568,
592
],
"parameters": {
"color": 4,
"width": 1568,
"height": 576,
"content": "## 紧急性分析和摘要生成"
},
"typeVersion": 1
}
],
"pinData": {
"Gmail Trigger1": [
{
"To": "Your Name <youremail@example.com>",
"id": "19879835a0159173",
"From": "Sender Name <sender@example.com>",
"labels": [
{
"id": "INBOX",
"name": "INBOX"
},
{
"id": "CATEGORY_UPDATES",
"name": "CATEGORY_UPDATES"
},
{
"id": "UNREAD",
"name": "UNREAD"
}
],
"Subject": "Sample Subject: A Great Deal!",
"payload": {
"mimeType": "multipart/alternative"
},
"snippet": "This is a sample snippet showing that great things don't have to cost a fortune. 🤑",
"threadId": "19879835a0159173",
"historyId": "7149053",
"internalDate": "1754385308000",
"sizeEstimate": 29762
}
]
},
"connections": {
"If1": {
"main": [
[
{
"node": "Send a text message1",
"type": "main",
"index": 0
},
{
"node": "Send message1",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "If1",
"type": "main",
"index": 0
}
],
[
{
"node": "Wait1",
"type": "main",
"index": 0
}
]
]
},
"Wait1": {
"main": [
[
{
"node": "AI Agent1",
"type": "main",
"index": 0
}
]
]
},
"Filter1": {
"main": [
[
{
"node": "Add label to thread1",
"type": "main",
"index": 0
}
]
]
},
"AI Agent1": {
"main": [
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"AI Agent3": {
"main": [
[
{
"node": "Loop Over Items1",
"type": "main",
"index": 0
}
]
]
},
"Check Sent2": {
"ai_tool": [
[
{
"node": "AI Agent3",
"type": "ai_tool",
"index": 0
}
]
]
},
"Check Sent3": {
"ai_tool": [
[
{
"node": "AI Agent3",
"type": "ai_tool",
"index": 0
}
]
]
},
"Get a message1": {
"main": [
[
{
"node": "AI Agent3",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger1": {
"main": [
[
{
"node": "Get a message1",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory1": {
"ai_memory": [
[
{
"node": "AI Agent1",
"type": "ai_memory",
"index": 0
}
]
]
},
"Loop Over Items1": {
"main": [
[
{
"node": "AI Agent1",
"type": "main",
"index": 0
}
],
[
{
"node": "Create Label if Doesn't exist1",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Structured Output Parser1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Add label to thread1": {
"main": [
[
{
"node": "Loop Over Items1",
"type": "main",
"index": 0
}
]
]
},
"Get Existing Labels1": {
"main": [
[
{
"node": "Filter1",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model2": {
"ai_languageModel": [
[
{
"node": "AI Agent3",
"type": "ai_languageModel",
"index": 1
}
]
]
},
"OpenRouter Chat Model3": {
"ai_languageModel": [
[
{
"node": "AI Agent1",
"type": "ai_languageModel",
"index": 1
}
]
]
},
"Google Gemini Chat Model2": {
"ai_languageModel": [
[
{
"node": "AI Agent3",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Google Gemini Chat Model3": {
"ai_languageModel": [
[
{
"node": "AI Agent1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser1": {
"ai_outputParser": [
[
{
"node": "AI Agent3",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Create Label if Doesn't exist1": {
"main": [
[
{
"node": "Get Existing Labels1",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 工单管理, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
完整的 B2B 销售流程:Apollo 潜在客户生成、Mailgun 外展和 AI 回复管理
完整的 B2B 销售流程:Apollo 潜在客户生成、Mailgun 外展和 AI 回复管理
If
Set
Code
+26
116 节点Paul
内容创作
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
构建带记忆、Google套件和多AI研究成像的WhatsApp助手
构建带记忆、Google套件和多AI研究成像的WhatsApp助手
If
Set
Code
+27
71 节点Iniyavan JC
AI 聊天机器人
GPT-4驱动的冷邮件工作流,包含完全定制的3封邮件跟进
使用GPT-4、Mailgun和Supabase自动化个性化冷邮件序列
If
Set
Code
+22
100 节点Paul
客户培育
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
If
Set
Gmail
+20
68 节点Abdullahi Ahmed
内容创作
使用GPT、Google日历和Supabase的自动邮件管理系统
使用GPT、Google日历和Supabase的自动邮件管理系统
If
Code
Gmail
+15
42 节点Abdul Mir
工单管理
工作流信息
难度等级
高级
节点数量28
分类2
节点类型17
作者
Iniyavan JC
@netwithjc🚀 Automation expert & AI enthusiast. I build custom n8n workflows, AI agents, API integrations, and smart automations using LLMs, databases, cloud tools & more. Skilled in Docker, MongoDB, Google Sheets, ACRCloud, and building fast, context-aware agents. Let's turn your idea into a powerful workflow!
外部链接
在 n8n.io 查看 →
分享此工作流