All Projects → alik0211 → Mtproto Core

alik0211 / Mtproto Core

Licence: gpl-3.0
Telegram API JS (MTProto) client library for browser and nodejs

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mtproto Core

Grammers
(tele)gramme.rs - use Telegram's API from Rust
Stars: ✭ 109 (-54.96%)
Mutual labels:  api, telegram-api, library, telegram, mtproto
Pyrogram
Telegram MTProto API Client Library and Framework in Pure Python for Users and Bots
Stars: ✭ 2,252 (+830.58%)
Mutual labels:  telegram-api, library, telegram, mtproto, client
Novagram
An Object-Oriented PHP library for Telegram Bots
Stars: ✭ 112 (-53.72%)
Mutual labels:  api, telegram-api, telegram, mtproto
Telethon
Pure Python 3 MTProto API Telegram client library, for bots too!
Stars: ✭ 5,805 (+2298.76%)
Mutual labels:  telegram-api, library, telegram, mtproto
Mtproto
Full-native go implementation of Telegram API
Stars: ✭ 566 (+133.88%)
Mutual labels:  telegram-api, telegram, mtproto
Messenger4j
A Java library for building Chatbots on the Facebook Messenger Platform - easy and fast.
Stars: ✭ 199 (-17.77%)
Mutual labels:  api, library, messenger
Gitter Api
[production-ready] Gitter API implementation for php 7.0+ allowing sync, async and streaming access.
Stars: ✭ 11 (-95.45%)
Mutual labels:  api, library, client
Adrestia
APIs & SDK for interacting with Cardano.
Stars: ✭ 56 (-76.86%)
Mutual labels:  api, library, client
Telebot.nim
Async client for Telegram Bot API in pure Nim [Bot API 5.1]
Stars: ✭ 93 (-61.57%)
Mutual labels:  api, telegram, client
Telegram React
Experimental Telegram web client with tdlib, webassembly and react js under the hood
Stars: ✭ 1,332 (+450.41%)
Mutual labels:  telegram, messenger, mtproto
Madelineproto
Async PHP client/server API for the telegram MTProto protocol
Stars: ✭ 1,776 (+633.88%)
Mutual labels:  telegram-api, telegram, mtproto
Telegram Mtproto
Telegram client api (MTProto) library
Stars: ✭ 542 (+123.97%)
Mutual labels:  telegram-api, telegram, mtproto
Magento Chatbot
Magento Chatbot Integration with Telegram, Messenger, Whatsapp, WeChat, Skype and wit.ai.
Stars: ✭ 149 (-38.43%)
Mutual labels:  telegram-api, telegram, messenger
Telegramd
Unofficial open source telegram server written in golang
Stars: ✭ 609 (+151.65%)
Mutual labels:  telegram-api, telegram, mtproto
Libmqtt
MQTT v3.1.1/5.0 library in Go
Stars: ✭ 290 (+19.83%)
Mutual labels:  library, lib, client
Messenger
Package messenger is used for making bots for use with Facebook messenger
Stars: ✭ 278 (+14.88%)
Mutual labels:  api, messenger, client
Treact
📢 Telegram React application (TDLIB VERSION IS BEING WORKED ON!)
Stars: ✭ 110 (-54.55%)
Mutual labels:  telegram, messenger, client
Notion Js
🤯 Notion API
Stars: ✭ 136 (-43.8%)
Mutual labels:  api, lib, client
Deeply
PHP client for the DeepL.com translation API (unofficial)
Stars: ✭ 152 (-37.19%)
Mutual labels:  api, library, client
Aegis.cpp
Discord C++ library for interfacing with the API. Join our server:
Stars: ✭ 198 (-18.18%)
Mutual labels:  api, library

@mtproto/core

NPM GitHub Actions Downloads Telegram channel

Telegram API JS (MTProto) client library for browser and nodejs

Install

yarn add @mtproto/core -E
# or
npm i @mtproto/core -E

Quick start

You need api_id and api_hash. If you do not have them yet, then get them according to the official instructions: creating your Telegram application.

const { MTProto } = require('@mtproto/core');

const api_id = 'YOU_API_ID';
const api_hash = 'YOU_API_HASH';

// 1. Create an instance
const mtproto = new MTProto({
  api_id,
  api_hash,
});

// 2. Provide params for initConnection method (optional)
mtproto.updateInitConnectionParams({
  app_version: '10.0.0',
});

// 3. Get the user country code
mtproto.call('help.getNearestDc').then(result => {
  console.log(`country:`, result.country);
});

Guides

API

new MTProto({ api_id, api_hash, test, customLocalStorage }) => mtproto

api_id: number and api_hash: string

api_id and api_hash are required. If you do not have them yet, then get them according to the official instructions: creating your Telegram application.

test: boolean

Default: false. Use test data centers. On test servers, you can use test phone numbers.

customLocalStorage: localStorage

Default for browser: window.localStorage. Default for nodejs: node-localstorage. Custom storage for save auth data. Your localStorage must follow this API:

class MyAsyncLocalStorage {
  setItem(key: string, value: string): Promise<void>;
  getItem(key: string): Promise<string|null>;
}

We have ready-made storage:

  1. tempLocalStorage only stores data while the script is running

Example:

const { tempLocalStorage } = require('@mtproto/core/src/storage/temp');

const mtproto = new MTProto({
  customLocalStorage: tempLocalStorage,
});

mtproto.call(method, params, options) => Promise

method: string

Method name from methods list.

params: object

Parameters for method from https://core.telegram.org/method/{method}#parameters.

  1. If the method needs the flags parameter, flags is calculated automatically 🙃

  2. If you need to pass a constructor use _. Example for users.getFullUser:

const params = {
  id: {
    _: 'inputUserSelf',
  },
};

options.dcId: number

Specific DC id. By default, it is 2. You can change the default value using mtproto.setDefaultDc method.

options.syncAuth: boolean

Default: true. Copy authorization to all DC if the response contains auth.authorization.

Example:

mtproto.call('help.getNearestDc', {}, {
  dcId: 1
}).then(result => {
  console.log('result:', result);
  // { _: 'nearestDc', country: 'RU', this_dc: 1, nearest_dc: 2 }
}).catch(error => {
  console.log('error.error_code:', error.error_code);
  console.log('error.error_message:', error.error_message);
});

mtproto.updates.on(updates, listener)

Method for handles updates.

Example of handling a updateShort with updateUserStatus:

mtproto.updates.on('updateShort', message => {
  const { update } = message;

  if (update._ === 'updateUserStatus') {
    const { user_id, status } = update;

    console.log(`User with id ${user_id} change status to ${status}`);
  }
});

mtproto.setDefaultDc(dcId) => Promise

If a migration error occurs, you can use this function to change the default data center. You can also use options.dcId.

See the example in the authentication.

mtproto.updateInitConnectionParams(params)

Provide params for initConnection method. I recommend running this function immediately after creating an instance of MTProto.

See the example in the quick start.

getSRPParams({ g, p, salt1, salt2, gB, password }) => { A, M1 }

Function to calculate parameters for 2FA (Two-factor authentication). For more information about parameters, see the article on the Telegram website.

See the example in the authentication.

Useful references

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].