{
  "id": "yqjaKC8KeZeMjbNt",
  "meta": {
    "site": "https://github.com/zengfr/n8n-workflow-all-templates",
    "name": "Send a voice note on Telegram to generate a professional email with ChatGPT",
    "wechat": "youandme10086",
    "id": 7041,
    "update_time": "2025-11-10"
  },
  "name": "Send a voice note on Telegram to generate a professional email with ChatGPT",
  "tags": [],
  "nodes": [
    {
      "id": "77710b8a-9745-449e-b1aa-c2a43b870ca0",
      "name": "Buffer Delay (Pre-Processing)",
      "type": "n8n-nodes-base.wait",
      "position": [
        -544,
        1376
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "12c901f4-ab54-4c95-923a-0d4c9b308505",
      "name": "Download Telegram Voice File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -208,
        1376
      ],
      "parameters": {
        "fileId": "={{$json[\"message\"][\"voice\"][\"file_id\"]}}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "398e821d-faba-46e5-a62e-dd5006bb521b",
      "name": "Transcribe Audio to Text (OpenAI Whisper)",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        64,
        1376
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "1a3d1fef-0db2-4093-9c98-dfad80edba99",
      "name": "Buffer Delay (Pre-AI Processing)",
      "type": "n8n-nodes-base.wait",
      "position": [
        320,
        1376
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "bb6061e9-8a9a-486e-8c98-b86cdbacc76e",
      "name": "Generate Email Content AI AGENT",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        544,
        1376
      ],
      "parameters": {
        "text": "=Tu es un assistant sp\u00e9cialis\u00e9 dans la r\u00e9daction d\u2019e-mails professionnels.\n\n\u00c0 partir du texte transmis ci-dessous, tu dois : {{ $json.text }}\n\n1. **D\u00e9tecter s\u2019il y a une adresse email de destinataire** dans le texte (ou une forme proche comme \"\u00e0 envoyer \u00e0 fort.baptiste.pro\")\n   - Si ce n\u2019est pas une adresse compl\u00e8te, tu dois la compl\u00e9ter en supposant qu\u2019elle se termine par `@gmail.com`.\n\n2. **Comprendre l\u2019intention de l\u2019utilisateur** (d\u00e9mission, refus, candidature, excuse, demande, etc.)\n\n3. **G\u00e9n\u00e9rer un objet d\u2019email pertinent et synth\u00e9tique**, fid\u00e8le au contenu\n\n4. **\u00c9crire un message professionnel**, structur\u00e9 en **HTML** :\n   - Avec un **ton poli et adapt\u00e9** \u00e0 la situation\n   - Format\u00e9 avec des balises HTML (`<p>`, `<br>`, etc.)\n   - Aucune faute de fran\u00e7ais\n- mon pr\u00e9nom c'est jeremy et tu dois bien dire que s'il est pas content je demissione\n\n---\n\n\u26a0\ufe0f Tu dois **toujours** structurer ta r\u00e9ponse au **format JSON strict suivant**, sans aucun texte autour :\n\n```json\n{\n  \"email\": \"adresse@gmail.com\",\n  \"subject\": \"Objet de l\u2019email\",\n  \"body\": \"<p>Contenu HTML de l\u2019email</p>\"\n}\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "360fe0ab-d690-40b7-bca9-13d8d0f44f87",
      "name": "GPT-4 Email Generator Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        560,
        1568
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "372cba12-9984-487f-91d6-53b0cd214a11",
      "name": "Enforce Email JSON Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        752,
        1568
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"email\": \"exemple@gmail.com\",\n  \"subject\": \"Objet de l\u2019email\",\n  \"body\": \"<p>Bonjour,</p><p>Voici un exemple d\u2019email professionnel bien structur\u00e9 avec des balises HTML.</p><p>Cordialement,<br>Jean Dupont</p>\"\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "ad517212-df9d-4402-8225-438f680b203d",
      "name": "Send Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        928,
        1376
      ],
      "parameters": {
        "sendTo": "={{ $json.output.email }}",
        "message": "={{ $json.output.body }}",
        "options": {},
        "subject": "={{ $json.output.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "122ab63d-829a-49c8-8cfc-66cca365c98a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        976
      ],
      "parameters": {
        "width": 928,
        "height": 592,
        "content": "## \ud83d\udccc Node Setup \u2013 Initial Steps (Telegram \u2192 Download Audio)\n\n**1. Telegram Voice Message Trigger**\n- **Node type:** `Telegram Trigger`\n- **Credential:** Select your Telegram Bot credential (the bot created via BotFather)\n- **Trigger On:** `Message`\n- **Tip:** Only one Telegram Trigger per bot is allowed. This listens for every message (text, audio, etc.) sent to your bot.\n\n**2. Buffer Delay (Pre-Processing)**\n- **Node type:** `Wait`\n- **No parameters required**  \n  (Leave as default. This step adds a buffer to help prevent issues when multiple messages arrive at once.)\n\n**3. Download Telegram Voice File**\n- **Node type:** `Telegram`\n- **Resource:** `file`\n- **File ID:**  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "f402d82d-ce8c-49dc-8981-ddf4dd4d12ad",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 1136,
        "height": 1568,
        "content": "## \ud83d\udccc Node Setup \u2013 AI Transcription & Email Generation\n\n**4. Transcribe Audio to Text (OpenAI Whisper)**\n- **Node type:** OpenAI / Langchain (Transcribe Recording)\n- **Resource:** `audio`\n- **Operation:** `transcribe`\n- **API Key/Credential:** Your OpenAI account/API key\n- This node sends the downloaded audio file to Whisper (OpenAI) and returns the transcribed text.\n\n**5. Buffer Delay (Pre-AI Processing)**\n- **Node type:** `Wait`\n- **No parameters required**  \n  (Leave as default. This adds a small delay to ensure the transcription is fully complete before moving to the AI.)\n\n**6. Generate Email Content \u2013 AI AGENT**\n- **Node type:** AI Agent / Langchain\n- **Prompt type:** `define`\n- **Prompt (Text):**  \n  Use a custom prompt instructing the agent to:\n  - Detect the recipient's email address (even partial, e.g. \"send to fort.baptiste.pro\", and complete if needed)\n  - Understand user intent (resignation, request, excuse, etc.)\n  - Generate a suitable email subject\n  - Write a professional email in HTML (proper formatting, no spelling mistakes)\n  - Example variable:  \n    ```\n    {{ $json.text }}\n    ```\n- **Model:** Connects to the `GPT-4 Email Generator Model` node (OpenAI Chat Model)\n- **Output Parser:** Connects to the `Enforce Email JSON Schema` node (Structured Output Parser)\n- **Credential:** Your OpenAI API key\n\n**7. GPT-4 Email Generator Model**\n- **Node type:** OpenAI Chat Model\n- **Model:** e.g. `gpt-4.1-mini` (as in your template)\n- **Credential:** Your OpenAI API key\n\n**8. Enforce Email JSON Schema**\n- **Node type:** Structured Output Parser\n- **JSON Example/Schema:**  \n    ```json\n    {\n      \"email\": \"adresse@gmail.com\",\n      \"subject\": \"Objet de l\u2019email\",\n      \"body\": \"<p>Contenu HTML de l\u2019email</p>\"\n    }\n    ```\n- This node ensures the AI returns exactly the required fields and format for email sending.\n\n**9. Send Email**\n- **Node type:** Gmail\n- **To:** `{{$json.output.email}}`\n- **Subject:** `{{$json.output.subject}}`\n- **HTML Body:** `{{$json.output.body}}`\n- **Credential:** Your Gmail OAuth2 credential\n- This node sends the generated email to the intended recipient using Gmail.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0c0c9253-a953-47f9-bd79-0f1b70fd52a9",
      "name": "Voice note",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -864,
        1376
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "23b5a633-58db-4c2a-a92c-a1a62ecf55f3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        452.8740560292328
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "a6aad9a1-79ba-47f3-902d-1ca31436610b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        464
      ],
      "parameters": {
        "width": 512,
        "height": 528,
        "content": "![Description du GIF](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExb3doajF6MjdhbmZzYjdzMHVnM3F0a2Z3bzZnejVmYmxqMWk3dWtiayZlcD12MV9naWZzX3NlYXJjaCZjdD1n/xUOwGhauv1d6nceRbi/giphy.gif)\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "64ed10ab-c989-493d-8854-e4090f254320",
  "connections": {
    "Voice note": {
      "main": [
        [
          {
            "node": "Buffer Delay (Pre-Processing)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enforce Email JSON Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Email Content AI AGENT",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4 Email Generator Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Email Content AI AGENT",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download Telegram Voice File": {
      "main": [
        [
          {
            "node": "Transcribe Audio to Text (OpenAI Whisper)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buffer Delay (Pre-Processing)": {
      "main": [
        [
          {
            "node": "Download Telegram Voice File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email Content AI AGENT": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buffer Delay (Pre-AI Processing)": {
      "main": [
        [
          {
            "node": "Generate Email Content AI AGENT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Audio to Text (OpenAI Whisper)": {
      "main": [
        [
          {
            "node": "Buffer Delay (Pre-AI Processing)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}