使用GPT-4、Telegram和联系人数据库创建专业邮件草稿
高级
这是一个Miscellaneous, AI RAG, Multimodal AI领域的自动化工作流,包含 17 个节点。主要使用 Code, Gmail, Telegram, GoogleDocs, ManualTrigger 等节点。 通过GPT-4、Telegram和联系人数据库创建专业邮件草稿
前置要求
- •Google 账号和 Gmail API 凭证
- •Telegram Bot Token
- •OpenAI API Key
- •Pinecone API Key
使用的节点 (17)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "cf4d575edce4b7d398f7313598b706cceaba685fe3a0bb5bf06e3c97727abb23",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "b662d7e0-efcf-4810-a14a-9fe24a9d3ce0",
"name": "当点击“执行工作流”时",
"type": "n8n-nodes-base.manualTrigger",
"disabled": true,
"position": [
-144,
336
],
"parameters": {},
"typeVersion": 1
},
{
"id": "22e31736-6723-4e44-adc9-a5e5fb38a093",
"name": "Pinecone 向量存储",
"type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
"position": [
272,
192
],
"parameters": {
"mode": "insert",
"options": {
"pineconeNamespace": "contacts"
},
"pineconeIndex": {
"__rl": true,
"mode": "list",
"value": "gmailagent",
"cachedResultName": "gmailagent"
}
},
"credentials": {
"pineconeApi": {
"id": "VoL22Vm4vFVB0tEG",
"name": "PineconeApi account"
}
},
"typeVersion": 1.3
},
{
"id": "9f412fb3-5fbf-4e85-ba54-1a990d12a7cc",
"name": "OpenAI 嵌入",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
384,
416
],
"parameters": {
"options": {
"dimensions": 512
}
},
"credentials": {
"openAiApi": {
"id": "2bHK8I9Y4KDhH8Qn",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "ac2eaead-317c-4c66-a621-903074fdb137",
"name": "默认数据加载器",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
224,
416
],
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "0f0a1c99-29a8-4fe3-bdc5-815fe53e55ea",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-208,
96
],
"parameters": {
"color": 4,
"width": 928,
"height": 576,
"content": "## 将数据发送到向量数据库"
},
"typeVersion": 1
},
{
"id": "5014fbe1-e8b4-48c7-9585-6452bd1b8dc1",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
160,
944
],
"parameters": {
"text": "={{ $json.message.text }}",
"options": {
"systemMessage": "=You are an AI assistant that drafts professional emails. \nYou **must always write formal emails**. \n\nYou have access to the tool \"Pinecone Vector Store1\", which retrieves user data (including email addresses). \nIf the user specifies a name (e.g., \"Hoger\", \"Professor John\"), you **must call Pinecone Vector Store1** to fetch the correct email address. \nNever leave the `sendTo` field empty — if Pinecone returns nothing, return `\"sendTo= \"`. \n\n## Context\n- Input comes from a chat message. \n- Always output in the required format below. \n\n## Required Output Format\n[\n {\n \"query\": \"sendTo=<recipient email from Pinecone>&subject=<short subject line>&emailType=text&message=<formal email body>&bccList=<comma separated emails if any>&ccList=<comma separated emails if any>&senderName=<name of sender>\"\n }\n]\n\n## Rules\n- `sendTo` must come from Pinecone if not explicitly given. \n- `emailType=text` unless explicitly told otherwise. \n- If Pinecone fails, put `\"sendTo= \"`. \n- Always keep email language formal (university tone). \n- Output must be strict JSON, no markdown, no extra text. \nalywya set the sender name as Abbas Alaa"
},
"promptType": "define"
},
"typeVersion": 2.2
},
{
"id": "038e2d41-65bf-4abd-85e2-cd525c000644",
"name": "Pinecone 向量存储",
"type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
"position": [
208,
1184
],
"parameters": {
"mode": "retrieve-as-tool",
"options": {
"pineconeNamespace": "contacts"
},
"pineconeIndex": {
"__rl": true,
"mode": "list",
"value": "gmailagent",
"cachedResultName": "gmailagent"
},
"toolDescription": "Call this to retrieve information about contacts like email address."
},
"credentials": {
"pineconeApi": {
"id": "VoL22Vm4vFVB0tEG",
"name": "PineconeApi account"
}
},
"typeVersion": 1.3
},
{
"id": "471b39e4-48b2-4766-b8c2-de422cf20211",
"name": "嵌入 OpenAI1",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
320,
1360
],
"parameters": {
"options": {
"dimensions": 512
}
},
"credentials": {
"openAiApi": {
"id": "2bHK8I9Y4KDhH8Qn",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "3a9e5c26-76dc-48f3-bfa8-fa337ba98e44",
"name": "代码",
"type": "n8n-nodes-base.code",
"position": [
544,
1136
],
"parameters": {
"jsCode": "// Get model output from previous node\nconst rawOutput =$input.first().json.output ;\n\n// 1. Remove code fences if present\nlet cleaned = rawOutput.replace(/```json|```/g, \"\").trim();\n\n// 2. Parse into JSON\nlet parsed;\ntry {\n parsed = JSON.parse(cleaned);\n} catch (e) {\n throw new Error(\"Failed to parse model output: \" + e.message);\n}\n\n// 3. Extract query string\nconst queryString = parsed[0].query;\n\n// 4. Convert query string into key-value pairs\nconst params = {};\nqueryString.split(\"&\").forEach(pair => {\n const [key, value] = pair.split(\"=\");\n params[key] = decodeURIComponent(value || \"\");\n});\n\n// Return usable fields for Gmail node\nreturn [\n {\n json: {\n sendTo: params.sendTo,\n subject: params.subject,\n message: params.message,\n bccList: params.bccList,\n ccList: params.ccList,\n senderName: params.senderName,\n emailType: params.emailType\n }\n }\n];\n"
},
"typeVersion": 2
},
{
"id": "66cc9bc2-71eb-4fa0-b9a1-c61c7a497676",
"name": "创建草稿",
"type": "n8n-nodes-base.gmail",
"position": [
800,
1136
],
"webhookId": "0c76b19c-09cf-45b9-86a5-03581d8cd40e",
"parameters": {
"message": "={{ $json.message }}",
"options": {
"ccList": "={{ $json.ccList }}",
"sendTo": "={{ $json.sendTo }}",
"bccList": "={{ $json.bccList }}"
},
"subject": "={{ $json.subject }}",
"resource": "draft"
},
"credentials": {
"gmailOAuth2": {
"id": "JwEaiUptSaLJovzC",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "9f71e612-ac1d-4c16-9b95-fe454dfae55b",
"name": "获取文档",
"type": "n8n-nodes-base.googleDocs",
"position": [
32,
192
],
"parameters": {
"operation": "get",
"documentURL": "19DYlWxxKJanvRwMnQp0tyxt2Z5H7AheKA3WEegR9YDI"
},
"credentials": {
"googleDocsOAuth2Api": {
"id": "C25e8r7V7i2AN6GO",
"name": "Google Docs account"
}
},
"typeVersion": 2
},
{
"id": "c88bbd3a-6d96-49a5-a54c-58f66f826a06",
"name": "发送贴纸",
"type": "n8n-nodes-base.telegram",
"position": [
1248,
1136
],
"webhookId": "8e63d08c-6b04-41ae-b79f-cac04782e978",
"parameters": {
"file": "CAACAgIAAxkBAANEaL7Y0gABEcXooA-abKgPERguErxVAAIHRwAC839wS2T25-Ght_GiNgQ",
"chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
"operation": "sendSticker",
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "K26HYeLzDiVqdMpZ",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "dd1ae099-477d-49be-b443-d3b76147f65a",
"name": "Telegram触发器",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
-240,
1088
],
"webhookId": "dc3fa5b7-b65d-4151-89d5-b4229379dc4b",
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "K26HYeLzDiVqdMpZ",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "f1ce527e-329d-4272-81b1-a90985ce111e",
"name": "发送短信",
"type": "n8n-nodes-base.telegram",
"position": [
1024,
1136
],
"webhookId": "8e63d08c-6b04-41ae-b79f-cac04782e978",
"parameters": {
"text": "تم تآمر آمر",
"chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "K26HYeLzDiVqdMpZ",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "11908db3-323d-4dca-90be-f4eac9b33927",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-48,
848
],
"parameters": {
"color": 5,
"width": 768,
"height": 688,
"content": "## RAG AI 代理获取\"发送至\"电子邮件并格式化邮件"
},
"typeVersion": 1
},
{
"id": "cf6788a3-bd84-4ab6-ac42-6a677fe8e787",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
736,
864
],
"parameters": {
"color": 2,
"width": 768,
"height": 576,
"content": "## 起草电子邮件并发送带有搞笑贴纸的完成消息。"
},
"typeVersion": 1
},
{
"id": "95bf59f9-5bfe-4e66-8474-b4aa30f2c1d0",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
32,
1152
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "2bHK8I9Y4KDhH8Qn",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
}
],
"pinData": {},
"connections": {
"Code": {
"main": [
[
{
"node": "Create a draft",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Create a draft": {
"main": [
[
{
"node": "Send a text message",
"type": "main",
"index": 0
}
]
]
},
"Get a document": {
"main": [
[
{
"node": "Pinecone Vector Store",
"type": "main",
"index": 0
}
]
]
},
"Telegram Trigger": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI": {
"ai_embedding": [
[
{
"node": "Pinecone Vector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Embeddings OpenAI1": {
"ai_embedding": [
[
{
"node": "Pinecone Vector Store1",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Default Data Loader": {
"ai_document": [
[
{
"node": "Pinecone Vector Store",
"type": "ai_document",
"index": 0
}
]
]
},
"Send a text message": {
"main": [
[
{
"node": "Send a sticker",
"type": "main",
"index": 0
}
]
]
},
"Pinecone Vector Store1": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 杂项, AI RAG 检索增强, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
基于网站内容和Airtable数据构建用于RAG应用的聊天机器人
基于Pinecone、Airtable和OpenAI的网站内容聊天机器人(RAG应用)
Set
Code
Markdown
+15
27 节点Alok Kumar
AI RAG 检索增强
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
If
Set
Gmail
+20
68 节点Abdullahi Ahmed
内容创作
文档摄取
使用 Google Drive、Sheets 和 OpenAI 自动化文档摄取与 RAG 系统
If
Form
Crypto
+13
28 节点Mohamed Abdelwahab
杂项
Telegram AI支持聊天机器人(多模态输入)
使用GPT-4和Supabase RAG创建多模态Telegram支持机器人
If
Set
Code
+17
51 节点Ezema Kingsley Chibuzo
客服机器人
AIAutomationPro终极RAG聊天机器人v1 n8n市场模板
多语言Telegram RAG聊天机器人,集成监督AI和自动化Google Drive流程
If
Set
Wait
+29
128 节点Daniel Ng
客服机器人
使用Gmail、GPT-4和向量知识库的自动化客户支持系统
使用Gmail、GPT-4和向量知识库的自动化客户支持系统
If
Set
Code
+15
32 节点Khair Ahammed
AI RAG 检索增强