Class Router⚓︎
Here is the reference information for the Router class, including all its parameters, attributes, and methods.
You can import the Router class directly from the trueconf package:
trueconf.Router ⚓︎
Event router for handling incoming events in a structured and extensible way.
A Router allows you to register event handlers with specific filters, such as message types, chat events, or custom logic.
You can also include nested routers using include_router() to build modular and reusable event structures.
Handlers can be registered for:
- Messages (
@<router>.message(...)) - Chat creation events (
@<router>.created_personal_chat(),@<router>.created_group_chat(),@<router>.created_channel()) - Participant events (
@<router>.added_chat_participant(),@<router>.removed_chat_participant()) - Message lifecycle events (
@<router>.edited_message(),@<router>.removed_message()) - File upload events (
@<router>.uploading_progress()) - Removed chats (
@<router>.removed_chat())
Example:
router = Router()
@router.message(F.text == "hello")
async def handle_hello(msg: Message):
await msg.answer("Hi there!")
If you have multiple routers, use .include_router() to add them to a parent router.
added_chat_participant ⚓︎
Register a handler when a participant is added to a chat.
changed_file_upload_limits ⚓︎
Requires TrueConf Server 5.5.3+ Registers a handler for file upload limits change events.
This handler is triggered when the server's file upload restrictions are updated. The event is represented by the ChangedFileUploadLimits type and may include:
max_size— the maximum allowed file size in bytes (1 MB = 1000 bytes). If the size limit is disabled, the value isNone.extensions— file extension restrictions. If extension filtering is disabled, the value isNone.
If extensions is provided, it contains: - mode — restriction mode: - block — blocked extensions (blacklist) - allow — allowed extensions (whitelist) - list — list of file extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*filters | FilterLike | Optional filters to apply to the event. Multiple filters can be specified. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | A decorator function for registering the handler. |
Example
changed_participant_role ⚓︎
Requires TrueConf Server 5.5.2+ Registers a handler for participant role change events in chats.
This handler is triggered when a user's role is changed in a personal chat, group chat, channel, or conference chat. Used with the ChangedParticipantRole event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*filters | FilterLike | Optional filters to apply to the event. Multiple filters can be specified. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | A decorator function for registering the handler. |
Example
from trueconf.enums import ChatParticipantRole as role
from trueconf.types import ChangedParticipantRole
@router.changed_participant_role()
async def on_role_changed(event: ChangedParticipantRole):
if event.role == role.admin:
print(f"{event.user_id} has been promoted to admin in chat {event.chat_id}")
cleared_chat_history ⚓︎
Requires TrueConf Server 5.5.3+ Registers a handler for chat history clearing events.
This handler is triggered when the message history of a chat is cleared. Used with the ClearedChatHistory event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*filters | FilterLike | Optional filters to apply to the event. Multiple filters can be specified. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | A decorator function for registering the handler. |
created_favorites_chat ⚓︎
Requires TrueConf Server 5.5.2+. Register a handler for favorites chat creation events.
created_group_chat ⚓︎
Register a handler for group chat creation events.
created_personal_chat ⚓︎
Register a handler for personal chat creation events.
edited_chat_avatar ⚓︎
Requires TrueConf Server 5.5.3+ Registers a handler for chat avatar edit events.
This handler is triggered when a chat avatar is changed. Used with the EditedChatAvatar event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*filters | FilterLike | Optional filters to apply to the event. Multiple filters can be specified. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | A decorator function for registering the handler. |
edited_chat_title ⚓︎
Requires TrueConf Server 5.5.3+ Registers a handler for chat title edit events.
This handler is triggered when a chat title is changed. Used with the EditedChatTitle event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*filters | FilterLike | Optional filters to apply to the event. Multiple filters can be specified. | () |
Returns:
| Name | Type | Description |
|---|---|---|
Callable | A decorator function for registering the handler. |
event ⚓︎
removed_chat_participant ⚓︎
Register a handler when a participant is removed from a chat.
uploading_progress ⚓︎
Register a handler for file uploading progress events.