带Telegram审批的AI邮件回复助手
这是一个Ticket Management、AI Chatbot领域的自动化工作流,包含 16 个节点。主要使用 If、Gmail、Telegram、GmailTrigger、Agent 等节点。 使用 OpenAI 和 Telegram 审批实现 Gmail 邮件回复自动化
- •Google 账号和 Gmail API 凭证
- •Telegram Bot Token
- •OpenAI API Key
{
"id": "gXutAybKcZqblZjF",
"meta": {
"instanceId": "f339fb4cdac358dcfebe03c578dc787158fe3660e2856c0a125861bc0c95ef5c",
"templateCredsSetupCompleted": true
},
"name": "带Telegram审批的AI邮件回复助手",
"tags": [],
"nodes": [
{
"id": "a29a7c9c-cab6-479a-89f3-71c0abf02727",
"name": "结构化输出解析器1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
680,
1140
],
"parameters": {
"jsonSchemaExample": "{\n \"email\": \"email address\",\n \"subject\": \"subject text\",\n \"body\": \" body text .\"\n}\n"
},
"typeVersion": 1.2
},
{
"id": "954febca-8faf-4899-838f-854a5c344b97",
"name": "发送消息",
"type": "n8n-nodes-base.gmail",
"position": [
1340,
820
],
"webhookId": "2fac759a-1e15-489e-b619-ead2dea60008",
"parameters": {
"sendTo": "={{ $('AI: Generate Email Reply').item.json.output.email }}",
"message": "={{ $('AI: Generate Email Reply').item.json.output.body }}",
"options": {},
"subject": "={{ $('AI: Generate Email Reply').item.json.output.subject }}",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"id": "BjLuqt1WNTbWNBM1",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "feff315f-c008-4b67-bd89-0d88c79005ac",
"name": "触发器:新邮件",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-1000,
960
],
"parameters": {
"simple": false,
"filters": {},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "BjLuqt1WNTbWNBM1",
"name": "Gmail account"
}
},
"typeVersion": 1.1
},
{
"id": "b69c3e8d-cd36-4c72-8a8d-006dddd0280c",
"name": "检查:邮件是否在收件箱?",
"type": "n8n-nodes-base.if",
"position": [
-780,
960
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "3f7094d8-2756-493d-8721-be7d4c83297b",
"operator": {
"type": "array",
"operation": "contains",
"rightType": "any"
},
"leftValue": "={{ $json.labelIds }}",
"rightValue": "INBOX"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "3cc06ffd-8a5d-4daf-a4c1-55953fba0cc8",
"name": "AI:是否需要回复?",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-320,
940
],
"parameters": {
"text": "=todays date:- {{ $now }}\nmail date:- {{ $json.headers.date }}\nfrom :- {{ $json.headers.from }}\nsubject :- {{ $json.headers.subject.toJsonString() }}\n\ncontent :- {{ $json.text }}",
"options": {
"systemMessage": "You are a smart AI email assistant. Your job is to analyze each email and decide if it needs a response from the user. Most emails are promotions, newsletters, or notifications that do not need replies — skip those.\n\nOnly reply \"yes\" if:\n\nThe email asks a question\n\nThe email requests information or action\n\nThe email seems urgent or time-sensitive\n\nThe email involves work, deadlines, appointments, personal matters, or legal/financial implications\n\nOtherwise, reply \"no\".\n\nRespond in strict JSON format like this:\n\njson\nCopy\nEdit\n{\n \"response\": \"yes\"\n}\nor\n\njson\nCopy\nEdit\n{\n \"response\": \"no\"\n}\nDo not explain. No comments. Only JSON."
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2
},
{
"id": "47ddc596-591f-470c-bafd-6a5ee7881935",
"name": "解析:回复决策JSON",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-120,
1160
],
"parameters": {
"jsonSchemaExample": "{\n\t\"response\": \"no\"\n}"
},
"typeVersion": 1.2
},
{
"id": "02b4791e-6301-46b8-ad85-4c627651e08a",
"name": "检查:需要回复?",
"type": "n8n-nodes-base.if",
"position": [
100,
940
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "8aa9d41a-a218-456c-8b46-70b2e4a1af03",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.response }}",
"rightValue": "yes"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "a5efce44-3718-4ad4-ba19-b558f029228b",
"name": "退出:无需回复",
"type": "n8n-nodes-base.noOp",
"position": [
280,
1200
],
"parameters": {},
"typeVersion": 1
},
{
"id": "10b4cdbf-b2e0-4a75-baf2-d81184db8967",
"name": "无操作,不执行任何操作",
"type": "n8n-nodes-base.noOp",
"position": [
-600,
1180
],
"parameters": {},
"typeVersion": 1
},
{
"id": "f44760d0-60bf-4f04-9b7c-b1d4159e76ba",
"name": "AI:生成邮件回复",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
500,
920
],
"parameters": {
"text": "=todays date:- {{ $now }}\nmail date:- {{ $('Trigger: New Email').item.json.headers.date }}\nfrom :- {{ $('Trigger: New Email').item.json.headers.from }}\nsubject :- {{ $('Trigger: New Email').item.json.headers.subject }}\n\ncontent :- {{ $('Trigger: New Email').item.json.text }}",
"options": {
"systemMessage": "=📧 System Prompt: Email Reply Generator\nYou are an AI email assistant. Based on the following details, write a professional and relevant reply email on behalf of the user.\n\nToday's Date:\nOriginal Email Date:\nFrom: \nSubject:\nEmail Content:\n\n✍️ Instructions:\nWrite a clear and concise reply email that responds meaningfully to the content.\n\nKeep the tone professional, polite, and appropriate to the context.\n\nDo not include greetings like \"Hi\" or sign-offs like \"Best regards\" unless necessary.\n\nYour output must be strictly in the following JSON format:\n\n\n\n{\n \"email\": \"email address\",\n \"subject\": \"subject text\",\n \"body\": \" body text .\"\n}\n\n\n\nIf the email is promotional, spam, or clearly does not require a reply, leave both fields blank:\n\n\n{\n \"subject\": \"\",\n \"body\": \"\"\n}\n"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2
},
{
"id": "988af447-e485-4397-b6e8-c848d53384f8",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-300,
1160
],
"parameters": {
"options": {
"baseURL": "https://api.openai.com/v1"
}
},
"credentials": {
"openAiApi": {
"id": "e5xm7uBXWaCZn5Uk",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "79953edf-0e9a-42de-88f7-3202eefaf851",
"name": "OpenAI 聊天模型1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
520,
1140
],
"parameters": {
"options": {
"baseURL": "https://api.openai.com/v1"
}
},
"credentials": {
"openAiApi": {
"id": "e5xm7uBXWaCZn5Uk",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "d1bbf2f7-4506-4296-97fc-2044619dd524",
"name": "Telegram:发送+审批",
"type": "n8n-nodes-base.telegram",
"position": [
900,
920
],
"webhookId": "49190a52-864e-4c68-be6c-6ce530f70370",
"parameters": {
"chatId": "=7917193308",
"message": "=📥 *New Email Received*\n\n👤 *From:* \n{{ $('Trigger: New Email').item.json.headers.from }}\n\n📝 *Subject:* \n{{ $('Trigger: New Email').item.json.headers.subject }}\n\n💬 *Content:* \n{{ $('Trigger: New Email').item.json.text }}\n\n\n🤖 *AI-Generated Response*\n\n📤 *To:* \n{{ $('Trigger: New Email').item.json.headers.from }}\n\n📝 *Subject:* \n{{ $json.output.subject }}\n\n💬 *Content:* \n{{ $json.output.body }}\n",
"options": {
"limitWaitTime": {
"values": {
"resumeUnit": "minutes",
"resumeAmount": 5
}
}
},
"operation": "sendAndWait",
"approvalOptions": {
"values": {
"approvalType": "double"
}
}
},
"credentials": {
"telegramApi": {
"id": "x5kGTW8ojjPJjQtB",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "f61104a3-2350-4d5e-b613-94b7607dadd2",
"name": "检查:Telegram是否批准?",
"type": "n8n-nodes-base.if",
"position": [
1120,
920
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "c7315e3c-6ee1-40bb-8d74-0c70862f30a4",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data.approved }}",
"rightValue": "true"
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "d1e81ee3-db7b-4a46-b02a-ddd299d5cadf",
"name": "退出:Telegram未批准",
"type": "n8n-nodes-base.noOp",
"position": [
1340,
1020
],
"parameters": {},
"typeVersion": 1
},
{
"id": "27b00238-c6fe-49bb-b147-1121f6f6c897",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1520,
360
],
"parameters": {
"width": 3180,
"height": 1320,
"content": "## 🤖 AI邮件回复助手"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "29633a52-57b2-462e-be6e-4473426433d0",
"connections": {
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI: Should We Reply?",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "AI: Generate Email Reply",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Trigger: New Email": {
"main": [
[
{
"node": "Check: Is Email in Inbox?",
"type": "main",
"index": 0
}
]
]
},
"AI: Should We Reply?": {
"main": [
[
{
"node": " Check: Response Required?",
"type": "main",
"index": 0
}
]
]
},
"AI: Generate Email Reply": {
"main": [
[
{
"node": "Telegram: Send + Approve",
"type": "main",
"index": 0
}
]
]
},
"Telegram: Send + Approve": {
"main": [
[
{
"node": "Check: Telegram Approved?",
"type": "main",
"index": 0
}
]
]
},
"Check: Is Email in Inbox?": {
"main": [
[
{
"node": "AI: Should We Reply?",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Check: Telegram Approved?": {
"main": [
[
{
"node": "Send a message",
"type": "main",
"index": 0
}
],
[
{
"node": " Exit: Telegram Not Approved",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser1": {
"ai_outputParser": [
[
{
"node": "AI: Generate Email Reply",
"type": "ai_outputParser",
"index": 0
}
]
]
},
" Check: Response Required?": {
"main": [
[
{
"node": "AI: Generate Email Reply",
"type": "main",
"index": 0
}
],
[
{
"node": " Exit: No Reply Needed",
"type": "main",
"index": 0
}
]
]
},
"Parse: Reply Decision JSON": {
"ai_outputParser": [
[
{
"node": "AI: Should We Reply?",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Ticket Management、AI Chatbot等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Roshan Ramani
@rawsun007I love building smart n8n automations that actually work reliably. My focus is on making everyday tasks like email, social media, and CRM workflows simpler using AI. I've shared templates in the n8n community, including a WhatsApp Expense Tracker that people really enjoy. What keeps me excited is constantly trying new things - testing fresh nodes, playing with AI tools like LangChain, and discovering creative ways to connect systems!
分享此工作流