From 81dfcc41028f289bd46f6a817b3b313580e80f7e Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 15 Apr 2017 14:15:40 +0200 Subject: [PATCH] Improve the docs navigation --- docs/res/core.html | 128 ++++++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/docs/res/core.html b/docs/res/core.html index d36f11d2..60d541da 100644 --- a/docs/res/core.html +++ b/docs/res/core.html @@ -15,7 +15,7 @@
+ placeholder="Search for requests and types…" />
@@ -30,54 +30,36 @@ definition and parameters.

Although this documentation was generated for Telethon, it may - be useful for any other Telegram library out there.

Methods

+ be useful for any other Telegram library out there.

+ +

Index

+ + +

Methods

Currently there are {method_count} methods available for the layer {layer}. The complete list can be seen here. -
- To invoke any of these methods (also called requests), you can do - as shown on the following example:

-
#!/usr/bin/python3
-from telethon import TelegramClient
-from telethon.tl.functions.messages import GetHistoryRequest
-from telethon.utils import get_input_peer
-
-# Use your own values here
-api_id = 12345
-api_hash = '0123456789abcdef0123456789abcdef'
-phone_number = '+34600000000'
-
-# Create the client and connect
-client = TelegramClient('username', api_id, api_hash)
-client.connect()
-
-# Ensure you're authorized
-if not client.is_user_authorized():
-    client.send_code_request(phone)
-    client.sign_in(phone, input('Enter the code: '))
-
-# Using built-in methods
-dialogs, entities = client.get_dialogs(10)
-entity = entities[0]
-
-# !! Invoking a request manually !!
-result = client.invoke(
-    GetHistoryRequest(
-        get_input_peer(entity),
-        limit=20,
-        offset_date=None,
-        offset_id=0,
-        max_id=0,
-        min_id=0,
-        add_offset=0))
-
-# Now you have access to the first 20 messages
-messages = result.messages
- -

As you can see, manually invoking requests with client.invoke() - is way more verbose than using the built-in methods. However, and given - that there are so many methods available, it's impossible to provide a nice - interface to things that may change over time. To get full access, however, - you're still able to invoke these methods manually.

+

+ Methods, also known as requests, are used to interact with + the Telegram API itself and are invoked with a call to .invoke(). + Only these can be passed to .invoke()! You cannot + .invoke() types or constructors, only requests. After this, + Telegram will return a result, which may be, for instance, + a bunch of messages, some dialogs, users, etc.

Types

Currently there are {type_count} types. You can see the full @@ -152,6 +134,58 @@ messages = result.messages with date parameters. + +

Full example

+

The following example demonstrates:

+
    +
  1. How to create a TelegramClient.
  2. +
  3. Connecting to the Telegram servers and authorizing an user.
  4. +
  5. Retrieving a list of chats (dialogs).
  6. +
  7. Invoking a request without the built-in methods.
  8. +
+
#!/usr/bin/python3
+from telethon import TelegramClient
+from telethon.tl.functions.messages import GetHistoryRequest
+from telethon.utils import get_input_peer
+
+# (1) Use your own values here
+api_id = 12345
+api_hash = '0123456789abcdef0123456789abcdef'
+phone_number = '+34600000000'
+
+# (2) Create the client and connect
+client = TelegramClient('username', api_id, api_hash)
+client.connect()
+
+# Ensure you're authorized
+if not client.is_user_authorized():
+    client.send_code_request(phone)
+    client.sign_in(phone, input('Enter the code: '))
+
+# (3) Using built-in methods
+dialogs, entities = client.get_dialogs(10)
+entity = entities[0]
+
+# (4) !! Invoking a request manually !!
+result = client.invoke(
+    GetHistoryRequest(
+        get_input_peer(entity),
+        limit=20,
+        offset_date=None,
+        offset_id=0,
+        max_id=0,
+        min_id=0,
+        add_offset=0))
+
+# Now you have access to the first 20 messages
+messages = result.messages
+ +

As it can be seen, manually invoking requests with + client.invoke() is way more verbose than using the built-in + methods (such as client.get_dialogs(). However, and given + that there are so many methods available, it's impossible to provide a nice + interface to things that may change over time. To get full access, however, + you're still able to invoke these methods manually.