Telegram GramJS

Отправка сообщений через Telegram GramJS API

Overview

This node integrates with Telegram using the Telegram GramJS API to send text messages or authenticate a user session. The provided operation "Отправить сообщение" ("Send Message") allows sending a plain text message to a specified Telegram chat identified by username, phone number, or chat ID.

Typical use cases include:

  • Automating notifications or alerts to Telegram users or groups.
  • Sending updates or reminders to specific Telegram chats.
  • Integrating Telegram messaging into workflows for customer support or marketing.

For example, you can configure this node to send a message like "Server is down!" to a Telegram group chat or directly to a user's @username.

Properties

Name Meaning
ID чата Chat identifier: can be a Telegram username (e.g., @username), phone number (+1234567890), or chat ID. Used to specify the recipient of the message.
Сообщение Text content of the message to send. Supports multiline input.

Output

The node outputs JSON data with the following structure upon successful message sending:

{
  "success": true,
  "message": "Сообщение отправлено успешно!",
  "result": {
    "messageId": "<numeric_message_id>",
    "date": "<ISO8601_date_string>",
    "chatId": "<chat_id_as_string>",
    "message": "<sent_message_text>",
    "chat": {
      "id": "<chat_id>",
      "type": "<entity_type>",          // e.g., User, Channel, Group
      "username": "<optional_username>",
      "title": "<optional_title>",
      "firstName": "<optional_first_name>",
      "lastName": "<optional_last_name>"
    }
  }
}
  • messageId: Unique identifier of the sent message.
  • date: Timestamp when the message was sent.
  • chatId: Identifier of the chat where the message was sent.
  • chat: Metadata about the chat entity.

If the node supports binary data output, it is not applicable here since this node only sends and returns textual message information.

Dependencies

  • Requires an API key credential for Telegram authentication configured in n8n.
  • Uses the Telegram GramJS library (telegram and telegram/sessions packages) to interact with Telegram's MTProto API.
  • Requires valid Telegram API credentials (apiId, apiHash) and a saved session string for authorization.
  • Network access to Telegram servers is necessary.

Troubleshooting

Common Issues

  • User not authorized: If the Telegram client session is not authenticated, the node will throw an error instructing to run the "Authenticate" operation first.
  • Invalid chat identifier: If the provided chat ID, username, or phone number is incorrect or not found, the node will fail to find the recipient entity.
  • Rate limiting: Telegram may return errors if too many requests are made in a short time; the node handles some retry logic but excessive usage may cause temporary blocks.
  • Session expiration or invalid session string: Authentication sessions may expire or become invalid, requiring re-authentication.

Error Messages and Resolutions

  • "Пользователь не авторизован. Начала выполните операцию "Аутентификация".
    Means the user must authenticate before sending messages. Run the authentication operation to obtain a valid session.

  • "Не удалось найти получателя <chatId>: <error_message>"
    Indicates the chat identifier could not be resolved. Verify the chat ID, username, or phone number is correct and accessible.

  • "GramJS Error: Слишком много запросов. Попробуйте через N секунд."
    Telegram rate limit exceeded. Wait for the specified cooldown period before retrying.

  • "Ошибка авторизации. Проверьте учетные данные или повторите аутентификацию."
    Authentication failed. Check API credentials and re-authenticate if needed.

Links and References


Note: This summary is based solely on static analysis of the provided source code and property definitions. Runtime behavior such as dynamic session management or network conditions may affect actual execution.

Discussion