Telegram MTProto Client icon

Telegram MTProto Client

Use Telegram Client API with MTProto protocol

Overview

This node enables searching for messages within a specific Telegram chat or channel using the Telegram MTProto Client API. It allows users to provide a chat identifier and a search query string, returning messages that match the query. This is useful for scenarios such as retrieving past conversations containing certain keywords, auditing message history, or filtering messages for analysis.

Practical examples:

  • Searching for all messages mentioning a project name in a team channel.
  • Finding messages containing a specific hashtag or keyword in a community group.
  • Retrieving messages with particular content for compliance or moderation purposes.

Properties

Name Meaning
Chat ID The identifier of the chat or channel where the search will be performed. Can be a numeric ID (e.g., -100xxxx) or username (e.g., @username).
Search Query The text string to search for within the messages of the specified chat.
Options Additional optional parameters:
Silent: Send message silently without notification (not applicable here but part of options structure).
Caption: Caption for media messages (not applicable here).
Parse Mode: How to parse message text (none, markdown, html) (not applicable here).
Limit: Maximum number of messages to return (default 100).

Output

The output JSON contains:

  • success: Boolean indicating if the search was successful.
  • messages: An array of message objects matching the search query. Each message object includes details such as message ID, date, sender info, and message content depending on Telegram's message structure.

No binary data is output by this operation.

Example output snippet:

{
  "success": true,
  "messages": [
    {
      "id": 12345,
      "date": "2024-01-01T12:00:00Z",
      "message": "Sample message text containing the search query",
      ...
    },
    ...
  ]
}

Dependencies

  • Requires an active Telegram MTProto API client session authenticated with:
    • A valid API ID and API hash.
    • A session string credential representing the logged-in Telegram user.
  • The node uses the Telegram MTProto protocol via a specialized client library bundled with the node.
  • No additional external services are required beyond Telegram itself.

Troubleshooting

  • No credentials provided: The node requires valid Telegram API credentials and a session string. Ensure these are configured correctly in n8n.
  • Invalid Chat ID or Username: If the chat identifier is incorrect or inaccessible, the search will fail. Verify the chat/channel exists and the authenticated user has access.
  • Empty or invalid search query: The query parameter must be a non-empty string.
  • Limit too high: Setting the limit to a very large number may cause performance issues or API rate limits.
  • Connection issues: Network problems or Telegram server issues can cause connection failures. Retry or check network connectivity.
  • Permission errors: The authenticated user must have permission to read messages in the target chat/channel.

Links and References

Discussion