{
  "nodes": [
    {
      "id": "ef25fccf-50c5-4a84-a839-64fc4704510b",
      "name": "Download Audio File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        656,
        1344
      ],
      "parameters": {
        "url": "={{ $('Convert Text to Speech').item.json.audio.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "f8583784-356d-4775-b166-14d71ff5529c",
      "name": "Generate Summary with AI",
      "type": "n8n-nodes-aimlapi.aimlApi",
      "position": [
        -16,
        1344
      ],
      "parameters": {
        "model": "openai/gpt-5-1-chat-latest",
        "prompt": "=You are a voice assistant that creates brief, natural-sounding email summaries for audio playback. Create a concise summary (2-3 sentences max) in English. Make it sound natural when spoken aloud. Provide ONLY the summary text, nothing else.\n\nReceived email:  \n{{ $json.emailData }}",
        "options": {},
        "requestOptions": {}
      },
      "credentials": {
        "aimlApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "88cf8bfe-5aa5-44b5-993b-3c578b80950c",
      "name": "Get Telegram Chat ID",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        448,
        1344
      ],
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "W4PZ3kTX6XOGkEYy",
          "cachedResultUrl": "/projects/7EEYDo9ZR4Qfdly0/datatables/W4PZ3kTX6XOGkEYy",
          "cachedResultName": "Chat id"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d5d165c4-c3eb-4de7-9021-f2d560a4ba41",
      "name": "Save Chat ID to Database",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        192,
        928
      ],
      "parameters": {
        "columns": {
          "value": {
            "chat_id": "={{ $json.message.chat.id }}"
          },
          "schema": [
            {
              "id": "chat_id",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "chat_id",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "chat_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyValue": "1"
            }
          ]
        },
        "options": {},
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "W4PZ3kTX6XOGkEYy",
          "cachedResultUrl": "/projects/7EEYDo9ZR4Qfdly0/datatables/W4PZ3kTX6XOGkEYy",
          "cachedResultName": "Chat id"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "18ccc340-9dab-4582-b699-1d8fe3d8e581",
      "name": "Convert Text to Speech",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        1344
      ],
      "parameters": {
        "url": "https://api.aimlapi.com/v1/tts",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "inworld/tts-1-max"
            },
            {
              "name": "text",
              "value": "={{ $json.content }}"
            }
          ]
        },
        "nodeCredentialType": "aimlApi"
      },
      "credentials": {
        "aimlApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "13ac71d3-b059-45fa-b6a0-054a391e68da",
      "name": "Send Audio to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        864,
        1344
      ],
      "parameters": {
        "chatId": "={{ $json.chat_id }}",
        "operation": "sendAudio",
        "binaryData": true,
        "additionalFields": {
          "title": "={{ $('When Email Received').item.json.From }} | {{ $('When Email Received').item.json.Subject }}"
        },
        "binaryPropertyName": "=data"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "81094be1-79fb-4c5e-818e-21c4850718a6",
      "name": "When Email Received",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -496,
        1344
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "4a33ed91-5887-4ab6-8bc7-bfdc3a69bae7",
      "name": "Prepare Email Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -272,
        1344
      ],
      "parameters": {
        "jsCode": "const item = $input.first();\nconst from = item.json.From || 'Unknown sender';\nconst subject = item.json.Subject || 'No subject';\nconst snippet = item.json.snippet || '';\nconst date = item.json.date || '';\n\nconst emailData = `From: ${from}\\nSubject: ${subject}\\nDate: ${date}\\nSnippet: ${snippet}`;\n\nreturn { json: { emailData } };"
      },
      "typeVersion": 2
    },
    {
      "id": "69a93874-b95e-4f9e-ad4d-c062c30d810c",
      "name": "When Telegram Message Received",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -48,
        928
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "63c1f4d0-5dcf-4aec-ae7c-dedcbd100703",
      "name": "Sticky Note \u2014 Chat ID Flow",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        752
      ],
      "parameters": {
        "color": 4,
        "width": 512,
        "height": 368,
        "content": "## **\ud83d\udcac Telegram Chat ID Bootstrap (one-time)**\n\nCaptures your chat_id the first time you message the bot.\nNodes: **When Telegram Message Received**, **Save Chat ID to Database**.\nThe stored ID is reused by the main Gmail\u2192Voice automation.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "764f8bd1-099a-46b9-b78e-67cef7ac4efe",
      "name": "Sticky Note \u2014 Step 1 Email",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        1152
      ],
      "parameters": {
        "color": 5,
        "width": 456,
        "height": 392,
        "content": "## **\ud83d\udce5 Email Intake (Gmail)**\n\nGroups nodes that detect new emails and format them for AI processing.\nNodes: **When Email Received**, **Prepare Email Data**.\nProduces a compact text block containing sender, subject, date, and snippet.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "041ed7a6-f19a-453c-994d-115b088d101d",
      "name": "Sticky Note \u2014 Step 2 Summary",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        1152
      ],
      "parameters": {
        "color": 4,
        "width": 456,
        "height": 392,
        "content": "## **\ud83e\udde0 AI Summary & Voice Generation**\n\nCreates a short natural-sounding summary and converts it to speech.\nNodes: **Generate Summary with AI**, **Convert Text to Speech**.\nThe output is a downloadable audio file URL.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e17ef824-97e4-4693-8360-146b5f6bc028",
      "name": "Sticky Note \u2014 Step 4 Get ID & Download",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        1152
      ],
      "parameters": {
        "color": 6,
        "width": 616,
        "height": 392,
        "content": "\n## **\ud83d\udce4 Telegram Delivery**\n\nDownloads the TTS audio file and sends it to Telegram.\nNodes: **Get Telegram Chat ID**, **Download Audio File**, **Send Audio to Telegram**.\nUses the stored chat_id to deliver a voice message.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "313477f1-782a-4bca-b822-3843ab9d63e7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        592
      ],
      "parameters": {
        "width": 560,
        "height": 496,
        "content": "## **\ud83d\udce8 Gmail \u2192 AI Summary \u2192 Inworld TTS \u2192 \ud83c\udfa7 Telegram Voice**\n\nThis workflow turns new Gmail messages into short spoken briefings delivered to Telegram.\nIt works by detecting incoming emails, generating a concise summary using AI/ML API (GPT-5), converting that summary into natural speech using Inworld TTS-1-Max, and finally sending the audio file to a Telegram chat.\n\nThe process includes four parts:\n\n1. Gmail polling and preparing a clean text representation of the email.\n2. AI-generated 2\u20133 sentence summary suitable for audio playback.\n3. Text-to-speech conversion to produce an audio file.\n4. Delivery to a saved Telegram chat ID.\n\nA small helper flow captures your Telegram chat_id once and stores it in a Data Table.\nAfter that, every new email automatically arrives as a Telegram voice message \u2014 making inbox updates easy to listen to on the go.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Prepare Email Data": {
      "main": [
        [
          {
            "node": "Generate Summary with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio File": {
      "main": [
        [
          {
            "node": "Send Audio to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Email Received": {
      "main": [
        [
          {
            "node": "Prepare Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Telegram Chat ID": {
      "main": [
        [
          {
            "node": "Download Audio File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Text to Speech": {
      "main": [
        [
          {
            "node": "Get Telegram Chat ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Summary with AI": {
      "main": [
        [
          {
            "node": "Convert Text to Speech",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Telegram Message Received": {
      "main": [
        [
          {
            "node": "Save Chat ID to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}