{"_id":"57e386464d659c0e0006e909","parentDoc":null,"__v":0,"category":{"_id":"57e0f14b8929550e00f1d9bc","__v":0,"version":"5703d527bb69fc1700553ce3","project":"5703d527bb69fc1700553ce0","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-09-20T08:20:27.114Z","from_sync":false,"order":4,"slug":"api-module","title":"Api module"},"githubsync":"","user":"5631f962c3b04b0d00ba9bf1","version":{"_id":"5703d527bb69fc1700553ce3","hasDoc":true,"__v":6,"hasReference":true,"project":"5703d527bb69fc1700553ce0","createdAt":"2016-04-05T15:09:27.620Z","releaseDate":"2016-04-05T15:09:27.620Z","categories":["5703d527bb69fc1700553ce4","5703d8b7aceacc17003ef303","5703e60b6116142000db25f6","57e0db616a1c2e0e0081fe64","57e0f141ff540c22007b45fa","57e0f14b8929550e00f1d9bc"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.6","version":"0.0.6"},"project":"5703d527bb69fc1700553ce0","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-22T07:20:38.939Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The client will handle most of the things for you:\\n- Create an authorization key\\n- Init the connection with app's info\\n- Ensure datacenter choice\\n- PHONE_MIGRATE_X and FILE_MIGRATE_X errors\\n- Easy download of files\\n- ...\",\n  \"title\": \"Easy life :)\"\n}\n[/block]\nTo create a new instance, use `Kotlogram.getDefaultClient()` method.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Execute a method\"\n}\n[/block]\n`TelegramClient` implements the `TelegramApi` interface for more convenience, you have 1 java method for each method of Telegram's API.\nYou can also call `executeRpcQuery` manually, and specify a `dcId` where to execute the method if you have to.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Queue a method\"\n}\n[/block]\nFor more convenience, you can use the method `queueMethodImmediate` that is the same as `MTProtoHandler`'s `queueMethod` but it'll subscribe automatically.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Get a downloader client\"\n}\n[/block]\nTo 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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Download a user's photo\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.getUserPhoto(user);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Download a chat's photo\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.getChatPhoto(chat);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Download a channel's photo\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.getChannelPhoto(channel);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Download a file\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.downloadSync(inputLocation, size, partSize, outputStream);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n- `inputLocation` is an internal class of the library, it just contains a `TLAbsInputFileLocation` and the target `dcId` to know where to download the file.\n- `size` is the size in bytes of the file to download.\n- `partSize` **optional** parameter specifying the size of each parts to download (default is 512 KB)\n- `outputStream` stream to write in. A call to `flush` is made every **5 parts** downloaded. This stream can be a `ByteArrayOutputStream`, `FileOutputStream` or whatever you'd like :)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Close client\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.close();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nOr, if you're have multiple clients running, or you plan to open a new one\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"client.close(false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"com.github.badoualy.telegram.api.TelegramClient","slug":"telegramclient","type":"basic","title":"TelegramClient"}

TelegramClient

com.github.badoualy.telegram.api.TelegramClient

[block:callout] { "type": "info", "body": "The client will handle most of the things for you:\n- Create an authorization key\n- Init the connection with app's info\n- Ensure datacenter choice\n- PHONE_MIGRATE_X and FILE_MIGRATE_X errors\n- Easy download of files\n- ...", "title": "Easy life :)" } [/block] To create a new instance, use `Kotlogram.getDefaultClient()` method. [block:api-header] { "type": "basic", "title": "Execute a method" } [/block] `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. [block:api-header] { "type": "basic", "title": "Queue a method" } [/block] For more convenience, you can use the method `queueMethodImmediate` that is the same as `MTProtoHandler`'s `queueMethod` but it'll subscribe automatically. [block:api-header] { "type": "basic", "title": "Get a downloader client" } [/block] 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. [block:api-header] { "type": "basic", "title": "Download a user's photo" } [/block] [block:code] { "codes": [ { "code": "client.getUserPhoto(user);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Download a chat's photo" } [/block] [block:code] { "codes": [ { "code": "client.getChatPhoto(chat);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Download a channel's photo" } [/block] [block:code] { "codes": [ { "code": "client.getChannelPhoto(channel);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Download a file" } [/block] [block:code] { "codes": [ { "code": "client.downloadSync(inputLocation, size, partSize, outputStream);", "language": "java" } ] } [/block] - `inputLocation` is an internal class of the library, it just contains a `TLAbsInputFileLocation` and the target `dcId` to know where to download the file. - `size` is the size in bytes of the file to download. - `partSize` **optional** parameter specifying the size of each parts to download (default is 512 KB) - `outputStream` stream to write in. A call to `flush` is made every **5 parts** downloaded. This stream can be a `ByteArrayOutputStream`, `FileOutputStream` or whatever you'd like :) [block:api-header] { "type": "basic", "title": "Close client" } [/block] [block:code] { "codes": [ { "code": "client.close();", "language": "java" } ] } [/block] Or, if you're have multiple clients running, or you plan to open a new one [block:code] { "codes": [ { "code": "client.close(false);", "language": "java" } ] } [/block]