npm install easy-telegram-mtproto
const TelegramClient = require ('easy-telegram-mtproto');
const data = require ('./login-data.json');
const main = async () => {
console.log (data);
const client = new TelegramClient (data.app.api_id, data.app.api_hash,
data.phone,
async () => data.phone,
() => {
const readline = require ('readline');
const rl = readline.createInterface ({
input: process.stdin,
output: process.stdout
});
return new Promise (resolve => {
rl.question ('Code', (answer) => {
rl.close ();
resolve (answer);
});
});
});
await client.login ();
const chats = await client.getChats ();
const me = chats.find ((chat) => chat.self);
console.log (me);
client.sendMessage (me, 'Hello, is it me you\'re looking for?');
};
main ();
TelegramClient (apiId, apiHash, name, getPhone, getCode, getRandomMessageId, storageFolder)
async asInputPeer (...args)
converts chat object to InputPeerasync login ()
logs in telegram if was not logged in beforeasync getChats ()
returns list of all chats (max 1000)async getAndSaveChatsData (jsonFileName = 'chats.json', txtFileName = 'chats.txt')
gets short chats data and saves it to fileasync chatHistory (chat)
reads all history from chatasync forwardMessages (from, to, messages)
forwardes messages from on chat to anotherasync deleteMessagesFromChannel (from, messages)
deletes selected message from channel or supergroupasync sendMessage (target, message)
sends message to chatasync call (...args)
calls custom API method. List of methods
await client.call ('messages.sendMessage', {
peer: TelegramClient.asInputPeer (target),
random_id,
message,
});