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_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}")
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.
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.