def write_core_index(docs, tlobjects, layer): # Determine method, types and constructors count types = set() method_count = 0 constructor_count = 0 for tlobject in tlobjects: if tlobject.is_function: method_count += 1 else: constructor_count += 1 types.add(tlobject.result) type_count = len(types) types.clear() # Write the head and the full HTML docs.write_head('Telethon API', relative_css_path='css/docs.css') # Welcome text, small explanation about this page docs.write('''

Telethon API

This documentation was generated straight from the scheme.tl provided by Telegram. However, there is no official documentation per se on what the methods, constructors and types mean. Nevertheless, this page aims to provide easy access to all the available methods, their definition and parameters.

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

''' # Methods section '''

Methods

Currently there are {methodcount} 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:

''' # Example usage for the methods '''
#!/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
''' # Example end '''

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.

''' # Types section '''

Types

Currently there are {typecount} types. You can see the full list here.

The Telegram types are the abstract results that you receive after invoking a request. They are "abstract" because they can have multiple constructors. For instance, the abstract type User can be either UserEmpty or User. You should, most of the time, make sure you received the desired type by using the isinstance(result, Constructor) Python function. When a request needs a Telegram type as argument, you should create an instance of it by using one of its, possibly multiple, constructors.

''' # Constructors section '''

Constructors

Currently there are {constructorcount} constructors. You can see the full list here.

Constructors are the way you can create instances of the abstract types described above, and also the instances which are actually returned from the functions although they all share a common abstract type.

''' # Core types section '''

Core types

Core types are types from which the rest of Telegram types build upon:

'''.format( layer=layer, typecount=type_count, methodcount=method_count, constructorcount=constructor_count )) docs.end_body()