Home Reference Source Repository
import {Telegram} from 'telegram-js/src/telegram.js'
public class | source

Telegram

Main Telegram class An instance of Telegram can be used to instantiate new clients that will perform the API calls

Constructor Summary

Public Constructor
public

constructor(MTProto: MTProto, TL: TL)

Member Summary

Public Members
public

schema: *

Method Summary

Public Methods
public
public

buffer2String(buffer: String, length: Number): String

Utility method: converts a buffer into a string in hexadecimal format

public

createAuthKey(authKeyId: String, authKeyBody: String): AuthKey

Create a new <span><a href="https://github.com/enricostara/telegram-mt-node/blob/master/lib/auth/auth-key.js">AuthKey</a></span> instance from a key id and a key payload.

public

Create a new client to interact with the API

public

Creates a random string of chars.

public

decryptKey(keyBuffer: Buffer, keyPassword: String): AuthKey

Decrypt an AuthKey buffer.

public

string2Buffer(string: String, length: Number): Buffer

Utility method: converts a string to a Buffer object

public

useSchema(schema: Object, typePrefix: String, servicePrefix: String)

Imports a schema structure into the library.

Public Constructors

public constructor(MTProto: MTProto, TL: TL) source

Params:

NameTypeAttributeDescription
MTProto MTProto

An object with the MTProto implementation

TL TL

An object with the Telegram's TypeLanguage implementation

Public Members

public schema: * source

Properties:

NameTypeAttributeDescription
schema Object

Public Methods

public addPublicKey(key: Object) source

Params:

NameTypeAttributeDescription
key Object

The key config to add on MtProto layer

Example:

  Telegram.addPublicKey({
    fingerprint: '0x123123...',
    modulus: '...',
    exponent: '010001'
  })

public buffer2String(buffer: String, length: Number): String source

Utility method: converts a buffer into a string in hexadecimal format

Params:

NameTypeAttributeDescription
buffer String
length Number

Return:

String

public createAuthKey(authKeyId: String, authKeyBody: String): AuthKey source

Create a new <span><a href="https://github.com/enricostara/telegram-mt-node/blob/master/lib/auth/auth-key.js">AuthKey</a></span> instance from a key id and a key payload. These two parameters are returned from a Telegram server during the key exchange.

Params:

NameTypeAttributeDescription
authKeyId String
authKeyBody String

Return:

AuthKey

public createClient(): TelegramClient source

Create a new client to interact with the API

Return:

TelegramClient

An instance of Telegram.Client

public createRandomPassword(size: Number): * source

Creates a random string of chars. You can use it to generate an AuthKey encryption password

Params:

NameTypeAttributeDescription
size Number
  • optional
  • default: 128

Return:

*

public decryptKey(keyBuffer: Buffer, keyPassword: String): AuthKey source

Decrypt an AuthKey buffer. This buffer is usually generated from an authKey

Params:

NameTypeAttributeDescription
keyBuffer Buffer
keyPassword String

Return:

AuthKey

Example:

var keyBuffer = authKey.encrypt('password');
var key = tg.decryptKey(keyBuffer, 'password');

public string2Buffer(string: String, length: Number): Buffer source

Utility method: converts a string to a Buffer object

Params:

NameTypeAttributeDescription
string String
length Number

Return:

Buffer

public useSchema(schema: Object, typePrefix: String, servicePrefix: String) source

Imports a schema structure into the library. The default Telegram API schema can be downloaded here: https://core.telegram.org/schema

The prefixes are added in front of all types and methods declared on schema, so after loading the schema you will access them like this:

Params:

NameTypeAttributeDescription
schema Object

An object with all the types and methods.

typePrefix String

A prefix to all the schema types

servicePrefix String

A prefix to all the schema methods

Example:

    // let's assume that your schema has a "foo.TypeFoo" type and a
    // "foo.callFoo" method
    Telegram.useSchema(schema, 'types', 'methods');

    let types = Telegram.schema.type;
    let methods = Telegram.schema.service;

    let TypeFoo = types.foo.TypeFoo;
    let callFoo = methods.foo.callFoo;