Secure Message Routing Prevents Unauthorized API Abuse

Start with a Telegram Trigger node configured on webhook for voice, text, or image messages, connected to your bot token. Add a Sanitize node immediately after using JavaScript to check sender ID: if ($json.message.from.id.toString() !== '7773500682') return [];—replace 7773500682 with your Telegram User ID from @userinfobot. This blocks non-authorized users, protecting ElevenLabs credits.

Follow with a Switch node routing by message type: Condition 1 checks {{ $json.message.text }} exists for text; Condition 2 checks {{ $json.message.voice }} for voice (output 'Audio'); Condition 3 for images. Text routes to a reply like 'Send voice only'; this visual if-else ensures only voice messages proceed to cloning, handling mixed inputs reliably.

Voice Cloning Pipeline Downloads and Transforms Audio

For voice paths, use Telegram's Get File node (resource: File, operation: Get, file ID: {{ $json.message.voice.file_id }}, download: true) to fetch the actual OGG audio—Telegram webhooks send only IDs to save bandwidth.

Pipe to an HTTP Request node renamed 'Generate cloned audio' (POST to https://api.elevenlabs.io/v1/voice-generation, headers: xi-api-key: your ElevenLabs key, Content-Type: application/json). Body: { "voice_id": "your_voice_id_from_elevenlabs", "voice_settings": { "stability": 0.5, "similarity_boost": 0.5 }, "text_to_speech_prompt": "Convert this audio to the target voice", "files": [ { "file": "{{ $binary.data }}", "name": "input.ogg" } ], "model_id": "eleven_turbo_v2_5", "previous_text_to_speech_prompt": "", "previous_voice_id": "" }. Response: Output as binary MP3. Experiment with ElevenLabs voice IDs for voices like Morgan Freeman; this clones input audio directly, not text-to-speech, yielding natural results.

Persistent Storage and Instant Telegram Delivery

Route cloned MP3 to Google Drive Upload node (operation: Upload, name: cloned_{{ $json.original_filename }}.mp3, parent folder: search 'Elevenlabs' in My Drive). This prefixes files for organization, building a searchable library for content creators, podcasters (intros), or marketers (A/B tests)—avoids direct sends for easy reuse/sharing.

Finally, Telegram Send Audio node (chat ID: {{ $json.message.chat.id }}, audio: {{ $binary.data }}) replies in the same chat. Connect linearly: Trigger → Sanitize → Switch (Audio) → Get File → HTTP ElevenLabs → Drive → Send Audio. Activate workflow, test by sending voice to bot; check n8n execution logs for failures.

Prerequisites: n8n/ ElevenLabs/ Telegram Bot Token (via @BotFather)/ Google Drive accounts. No coding needed—drag/connect nodes like LEGO. This assembly-line architecture turns weeks of dev work into 15 minutes, enabling instant voiceovers.