Socket
Socket
Sign inDemoInstall

easy-telegram-mtproto

Package Overview
Dependencies
320
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    easy-telegram-mtproto

Telegram Client API wrapper for telegram-mtproto


Version published
Weekly downloads
13
increased by116.67%
Maintainers
1
Install size
10.7 MB
Created
Weekly downloads
 

Readme

Source

Easy Telegram Mtproto

  • Easy interface for telegram-mtproto
  • Allows you to create custom telegram clients, chat-bots as user, etc

Install

npm install easy-telegram-mtproto

Examples

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 ();

Methods

  • TelegramClient (apiId, apiHash, name, getPhone, getCode, getRandomMessageId, storageFolder)
    • apiId and apiHash you can get from telegram website.
    • name is needed to save login keys.
    • getPhone and getCode are async functions that are called when phone number or telegram login code are required.
    • getRandomMessageId is called when message random_id is required
    • storageFolder to save login keys.
  • async asInputPeer (...args) converts chat object to InputPeer
  • async login () logs in telegram if was not logged in before
  • async getChats () returns list of all chats (max 1000)
  • async getAndSaveChatsData (jsonFileName = 'chats.json', txtFileName = 'chats.txt') gets short chats data and saves it to file
  • async chatHistory (chat) reads all history from chat
  • async forwardMessages (from, to, messages) forwardes messages from on chat to another
  • async deleteMessagesFromChannel (from, messages) deletes selected message from channel or supergroup
  • async sendMessage (target, message) sends message to chat
  • async call (...args) calls custom API method. List of methods
await client.call ('messages.sendMessage', {
    peer: TelegramClient.asInputPeer (target),
    random_id,
    message,
});

Keywords

FAQs

Last updated on 23 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc