mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-23 10:28:00 +00:00
Created Usage (markdown)
parent
7c90c03ec2
commit
0bc3beb870
52
Usage.md
Normal file
52
Usage.md
Normal file
@ -0,0 +1,52 @@
|
||||
**Note:** All the snippets below assume you have created and started a Client instance.
|
||||
You also must be authorized, that is, a valid `*.session` file does exist in your working directory.
|
||||
|
||||
## Simple API Access
|
||||
|
||||
The easiest way to interact with the API is via the `pyrogram.Client` class which exposes [bot-like](https://core.telegram.org/bots/api#available-methods) 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 result is a much cleaner interface that allows you to:
|
||||
|
||||
- Get information about the authorized user:
|
||||
|
||||
``` python
|
||||
print(client.get_me())
|
||||
```
|
||||
|
||||
- Send a message to yourself (Saved Messages):
|
||||
|
||||
``` python
|
||||
client.send_message(
|
||||
chat_id="me",
|
||||
text="Hi there! I'm using Pyrogram"
|
||||
)
|
||||
```
|
||||
|
||||
## Using Raw Functions
|
||||
|
||||
If you want **complete**, low-level access to the Telegram API you have to use the raw `functions` and `types` exposed by the `pyrogram.api` package and call any Telegram API method you wish using the `send` method provided by the Client class:
|
||||
|
||||
- Update first name, last name and bio:
|
||||
|
||||
``` python
|
||||
from pyrogram.api import functions
|
||||
|
||||
client.send(
|
||||
functions.account.UpdateProfile(
|
||||
first_name="Dan", last_name="Tès",
|
||||
about="Bio written from Pyrogram"
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
- Share your Last Seen time only with your contacts:
|
||||
|
||||
``` python
|
||||
from pyrogram.api import functions, types
|
||||
|
||||
client.send(
|
||||
functions.account.SetPrivacy(
|
||||
key=types.InputPrivacyKeyStatusTimestamp(),
|
||||
rules=[types.InputPrivacyValueAllowContacts()]
|
||||
)
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user