Bulletin Helper
Easily display various types of bottom-screen notifications (Bulletins) in your plugins.
The BulletinHelper
class, found in bulletin.py
, provides a set of static methods to conveniently show Telegram's "Bulletin" notifications. Bulletins are small, non-intrusive messages that typically appear at the bottom of the screen and dismiss automatically.
Basic Usage
Most BulletinHelper
methods are class methods and can be called directly. They often accept an optional fragment
argument; if not provided, the helper tries to use the currently active fragment or a global context.
UI Thread
All BulletinHelper.show_...
methods automatically ensure that the bulletin is shown on the Android UI thread, so you don't need to wrap these calls in run_on_ui_thread
yourself.
Bulletin Types and Methods
BulletinHelper
wraps common functionalities of org.telegram.ui.Components.BulletinFactory
.
Standard Bulletins
BulletinHelper.show_info(message: str, fragment: Optional[BaseFragment] = None)
- Shows a bulletin with a default info icon (e.g.,
R.raw.info
).
- Shows a bulletin with a default info icon (e.g.,
BulletinHelper.show_error(message: str, fragment: Optional[BaseFragment] = None)
- Shows a bulletin with a default error/alert icon.
BulletinHelper.show_success(message: str, fragment: Optional[BaseFragment] = None)
- Shows a bulletin with a default success/check icon.
Custom Simple Bulletins
BulletinHelper.show_simple(text: str, icon_res_id: int, fragment: Optional[BaseFragment] = None)
- Shows a single-line bulletin with a custom Lottie animation icon.
icon_res_id
: A Lottie animation resource ID (e.g.,R_tg.raw.some_animation
).
BulletinHelper.show_two_line(title: str, subtitle: str, icon_res_id: int, fragment: Optional[BaseFragment] = None)
- Shows a two-line bulletin with a custom icon, title, and subtitle.
Bulletins with Actions
BulletinHelper.show_with_button(text: str, icon_res_id: int, button_text: str, on_click: Optional[Callable[[], None]], fragment: Optional[BaseFragment] = None, duration: int = BulletinHelper.DURATION_PROLONG)
- Shows a bulletin with an icon, text, and a clickable button.
on_click
: A callable to execute when the button is pressed.duration
: How long the bulletin stays visible (e.g.,BulletinHelper.DURATION_SHORT
,DURATION_LONG
,DURATION_PROLONG
).
BulletinHelper.show_undo(text: str, on_undo: Callable[[], None], on_action: Optional[Callable[[], None]] = None, subtitle: Optional[str] = None, fragment: Optional[BaseFragment] = None)
- Shows an "Undo"-style bulletin.
on_undo
: Called if the "Undo" button is pressed.on_action
: Called after a delay if "Undo" is not pressed (e.g., to commit an action).
Contextual Bulletins (Predefined)
BulletinHelper.show_copied_to_clipboard(message: Optional[str] = None, fragment: Optional[BaseFragment] = None)
- Shows "Text copied to clipboard" or a custom message.
BulletinHelper.show_link_copied(is_private_link_info: bool = False, fragment: Optional[BaseFragment] = None)
- Shows "Link copied" bulletin, with a variant for private link info.
BulletinHelper.show_file_saved_to_gallery(is_video: bool = False, amount: int = 1, fragment: Optional[BaseFragment] = None)
- Shows "Photo/Video saved to gallery" (or plural versions).
BulletinHelper.show_file_saved_to_downloads(file_type_enum_name: str = "UNKNOWN", amount: int = 1, fragment: Optional[BaseFragment] = None)
- Shows "File saved to downloads" or similar, based on
BulletinFactory.FileType
. file_type_enum_name
: String name of the enum fromBulletinFactory.FileType
(e.g.,"PHOTO_TO_DOWNLOADS"
,"GIF"
).
- Shows "File saved to downloads" or similar, based on
Durations
The BulletinHelper
class defines constants for common durations:
BulletinHelper.DURATION_SHORT
(1500 ms)BulletinHelper.DURATION_LONG
(2750 ms)BulletinHelper.DURATION_PROLONG
(5000 ms)
These can be used with methods like show_with_button
.
Finding Lottie Animations (R.raw...
)
Lottie animations used for bulletin icons are typically stored as raw resources in Telegram's codebase. You can explore Telegram's source (specifically TMessagesProj/src/main/res/raw/
) to find available animations (e.g., info.json
, success.json
, delete.json
). In Python, these are accessed via org.telegram.messenger.R.raw.animation_name
(e.g., R_tg.raw.info
).