Plugin Settings
Learn how to build settings pages, sub-pages, and custom setting items for your plugin.
You can build a plugin settings screen by implementing create_settings(self) -> List[Any] on your BasePlugin.
The method should return a list of dataclass instances from ui.settings.
General Example
This example intentionally uses almost every built-in setting type so you can see how the pieces fit together.
Accessing and Modifying Settings
Use the helper methods from BasePlugin.
To save a value:
You can also export or import all settings for the current plugin:
Built-in Setting Types
The SDK currently exposes these public dataclasses from ui.settings:
HeaderDividerSwitchSelectorInputTextEditTextCustom
Supported Controls
| Control | key | text | default | Other Important Parameters |
|---|---|---|---|---|
| Header | - | Required | - | text: section title |
| Divider | - | - | - | text: optional caption shown on the divider |
| Switch | Required | Required | Required (bool) | subtext, icon, on_change, on_long_click, link_alias |
| Selector | Required | Required | Required (int) | items, icon, on_change, on_long_click, link_alias |
| Input | Required | Required | optional str | subtext, icon, on_change, on_long_click, link_alias |
| Text | - | Required | - | subtext, icon, accent, red, on_click, on_long_click, create_sub_fragment, link_alias |
| EditText | Required | - | optional str | hint (required), multiline, max_length, mask, on_change |
| Custom | - | - | - | item, view, factory, factory_args, on_click, on_long_click, create_sub_fragment, link_alias |
Parameter Details
| Parameter | Type | Description |
|---|---|---|
key | str | Unique key for persisted settings. Used with get_setting() and set_setting(). |
text | str | Main visible text for the setting row. |
default | Any | Default value used if the setting was never saved. |
subtext | str | Optional second line of text. |
icon | str | Optional drawable name such as "msg_settings". |
on_change | Callable | Runs when the value changes. Signature depends on control type. |
on_click | Callable | Runs when the row is clicked. Usually receives the clicked View. |
on_long_click | Callable | Runs on long press. Usually receives the clicked View. |
link_alias | str | Enables a copyable deeplink alias for the setting row. |
items | List[str] | Selector option labels. |
create_sub_fragment | Callable[[], List[Any]] | Builds a nested settings page when the item is tapped. |
accent | bool | Applies accent coloring to Text. |
red | bool | Applies red coloring to Text. |
hint | str | Placeholder text for EditText. |
multiline | bool | Allows multiple lines in EditText. |
max_length | int | Maximum allowed input length. |
mask | str | Regex-like input restriction for EditText. |
factory | CustomSetting.Factory | Java factory used for advanced custom items. |
item | UItem | Prebuilt Telegram UItem instance. |
view | View | Plain Android View instance. |
Custom Settings
Custom is the flexible entry point for settings rows which do not fit the built-in controls.
There are three main ways to use it.
1. Provide an existing UItem
This is the lightest solution when Telegram already has a suitable row type.
2. Provide a ready Android View
This is useful for static or already-constructed views.
This form is usually best for simple one-off views. If the row needs recycling, binding, click handling, or per-item behavior, prefer a factory.
3. Use SimpleSettingFactory
SimpleSettingFactory is the recommended high-level API for custom settings.
It internally creates a Java CustomSetting.Factory, handles binding, and exposes Python callbacks for the parts you usually want to customize.
Factory callbacks
SimpleSettingFactory(...) supports these callbacks:
create_view(context, list_view, current_account, class_guid, resources_provider) -> Viewbind_view(view, item, divider, adapter, list_view) -> Nonecreate_item(plugin, setting, args) -> UItemon_click(plugin, item, view) -> Noneon_long_click(plugin, item, view) -> boolattached_view(list_view, view, item) -> Noneequals(a, b) -> boolcontent_equals(a, b) -> bool
Constructor options:
A few important notes:
create_view(...)builds the row view itself.bind_view(...)fills the current data into that view.is_clickableandis_shadoware optimized Java-side flags used in hot paths.- if
create_itemis omitted, the factory creates a defaultUItemfor you - if
equalsorcontent_equalsare omitted, Telegram's defaultUItemcomparison logic is used
Using SimpleSettingFactory as a callable
SimpleSettingFactory also implements __call__, so you can use it as a small builder for Custom(...).
You can also pass positional arguments:
Those values are stored in factory_args for the created custom row and can be used by advanced factory logic.
Advanced Custom Factories
If SimpleSettingFactory is not enough, you can generate your own CustomSetting.Factory subclass through the class proxy system.
That route is useful when you need:
- a real Java subclass
- custom Java fields
super()support- overload-specific behavior
- MVEL-backed hot-path methods
For that API, see Class Proxy.