Skip to content

Telegram Convert File

This module downloads files (images, documents, etc.) received through a Telegram bot using the file_id provided by the Telegram API. Its execution flow is:

  1. Gets the file_id from the input content (data.content).
  2. Verifies that the botToken is available in the input data.
  3. Calls the Telegram getFile API to get the file path on Telegram servers.
  4. Downloads the file from https://api.telegram.org/file/bot{token}/{file_path}.
  5. Saves the file to the temporary directory temporal/cli_{client_id}/:
    • For photos: generates a name with timestamp (image-{timestamp}.png).
    • For documents: uses the original file name (data.metadata.file_name).
  6. Generates a public download URL based on ENGINE_HOST.
  7. Returns the original data enriched with filename, filePath (local path) and urlPath (public URL).

The downloaded file is available for subsequent nodes that need to process it (e.g.: agentChat for image analysis, sendMail for attachments, etc.).

This module has no configuration parameters in scheme. The necessary data is obtained from the flow input:

Parameter (in input data)TypeRequiredDescription
contenttextYesThe file_id of the file sent by Telegram (e.g.: message.photo[n].file_id).
botTokentextYesTelegram bot token.
chatIdtextNoTelegram chat ID.
typetextNoFile type: “photo” for images, other for documents.
metadata.file_nametextNoOriginal file name (for documents).

The Telegram bot botToken is expected in data.botToken. It does not use the credentials system directly but receives the token from the Telegram trigger node.

{
"nextModule": "siguiente-nodo",
"data": {
"content": "AgACAgIAAxkBAAI...",
"botToken": "123456:ABC-DEF...",
"chatId": "987654321",
"type": "photo",
"filename": "image-1711180800000.png",
"filePath": "/app/temporal/cli_1/image-1711180800000.png",
"urlPath": "https://mi-engine.com/download/cli_1/image-1711180800000.png"
}
}

This module is placed after a Telegram trigger that receives messages with files. Typical input data comes automatically from the trigger:

{
"content": "AgACAgIAAxkBAAI...",
"botToken": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
"chatId": "987654321",
"type": "photo",
"metadata": {
"file_name": "documento.pdf"
}
}
  • Telegram Bot API:
    • GET https://api.telegram.org/bot{token}/getFile?file_id={fileId} - Get file path.
    • GET https://api.telegram.org/file/bot{token}/{file_path} - Download the file.
  • Documentation: https://core.telegram.org/bots/api#getfile
  • Files are saved in temporal/cli_{client_id}/. The directory is created automatically if it doesn’t exist.
  • Telegram has a 20 MB limit for file downloads via the bots API.
  • For photos, the name is automatically generated with a timestamp. For documents, the original name is used.
  • The public download URL depends on the ENGINE_HOST environment variable.
  • The original input data is preserved in the output, enriched with the file fields.
  • This module is ideal for preprocessing files before passing them to modules like agentChat (image analysis) or sendMail (attachments).
  • agentChat (Conversational AI Agent - for analyzing downloaded images)
  • sendMail (Send Mail - for attaching downloaded files)
  • openaiImages (OpenAI Generate Image)