Skip to main content

Get File Path

Retrieves the file path for a Telegram file using its file ID. This path can be used to construct a download URL or get file information without downloading the entire file.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Input

  • Client Id - (Optional) The unique identifier for the bot client connection obtained from the Connect node. If not provided, you can use Bot Token instead.
  • File Id - The unique identifier for the file. This ID is obtained from received messages that contain files (photos, documents, audio, video, etc.).

Options

  • Bot Token - (Optional) The Telegram bot token credential. This is an alternative to using Client Id - provide either Client Id OR Bot Token.

Output

  • Result - The file path string on Telegram's servers. This path is relative to Telegram's file storage and can be used with the Telegram API to download the file.

How It Works

The Get File Path node queries Telegram's Bot API to retrieve metadata about a file. When executed, the node:

  1. Either uses the provided Client Id or creates a temporary connection using Bot Token
  2. Validates the File Id
  3. Calls Telegram's getFile API method with the File Id
  4. Retrieves file information including the file path
  5. Returns the file path as a string in the Result output

The file path returned is a relative path on Telegram's servers, not a full URL or local path.

Requirements

  • Either a valid Client Id from a Connect node OR a valid Bot Token credential
  • A valid File Id from a Telegram message
  • The file must still be available on Telegram's servers

Error Handling

The node will return errors in the following cases:

  • Empty or invalid File Id
  • Invalid Client Id or Bot Token
  • File not found (may have been deleted or expired)
  • Network connectivity issues
  • Telegram API errors

Usage Examples

Get File Path from Message:

Receive Message
→ If (message.document exists)
→ Get File Path (File Id: message.document.file_id)
→ Log (result)

Check File Before Downloading:

Receive Message
→ Get File Path (File Id: message.photo.file_id)
→ If (result exists)
→ Download File
→ Else
→ Send Message ("File not available")

Build Download URL:

Get File Path (File Id: file_id)
→ Build URL: https://api.telegram.org/file/bot<token>/<result>
→ Download via HTTP

Get Multiple File Paths:

For Each (attachment in message.attachments)
→ Get File Path (File Id: attachment.file_id)
→ Log (result)

Understanding File Paths

The Result output contains a relative path like:

photos/file_123.jpg
documents/file_456.pdf
voice/file_789.ogg

This is not a full URL. To download the file directly via HTTP, construct the URL:

https://api.telegram.org/file/bot<YOUR_BOT_TOKEN>/<FILE_PATH>

Use Cases

File Validation:

Receive Message
→ Get File Path
→ If (result exists)
→ Process File
→ Else
→ Send Message ("File expired")

File Information Logging:

Receive Message
→ Get File Path (for all files)
→ Log to Database
→ Track File Statistics

Direct Download URL:

Get File Path
→ Construct Download URL
→ Send URL to User
→ User downloads directly

File Availability Check:

Get File Path
→ If (successful)
→ File still available
→ Else
→ File expired or deleted

Get File Path vs. Download File

Use Get File Path when:

  • You only need file metadata
  • You want to check if a file is available
  • You need to construct a custom download URL
  • You want to minimize API calls

Use Download File when:

  • You need the actual file content
  • You want to process the file locally
  • You need to save the file to disk
  • You want automatic file handling

File Path Information

The file path returned contains:

  • A relative directory (photos/, documents/, etc.)
  • The file identifier
  • The original file extension (if applicable)

Example Paths:

photos/AgACAgIAAxkBAAIC...
documents/BQACAgIAAxkB...
voice/AwACAgIAAxkBAAI...
video/BAACAgIAAxkBAAI...

Common Patterns

Verify Before Download:

Get File Path (File Id: file_id)
→ If (result exists)
→ Download File (File Id: file_id)
→ Else
→ Send Message ("File no longer available")

Log All File Paths:

Receive Message
→ Extract All File Ids
→ For Each (file_id)
→ Get File Path
→ Save to Database (file_id, result)

Construct Download URL:

// After Get File Path
let filePath = result; // from Get File Path output
let token = "YOUR_BOT_TOKEN";
let downloadUrl = `https://api.telegram.org/file/bot${token}/${filePath}`;
// Use downloadUrl for HTTP download

File Path Structure

Photos:

photos/file_0.jpg
photos/file_1.jpg // Different sizes
photos/file_2.jpg

Documents:

documents/file_name.pdf
documents/archive.zip

Audio:

audio/song.mp3
voice/voice_message.ogg

Best Practices

  • Check availability - Use Get File Path to verify files exist before downloading
  • Cache file paths - Store paths if you need to access files multiple times
  • Validate File Ids - Ensure File Ids are from valid messages
  • Handle errors gracefully - Files may expire over time
  • Don't expose file paths - They contain internal Telegram identifiers

Telegram File Storage

Important Notes:

  • Telegram stores files temporarily
  • Files may expire after a period of inactivity
  • File paths can change (don't hardcode them)
  • Always use File Ids as the primary reference
  • Get fresh file paths when needed

API Response Details

When you call Get File Path, Telegram returns information about the file:

  • file_id - The unique file identifier
  • file_unique_id - Another unique identifier
  • file_size - Size in bytes
  • file_path - The relative path (this is what the node returns)

The node extracts and returns only the file_path.

Constructing Download URLs

If you want to download files via HTTP instead of using the Download File node:

Step 1: Get the file path

Get File Path (File Id: message.document.file_id)

Step 2: Construct the URL

let filePath = result;  // Output from Get File Path
let botToken = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11";
let url = `https://api.telegram.org/file/bot${botToken}/${filePath}`;

Step 3: Download via HTTP

HTTP Request (GET, url)
→ Save Response to File

Troubleshooting

Empty Result:

  • File Id may be invalid
  • File may have been deleted
  • File may have expired
  • Check that File Id is from a valid message

File Not Found:

  • Telegram files are not permanent
  • Files from old messages may be unavailable
  • Download important files promptly

Invalid File Id:

  • Verify the File Id string is complete
  • Check that it's from a message with a file
  • Different file types have different File Id formats

Performance Considerations

API Calls:

  • Get File Path makes an API call to Telegram
  • Use sparingly for frequently accessed files
  • Consider caching file paths when possible

Rate Limiting:

  • Telegram has rate limits on API calls
  • Avoid calling Get File Path in tight loops
  • Batch operations when possible

Tips

  • Get File Path is lightweight - it doesn't download the file
  • Use it to validate File Ids before downloading
  • The file path can change - don't store it long-term
  • Always use the File Id as the permanent reference
  • File paths are relative to Telegram's storage, not absolute URLs
  • You can't use the file path alone - you need the bot token for downloads
  • The result is just a string - parse it if you need specific information
  • Different file types use different directory structures in the path
  • This node is useful for debugging and logging file information
  • Combine with Download File for complete file handling