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

TelegramClient

Telegram Client class

Method Summary

Public Methods
public

Creates an authKey and setups an encrypted channel in the client with this new key.

public

callApi(apiMethod: String, args: Object): Promise

Entry method to all the API calls

public

Negotiates a new AuthKey with the server

public

createEncryptedChannel(authKey: Object, options: Object): *

Creates an encrypted channel with a previously created {AuthKey}

public

Creates a plain-text channel to make API calls.

public

Restores an encrypted channel in this client from a config object.

public

A channel to execute API calls.

public

setConnection(connection: Object)

Set the connection to be used as the transport for API calls in this client

public

setup(config: *): *

Top-level method to setup the client.

Public Methods

public authenticate(config: Object): Promise<TelegramClient> source

Creates an authKey and setups an encrypted channel in the client with this new key.

Params:

NameTypeAttributeDescription
config Object

Configuration passed in to the EncryptedRpcChannel

Return:

Promise<TelegramClient>

Returns back the client once it finishes the setup

public callApi(apiMethod: String, args: Object): Promise source

Entry method to all the API calls

Params:

NameTypeAttributeDescription
apiMethod String

A method to call in the API, e.g. auth.sendCode

args Object

The arguments, if any, to send with the API call

Return:

Promise

public createAuthKey(): Promise<AuthKey> source

Negotiates a new AuthKey with the server

Return:

Promise<AuthKey>

public createEncryptedChannel(authKey: Object, options: Object): * source

Creates an encrypted channel with a previously created {AuthKey}

Params:

NameTypeAttributeDescription
authKey Object
options Object

Configuration passed to the EncryptedRpcChannel

Return:

*

Return Properties:

NameTypeAttributeDescription
authKey.key String
authKey.serverSalt String

public createUnencryptedChannel(): * source

Creates a plain-text channel to make API calls. Used on the initial calls to create an authentication key

Return:

*

public restoreFromConfig(config: Object) source

Restores an encrypted channel in this client from a config object. A previously created AuthKey must be present in the config.

Params:

NameTypeAttributeDescription
config Object

Configuration passed in to the EncryptedRpcChannel

public setChannel(channel: RcpChannel | EncryptedRpcChannel) source

A channel to execute API calls. Usually created through one of these methods:

Client#createUnencryptedChannel Client#createEncryptedChannel

Params:

NameTypeAttributeDescription
channel RcpChannel | EncryptedRpcChannel

public setConnection(connection: Object) source

Set the connection to be used as the transport for API calls in this client

Params:

NameTypeAttributeDescription
connection Object

public setup(config: *): * source

Top-level method to setup the client. Give it a configuration and the client will handle the creation of an encrypted channel.

Don't forget to set a connection in the client before starting the setup!

Params:

NameTypeAttributeDescription
config *

Return:

*