Client Utilities
This module provides utility functions and classes for asynchronous tasks, making API requests, sending messages, and displaying UI notifications like bulletins.
This module contains helpers for interacting with Telegram's core functionalities, managing background tasks, and providing user feedback.
Queues (Background Threads)
For performing long-running or blocking operations (like network requests or heavy computations) without freezing the UI, you should run your functions on a background thread. client_utils provides run_on_queue for this.
You can specify which queue to use and add a delay (in milliseconds):
Available Queues (as string constants): These allow you to target specific Telegram dispatch queues.
To get a direct Java org.telegram.messenger.DispatchQueue instance:
Utilities
Sending Telegram API Requests
To send raw Telegram API requests (TLObjects), use send_request. This function handles sending the request via the current account's connection manager and invoking your callback upon response or error.
RequestCallback is a dynamic_proxy for org.telegram.tgnet.RequestDelegate, simplifying callback implementation in Python.
Sending Messages and Media
This module provides several high-level functions to easily send text, photos, videos, and other files. These functions handle file processing and sending on the appropriate threads.
send_text
Sends a simple text message.
send_photo
Uploads and sends a photo from a local file path.
send_document
Uploads and sends a generic file/document.
send_video
Uploads and sends a video file, automatically extracting metadata like duration and dimensions.
send_audio
Uploads and sends an audio file as a music track, automatically extracting metadata.
All send_* functions also accept any additional keyword arguments (**kwargs) that will be passed along to the underlying SendMessageParams object, such as replyToMsg, scheduleDate, etc.
Editing Messages
You can edit existing messages using the edit_message function.
The edit_message function can also be used to add a media spoiler by passing with_spoiler=True.
Displaying Bulletins (Bottom Notifications)
Bulletins are small, non-intrusive notifications shown at the bottom of the screen. The BulletinHelper class provides an easy way to show them.
For detailed information and examples on how to use various types of bulletins, please refer to the Bulletin Helper documentation.
Accessing Controllers and Managers
client_utils.py provides convenient getter functions for accessing various core Telegram controllers, managers, and configurations for the currently selected account.
These functions simplify access to key components of the Telegram client.