Skip to content

Releases: LonamiWebs/Telethon

Several requests at once and upload compression

27 Sep 11:57
Compare
Choose a tag to compare

New major release, since I've decided that these two features are big enough:

  • Requests larger than 512 bytes will be compressed through gzip, and if the result is smaller, this will be uploaded instead.
  • You can now send multiple requests at once, they're simply *var_args on the .invoke(). Note that the server doesn't guarantee the order in which they'll be executed!

Internally, another important change. The .on_send function on the TLObjects is gone, and now there's a new .to_bytes(). From my tests, this has always been over twice as fast serializing objects, although more replacements need to be done, so please report any issues.

Besides this:

  • Downloading media from CDNs wasn't working (wrong access to a parameter).
  • Correct type hinting.
  • Added a tiny sleep when trying to perform automatic reconnection.
  • Error reporting is done in the background, and has a shorter timeout.
  • Implemented .get_input_media helper methods. Now you can even use another message as input media!
  • setup.py used to fail with wrongly generated code.

Quick fix-up

23 Sep 09:51
Compare
Choose a tag to compare
Quick fix-up Pre-release
Pre-release

Before getting any further, here's a quick fix-up with things that should have been on v0.13.5 but were missed. Specifically, the timeout when receiving a request will now work properly.

Some other additions are a tiny fix when handling updates, which was ignoring some of them, nicer __str__ and .stringify() methods for the TLObject's, and not stopping the ReadThread if you try invoking something there (now it simply returns None).

Attempts at more stability

23 Sep 09:48
Compare
Choose a tag to compare
Pre-release

Yet another update to fix some bugs and increase the stability of the library, or, at least, that was the attempt!

This release should really improve the experience with the background thread that the library starts to read things from the network as soon as it can, but I can't spot every use case, so please report any bug (and as always, minimal reproducible use cases will help a lot).

Bug fixes

  • setup.py was failing on Python < 3.5 due to some imports.
  • Duplicated updates should now be ignored.
  • .send_message would crash in some cases, due to having a typo using the wrong object.
  • "socket is None" when calling .connect() should not happen anymore.
  • BrokenPipeError was still being raised due to an incorrect order on the try/except block.

Enhancements

  • Type hinting for all the generated Request's and TLObjects! IDEs like PyCharm will benefit from this.
  • ProxyConnectionError should properly be passed to the main thread for you to handle.
  • The background thread will only be started after you're authorized on Telegram (i.e. logged in), and several other attempts at polishing the experience with this thread.
  • The Connection instance is only created once now, and reused later.
  • Calling .connect() should have a better behavior now (like actually trying to connect even if we seemingly were connected already).
  • .reconnect() behavior has been changed to also be more consistent by making the assumption that we'll only reconnect if the server has disconnected us, and is now private.

Other changes

  • TLObject.__repr__ doesn't show the original TL definition anymore, it was a lot of clutter. If you have any complaints open an issue and we can discuss it.
  • Internally, the '+' from the phone number is now stripped, since it shouldn't be included.
  • Spotted a new place where BrokenAuthKeyError would be raised, and it now is raised there.

More bug fixes and enhancements

18 Sep 11:42
Compare
Choose a tag to compare
Pre-release

New stuff:

  • TelegramClient now exposes a .is_connected() method.
  • Initial authorization on a new data center will retry up to 5 times by default.
  • Errors that couldn't be handled on the background thread will be raised on the next call to .invoke() or updates.poll().

Bugs fixed:

  • Now you should be able to sign in even if you have process_updates=True and no previous session.
  • Some errors and methods are documented a bit clearer.
  • .send_message() could randomly fail, as the returned type was not expected.

Things that should reduce the amount of crashes:

  • TimeoutError is now ignored, since the request will be retried up to 5 times by default.
  • "-404" errors (BrokenAuthKeyError's) are now detected when first connecting to a new data center.
  • BufferError is handled more gracefully, in the same way as InvalidCheckSumError's.
  • Attempt at fixing some "NoneType has no attribute…" errors (with the .sender).

Other internal changes:

  • Calling GetConfigRequest is now made less often.
  • The initial_query parameter from .connect() is gone, as it's not needed anymore.
  • Renamed all_tlobjects.layer to all_tlobjects.LAYER (since it's a constant).
  • The message from BufferError is now more useful.

Bug fixes and enhancements

14 Sep 09:53
Compare
Choose a tag to compare
Pre-release

Bugs fixed

  • Reconnection used to fail because it tried invoking things from the ReadThread.
  • Inferring random ids for ForwardMessagesRequest wasn't working.
  • Downloading media from CDNs failed due to having forgotten to remove a single line.
  • TcpClient.close() now has a threading.Lock, so NoneType has no close() should not happen.
  • New workaround for msg seqno too low/high. Also, both Session.id/seq are not saved anymore.

Enhancements

  • Request will be retried up to 5 times by default rather than failing on the first attempt.
  • InvalidChecksumError's are now ignored by the library.
  • TelegramClient.get_entity() is now public, and uses the @lru_cache() decorator.
  • New method to .send_voice_note()'s.
  • Methods to send message and media now support a reply_to parameter.
  • .send_message() now returns the full message which was just sent.

New way to work with updates

08 Sep 16:46
Compare
Choose a tag to compare
Pre-release

This update brings a new way to work with updates, and it's begging for your feedback, or better names or ways to do what you can do now.

Please refer to the wiki/Usage Modes for an in-depth description on how to work with updates now. Notice that you cannot invoke requests from within handlers anymore, only the v.0.13.1 patch allowed you to do so.

Other fixes:

  • Periodic pings are back.
  • The username regex mentioned on UsernameInvalidError was invalid, but it has now been fixed.
  • Sending a message to a phone number was failing because the type used for a request had changed on layer 71.
  • CDN downloads weren't working properly, and now a few patches have been applied to ensure more reliability, although I couldn't personally test this, so again, report any feedback.

Invoke other requests from within update callbacks

04 Sep 18:38
Compare
Choose a tag to compare

Please read, unless you don't handle updates in any way.

A silly "bug" which hadn't been spotted has now been fixed. Now you can invoke other requests from within your update callbacks. However this is not advised. You should post these updates to some other thread, and let that thread do the job instead. Invoking a request from within a callback will mean that, while this request is being invoked, no other things will be read.

Internally, the generated code now resides under a lot less files, simply for the sake of avoiding so many unnecessary files. The generated code is not meant to be read by anyone, simply to do its job.

Unused attributes have been removed from the TLObject class too, and .sign_up() returns the user that just logged in in a similar way to .sign_in() now.

Connection modes

04 Sep 10:33
Compare
Choose a tag to compare
Connection modes Pre-release
Pre-release
Scheme layer used: 71

The purpose of this release is to denote a big change, now you can connect to Telegram through different connection modes. Also, a second thread will always be started when you connect a TelegramClient, despite whether you'll be handling updates or ignoring them, whose sole purpose is to constantly read from the network.

The reason for this change is as simple as "reading and writing shouldn't be related". Even when you're simply ignoring updates, this way, once you send a request you will only need to read the result for the request. Whatever Telegram sent before has already been read and outside the buffer.

Additions

  • The mentioned different connection modes, and a new thread.
  • You can modify the Session attributes through the TelegramClient constructor (using **kwargs).
  • RPCError's now belong to some request you've made, which makes more sense.
  • get_input_* now handles None (default) parameters more gracefully (it used to crash).

Enhancements

  • The low-level socket doesn't use a handcrafted timeout anymore, which should benefit by avoiding the arbitrary sleep(0.1) that there used to be.
  • TelegramClient.sign_in will call .send_code_request if no code was provided.

Deprecation:

  • .sign_up does not take a phone argument anymore. Change this or you will be using phone as code, and it will fail! The definition looks like def sign_up(self, code, first_name, last_name='').
  • The old JsonSession finally replaces the original Session (which used pickle). If you were overriding any of these, you should only worry about overriding Session now.

Added verification for CDN file

28 Aug 15:33
Compare
Choose a tag to compare
Pre-release

Since the Content Distributed Network (CDN) is not handled by Telegram itself, the owners may tamper these files. Telegram sends their sha256 sum for clients to implement this additional verification step, which now the library has. If any CDN has altered the file you're trying to download, CdnFileTamperedError will be raised to let you know.

Besides this. TLObject.stringify() was showing bytes as lists (now fixed) and RPC errors are reported by default:

In an attempt to help everyone who works with the Telegram API, Telethon will by default report all Remote Procedure Call errors to PWRTelegram, a public database anyone can query, made by Daniil. All the information sent is a GET request with the error code, error message and method used.

If you still would like to opt out, simply set client.session.report_errors = False to disable this feature. However Daniil would really thank you if you helped him (and everyone) by keeping it on!

CDN support

24 Aug 17:26
Compare
Choose a tag to compare
CDN support Pre-release
Pre-release

The biggest news for this update are that downloading media from CDN's (you'll often encounter this when working with popular channels) now works.

Some bug fixes:

  • The method used to download documents crashed because two lines were swapped.
  • Determining the right path when downloading any file was very weird, now it's been enhanced.
  • The .sign_in() method didn't support integer values for the code! Now it does again.

Some important internal changes are that the old way to deal with RSA public keys now uses a different module instead the old strange hand-crafted version.

Hope the new, super simple README.rst encourages people to use Telethon and make it better with either suggestions, or pull request. Pull requests are super appreciated, but showing some support by leaving a star also feels nice ⭐️