Skip to content

Latest commit

 

History

History
119 lines (90 loc) · 6.11 KB

README.md

File metadata and controls

119 lines (90 loc) · 6.11 KB

Telegram client nodes for Node-RED

Platform License Downloads Total Downloads NPM Known Vulnerabilities Telegram Package Quality Build Open Issues Closed Issues ...

This package contains a node which act as a Telegram Client. It is based on gramjs which implements the mtproto mobile protocol. (see https://core.telegram.org/mtproto). Unlike node-red-contrib-telegrambot it does not support the telegram bot api. The package can be used to create so-called userbots or selfbots which to automate things under your own user-name. However you should be aware of the fact, that if you cause flooding and other havoc telegram will quickly ban your account either for 24h or even forever. It is recommended to use a test account while developing.

Thanks for your donation

If you want to support this free project. Any help is welcome. You can donate by clicking one of the following links:

Buy Me A Coffee

Credits

Installation

NPM

You can install the nodes using node-red's "Manage palette" in the side bar.

Or run the following command in the root directory of your Node-RED installation

npm install node-red-node-telegrambot --save

Note that the minimum node-red version 1.3.7 and minimum nodejs version is 12.x.

Dependencies

The nodes are tested with Node.js v18.12.1 and Node-RED v3.0.2.

Changelog

Changes can be followed here.

Usage

Basics

Authentication

The Telegram client receiver node receives messages from like a telegram client. You need to login with a phone-number and an API ID and API Hash in order to be able to receive message under your own user name. In addition to that you can also login using a bot token retrieved from @botfather.

You can create an API ID and Hash when you login to your telegram account here https://my.telegram.org/auth Then go to 'API Development Tools' and create your API ID and API Hash. Both are required when configuring your nodes. The nodes login only once to create a so-called session string. This string can be created from within the config node or as an alternative you can also create it online here https://tgsnake.js.org/login This session string is used instead of interactive login (where you need to enter a phone-code and your password if set).

Receiver Node

The Telegram client receiver node receives message which are sent to your account or bot. Just add a debug node to the output and investigate the objects in msg.payload.

Sender Node

The Telegram client sender node is able to call nearly all functions provides by gramjs. For a full list of methods please visit https://gram.js.org/ under TL.

Examples

Api.messages.SendMessage

To call the SendMessage function, you must do the following: Create a function node and enter 'messages' for the api property and 'SendMessage' for the func property. The arguments described in the api must be added to args. SendMessage contains a field randomId which must be set by the user to a random number to prevent message looping in the telegram server. Peer must be set to the name of the user you want to send the message to.

let randomId = BigInt(Math.floor(Math.random() * 1e15));
let username = msg.payload;
msg.payload = {
   api: 'messages',
   func: 'SendMessage',
   args: {
       peer: "to username",
       message: "Test1",
       randomId: randomId,
       noWebpage: true,
       noforwards: true,
       scheduleDate: 0,
       // sendAs: "from username",
   }
}
return msg;

send message flow

Api.account.CheckUsername

To call the CheckUsername function, you must do the following: Create a function node and enter 'account' for the api property and 'CheckUsername' for the func property. The arguments described in the api must be added to args. In this case it is only the username property.

let username = msg.payload;
msg.payload = {
   api: "account",
   func: "CheckUsername",
   args: {
       username: 'usernameToCheckHere'
   }
}
return msg;

check username flow