Skip to content

AI Trainer: Telegram Message Send

This workflow delivers AI-generated responses to Telegram users with optional text-to-speech conversion. It serves as a message delivery service that can send either plain text messages or audio messages generated from text using ElevenLabs or OpenAI's speech synthesis.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow appears to be part of an AI training or educational system that communicates with users via Telegram. It provides flexible message delivery with voice synthesis capabilities, allowing for more engaging and accessible communication.

How It Works

  1. Receives Input: The workflow is triggered by another workflow with message content, voice preference, and target chat ID
  2. Voice Decision: Checks if the message should be delivered as audio or text
  3. Voice Generation (if audio requested):
    • Sets a specific voice ID for ElevenLabs
    • Attempts to generate audio using ElevenLabs API
    • Falls back to OpenAI's text-to-speech if ElevenLabs fails
  4. Message Delivery: Sends either the audio file or plain text to the specified Telegram chat
  5. Output: Returns a success status to the calling workflow

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[If Voice Out]
    B -->|Voice=true| C[Voice ID]
    B -->|Voice=false| G[Telegram1 - Text Message]
    C --> D[Generate voice 11labs]
    D -->|Success| E[Telegram - Audio Message]
    D -->|Error| F[Generate voice openai backup]
    F --> E
    E --> H[Output]
    G --> H

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It expects three input parameters: - output (string): The message content to send - is_voice (boolean): Whether to convert text to speech - chat_id (string): The Telegram chat ID to send the message to

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input from calling workflow
If If Voice Out Determines whether to send voice or text message
Set Voice ID Sets the ElevenLabs voice ID for speech synthesis
HTTP Request Generate voice 11labs Converts text to speech using ElevenLabs API
OpenAI Generate voice openai (backup) Backup text-to-speech using OpenAI
Telegram Telegram Sends audio message to Telegram chat
Telegram Telegram1 Sends text message to Telegram chat
Set Output Formats the final response

External Services & Credentials Required

ElevenLabs

  • Purpose: Primary text-to-speech service
  • Credential Type: HTTP Header Authentication
  • Required: API key for ElevenLabs service

OpenAI

  • Purpose: Backup text-to-speech service
  • Credential Type: OpenAI API credentials
  • Required: OpenAI API key

Telegram

  • Purpose: Message delivery platform
  • Credential Type: Telegram Bot API
  • Required: Telegram bot token

Environment Variables

No environment variables are explicitly used in this workflow. All configuration is handled through n8n credentials and hardcoded values.

Data Flow

Input

1
2
3
4
5
{
  "output": "Message text to send",
  "is_voice": true/false,
  "chat_id": "Telegram chat ID"
}

Output

1
2
3
{
  "ok": true/false
}

The workflow returns a boolean indicating whether the message was successfully delivered.

Error Handling

  • ElevenLabs Fallback: If ElevenLabs voice generation fails, the workflow automatically falls back to OpenAI's text-to-speech service
  • Continue on Error: The ElevenLabs node is configured to continue execution even if it encounters an error, ensuring the backup system activates

Known Limitations

  • Voice ID is hardcoded (Z8dg0fyk7p6js7cQ7lgi) and cannot be dynamically changed
  • No retry mechanism if both voice generation services fail
  • Limited error reporting - only returns a simple success/failure status
  • Audio files are always named "audio.mp3" regardless of content

This workflow is designed to be called by other workflows in the AI training system. Look for workflows that handle user interactions or AI response generation that might call this message delivery service.

Setup Instructions

  1. Import the Workflow

    • Copy the workflow JSON and import it into your n8n instance
  2. Configure Credentials

    • Set up ElevenLabs HTTP Header Auth with your API key
    • Configure OpenAI API credentials
    • Add Telegram Bot API credentials
  3. Verify Voice ID

    • Check that the hardcoded voice ID (Z8dg0fyk7p6js7cQ7lgi) exists in your ElevenLabs account
    • Update the Voice ID node if you want to use a different voice
  4. Test the Workflow

    • Create a test workflow that calls this one with sample data
    • Verify both text and voice message delivery work correctly
  5. Integration

    • Update calling workflows to use the correct workflow ID
    • Ensure input parameters match the expected format