diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 494697de..73b5a578 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -77,7 +77,8 @@ def generate(source_path, base): build(source_path) - for k, v in all_entities.items(): + for k, v in sorted(all_entities.items()): + v = sorted(v) entities = [] for i in v: diff --git a/docs/source/index.rst b/docs/source/index.rst index c52e239b..051b5af8 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -26,11 +26,11 @@ Welcome to Pyrogram

- Scheme Layer 75 + Scheme Layer - TgCrypto

@@ -56,7 +56,7 @@ button at the end of each page. But first, here's a brief overview of what is th About ----- -Pyrogram is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building +**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building custom Telegram applications that interact with the MTProto API as both User and Bot. Features @@ -65,8 +65,8 @@ Features - **Easy to use**: You can easily install Pyrogram using pip and start building your app right away. - **High-level**: The low-level details of MTProto are abstracted and automatically handled. - **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C. -- **Updated** to the latest Telegram API version, currently Layer 76 running on MTProto 2.0. -- **Documented**: Pyrogram API methods are documented and resemble the Telegram Bot API. +- **Updated** to the latest Telegram API version, currently Layer 81 on top of MTProto 2.0. +- **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API. - **Full API**, allowing to execute any advanced action an official client is able to do, and more. To get started, press the Next button. @@ -84,10 +84,11 @@ To get started, press the Next button. :caption: Resources resources/UpdateHandling - resources/SOCKS5Proxy - resources/TgCrypto resources/AutoAuthorization + resources/CustomizeSessions + resources/TgCrypto resources/TextFormatting + resources/SOCKS5Proxy resources/BotsInteraction resources/ErrorHandling diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 0448c3cb..0000b35f 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -62,6 +62,7 @@ Client get_inline_bot_results send_inline_bot_result answer_callback_query + request_callback_answer get_users get_chat get_messages diff --git a/docs/source/resources/BotsInteraction.rst b/docs/source/resources/BotsInteraction.rst index cbbe23c1..de7925a2 100644 --- a/docs/source/resources/BotsInteraction.rst +++ b/docs/source/resources/BotsInteraction.rst @@ -28,8 +28,12 @@ Inline Bots .. code-block:: python - # Send the first result (bot_results.results[0]) to your own chat (Saved Messages) - app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id) + # Send the first result to your own chat + app.send_inline_bot_result( + "me", + bot_results.query_id, + bot_results.results[0].id + ) .. figure:: https://i.imgur.com/wwxr7B7.png :width: 90% diff --git a/docs/source/resources/CustomizeSessions.rst b/docs/source/resources/CustomizeSessions.rst new file mode 100644 index 00000000..e98792b7 --- /dev/null +++ b/docs/source/resources/CustomizeSessions.rst @@ -0,0 +1,66 @@ +Customize Sessions +================== + +As you may probably know, Telegram allows Users (and Bots) having more than one session (authorizations) registered +in the system at the same time. + +Briefly explaining, sessions are simply new logins in your account. They can be reviewed in the settings of an official +app (or by invoking `GetAuthorizations <../functions/account/GetAuthorizations.html>`_ with Pyrogram) and store some useful +information about the client who generated them. + + +.. figure:: https://i.imgur.com/lzGPCdZ.png + :width: 70% + :align: center + + A Pyrogram session running on Linux, Python 3.6. + +That's how a session looks like on the Android app, showing the three main pieces of information. + +- ``app_version``: **Pyrogram 🔥 0.7.5** +- ``device_model``: **CPython 3.6.5** +- ``system_version``: **Linux 4.15.0-23-generic** + +Set Custom Values +----------------- + +To set custom values, you can either make use of the ``config.ini`` file, this way: + +.. code-block:: ini + + [pyrogram] + app_version = 1.2.3 + device_model = PC + system_version = Linux + +Or, pass the arguments directly in the Client's constructor. + +.. code-block:: python + + app = Client( + "my_account", + app_version="1.2.3", + device_model="PC", + system_version="Linux" + ) + +Set Custom Languages +-------------------- + +To tell Telegram in which language should speak to you (terms of service, bots, service messages, ...) you can +set ``lang_code`` in `ISO 639-1 `_ standard (defaults to "en", +English). + +With the following code we make Telegram know we want it to speak in Italian (it): + +.. code-block:: ini + + [pyrogram] + lang_code = it + +.. code-block:: python + + app = Client( + "my_account", + lang_code="it", + ) \ No newline at end of file diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index ffa01be9..0aa6457f 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -9,6 +9,7 @@ from, one for each kind of update: - `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_ - `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_ - `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_ +- `DisconnectHandler <../pyrogram/handlers/DisconnectHandler.html>`_ Registering an Handler ---------------------- diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 8b7c0597..417d62d8 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -54,7 +54,7 @@ User Authorization In order to use the API, Telegram requires that Users be authorized via their phone numbers. Pyrogram automatically manages this access, all you need to do is create an instance of the :class:`Client ` class by passing to it a ``session_name`` of your choice -(e.g.: "my_account") and call the :meth:`start() ` method: +(e.g.: "my_account") and call the :meth:`run() ` method: .. code-block:: python diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index d9cb8fe1..6c20decd 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -10,10 +10,6 @@ High-level API The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods_ and types_, which are named after the `Telegram Bot API`_. -.. hint:: If you can't find an high-level method you want to use, chances are it's not implemented yet. - In this case, you must use the `Raw Functions`_. Meanwhile, feel free to join our Community_ if you get stuck - or want to propose a new method! - Examples (more on `GitHub `_): - Get information about the authorized user: @@ -34,10 +30,8 @@ Examples (more on `GitHub ` and :mod:`types ` exposed by the @@ -45,8 +39,10 @@ you have to use the raw :mod:`functions ` and :mod:`type method provided by the Client class. .. hint:: Every high-level method mentioned in the section above is built on top of these raw functions. + Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API. + If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_! Examples (more on `GitHub `_): diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index f681e9cd..51f25e51 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -31,7 +31,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès ` - ``ValueError``: If the provided index or position is out of range or the button label was not found. + ``ValueError``: If the provided index or position is out of range or the button label was not found + ``TimeoutError``: If, after clicking an inline button, the bot fails to answer within 10 seconds """ if isinstance(self.reply_markup, ReplyKeyboardMarkup): if quote is None: @@ -561,7 +562,7 @@ class Message(Object): return await self._client.request_callback_answer( chat_id=self.chat.id, message_id=self.message_id, - data=button.callback_data + callback_data=button.callback_data ) elif button.url: return button.url diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index c6db20e8..04033885 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -132,7 +132,7 @@ class Session: app_version=self.client.app_version, device_model=self.client.device_model, system_version=self.client.system_version, - system_lang_code=self.client.system_lang_code, + system_lang_code=self.client.lang_code, lang_code=self.client.lang_code, lang_pack="", query=functions.help.GetConfig(),