Skip to content

API


class APIData

class APIData(object, metaclass=BaseAPIMetaClass)

API configuration to connect to TelegramClient and TDesktop

Attributes:

Name Type Description
api_id int API_ID
api_hash str API_HASH
device_model str Device model name
system_version str Operating System version
app_version str Current app version
lang_code str Language code of the client
system_lang_code str Language code of operating system
lang_pack str Language pack

Methods:

  • Generate() :
    Generate random device model and system version


APIData()

@typing.overload
def __init__(api_id: int, api_hash: str, device_model: str = None, system_version: str = None, app_version: str = None, lang_code: str = None, system_lang_code: str = None, lang_pack: str = None) -> None

Create your own customized API

Arguments:

Name Type Default Description
api_id int API_ID
api_hash str API_HASH
device_model str None Device model name
system_version str None Operating System version
app_version str None Current app version
lang_code str "en" Language code of the client
system_lang_code str "en" Language code of operating system
lang_pack str "" Language pack
Use at your own risk!

Using the wrong API can lead to your account banned.
If the session was created using an official API, you must continue using official APIs for that session.
Otherwise that account is at risk of getting banned.


Generate()

@classmethod
def Generate(cls: Type[_T], unique_id: str = None) -> _T

Generate random device model and system version

Arguments:

Name Type Default Description
unique_id str None The unique ID to generate - can be anything.
This will be used to ensure that it will generate the same data everytime.
If not set then the data will be randomized each time we runs it.

Raises:

NotImplementedError : Not supported for web browser yet

Returns:

APIData : Return a copy of the api with random device data

Examples:

Create a TelegramClient with custom API:

api = API.TelegramIOS.Generate(unique_id="new.session")
client = TelegramClient(session="new.session" api=api)
client.start()


class API

class API(BaseObject)

Built-in templates for Telegram API

  • opentele offers the ability to use official APIs, which are used by official apps.

  • According to Telegram TOS : all accounts that sign up or log in using unofficial Telegram API clients are automatically put under observation to avoid violations of the Terms of Service.

  • It also uses the lang_pack parameter, of which telethon can't use because it's for official apps only.

  • Therefore, there are no differences between using opentele and official apps, the server can't tell you apart.

  • You can use TelegramClient.PrintSessions() to check this out.

Attributes:

Name Type Description
TelegramDesktop API Official Telegram for Desktop (Windows, macOS and Linux)View on GitHub
TelegramAndroid API Official Telegram for Android View on GitHub
TelegramAndroidX API Official TelegramX for Android View on GitHub
TelegramIOS API Official Telegram for iOS View on GitHub
TelegramMacOS API Official Telegram-Swift For MacOS View on GitHub
TelegramWeb_Z API Default Official Telegram Web Z For Browsers View on GitHub
TelegramWeb_K API Official Telegram Web K For Browsers View on GitHub
Webogram API Old Telegram For Browsers View on GitHub


class TelegramDesktop

class TelegramDesktop(APIData)

Official Telegram for Desktop (Windows, macOS and Linux) View on GitHub

Attributes:

Name Type Description
api_id int 2040
api_hash str "b18441a1ff607e10a989891a5462e627"
device_model str "Desktop"
system_version str "Windows 10"
app_version str "3.4.3 x64"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "tdesktop"

Methods:

  • Generate() :
    Generate random device data for Windows, macOS and Linux


Generate()

@typing.overload
@classmethod
def Generate(cls: Type[_T], system: str = "windows", unique_id: str = None) -> _T

Generate random TelegramDesktop devices

Arguments:

Name Type Default Description
system str "random" Which OS to generate, either "windows", "macos", or "linux".
Default is None or "random" - which means it will be selected randomly.
unique_id str None The unique ID to generate - can be anything.
This ID will be used to ensure that it will generate the same data every single time.
If not set then the data will be randomized each time we runs it.

Returns:

APIData : Return a copy of the api with random device data

Examples:

Save a telethon session to tdata:

# unique_id will ensure that this data will always be the same (per unique_id).
# You can use the session file name, or user_id as a unique_id.
# If unique_id isn't specify, the device data will be randomized each time we runs it.
oldAPI = API.TelegramDesktop.Generate(system="windows", unique_id="old.session")
oldclient = TelegramClient("old.session", api=oldAPI)
await oldClient.connect()

# We can safely CreateNewSession with a different API.
# Be aware that you should not use UseCurrentSession with a different API than the one that first authorized it.
# You can print(newAPI) to see what it had generated.
newAPI = API.TelegramDesktop.Generate("macos", "new_tdata")
tdesk = oldclient.ToTDesktop(oldclient, flag=CreateNewSession, api=newAPI)

# Save the new session to a folder named "new_tdata"
tdesk.SaveTData("new_tdata")


class TelegramAndroid

class TelegramAndroid(APIData)

Official Telegram for Android
View on GitHub

Attributes:

Name Type Description
api_id int 6
api_hash str "eb06d4abfb49dc3eeb1aeb98ae0f581e"
device_model str "Samsung SM-G998B"
system_version str "SDK 31"
app_version str "8.4.1 (2522)"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "android"


class TelegramAndroidX

class TelegramAndroidX(APIData)

Official TelegramX for Android
View on GitHub

Attributes:

Name Type Description
api_id int 21724
api_hash str "3e0cb5efcd52300aec5994fdfc5bdc16"
device_model str "Samsung SM-G998B"
system_version str "SDK 31"
app_version str "8.4.1 (2522)"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "android"


class TelegramIOS

class TelegramIOS(APIData)

Official Telegram for iOS
View on GitHub

Attributes:

Name Type Description
api_id int 10840
api_hash str "33c45224029d59cb3ad0c16134215aeb"
device_model str "iPhone 13 Pro Max"
system_version str "14.8.1"
app_version str "8.4"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "ios"


class TelegramMacOS

class TelegramMacOS(APIData)

Official Telegram-Swift For MacOS View on GitHub

Attributes:

Name Type Description
api_id int 2834
api_hash str "68875f756c9b437a8b916ca3de215815"
device_model str "MacBook Pro"
system_version str "macOS 12.0.1"
app_version str "8.4"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "macos"


class TelegramWeb_Z

class TelegramWeb_Z(APIData)

Default Official Telegram Web Z For Browsers
View on GitHub| Visit on Telegram

Attributes:

Name Type Description
api_id int 2496
api_hash str "8da85b0d5bfe62527e5b244c209159c3"
device_model str "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
system_version str "Windows"
app_version str "1.28.3 Z"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str ""


class TelegramWeb_K

class TelegramWeb_K(APIData)

Official Telegram Web K For Browsers
View on GitHub| Visit on Telegram

Attributes:

Name Type Description
api_id int 2496
api_hash str "8da85b0d5bfe62527e5b244c209159c3"
device_model str "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
system_version str "Win32"
app_version str "1.0.1 K"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str "macos"


class Webogram

class Webogram(APIData)

Old Telegram For Browsers
View on GitHub| Vist on Telegram

Attributes:

Name Type Description
api_id int 2496
api_hash str "8da85b0d5bfe62527e5b244c209159c3"
device_model str "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
system_version str "Win32"
app_version str "0.7.0"
lang_code str "en"
system_lang_code str "en-US"
lang_pack str ""