2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-09-03 07:45:14 +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

@@ -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

View File

@@ -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
-------------