From 47c06fdae2cea91a033b491b769061160e84ccfa Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Thu, 23 May 2019 18:59:29 +0200
Subject: [PATCH] Docs revamp. Part 7
---
README.md | 9 -
docs/source/_images/logo.png | Bin 13344 -> 0 bytes
docs/source/api/client.rst | 2 +-
docs/source/api/decorators.rst | 2 +
docs/source/conf.py | 214 ++++--------------
docs/source/{meta => }/faq.rst | 104 +++++----
docs/source/{meta => }/glossary.rst | 22 +-
docs/source/index.rst | 68 +++---
docs/source/intro/install.rst | 4 +-
docs/source/intro/setup.rst | 2 +-
docs/source/meta/support-pyrogram.rst | 2 -
docs/source/{meta => }/powered-by.rst | 4 +-
docs/source/{meta => }/releases.rst | 0
docs/source/start/auth.rst | 4 +-
docs/source/support-pyrogram.rst | 26 +++
docs/source/topics/mtproto-vs-botapi.rst | 106 ++++++---
docs/source/topics/serialize.rst | 55 +++++
docs/source/topics/session-settings.rst | 2 +-
docs/source/topics/tgcrypto.rst | 4 +-
pyrogram/client/client.py | 8 +-
.../types/messages_and_media/message.py | 2 +-
setup.py | 1 +
22 files changed, 327 insertions(+), 314 deletions(-)
delete mode 100644 docs/source/_images/logo.png
rename docs/source/{meta => }/faq.rst (76%)
rename docs/source/{meta => }/glossary.rst (83%)
delete mode 100644 docs/source/meta/support-pyrogram.rst
rename docs/source/{meta => }/powered-by.rst (95%)
rename docs/source/{meta => }/releases.rst (100%)
create mode 100644 docs/source/support-pyrogram.rst
create mode 100644 docs/source/topics/serialize.rst
diff --git a/README.md b/README.md
index 017b513b..4e758b5a 100644
--- a/README.md
+++ b/README.md
@@ -16,15 +16,6 @@
Community
-
-
-
-
-
-
-
ZFdb
z-2V19DXF_{Ym2n{ ?d;TtKJvnD<7JTo4z;bTN-W(hOb_I70YbN>Q0o2o82if7pS8*kBiN!x-FsqI2>I5
zTnLdrnzE?O^=AJxja&~q^5B{mdUcY5O6c*JovtST0sr3dE*sFSCNE6t-gMgF*>_da
z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Q|8
zo7UX!q8vVY>0AC|kGSirYZuMWD|F?K9|
=70;D40i~-{rY5+oN)_2o7&vHLv<>Jn9rS(L}X-NUd*x-=J&0FtX3_~
zJc|Yi<-|-6@GsmD|E!OTX1U!bxkmJu9zDqk0c^8r=$*^^@9%cwAU-6Uf1zXuW~UpM
z2#N08Vs&e*<^|xjO!~r6S<3tz%49BAA+{NgsIp|s4z)6Q=3u)es0dnd^58AO0teI=
zdLm;q+v~NfUs#CUN#G&))iYrrBWvEEp5zFdO)ZAHb3JrWh!Bq8l}%Zc`|gMA@Gta}
zq5xBdsko;fIEx
+
+Donate
+------
+
+If you'd also like to donate in order to support Pyrogram -- or any of my `other works`_ -- you can use the PayPal
+button below. Thank you.
+
+.. image:: https://i.imgur.com/fasFTzK.png
+ :target: https://paypal.me/delivrance
+ :width: 128
+
+--- `Dan`_
+
+.. _Star on GitHub: https://github.com/pyrogram/pyrogram
+.. _other works: https://github.com/delivrance
+.. _Dan: https://t.me/haskell
diff --git a/docs/source/topics/mtproto-vs-botapi.rst b/docs/source/topics/mtproto-vs-botapi.rst
index accebcd5..cad84251 100644
--- a/docs/source/topics/mtproto-vs-botapi.rst
+++ b/docs/source/topics/mtproto-vs-botapi.rst
@@ -1,58 +1,110 @@
MTProto vs. Bot API
===================
-Being Pyrogram an MTProto-based library, this very feature makes it already superior to, what is usually called, the
-official Bot API.
+Pyrogram is a framework that acts as a fully-fledged Telegram client based on MTProto, and this very feature makes it
+already superior to, what is usually called, the official Bot API, in many respects. This page will therefore show you
+why Pyrogram might be a better choice for your project by comparing the two APIs, but first, let's make it clear what
+actually is the MTProto and the Bot API.
What is the MTProto API?
------------------------
-MTProto, took alone, is the name of the custom-made, open and encrypted communication protocol created by Telegram
-itself --- it's the only protocol used to exchange information between a client application and the actual Telegram
-servers.
+`MTProto`_, took alone, is the name of the custom-made, open and encrypted communication protocol created by Telegram
+itself --- it's the only protocol used to exchange information between a client and the actual Telegram servers.
-The MTProto **API** however, is what people, for convenience, call the main Telegram API as a whole. This API is able
-to authorize both users and bots and happens to be built on top of the MTProto encryption protocol by means of binary
-data serialized in a specific way, as described by the TL language, hence the correlation.
+The MTProto **API** on the other hand, is what people, for convenience, call the main Telegram API as a whole. This API
+is able to authorize both users and bots and is built on top of the MTProto encryption protocol by means of
+`binary data serialized`_ in a specific way, as described by the `TL language`_, and delivered using UDP, TCP or even
+HTTP as transport-layer protocol.
+
+.. _MTProto: https://core.telegram.org/mtproto
+.. _binary data serialized: https://core.telegram.org/mtproto/serialize
+.. _TL language: https://core.telegram.org/mtproto/TL
What is the Bot API?
--------------------
-The Bot API is an HTTP(S) interface for building normal bots. Bots are special accounts that are authorized via tokens
-instead of phone numbers. The Bot API is built yet again on top of the main Telegram API, but runs on an intermediate
-server application that in turn communicates with the actual Telegram servers using MTProto.
+The `Bot API`_ is an HTTP(S) interface for building normal bots using a sub-set of the main MTProto API. Bots are special
+accounts that are authorized via tokens instead of phone numbers. The Bot API is built yet again on top of the main
+Telegram API, but runs on an intermediate server application that in turn communicates with the actual Telegram servers
+using MTProto.
.. figure:: https://i.imgur.com/C108qkX.png
:align: center
+.. _Bot API: https://core.telegram.org/bots/api
+
Advantages of the MTProto API
-----------------------------
-Here is a list of all the known advantages in using MTProto-based libraries (such as Pyrogram) instead of the official
+Here is a list of all the advantages in using MTProto-based libraries -- such as Pyrogram -- instead of the official
HTTP Bot API. Using Pyrogram you can:
-- **Authorize both user and bot identities**: The Bot API only allows bot accounts.
+.. hlist::
+ :columns: 1
-- **Upload & download any file, up to 1500 MB each (~1.5 GB)**: The Bot API allows uploads and downloads of files only
- up to 50 MB / 20 MB in size (respectively).
+ - :guilabel:`+` **Authorize both user and bot identities**
+ - :guilabel:`--` The Bot API only allows bot accounts
-- **Has less overhead due to direct connections to Telegram**: The Bot API uses an intermediate server to handle HTTP
- requests before they are sent to the actual Telegram servers.
+.. hlist::
+ :columns: 1
-- **Run multiple sessions at once, up to 10 per account (either bot or user)**: The Bot API intermediate server will
- terminate any other session in case you try to use the same bot again in a parallel connection.
+ - :guilabel:`+` **Upload & download any file, up to 1500 MB each (~1.5 GB)**
+ - :guilabel:`--` The Bot API allows uploads and downloads of files only up to 50 MB / 20 MB in size (respectively).
-- **Get information about any public chat by usernames, even if not a member**: The Bot API simply doesn't support this.
+.. hlist::
+ :columns: 1
-- **Obtain information about any message existing in a chat using their ids**: The Bot API simply doesn't support this.
+ - :guilabel:`+` **Has less overhead due to direct connections to Telegram**
+ - :guilabel:`--` The Bot API uses an intermediate server to handle HTTP requests before they are sent to the actual
+ Telegram servers.
-- **Retrieve the whole chat members list of either public or private chats**: The Bot API simply doesn't support this.
+.. hlist::
+ :columns: 1
-- **Receive extra updates, such as the one about a user name change**: The Bot API simply doesn't support this.
+ - :guilabel:`+` **Run multiple sessions at once, up to 10 per account (either bot or user)**
+ - :guilabel:`--` The Bot API intermediate server will terminate any other session in case you try to use the same
+ bot again in a parallel connection.
-- **Has more meaningful errors in case something went wrong**: The Bot API reports less detailed errors.
+.. hlist::
+ :columns: 1
-- **Has much more detailed types and powerful methods**: The Bot API types often miss some useful information about
- Telegram's type and some of the methods are limited as well.
+ - :guilabel:`+` **Has much more detailed types and powerful methods**
+ - :guilabel:`--` The Bot API types often miss some useful information about Telegram entities and some of the
+ methods are limited as well.
-- **Get API version updates, and thus new features, sooner**: The Bot API is simply slower in implementing new features.
\ No newline at end of file
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Get information about any public chat by usernames, even if not a member**
+ - :guilabel:`--` The Bot API simply doesn't support this
+
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Obtain information about any message existing in a chat using their ids**
+ - :guilabel:`--` The Bot API simply doesn't support this
+
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Retrieve the whole chat members list of either public or private chats**
+ - :guilabel:`--` The Bot API simply doesn't support this
+
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Receive extra updates, such as the one about a user name change**
+ - :guilabel:`--` The Bot API simply doesn't support this
+
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Has more meaningful errors in case something went wrong**
+ - :guilabel:`--` The Bot API reports less detailed errors
+
+.. hlist::
+ :columns: 1
+
+ - :guilabel:`+` **Get API version updates, and thus new features, sooner**
+ - :guilabel:`--` The Bot API is simply slower in implementing new features
diff --git a/docs/source/topics/serialize.rst b/docs/source/topics/serialize.rst
new file mode 100644
index 00000000..32208199
--- /dev/null
+++ b/docs/source/topics/serialize.rst
@@ -0,0 +1,55 @@
+Object Serialization
+====================
+
+Serializing means converting a Pyrogram object, which exists as Python class instance, to a text string that can be
+easily shared and stored anywhere. Pyrogram provides two formats for serializing its objects: one good looking for
+humans and another more compact for machines that is able to recover the original structures.
+
+For Humans - str(obj)
+---------------------
+
+If you want a nicely formatted, human readable JSON representation of any object in the API -- namely, any object from
+`Pyrogram types`_, `raw functions`_ and `raw types`_ -- you can use use ``str(obj)``.
+
+.. code-block:: python
+
+ ...
+
+ with app:
+ r = app.get_chat("haskell")
+
+ print(str(r))
+
+.. tip::
+
+ When using ``print()`` you don't actually need to use ``str()`` on the object because it is called automatically, we
+ have done that above just to show you how to explicitly convert a Pyrogram object to JSON.
+
+.. _Pyrogram types: ../api/types
+.. _raw functions: ../telegram/functions
+.. _raw types: ../telegram/types
+
+For Machines - repr(obj)
+------------------------
+
+If you want to share or store objects for future references in a more compact way, you can use ``repr(obj)``. While
+still pretty much readable, this format is not intended for humans. The advantage of this format is that once you
+serialize your object, you can use ``eval()`` to get back the original structure; just make sure to ``import pyrogram``,
+as the process requires the package to be in scope.
+
+.. code-block:: python
+
+ import pyrogram
+
+ ...
+
+ with app:
+ r = app.get_chat("haskell")
+
+ print(repr(r))
+ print(eval(repr(r)) == r) # True
+
+.. note::
+
+ Type definitions are subject to changes between versions. You should make sure to store and load objects using the
+ same Pyrogram version.
\ No newline at end of file
diff --git a/docs/source/topics/session-settings.rst b/docs/source/topics/session-settings.rst
index c8e10479..91e3f050 100644
--- a/docs/source/topics/session-settings.rst
+++ b/docs/source/topics/session-settings.rst
@@ -9,7 +9,7 @@ app (or by invoking `GetAuthorizations <../telegram/functions/account/GetAuthori
store some useful information such as the client who's using them and from which country and IP address.
.. figure:: https://i.imgur.com/YaqtMLO.png
- :width: 90%
+ :width: 600
:align: center
**A Pyrogram session running on Linux, Python 3.7.**
diff --git a/docs/source/topics/tgcrypto.rst b/docs/source/topics/tgcrypto.rst
index 2af09a06..454bf05c 100644
--- a/docs/source/topics/tgcrypto.rst
+++ b/docs/source/topics/tgcrypto.rst
@@ -2,7 +2,7 @@ Fast Crypto
===========
Pyrogram's speed can be *dramatically* boosted up by TgCrypto_, a high-performance, easy-to-install Telegram Crypto
-Library specifically written in C for Pyrogram [#f1]_ as a Python extension.
+Library specifically written in C for Pyrogram [1]_ as a Python extension.
TgCrypto is a replacement for the much slower PyAES and implements the crypto algorithms Telegram requires, namely
**AES-IGE 256 bit** (used in MTProto v2.0) and **AES-CTR 256 bit** (used for CDN encrypted files).
@@ -28,5 +28,5 @@ what you should do next:
.. _TgCrypto: https://github.com/pyrogram/tgcrypto
-.. [#f1] Although TgCrypto is intended for Pyrogram, it is shipped as a standalone package and can thus be used for
+.. [1] Although TgCrypto is intended for Pyrogram, it is shipped as a standalone package and can thus be used for
other Python projects too.
diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py
index 1cfa7c79..8c1e3001 100644
--- a/pyrogram/client/client.py
+++ b/pyrogram/client/client.py
@@ -66,15 +66,13 @@ class Client(Methods, BaseClient):
session_name (``str``):
Name to uniquely identify a session of either a User or a Bot, e.g.: "my_account". This name will be used
to save a file to disk that stores details needed for reconnecting without asking again for credentials.
- Note for bots: You can pass a bot token here, but this usage will be deprecated in next releases.
- Use *bot_token* instead.
api_id (``int``, *optional*):
The *api_id* part of your Telegram API Key, as integer. E.g.: 12345
This is an alternative way to pass it if you don't want to use the *config.ini* file.
api_hash (``str``, *optional*):
- The *api_hash* part of your Telegram API Key, as string. E.g.: "0123456789abcdef0123456789abcdef"
+ The *api_hash* part of your Telegram API Key, as string. E.g.: "0123456789abcdef0123456789abcdef".
This is an alternative way to pass it if you don't want to use the *config.ini* file.
app_version (``str``, *optional*):
@@ -104,7 +102,7 @@ class Client(Methods, BaseClient):
This is an alternative way to setup a proxy if you don't want to use the *config.ini* file.
test_mode (``bool``, *optional*):
- Enable or disable log-in to testing servers. Defaults to False.
+ Enable or disable login to the test servers. Defaults to False.
Only applicable for new sessions and will be ignored in case previously
created sessions are loaded.
@@ -170,7 +168,7 @@ class Client(Methods, BaseClient):
Defaults to False (updates enabled and always received).
takeout (``bool``, *optional*):
- Pass True to let the client use a takeout session instead of a normal one, implies no_updates.
+ Pass True to let the client use a takeout session instead of a normal one, implies *no_updates=True*.
Useful for exporting your Telegram data. Methods invoked inside a takeout session (such as get_history,
download_media, ...) are less prone to throw FloodWait exceptions.
Only available for users, bots will ignore this parameter.
diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py
index e51f3425..09cb9ca3 100644
--- a/pyrogram/client/types/messages_and_media/message.py
+++ b/pyrogram/client/types/messages_and_media/message.py
@@ -2928,7 +2928,7 @@ class Message(PyrogramType, Update):
True on success.
Raises:
- :class:`RPCError