AutomationFlowsAI & RAG › Create Professional Email Drafts with Gpt-4, Telegram & Contact Database

Create Professional Email Drafts with Gpt-4, Telegram & Contact Database

ByNinja - Abbas @abbas-ghazi on n8n.io

Transform your email workflow with this intelligent automation that drafts professional emails through Telegram commands using AI and contact retrieval. Key Features

Event trigger★★★★☆ complexityAI-powered17 nodesPinecone Vector StoreOpenAI EmbeddingsDocument Default Data LoaderAgentGmailGoogle DocsTelegramTelegram Trigger
AI & RAG Trigger: Event Nodes: 17 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #8395 — we link there as the canonical source.

This workflow follows the Agent → Documentdefaultdataloader recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "b662d7e0-efcf-4810-a14a-9fe24a9d3ce0",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "disabled": true,
      "position": [
        -144,
        336
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "22e31736-6723-4e44-adc9-a5e5fb38a093",
      "name": "Pinecone Vector Store",
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9f412fb3-5fbf-4e85-ba54-1a990d12a7cc",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        384,
        416
      ],
      "parameters": {
        "options": {
          "dimensions": 512
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ac2eaead-317c-4c66-a621-903074fdb137",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        224,
        416
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "0f0a1c99-29a8-4fe3-bdc5-815fe53e55ea",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -208,
        96
      ],
      "parameters": {
        "color": 4,
        "width": 928,
        "height": 576,
        "content": "##  Send data to vector database \n**connect** the trigger node when you ready to push your contacts data to the database "
      },
      "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 \u2014 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 Vector Store1",
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "471b39e4-48b2-4766-b8c2-de422cf20211",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        320,
        1360
      ],
      "parameters": {
        "options": {
          "dimensions": 512
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3a9e5c26-76dc-48f3-bfa8-fa337ba98e44",
      "name": "Code",
      "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": "Create a draft",
      "type": "n8n-nodes-base.gmail",
      "position": [
        800,
        1136
      ],
      "parameters": {
        "message": "={{ $json.message }}",
        "options": {
          "ccList": "={{ $json.ccList }}",
          "sendTo": "={{ $json.sendTo }}",
          "bccList": "={{ $json.bccList }}"
        },
        "subject": "={{ $json.subject }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9f71e612-ac1d-4c16-9b95-fe454dfae55b",
      "name": "Get a document",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        32,
        192
      ],
      "parameters": {
        "operation": "get",
        "documentURL": "19DYlWxxKJanvRwMnQp0tyxt2Z5H7AheKA3WEegR9YDI"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c88bbd3a-6d96-49a5-a54c-58f66f826a06",
      "name": "Send a sticker",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1248,
        1136
      ],
      "parameters": {
        "file": "CAACAgIAAxkBAANEaL7Y0gABEcXooA-abKgPERguErxVAAIHRwAC839wS2T25-Ght_GiNgQ",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "operation": "sendSticker",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "dd1ae099-477d-49be-b443-d3b76147f65a",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -240,
        1088
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f1ce527e-329d-4272-81b1-a90985ce111e",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1024,
        1136
      ],
      "parameters": {
        "text": "\u062a\u0645 \u062a\u0622\u0645\u0631 \u0622\u0645\u0631",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "11908db3-323d-4dca-90be-f4eac9b33927",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        848
      ],
      "parameters": {
        "color": 5,
        "width": 768,
        "height": 688,
        "content": "## RAG AI agent to get the \"send to\" emails and format the emails\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cf6788a3-bd84-4ab6-ac42-6a677fe8e787",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        864
      ],
      "parameters": {
        "color": 2,
        "width": 768,
        "height": 576,
        "content": "## Draft the email and send the completion message with a funny sticker.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "95bf59f9-5bfe-4e66-8474-b4aa30f2c1d0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        32,
        1152
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "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
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Transform your email workflow with this intelligent automation that drafts professional emails through Telegram commands using AI and contact retrieval. Key Features

Source: https://n8n.io/workflows/8395/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Alfred (funcional). Uses gmailTool, googleCalendarTool, gmail, embeddingsOpenAi. Event-driven trigger; 83 nodes.

Gmail Tool, Google Calendar Tool, Gmail +24
AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This comprehensive workflow bundle is designed as a powerful starter kit, enabling you to build a multi-functional AI assistant on Telegram. It seamlessly integrates AI-powered voice interactions, an

Telegram Trigger, Telegram, OpenAI +19
AI & RAG

This advanced n8n workflow automates the full lead enrichment, qualification, and personalized outreach process tailored specifically for the B2B real estate sector. Integrating top platforms like Api

N8N Nodes Fillout, OpenAI Chat, Pinecone Vector Store +11
AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16