Перейти к содержанию

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:

from trueconf import Router

trueconf.Router ⚓︎

Router(name=None, stop_on_first=True)

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.

name instance-attribute ⚓︎

name = name or hex(id(self))

stop_on_first instance-attribute ⚓︎

stop_on_first = stop_on_first

added_chat_participant ⚓︎

added_chat_participant(*filters)

Register a handler when a participant is added to a chat.

created_channel ⚓︎

created_channel(*filters)

Register a handler for channel creation events.

created_group_chat ⚓︎

created_group_chat(*filters)

Register a handler for group chat creation events.

created_personal_chat ⚓︎

created_personal_chat(*filters)

Register a handler for personal chat creation events.

edited_message ⚓︎

edited_message(*filters)

Register a handler for message edit events.

event ⚓︎

event(method, *filters)

Register a handler for a generic event type, filtered by method name.

Examples:

>>> @r.event(F.method == "SendMessage")
>>> async def handle_message(msg: Message): ...

include_router ⚓︎

include_router(router)

Include a child router for hierarchical event routing.

message ⚓︎

message(*filters)

Register a handler for incoming Message events.

removed_chat ⚓︎

removed_chat(*filters)

Register a handler when a chat is removed.

removed_chat_participant ⚓︎

removed_chat_participant(*filters)

Register a handler when a participant is removed from a chat.

removed_message ⚓︎

removed_message(*filters)

Register a handler for message deletion events.

uploading_progress ⚓︎

uploading_progress(*filters)

Register a handler for file uploading progress events.