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
The send_message
utility simplifies sending various types of messages. It takes a dictionary of parameters.
This function internally handles execution on the UI thread, so you don't need to wrap calls to send_message
in run_on_ui_thread
.
A comprehensive list of supported parameters for the params
dictionary can be inferred from the fields of org.telegram.messenger.SendMessagesHelper.SendMessageParams
. You can find its definition here (SendMessagesHelper.java#L10185). Common parameters include peer
, message
, replyToMsg
, entities
, scheduleDate
, etc.
Sending Files
For sending files (photos, videos, documents not already uploaded), you'll typically need to use the Java methods of SendMessagesHelper
directly, often involving preparing the file path, creating TLRPC.InputMedia
objects, etc. The send_message
Python utility is more for messages where media is already represented by an ID or for simpler text-based messages.
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.