|
1 | 1 | Usage |
2 | 2 | ===== |
3 | 3 |
|
4 | | -Having your `project set up`_ and your account authorized_, it's time to play with the API. |
5 | | -In this section, you'll be shown two ways of communicating with Telegram using Pyrogram. Let's start! |
| 4 | +Having your `project set up`_ and your account authorized_, it's time to play with the API. Let's start! |
6 | 5 |
|
7 | 6 | High-level API |
8 | 7 | -------------- |
@@ -43,79 +42,8 @@ exceptions in your code: |
43 | 42 |
|
44 | 43 | More examples on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_. |
45 | 44 |
|
46 | | -Raw Functions |
47 | | -------------- |
48 | | - |
49 | | -If you can't find a high-level method for your needs or if you want complete, low-level access to the whole Telegram API, |
50 | | -you have to use the raw :mod:`functions <pyrogram.api.functions>` and :mod:`types <pyrogram.api.types>` exposed by the |
51 | | -``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() <pyrogram.Client.send>` |
52 | | -method provided by the Client class. |
53 | | - |
54 | | -.. hint:: |
55 | | - |
56 | | - Every high-level method mentioned in the section above is built on top of these raw functions. |
57 | | - |
58 | | - Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already |
59 | | - re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API. |
60 | | - |
61 | | - If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_! |
62 | | - |
63 | | -Examples (more on `GitHub <https://github.com/pyrogram/pyrogram/tree/develop/examples>`_): |
64 | | - |
65 | | -- Update first name, last name and bio: |
66 | | - |
67 | | - .. code-block:: python |
68 | | -
|
69 | | - from pyrogram import Client |
70 | | - from pyrogram.api import functions |
71 | | -
|
72 | | - with Client("my_account") as app: |
73 | | - app.send( |
74 | | - functions.account.UpdateProfile( |
75 | | - first_name="Dan", last_name="Tès", |
76 | | - about="Bio written from Pyrogram" |
77 | | - ) |
78 | | - ) |
79 | | -
|
80 | | -- Share your Last Seen time only with your contacts: |
81 | | - |
82 | | - .. code-block:: python |
83 | | -
|
84 | | - from pyrogram import Client |
85 | | - from pyrogram.api import functions, types |
86 | | -
|
87 | | - with Client("my_account") as app: |
88 | | - app.send( |
89 | | - functions.account.SetPrivacy( |
90 | | - key=types.InputPrivacyKeyStatusTimestamp(), |
91 | | - rules=[types.InputPrivacyValueAllowContacts()] |
92 | | - ) |
93 | | - ) |
94 | | -
|
95 | | -- Invite users to your channel/supergroup: |
96 | | - |
97 | | - .. code-block:: python |
98 | | -
|
99 | | - from pyrogram import Client |
100 | | - from pyrogram.api import functions, types |
101 | | -
|
102 | | - with Client("my_account") as app: |
103 | | - app.send( |
104 | | - functions.channels.InviteToChannel( |
105 | | - channel=app.resolve_peer(123456789), # ID or Username |
106 | | - users=[ # The users you want to invite |
107 | | - app.resolve_peer(23456789), # By ID |
108 | | - app.resolve_peer("username"), # By username |
109 | | - app.resolve_peer("393281234567"), # By phone number |
110 | | - ] |
111 | | - ) |
112 | | - ) |
113 | | -
|
114 | | -.. _methods: ../pyrogram/Client.html#messages |
115 | | -.. _plenty of them: ../pyrogram/Client.html#messages |
116 | | -.. _types: ../pyrogram/Types.html |
117 | | -.. _Raw Functions: Usage.html#using-raw-functions |
118 | | -.. _Community: https://t.me/PyrogramChat |
119 | 45 | .. _project set up: Setup.html |
120 | 46 | .. _authorized: Setup.html#user-authorization |
121 | | -.. _Telegram Bot API: https://core.telegram.org/bots/api |
| 47 | +.. _Telegram Bot API: https://core.telegram.org/bots/api |
| 48 | +.. _methods: ../pyrogram/Client.html#messages |
| 49 | +.. _types: ../pyrogram/Types.html |
0 commit comments