TelegramClient
com.github.badoualy.telegram.api.TelegramClient
Easy life :)
The client will handle most of the things for you:
- Create an authorization key
- Init the connection with app's info
- Ensure datacenter choice
- PHONE_MIGRATE_X and FILE_MIGRATE_X errors
- Easy download of files
- ...
To create a new instance, use Kotlogram.getDefaultClient() method.
Execute a method
TelegramClient implements the TelegramApi interface for more convenience, you have 1 java method for each method of Telegram's API.
You can also call executeRpcQuery manually, and specify a dcId where to execute the method if you have to.
Queue a method
For more convenience, you can use the method queueMethodImmediate that is the same as MTProtoHandler's queueMethod but it'll subscribe automatically.
Get a downloader client
To avoid blocking your main client when uploading/downloading a file, it's strongly advised to use another connection, to do so, just use getDownloaderClient() to get a new instance of a client for the same account.
Download a user's photo
client.getUserPhoto(user);
Download a chat's photo
client.getChatPhoto(chat);
Download a channel's photo
client.getChannelPhoto(channel);
Download a file
client.downloadSync(inputLocation, size, partSize, outputStream);
inputLocationis an internal class of the library, it just contains aTLAbsInputFileLocationand the targetdcIdto know where to download the file.sizeis the size in bytes of the file to download.partSizeoptional parameter specifying the size of each parts to download (default is 512 KB)outputStreamstream to write in. A call toflushis made every 5 parts downloaded. This stream can be aByteArrayOutputStream,FileOutputStreamor whatever you'd like :)
Close client
client.close();
Or, if you're have multiple clients running, or you plan to open a new one
client.close(false);
Updated less than a minute ago