AI Trainer: Telegram Message Send¶
A reusable sub-workflow that handles message delivery for AI trainer bots, supporting both text and voice responses via Telegram. This workflow provides reliable message delivery with voice generation capabilities using ElevenLabs and OpenAI as a fallback.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a centralized messaging service for AI trainer applications, enabling them to send either text messages or voice messages to users via Telegram. It's designed to be called by other workflows (like Trainer Prod and Trainer MVP) to handle the final step of delivering AI-generated responses to users.
How It Works¶
- Receive Input: The workflow is triggered by another workflow with message content, voice preference, and chat ID
- Voice Decision: Checks if a voice response is requested via the
is_voiceparameter - Voice Generation (if requested):
- Sets the voice ID for ElevenLabs TTS
- Calls ElevenLabs API to generate audio from text
- If ElevenLabs fails, falls back to OpenAI's TTS service
- Message Delivery:
- For voice: Sends the generated audio file to Telegram
- For text: Sends the plain text message to Telegram
- Return Status: Outputs the delivery status back to the calling workflow
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[If Voice Out]
B -->|Voice Requested| C[Voice ID]
B -->|Text Only| D[Telegram1 - Text Message]
C --> E[Generate voice 11labs]
E -->|Success| F[Telegram - Audio Message]
E -->|Error| G[Generate voice openai backup]
G --> F
F --> H[Output]
D --> H
Trigger¶
- Type: Execute Workflow Trigger
- Called by: Other workflows (Trainer Prod, Trainer MVP)
- Cannot be triggered directly - only executes when called by another workflow
Nodes Used¶
| Node | Type | Purpose |
|---|---|---|
| When Executed by Another Workflow | Execute Workflow Trigger | Receives input from calling workflow |
| If Voice Out | If | Determines whether to generate voice or send text |
| Voice ID | Set | Sets the ElevenLabs voice ID for TTS |
| Generate voice 11labs | HTTP Request | Calls ElevenLabs API for text-to-speech |
| Generate voice openai (backup) | OpenAI | Fallback TTS service if ElevenLabs fails |
| Telegram | Telegram | Sends audio messages |
| Telegram1 | Telegram | Sends text messages |
| Output | Set | Returns execution status to calling workflow |
External Services & Credentials Required¶
Required Credentials¶
- Telegram Bot API: For sending messages
- Credential name: "Waringa"
- Type: telegramApi
- ElevenLabs API: For voice generation
- Credential name: "Textit Token"
- Type: httpHeaderAuth
- OpenAI API: For backup voice generation
- Credential name: "Waringa"
- Type: openAiApi
External Services¶
- ElevenLabs: Primary text-to-speech service
- OpenAI: Backup text-to-speech service
- Telegram Bot API: Message delivery platform
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through credentials and hardcoded values.
Data Flow¶
Input Parameters¶
output(string): The message text to sendis_voice(boolean): Whether to generate and send voice messagechat_id(string): Telegram chat ID for message delivery
Output¶
ok(boolean): Success status of the message delivery
Voice Settings¶
- Voice ID:
Z8dg0fyk7p6js7cQ7lgi(hardcoded) - Model:
eleven_turbo_v2_5 - Stability: 0.5
- Similarity Boost: 0.5
Error Handling¶
The workflow includes robust error handling:
- ElevenLabs Fallback: If the primary ElevenLabs API fails, the workflow automatically falls back to OpenAI's TTS service
- Continue on Error: The ElevenLabs node is configured with "continueErrorOutput" to ensure the workflow doesn't stop on API failures
- Status Reporting: The output node captures the success status and returns it to the calling workflow
Known Limitations¶
- Voice ID is hardcoded and cannot be customized per request
- No retry mechanism for failed Telegram deliveries
- Cannot be tested directly due to the Execute Workflow Trigger
- Limited voice customization options
Related Workflows¶
This workflow is called by: - Trainer Prod: Production AI trainer workflow - Trainer MVP: Minimum viable product trainer workflow
Setup Instructions¶
-
Import the Workflow
- Copy the workflow JSON
- Import into your n8n instance
-
Configure Credentials
- Set up Telegram Bot API credentials:
- Get bot token from @BotFather on Telegram
- Create telegramApi credential in n8n
- Set up ElevenLabs API credentials:
- Get API key from ElevenLabs dashboard
- Create httpHeaderAuth credential with header "xi-api-key"
- Set up OpenAI API credentials:
- Get API key from OpenAI platform
- Create openAiApi credential
- Set up Telegram Bot API credentials:
-
Activate the Workflow
- Ensure the workflow is active
- Verify it appears in the "Execute Workflow" node options of calling workflows
-
Test Integration
- Test through a calling workflow (cannot test directly)
- Verify both text and voice message delivery
- Check error handling with invalid inputs
-
Voice Configuration (Optional)
- Update the Voice ID in the "Voice ID" node if you want to use a different ElevenLabs voice
- Adjust voice settings (stability, similarity_boost) in the "Generate voice 11labs" node