Telegram (Pro)

Взаимодействие с Telegram через telegram (GramJS for Node.js)

Overview

This node enables interaction with Telegram through the Telegram API using the GramJS library for Node.js. It supports two main scenarios:

  1. Generating a session string: By providing your phone number, confirmation code, and optionally a two-factor authentication password, you can generate a sessionString. This string is used to authenticate future requests without needing to re-enter credentials.

  2. Sending messages: Using an existing sessionString, the node connects to Telegram and sends text messages to specified chat IDs.

Practical examples:

  • Automate sending notifications or alerts to specific Telegram chats.
  • Generate and store a session string securely once, then reuse it for multiple message sends without manual login each time.

Properties

Name Meaning
Message Text content of the message to be sent.
Chat ID Identifier of the Telegram chat where the message will be sent.
Phone Number Your Telegram phone number (used only when generating a new session string).
Code Confirmation code received from Telegram (used only when generating a new session string).
Password Two-factor authentication password if enabled (used only when generating a new session string).

Output

The node outputs JSON data in two different formats depending on the operation:

  • Session String Generation: Outputs an object containing:

    • sessionString: The generated session string to be saved for future use.
    • info: A message prompting the user to copy and save the session string securely.
  • Message Sending: Outputs an object containing:

    • result: The response object returned by Telegram after sending the message, which includes details about the sent message.

The node does not output binary data.

Dependencies

  • Requires an API key credential consisting of:
    • API ID
    • API Hash
    • Optionally, a saved sessionString for authentication.
  • Uses the telegram and telegram/sessions npm packages (GramJS) internally.
  • Requires network access to Telegram servers.

Troubleshooting

  • Common issues:

    • Failure to generate a session string due to incorrect phone number, code, or password.
    • Invalid or expired sessionString causing authentication errors.
    • Incorrect chat ID leading to message send failures.
    • Network connectivity problems preventing connection to Telegram.
  • Error messages and resolutions:

    • Errors during start() method usually indicate wrong phone number, code, or password. Verify these inputs carefully.
    • Authentication errors when using a sessionString suggest it may be invalid or expired; regenerate if needed.
    • If message sending fails, confirm that the chat ID is correct and that the bot/user has permission to send messages there.
    • Connection retries are set to 5; persistent network issues may require checking firewall or proxy settings.

Links and References

Discussion