1 | # telegram-mtproto
|
2 |
|
3 | [![npm version][npm-image]][npm-url]
|
4 |
|
5 | **Telegram Mobile Protocol** [(MTProto)](https://core.telegram.org/mtproto) library in **es6**
|
6 |
|
7 | ## About MTProto..
|
8 |
|
9 | **MTProto** is the [Telegram Messenger](http://www.telegram.org ) protocol
|
10 | _"designed for access to a server API from applications running on mobile devices"_.
|
11 |
|
12 | The Mobile Protocol is subdivided into three components ([from the official site](https://core.telegram.org/mtproto#general-description)):
|
13 |
|
14 | - High-level component (API query language): defines the method whereby API
|
15 | queries and responses are converted to binary messages.
|
16 |
|
17 | - Cryptographic (authorization) layer: defines the method by which messages
|
18 | are encrypted prior to being transmitted through the transport protocol.
|
19 |
|
20 | - Transport component: defines the method for the client and the server to transmit
|
21 | messages over some other existing network protocol (such as, http, https, tcp, udp).
|
22 |
|
23 |
|
24 |
|
25 | ## telegram-mtproto in short..
|
26 |
|
27 | No more additional libs.
|
28 | The **telegram-mtproto** library implements the **Mobile Protocol** and provides all features for work with telegram protocol:
|
29 |
|
30 | - A high level api for server connection
|
31 |
|
32 | - Promise-based API
|
33 |
|
34 | - Both **TCP** and **HTTP connections** implemented in the transport layer
|
35 |
|
36 | - A cipher implementation for **AES and RSA encryption** in the security layer
|
37 |
|
38 | - Both **plain-text and encrypted message** to communicate data with the server
|
39 |
|
40 | - **Diffie-Hellman key exchange** supported by the **prime factorization** function implemented in the security layer
|
41 |
|
42 | - **MTProto TL-Schema** compilation as **javascript classes and functions**
|
43 |
|
44 | ## Usage
|
45 |
|
46 | ```javascript
|
47 | const { Telegram, network } = require('telegram-mtproto')
|
48 |
|
49 | const fileSchema = require('./api-schema-57.json')
|
50 |
|
51 | const telegram = new Telegram(fileSchema)
|
52 | const addKey = key => telegram.addPublicKey(key)
|
53 | publicKeys.forEach(addKey)
|
54 |
|
55 | const connection = new network.http(server)
|
56 | const client = telegram.createClient()
|
57 |
|
58 | client.setConnection(connection)
|
59 | connection.connect()
|
60 | .then(() => console.log(`api ready for requests`))
|
61 | .then(() => client.callApi('auth.sendCode', {
|
62 | phone_number : phone.num,
|
63 | current_number: false,
|
64 | api_id : config.id,
|
65 | api_hash : config.hash
|
66 | }).then(
|
67 | ({ phone_code_hash }) =>
|
68 | client.callApi('auth.signIn', {
|
69 | phone_number : phone.num,
|
70 | phone_code_hash: phone_code_hash,
|
71 | phone_code : phone.code
|
72 | }))
|
73 | ```
|
74 |
|
75 | ## Installation
|
76 |
|
77 | ```bash
|
78 | $ npm install --save telegram-mtproto
|
79 | ```
|
80 |
|
81 | ## API
|
82 |
|
83 | - **network**. Classes for network connection
|
84 |
|
85 | - **http**
|
86 |
|
87 | - **tcp**
|
88 |
|
89 | - **tl**. Telegram schema api
|
90 |
|
91 | - **Telegram**. High level api.
|
92 |
|
93 | - **createClient** *() => TelegramClient*
|
94 |
|
95 | ## License
|
96 |
|
97 | The project is released under the [Mit License](./LICENSE)
|
98 |
|
99 | [npm-url]: https://www.npmjs.org/package/telegram-mtproto
|
100 | [npm-image]: https://badge.fury.io/js/telegram-mtproto.svg |
\ | No newline at end of file |