mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-02 15:25:41 +00:00
Update Docs
This commit is contained in:
@@ -9,9 +9,9 @@ Basic Usage
|
||||
Simple API Access
|
||||
-----------------
|
||||
|
||||
The easiest way to interact with the API is via the :class:`Client <pyrogram.Client>` class which exposes bot-like_
|
||||
methods. The purpose of this Client class is to make it even simpler to work with Telegram's API by abstracting the
|
||||
raw functions listed in the API scheme.
|
||||
The easiest way to interact with the Telegram API is via the :class:`Client <pyrogram.Client>` class,
|
||||
which exposes bot-like_ methods. The purpose of this Client class is to make it even simpler to work with the
|
||||
API by abstracting the raw functions listed in the scheme.
|
||||
|
||||
The result is a much cleaner interface that allows you to:
|
||||
|
||||
@@ -25,10 +25,13 @@ The result is a much cleaner interface that allows you to:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
client.send_message(
|
||||
chat_id="me",
|
||||
text="Hi there! I'm using Pyrogram"
|
||||
)
|
||||
client.send_message("me", "Hi there! I'm using Pyrogram")
|
||||
|
||||
- Upload a photo (with caption):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
client.send_photo("me", "/home/dan/perla.jpg", "Cute!")
|
||||
|
||||
.. seealso:: For a complete list of the available methods have a look at the :class:`Client <pyrogram.Client>` class.
|
||||
|
||||
@@ -39,7 +42,7 @@ Using Raw Functions
|
||||
|
||||
If you want **complete**, low-level access to the Telegram API you have to use the raw
|
||||
:mod:`functions <pyrogram.api.functions>` and :mod:`types <pyrogram.api.types>` exposed by the ``pyrogram.api``
|
||||
package and call any Telegram API method you wish using the :meth:`send <pyrogram.Client.send>` method provided by
|
||||
package and call any Telegram API method you wish using the :meth:`send() <pyrogram.Client.send>` method provided by
|
||||
the Client class.
|
||||
|
||||
Here some examples:
|
||||
|
@@ -8,7 +8,7 @@ API Keys
|
||||
--------
|
||||
|
||||
The very first step requires you to obtain a valid Telegram API key.
|
||||
If you already have one you can skip this, otherwise:
|
||||
If you already have one you can skip this step, otherwise:
|
||||
|
||||
#. Visit https://my.telegram.org/apps and log in with your Telegram Account.
|
||||
#. Fill out the form to register a new Telegram application.
|
||||
@@ -31,8 +31,8 @@ There are two ways to configure a Pyrogram application project, and you can choo
|
||||
api_id = 12345
|
||||
api_hash = 0123456789abcdef0123456789abcdef
|
||||
|
||||
- Alternatively, you can pass your API key to Pyrogram by simply using the *api_key* parameter of the Client class.
|
||||
This way you can have full control on how to store and load your credentials:
|
||||
- Alternatively, you can pass your API key to Pyrogram by simply using the *api_id* and *api_hash*
|
||||
parameters of the Client class. This way you can have full control on how to store and load your credentials:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -40,25 +40,26 @@ There are two ways to configure a Pyrogram application project, and you can choo
|
||||
|
||||
client = Client(
|
||||
session_name="example",
|
||||
api_key=(12345, "0123456789abcdef0123456789abcdef")
|
||||
api_id=12345
|
||||
api_hash="0123456789abcdef0123456789abcdef"
|
||||
)
|
||||
|
||||
.. note:: The examples below will assume you have created a *config.ini* file, thus they won't show the *api_key*
|
||||
parameter usage in the :class:`Client <pyrogram.Client>` class.
|
||||
.. note:: The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id*
|
||||
and *api_hash* parameters usage.
|
||||
|
||||
Authorization
|
||||
-------------
|
||||
User Authorization
|
||||
------------------
|
||||
|
||||
Telegram requires that users be authorized in order to use the API.
|
||||
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 <pyrogram.Client>` class by passing to it a ``<session_name>`` of your choice
|
||||
and call the :meth:`start <pyrogram.Client.start>` method:
|
||||
(e.g.: "my_account") and call the :meth:`start <pyrogram.Client.start>` method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
client = Client(session_name="example")
|
||||
client = Client("my_account")
|
||||
client.start()
|
||||
|
||||
This starts an interactive shell asking you to input your **phone number** (including your `Country Code`_)
|
||||
@@ -70,15 +71,26 @@ and the **phone code** you will receive:
|
||||
Is "+39**********" correct? (y/n): y
|
||||
Enter phone code: 32768
|
||||
|
||||
After successfully authorizing yourself, a new file called ``example.session`` will be created allowing
|
||||
Pyrogram executing API calls with your identity.
|
||||
After successfully authorizing yourself, a new file called ``my_account.session`` will be created allowing
|
||||
Pyrogram executing API calls with your identity. This file will be loaded again when you restart your app,
|
||||
and as long as you keep the session alive, Pyrogram won't ask you again to enter your phone number.
|
||||
|
||||
.. important:: Your *.session file(s) must be kept secret.
|
||||
|
||||
.. note::
|
||||
Bot Authorization
|
||||
-----------------
|
||||
|
||||
The authorization process is executed only once.
|
||||
However, the code above is always required; as long as a valid session file exists,
|
||||
Pyrogram will use that and won't ask you to enter your phone number again when you restart your script.
|
||||
Being written entirely from the ground up, Pyrogram is also able to authorize Bots.
|
||||
This means that you can use Pyrogram to execute API calls with a Bot identity.
|
||||
Instead of phone numbers, Bots are authorized via their tokens which are created by BotFather_:
|
||||
|
||||
.. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes
|
||||
.. code-block:: python
|
||||
|
||||
from pyrogram import Client
|
||||
|
||||
client = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11")
|
||||
client.start()
|
||||
|
||||
|
||||
.. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes
|
||||
.. _BotFather: https://t.me/botfather
|
@@ -7,6 +7,12 @@ The most straightforward and recommended way to install or upgrade Pyrogram is b
|
||||
|
||||
$ pip3 install --upgrade pyrogram
|
||||
|
||||
or, with TgCrypto_ (recommended):
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip3 install --upgrade pyrogram[tgcrypto]
|
||||
|
||||
Bleeding Edge
|
||||
-------------
|
||||
|
||||
|
Reference in New Issue
Block a user