class pyrubrum.BaseHandler

Basic representation of an handler, which is an entity that manages the setup of a Client instance (i.e. the bot).

The purpose of this class is to give a general interface for an handler, even if it already implements both a sample setup and a keyboard processing function.

See also

For complete implementations of this class:


In order to create a subclass or to access this interface, you will need to implement the abstract method get_menus. Otherwise, you will get an error.

abstract get_menus() → Set[BaseMenu]

This abstract method is intended to be implemented as a collector of all the menus which were defined while initializing this object.


The set of the menus that were collected during the lookup process.

Return type


process_keyboard(keyboard: List[List[pyrubrum.keyboard.button.Button]], callback_query_id: str, chat_id: int) → List[List[pyrogram.client.types.bots_and_keyboards.inline_keyboard_button.InlineKeyboardButton]]

Given a list which represents an inline keyboard, a unique identifier for the callback and one for the chat from which the query was called, generate a Pyrogram-compatible inline keyboard.

  • keyboard (List[List[Button]]) – The inline keyboard you want to process.

  • callback_query_id (str) – The unique identifier of the callback for which the keyboard is generated.

  • chat_id (int) – The identifier of the chat from which the query has been sent.


The generated keyboard in a Pyrogram-compatible type.

Return type


setup(client: pyrogram.client.client.Client)

Make all the defined menus reachable by the client by adding handlers that catch all their identifiers to it. It also calls pass_handler, which lets the callback functions get this handler as argument.


client (Client) – The client which is being set up.


The functions the handlers make use of are not set up in the same way objects added using Pyrogram handlers are. Pyrubrum implements the following pattern:

callback(handler, client, context, parameters)