mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2026-09-05 16:40:42 +00:00
Several updates, fixes and additions (TcpClient, MtProto...)
README.md was updated to reflect more useful information More errors from the official Telegrm website have been added MtProtoSender now handles updates (and doesn't crash!) Fixes on TcpClient to be able to receive whole large packets Updated scheme.tl to the layer 55 Session is now saved more often (to prevent damages from crashes) Fixes to the code generator (generated invalid code for reading "bytes")
This commit is contained in:
@@ -15,6 +15,34 @@ Also, you need to obtain your both [API ID and Hash](my.telegram.org). Once you
|
||||
the `settings_example` file, naming it `settings` (lowercase!). Then fill the file with the corresponding values (your `api_id`,
|
||||
`api_hash` and phone number in international format). Now it is when you're ready to go!
|
||||
|
||||
### How to add more functions to TelegramClient
|
||||
As of now, you cannot call any Telegram function unless you first write it by hand under `tl/telegram_client.py`. Why?
|
||||
Every Telegram function (or _request_) work in its own way. In some, you may only be interested in a single result field,
|
||||
and in others you may need to format the result in a different way. However, a plan for the future is to be able to call
|
||||
any function by giving its `namespace.name` and passing the arguments. But until that happens, to add a new function do:
|
||||
|
||||
1. Have a look under `tl/functions/` and find the `Request` that suits your needs.
|
||||
2. Have a look inside that `Request` you chose, and find what arguments and in what order you'll need to call it.
|
||||
3. Import it in `tl/telegram_client.py` by using `from tl.functions import SomeTelegramRequest`.
|
||||
4. Add a new method, or function, that looks as follows:
|
||||
```python
|
||||
def my_function(self, my_arguments):
|
||||
request = SomeTelegramRequest(my_arguments)
|
||||
|
||||
self.sender.send(request)
|
||||
self.sender.receive(request)
|
||||
|
||||
return request.result
|
||||
```
|
||||
5. To determine how the result will look like, simply look at the original `.tl` definition. After the `=`,
|
||||
you will see the type. Let's see an example:
|
||||
`stickerPack#12b299d4 emoticon:string documents:Vector<long> = StickerPack;`
|
||||
As it turns out, the result is going to be an `StickerPack`. Without a second doubt, head into `tl/types/` and find it;
|
||||
open the file and see what the result will look like. Alternatively, you can simply `print(str(request.result))`!
|
||||
|
||||
Be warned that there may be more than one different type on the results. This is due to Telegram's polymorphism,
|
||||
for example, a message may or not be empty, etc.
|
||||
|
||||
### Plans for the future
|
||||
If everything works well, this probably ends up being a Python package :)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user