From 7439e1e8f28c2eaa5e367cfc5023fb8882ae1fe4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 22 Feb 2018 11:02:38 +0100 Subject: [PATCH] Update docs --- docs/source/pyrogram/Client.rst | 4 +- docs/source/pyrogram/InputPhoneContact.rst | 6 ++ docs/source/pyrogram/index.rst | 1 + docs/source/resources/SOCKS5Proxy.rst | 25 +++++- docs/source/start/BasicUsage.rst | 91 ++++++++++++++++++++++ docs/source/start/ProjectSetup.rst | 28 +++++-- 6 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 docs/source/pyrogram/InputPhoneContact.rst diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index b4bb1270..84e49749 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -26,6 +26,7 @@ Client send_video send_voice send_video_note + send_media_group send_location send_venue send_contact @@ -40,4 +41,5 @@ Client enable_cloud_password change_cloud_password remove_cloud_password - send_media_group \ No newline at end of file + add_contacts + delete_contacts \ No newline at end of file diff --git a/docs/source/pyrogram/InputPhoneContact.rst b/docs/source/pyrogram/InputPhoneContact.rst new file mode 100644 index 00000000..e5c4a20d --- /dev/null +++ b/docs/source/pyrogram/InputPhoneContact.rst @@ -0,0 +1,6 @@ +InputPhoneContact +================= + +.. autoclass:: pyrogram.InputPhoneContact + :members: + :undoc-members: diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index aa10ec4c..7f64648d 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -13,6 +13,7 @@ the same parameters as well, thus offering a familiar look to Bot developers. ParseMode Emoji InputMedia + InputPhoneContact Error .. _Telegram Bot API: https://core.telegram.org/bots/api#available-methods diff --git a/docs/source/resources/SOCKS5Proxy.rst b/docs/source/resources/SOCKS5Proxy.rst index 55993deb..0004ecad 100644 --- a/docs/source/resources/SOCKS5Proxy.rst +++ b/docs/source/resources/SOCKS5Proxy.rst @@ -25,5 +25,26 @@ with your own settings: - ``1``, ``yes``, ``True`` or ``on``: Enables the proxy - ``0``, ``no``, ``False`` or ``off``: Disables the proxy -- If your proxy doesn't require authorization you can omit username and password by either leaving the values blank - or completely delete the lines. \ No newline at end of file +Alternatively, you can setup your proxy without the need of the *config.ini* file by using the *proxy* parameter +in the Client class: + +.. code-block:: python + + from pyrogram import Client + + client = Client( + session_name="example", + proxy=dict( + hostname="11.22.33.44", + port=1080, + username="", + password="" + ) + ) + + client.start() + + ... + +.. note:: If your proxy doesn't require authorization you can omit *username* and *password* by either leaving the + values blank/empty or completely delete the lines. \ No newline at end of file diff --git a/docs/source/start/BasicUsage.rst b/docs/source/start/BasicUsage.rst index e9411c60..c602b413 100644 --- a/docs/source/start/BasicUsage.rst +++ b/docs/source/start/BasicUsage.rst @@ -50,6 +50,8 @@ Here some examples: from pyrogram.api import functions + ... + client.send( functions.account.UpdateProfile( first_name="Dan", last_name="Tès", @@ -63,6 +65,8 @@ Here some examples: from pyrogram.api import functions, types + ... + client.send( functions.account.SetPrivacy( key=types.InputPrivacyKeyStatusTimestamp(), @@ -70,4 +74,91 @@ Here some examples: ) ) +- Invite users to your channel/supergroup: + + .. code-block:: python + + from pyrogram.api import functions, types + + ... + + client.send( + functions.channels.InviteToChannel( + channel=client.resolve_peer(123456789), # ID or Username of your channel + users=[ # The users you want to invite + client.resolve_peer(23456789), # By ID + client.resolve_peer("username"), # By username + client.resolve_peer("393281234567"), # By phone number + ] + ) + ) + +- Get channel/supergroup participants: + + .. code-block:: python + + import time + from pyrogram.api import types, functions + + ... + + users = [] + limit = 200 + offset = 0 + + while True: + try: + participants = client.send( + functions.channels.GetParticipants( + channel=client.resolve_peer("username"), # ID or username + filter=types.ChannelParticipantsSearch(""), # Filter by empty string (search for all) + offset=offset, + limit=limit, + hash=0 + ) + ) + except FloodWait as e: + # Very large channels will trigger FloodWait. + # In that case wait X seconds before continuing + time.sleep(e.x) + continue + + if not participants.participants: + break # No more participants left + + users.extend(participants.users) + offset += len(participants.users) + +- Get history of a chat: + + .. code-block:: python + + import time + from pyrogram.api import types, functions + + ... + + history = [] + limit = 100 + offset = 0 + + while True: + try: + messages = client.send( + functions.messages.GetHistory( + client.resolve_peer("me"), # Get your own history + 0, 0, offset, limit, 0, 0, 0 + ) + ) + except FloodWait as e: + # For very large histories the method call can raise a FloodWait + time.sleep(e.x) + continue + + if not messages.messages: + break # No more messages left + + history.extend(messages.messages) + offset += len(messages.messages) + .. _bot-like: https://core.telegram.org/bots/api#available-methods \ No newline at end of file diff --git a/docs/source/start/ProjectSetup.rst b/docs/source/start/ProjectSetup.rst index bc2b6b74..2899fb7a 100644 --- a/docs/source/start/ProjectSetup.rst +++ b/docs/source/start/ProjectSetup.rst @@ -19,14 +19,30 @@ If you already have one you can skip this, otherwise: Configuration ------------- -Create a new ``config.ini`` file at the root of your working directory, -copy-paste the following and replace the **api_id** and **api_hash** values with `your own <#api-keys>`_: +There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you: -.. code-block:: ini +- Create a new ``config.ini`` file at the root of your working directory, + copy-paste the following and replace the **api_id** and **api_hash** values with `your own <#api-keys>`_: - [pyrogram] - api_id = 12345 - api_hash = 0123456789abcdef0123456789abcdef + .. code-block:: ini + + [pyrogram] + 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: + + .. code-block:: python + + from pyrogram import Client + + client = Client( + session_name="example", + api_key=(12345, "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 Client class. Authorization -------------