2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Update docs

This commit is contained in:
Dan 2018-02-22 11:02:38 +01:00
parent 6a5810134b
commit 7439e1e8f2
6 changed files with 146 additions and 9 deletions

View File

@ -26,6 +26,7 @@ Client
send_video send_video
send_voice send_voice
send_video_note send_video_note
send_media_group
send_location send_location
send_venue send_venue
send_contact send_contact
@ -40,4 +41,5 @@ Client
enable_cloud_password enable_cloud_password
change_cloud_password change_cloud_password
remove_cloud_password remove_cloud_password
send_media_group add_contacts
delete_contacts

View File

@ -0,0 +1,6 @@
InputPhoneContact
=================
.. autoclass:: pyrogram.InputPhoneContact
:members:
:undoc-members:

View File

@ -13,6 +13,7 @@ the same parameters as well, thus offering a familiar look to Bot developers.
ParseMode ParseMode
Emoji Emoji
InputMedia InputMedia
InputPhoneContact
Error Error
.. _Telegram Bot API: https://core.telegram.org/bots/api#available-methods .. _Telegram Bot API: https://core.telegram.org/bots/api#available-methods

View File

@ -25,5 +25,26 @@ with your own settings:
- ``1``, ``yes``, ``True`` or ``on``: Enables the proxy - ``1``, ``yes``, ``True`` or ``on``: Enables the proxy
- ``0``, ``no``, ``False`` or ``off``: Disables 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 Alternatively, you can setup your proxy without the need of the *config.ini* file by using the *proxy* parameter
or completely delete the lines. 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="<your_username>",
password="<your_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.

View File

@ -50,6 +50,8 @@ Here some examples:
from pyrogram.api import functions from pyrogram.api import functions
...
client.send( client.send(
functions.account.UpdateProfile( functions.account.UpdateProfile(
first_name="Dan", last_name="Tès", first_name="Dan", last_name="Tès",
@ -63,6 +65,8 @@ Here some examples:
from pyrogram.api import functions, types from pyrogram.api import functions, types
...
client.send( client.send(
functions.account.SetPrivacy( functions.account.SetPrivacy(
key=types.InputPrivacyKeyStatusTimestamp(), 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 .. _bot-like: https://core.telegram.org/bots/api#available-methods

View File

@ -19,15 +19,31 @@ If you already have one you can skip this, otherwise:
Configuration Configuration
------------- -------------
Create a new ``config.ini`` file at the root of your working directory, There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you:
copy-paste the following and replace the **api_id** and **api_hash** values with `your own <#api-keys>`_:
.. 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>`_:
.. code-block:: ini
[pyrogram] [pyrogram]
api_id = 12345 api_id = 12345
api_hash = 0123456789abcdef0123456789abcdef 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 Authorization
------------- -------------