{
  "active": false,
  "connections": {
    "Authorization": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Authorization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message10": {
      "main": [
        [
          {
            "node": "Link exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger2": {
      "main": [
        [
          {
            "node": "Send a text message10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Files to Disk": {
      "main": [
        [
          {
            "node": "Execute Command1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Files from Disk": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "optimization": {
      "main": [
        [
          {
            "node": "full_article1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Sum the text1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send the transcription",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command1": {
      "main": [
        [
          {
            "node": "Read Files from Disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter": {
      "ai_languageModel": [
        [
          {
            "node": "optimization",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "full_article1": {
      "main": [
        [
          {
            "node": "Clean the text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send the optimized text1": {
      "main": [
        []
      ]
    },
    "Link exists": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Audio exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audio exists": {
      "main": [
        [
          {
            "node": "Write Files to Disk",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error sender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sum the text1": {
      "main": [
        [
          {
            "node": "optimization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send the transcription1": {
      "main": [
        []
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Send the optimized text1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Send the transcription1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube subtitle": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "iF": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "Send the optimized text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean the text": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command": {
      "main": [
        [
          {
            "node": "Read Files from Disk1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Files from Disk1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Files to Disk1": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube transecriptor": {
      "main": [
        [
          {
            "node": "Error sender1",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "YouTube transecriptor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "iF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "YouTube subtitle",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Write Files to Disk1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2026-02-09T09:11:09.540Z",
  "id": "Wh0csYQLTyh9LCQT",
  "isArchived": false,
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Transcript",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/audio/transcriptions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "audio"
            },
            {
              "name": "model",
              "value": "whisper-large-v3"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3216,
        -352
      ],
      "id": "5bc9f2dd-0061-472b-95e8-c62a12ce5d3a",
      "name": "Authorization",
      "retryOnFail": true,
      "maxTries": 2,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        2944,
        -432
      ],
      "id": "6e6e33e8-c927-4f7e-b0c5-c909929414f6",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "chatId": "={{ $json.message.chat.id }}",
        "message": "Put the link or audio not both of them please",
        "responseType": "customForm",
        "formFields": {
          "values": [
            {
              "fieldLabel": "audio",
              "fieldType": "file",
              "multipleFiles": false
            },
            {
              "fieldLabel": "Do you want to optimize the audio or not?",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Optimize it"
                  },
                  {
                    "option": "Send directly "
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "Link",
              "placeholder": "Link"
            }
          ]
        },
        "options": {
          "responseFormCustomCss": ":root {\n\t/* Typography - Switching to a more modern system stack */\n\t--font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n\t--font-weight-normal: 400;\n\t--font-weight-medium: 500;\n\t--font-weight-bold: 600;\n\t\n\t/* Font Sizes - Bumped up for accessibility */\n\t--font-size-body: 14px;\n\t--font-size-label: 14px;\n\t--font-size-input: 16px; /* Prevents iOS auto-zoom on focus */\n\t--font-size-header: 24px;\n\t--font-size-subheader: 16px;\n\t--font-size-html-h1: 32px;\n\t--font-size-html-h2: 24px;\n\t--font-size-error: 13px;\n\n\t/* Colors - Refined palette */\n\t--color-background: #f8fafc;        /* Soft Slate */\n\t--color-card-bg: #ffffff;\n\t--color-card-border: #e2e8f0;\n\t--color-card-shadow: rgba(15, 23, 42, 0.08);\n\t\n\t--color-header: #1e293b;            /* Deep Slate */\n\t--color-label: #475569;\n\t--color-input-text: #1e293b;\n\t--color-input-border: #cbd5e1;\n\t\n\t--color-primary: #6366f1;           /* Modern Indigo */\n\t--color-primary-hover: #4f46e5;\n\t--color-focus-border: #818cf8;      /* Soft focus ring */\n\t\n\t--color-submit-btn-bg: var(--color-primary);\n\t--color-submit-btn-text: #ffffff;\n\t\n\t--color-error: #ef4444;             /* Vibrant Red */\n\t--color-required: #f43f5e;\n\t--color-success: #10b981;\n\n\t/* Shapes - Softer, friendlier edges */\n\t--border-radius-card: 12px;\n\t--border-radius-input: 8px;\n\t--border-radius-btn: 8px;\n\n\t/* Layout & Spacing */\n\t--container-width: 480px;           /* Slightly wider for comfort */\n\t--padding-card: 32px;               /* More \"breathing room\" */\n\t--submit-btn-height: 52px;\n\t\n\t/* Animation */\n\t--transition-speed: 0.2s ease-in-out;\n}",
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        176,
        -384
      ],
      "id": "d09bc819-9487-44c0-aa7f-23401cb530f2",
      "name": "Send a text message10",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -48,
        -384
      ],
      "id": "ccc26169-6a8f-4436-96f6-a1cabf95ffd3",
      "name": "Telegram Trigger2",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "/tmp/input_audio",
        "dataPropertyName": "audio",
        "options": {
          "append": false
        }
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        1872,
        16
      ],
      "id": "e7d590d3-8ce8-4df3-8d0d-292a854c96a6",
      "name": "Write Files to Disk"
    },
    {
      "parameters": {
        "fileSelector": "=/tmp/output_*.wav",
        "options": {
          "dataPropertyName": "audio"
        }
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        2320,
        16
      ],
      "id": "6c91b87d-e08d-45ff-af3d-2cefc5f2457d",
      "name": "Read Files from Disk",
      "alwaysOutputData": false,
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Sum the text1').item.json.fullTranscript }}",
        "messages": {
          "messageValues": [
            {
              "message": "The \"Deep Discovery\" Prompt \"I am providing a transcript from a YouTube video. Please analyze the text and provide the following:  Executive Summary: A 3-sentence overview of the main message.  Key Themes: Identify the 3\u20135 most important topics discussed.  Deep Explanation: Explain any complex concepts or cultural/religious references mentioned in the text (specifically focus on the Arabic context if applicable).  Key Quotes: Extract 2\u20133 powerful or \"must-read\" sentences.  Tone Analysis: Describe the speaker's tone (e.g., educational, motivational, solemn).  Transcript Text:. The output is always in Arabic\""
            }
          ]
        },
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        3648,
        -528
      ],
      "id": "4c8d1f97-09f1-46c1-a0ae-3799fae97901",
      "name": "optimization"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "be73193c-7c91-4cd8-8611-a6dbe0ee6e46",
              "leftValue": "={{ $('Send a text message10').first().json.data['Do you want to optimize the audio or not?'] }}",
              "rightValue": "Optimize it",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3216,
        -496
      ],
      "id": "16311a7d-7478-4f54-8943-b6e5e53cbb3a",
      "name": "IF"
    },
    {
      "parameters": {
        "command": "=rm -f /tmp/output_*.* && \\\nffmpeg -i /tmp/input_audio \\\n-ac 1 -ar 16000 \\\n-f segment \\\n-segment_time 300 \\\n-reset_timestamps 1 \\\n-c:a pcm_s16le \\\n/tmp/output_%03d.wav\n"
      },
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        2096,
        16
      ],
      "id": "24d9e2e6-b5b4-4550-8326-d9329f54f755",
      "name": "Execute Command1"
    },
    {
      "parameters": {
        "model": "deepseek/deepseek-r1-0528:free",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        3856,
        -304
      ],
      "id": "20e7e664-3ab8-41ee-9355-2cd40846d673",
      "name": "OpenRouter",
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "=6526726666",
        "text": "={{ $json.single_message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        4576,
        -528
      ],
      "id": "c9737440-f47d-44a3-b3bb-dd7b5027007a",
      "name": "Send the optimized text1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e83461b2-3bbf-449d-b1cf-962c82a6c5cb",
              "name": "text",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        3984,
        -528
      ],
      "id": "934725dc-7f45-4dc7-b263-0f326e38a3dd",
      "name": "full_article1"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger2').item.json.message.from.id }} ",
        "text": "Please upload either an audio OR a link, not both.",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2192,
        432
      ],
      "id": "80026939-d334-48c3-aac1-1e49b41edb5a",
      "name": "Error sender",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "6b791be0-38ee-4b17-be57-db14e6707992",
              "leftValue": "={{ $json.data.Link }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "9678968a-5630-4b4b-9453-112351d26e93",
              "leftValue": "={{ $json.data.audio.filename }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        384,
        -384
      ],
      "id": "7363e57c-eaac-44bd-93ab-63868c5a03ca",
      "name": "Link exists"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "76815259-b7e9-4233-86ad-4211fca0d414",
              "leftValue": "={{ $json.data.audio.filename }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "a2cafeba-e156-48b9-ac47-6db79f6bc580",
              "leftValue": "={{ $json.data.Link }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1344,
        32
      ],
      "id": "b56cbafa-b82d-4a4b-a629-59cb32f287aa",
      "name": "Audio exists"
    },
    {
      "parameters": {
        "jsCode": "// \u0627\u0633\u062a\u0628\u062f\u0644 'transcript' \u0628\u0627\u0633\u0645 \u0627\u0644\u062d\u0642\u0644 \u0627\u0644\u0635\u062d\u064a\u062d \u0645\u0646 Whisper Node\nconst full = items.map(i => i.json.text).join(\"\\n\\n\"); // \u0641\u0635\u0644 \u0643\u0644 \u0645\u0642\u0637\u0639 \u0628\u0633\u0637\u0631\u064a\u0646\n\nreturn [{ json: { fullTranscript: full } }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3488,
        -528
      ],
      "id": "723e608f-0767-4361-b2b1-ac9c13013dc7",
      "name": "Sum the text1"
    },
    {
      "parameters": {
        "jsCode": "const chunks = [];\nconst items = $input.all();\n\nfor (const item of items) {\n  const data = item.json;\n  // Safely extract and combine the transcript text\n  const transcriptArray = Array.isArray(data.transcript) ? data.transcript : [];\n  const fullText = transcriptArray.map(t => t.text || \"\").join(\" \").trim();\n  \n  // Telegram's limit is 4096. We use 4000 to leave room for headers/formatting.\n  const chunkSize = 4000;\n  \n  for (let i = 0; i < fullText.length; i += chunkSize) {\n    chunks.push({\n      json: {\n        // We add a part number so you can track the sequence in Telegram\n        part: (i / chunkSize) + 1,\n        total_parts: Math.ceil(fullText.length / chunkSize),\n        combinedText: fullText.substring(i, i + chunkSize)\n      }\n    });\n  }\n}\n\nreturn chunks;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1776,
        -256
      ],
      "id": "212c6c02-c548-44bd-ae1f-97794b994469",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.fullTranscript }}",
        "messages": {
          "messageValues": [
            {
              "message": "=The \"Deep Discovery\" Prompt \"I am providing a transcript from a YouTube video. Please analyze the text and provide the following:  Executive Summary: A 3-sentence overview of the main message.  Key Themes: Identify the 3\u20135 most important topics discussed.  Deep Explanation: Explain any complex concepts or cultural/religious references mentioned in the text (specifically focus on the Arabic context if applicable).  Key Quotes: Extract 2\u20133 powerful or \"must-read\" sentences.  Tone Analysis: Describe the speaker's tone (e.g., educational, motivational, solemn).  Transcript Text: . All of this in arabic\""
            }
          ]
        },
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        1968,
        -512
      ],
      "id": "46027cac-4837-4b94-88d0-993cbdb3f662",
      "name": "Basic LLM Chain"
    },
    {
      "parameters": {
        "model": "deepseek/deepseek-r1-0528:free",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        2112,
        -384
      ],
      "id": "714dd879-aed1-43a0-9bca-5819318be1a9",
      "name": "OpenRouter1",
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger2').item.json.message.from.id }}",
        "text": "={{ $json.chunk_text }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2512,
        -512
      ],
      "id": "457214ec-da2d-4d7b-a002-7341ca97c712",
      "name": "Send the optimized text",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger2').item.json.message.from.id }}",
        "text": "=Part {{ $json.part }}/{{ $json.total_parts }}: {{ $json.combinedText }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2288,
        -256
      ],
      "id": "03d81a42-b431-48f5-a02f-6b3b26b61383",
      "name": "Send the transcription1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 1
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        4368,
        -528
      ],
      "id": "815b8ca2-4c9a-48d6-9dd8-bb81deb0fc01",
      "name": "Wait"
    },
    {
      "parameters": {
        "amount": 1
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2032,
        -256
      ],
      "id": "13fe7402-d063-4df6-b013-bc67877d7e35",
      "name": "Wait1"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Combine all transcript text from the first item\nconst data = items[0].json;\nconst transcriptArray = Array.isArray(data.transcript) ? data.transcript : [];\n\n// Join all text into one string\nconst fullText = transcriptArray.map(t => t.text || \"\").join(\" \").trim();\n\n// Return a single item with just the combined text\nreturn [\n  {\n    json: {\n      videoId: data.videoId,\n      language: data.language,\n      fullTranscript: fullText\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1760,
        -512
      ],
      "id": "32dfc372-b9b5-4c0e-984f-26db1f413827",
      "name": "Code in JavaScript1"
    },
    {
      "parameters": {
        "url": "=https://yt-api.p.rapidapi.com/get_transcript",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "id",
              "value": "={{ $json.Link }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-RapidAPI-Key",
              "value": "970856cc67mshe02b661d30ff9f3p1e5fd1jsn97b7f226c046"
            },
            {
              "name": "X-RapidAPI-Host",
              "value": "yt-api.p.rapidapi.com"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1072,
        -400
      ],
      "id": "cfe81512-5d76-43d5-a6bc-ad3ba23c68c1",
      "name": "YouTube subtitle",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d47d3676-b158-45c1-ab8b-45cb0e0d0d38",
              "leftValue": "={{ $('Send a text message10').item.json.data['Do you want to optimize the audio or not?'] }}",
              "rightValue": "=Optimize it",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1552,
        -384
      ],
      "id": "0bd70a29-6cf5-431d-bbbc-4e77c90066bc",
      "name": "iF"
    },
    {
      "parameters": {
        "jsCode": "// 1. Set your desired maximum length per message\nconst MAX_LENGTH = 4000; \n\n// 2. Updated this line to match your LLM output (\"text\")\nconst text = $input.first().json.text || \"\";\nconst chunks = [];\n\nif (text.length === 0) return [];\n\nfor (let i = 0; i < text.length; i += MAX_LENGTH) {\n  let chunk = text.substring(i, i + MAX_LENGTH);\n  \n  // Clean up chunking so it doesn't break in the middle of a word\n  if (i + MAX_LENGTH < text.length) {\n    const lastSpace = chunk.lastIndexOf(' ');\n    if (lastSpace > MAX_LENGTH * 0.8) { \n      chunk = text.substring(i, i + lastSpace);\n      i = i - (MAX_LENGTH - lastSpace);\n    }\n  }\n  \n  chunks.push({ json: { chunk_text: chunk.trim() } });\n}\n\nreturn chunks;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2320,
        -512
      ],
      "id": "ba90a1f5-97e8-42b4-b3bf-b68b7adca074",
      "name": "Code in JavaScript2"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger2').item.json.message.from.id }}",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        3488,
        -336
      ],
      "id": "2c257680-1dd9-4b45-8887-7b3902b6b47d",
      "name": "Send the transcription",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const fullText = $json.text; \nconst sections = fullText.split('###').filter(s => s.trim() !== \"\");\n\nreturn sections.map(section => {\n  // This line removes single '*' or '_' that cause the parsing error\n  let cleanSection = section.replace(/[*_`]/g, ''); \n  return {\n    json: {\n      single_message: '### ' + cleanSection.trim()\n    }\n  };\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4160,
        -528
      ],
      "id": "dbdd44a1-cdea-49e4-b50a-ea0fc2b64763",
      "name": "Clean the text"
    },
    {
      "parameters": {
        "command": "=rm -f /tmp/output_*.* && \\\nffmpeg -i /tmp/input_audio \\\n-ac 1 -ar 16000 \\\n-f segment \\\n-segment_time 300 \\\n-reset_timestamps 1 \\\n-c:a pcm_s16le \\\n/tmp/output_%03d.wav\n"
      },
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        2384,
        -832
      ],
      "id": "1bde0f06-11f7-4e08-a074-46915aa3b914",
      "name": "Execute Command"
    },
    {
      "parameters": {
        "fileSelector": "=/tmp/output_*.wav",
        "options": {
          "dataPropertyName": "audio"
        }
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        2576,
        -832
      ],
      "id": "3b0cbd2a-ab20-47db-9163-336fe7a683e6",
      "name": "Read Files from Disk1",
      "alwaysOutputData": false,
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "/tmp/input_audio",
        "options": {
          "append": false
        }
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        2176,
        -832
      ],
      "id": "a6bd2366-29c8-42d5-901f-5242da3de506",
      "name": "Write Files to Disk1"
    },
    {
      "parameters": {
        "url": "=https://youtube-video-fast-downloader-24-7.p.rapidapi.com/download_audio/{{ $('Edit Fields').item.json.Link }}?quality=251\n",
        "sendQuery": true,
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-RapidAPI-Key",
              "value": "970856cc67mshe02b661d30ff9f3p1e5fd1jsn97b7f226c046"
            },
            {
              "name": "X-RapidAPI-Host",
              "value": "youtube-video-fast-downloader-24-7.p.rapidapi.com"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1776,
        -832
      ],
      "id": "5ca84a87-cf30-41d4-af3b-07e4dfb77e36",
      "name": "YouTube transecriptor"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c910c10d-0f6a-46cb-905f-c5af501c7de8",
              "leftValue": "={{ $json.error?.statusCode}}",
              "rightValue": 400,
              "operator": {
                "type": "number",
                "operation": "lte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1280,
        -400
      ],
      "id": "68511b0a-3658-421f-b140-dbbbd12d49ce",
      "name": "If"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "95566e26-4558-4c58-a81f-2247afd8462b",
              "name": "Link",
              "value": "={{$json[\"data\"][\"Link\"].split(\"v=\")[1].split(\"&\")[0]}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        896,
        -400
      ],
      "id": "4e666e79-701d-46f1-9776-d02b8cd6ca14",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger2').item.json.message.from.id }} ",
        "text": "={{ $json.comment }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2144,
        -1200
      ],
      "id": "1e26efaa-0a68-4ca9-9194-dfb6cff30fc1",
      "name": "Error sender1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.file }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1984,
        -832
      ],
      "id": "e19dc34e-28b3-40d5-bff7-d1b98b7a0d35",
      "name": "HTTP Request"
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "shared": [
    {
      "createdAt": "2026-02-09T09:11:09.561Z",
      "updatedAt": "2026-02-09T09:11:09.561Z",
      "role": "workflow:owner",
      "workflowId": "Wh0csYQLTyh9LCQT",
      "projectId": "MwHoDPY5SoqTt3hY"
    }
  ],
  "staticData": null,
  "tags": [
    {
      "createdAt": "2026-02-09T09:11:24.286Z",
      "updatedAt": "2026-02-09T09:11:24.286Z",
      "id": "3tbMFQhctP9UknU5",
      "name": "AI"
    },
    {
      "createdAt": "2026-02-19T12:11:09.401Z",
      "updatedAt": "2026-02-19T12:11:09.401Z",
      "id": "VE1NQb7Vz3FlZbCm",
      "name": "code"
    },
    {
      "createdAt": "2026-02-11T16:46:23.244Z",
      "updatedAt": "2026-02-11T16:46:23.244Z",
      "id": "fsfPs2SHyIitL6re",
      "name": "https"
    },
    {
      "createdAt": "2026-02-10T15:16:08.742Z",
      "updatedAt": "2026-02-10T15:16:08.742Z",
      "id": "l3WH0MdMAXNn3Iww",
      "name": "production"
    },
    {
      "createdAt": "2026-02-09T09:11:18.276Z",
      "updatedAt": "2026-02-09T09:11:18.276Z",
      "id": "yQIVzhQcFfTzhUit",
      "name": "Telegram"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-02-24T13:18:20.000Z",
  "versionId": "6fa53121-36a7-4fc5-99f6-3929879494cb"
}