Telegram MTProto icon

Telegram MTProto

Get messages from Telegram using MTProto API with smart filtering: by message ID, only new messages, formatted dates, media download links

Overview

This node connects to Telegram using the MTProto API to retrieve chat messages from a specified chat by its ID or username. It supports advanced filtering options such as fetching only new messages since the last retrieval, limiting the number of messages, and including or excluding bot messages. The node can also download media attached to messages and provide base64-encoded data URLs for smaller files.

Common scenarios where this node is useful include:

  • Monitoring Telegram chats or channels for new messages.
  • Archiving or processing recent chat history.
  • Integrating Telegram message data into workflows for notifications, analytics, or further automation.
  • Extracting media content shared in chats for downstream processing.

Practical example: A user wants to automatically fetch the latest 20 messages from a Telegram group chat every hour, ignoring messages sent by bots, and process any photos shared in those messages.

Properties

Name Meaning
Chat ID or Username Chat identifier as a numeric ID or username starting with '@'. Specifies which chat to fetch messages from.
Limit Maximum number of messages to retrieve (between 1 and 100).
From Message ID Starting message ID to fetch messages after. If set to 0, retrieves the most recent messages.
Only New Messages When enabled, fetches only messages newer than the last retrieved message automatically, disabling "From Message ID".
Include Bot Messages Whether to include messages sent by bots.
Debug Mode Enables additional debug information in the output for troubleshooting or development purposes.

Output

The node outputs an array of items, each containing a json object representing a single Telegram message with the following structure:

  • id: Numeric message ID.
  • date: Formatted date string of the message timestamp (localized).
  • timestamp: Original Unix timestamp of the message date.
  • message: Text content of the message (empty string if none).
  • fromId: Sender identification object.
  • chatId: Identifier of the chat the message belongs to.
  • isBot: Boolean indicating if the sender is a bot.
  • media: If present, an object describing attached media with:
    • className: Media class/type name.
    • type: General media type (e.g., photo, video, audio, document, contact, location, webpage).
    • downloadUrl: For small media files (<1MB), a base64-encoded data URL.
    • size: Size in bytes for large media files.
    • downloadInfo: Note about file size limitations for downloading.
    • downloadError: Error message if media download failed.

If debug mode is enabled, additional _debug fields are included with original raw message data and chat entity info.

If no messages are found, a single item is returned with a message indicating no results.

The node does not output binary data directly but provides media as base64 data URLs or metadata for larger files.

Dependencies

  • Requires valid Telegram MTProto API credentials including API ID, API hash, and session string or phone number for authentication.
  • Uses the telegram and telegram/sessions libraries internally to interact with Telegram's MTProto API.
  • Needs network access to Telegram servers.
  • Session management is handled automatically; first-time authentication requires manual setup with phone number and session string.

Troubleshooting

  • Authentication errors: If the node throws errors related to phone code verification, it means manual authentication is required initially to generate a session string. Provide the phone number in credentials and authenticate outside the node to obtain the session string.
  • Chat not found: Errors indicating failure to find the chat usually mean the chat ID/username is incorrect or the authenticated user lacks access.
  • Media download failures: Large media files (>1MB) are not fully downloaded due to size limits; only metadata is provided. Smaller files are embedded as base64 data URLs.
  • Empty results: If no messages are returned, verify the chat identifier, message ID filters, and that the chat contains messages matching criteria.
  • Parameter conflicts: Enabling "Only New Messages" disables "From Message ID" parameter to avoid conflicting filters.

To resolve issues, ensure correct credentials, valid chat identifiers, and appropriate filter settings.

Links and References

Discussion