Buttons Handler

class telegram_bot_discussion.handlers.buttons_handler.buttons_handler.ButtonsHandler(coder, buttons_map)[source]

Bases: object

Parameters:
coder: CoderInterface

how to serialize and deserialize stored in button data.

Type:

CoderInterface

buttons_map: ButtonsMap

accordance of action and Button class.

Type:

ButtonsMap

set_buttons_map(buttons_map)[source]
Parameters:

buttons_map (ButtonsMap)

async access_control_list(context, user_id, button_class)[source]

Check user access to Button-class within handle().

Return type:

bool

Parameters:
  • context (CallbackContext)

  • user_id (int)

  • button_class (Type[Button])

async middleware(update, context)[source]

Middleware work within handle(). If it returns None, handle() will not work.

Return type:

Optional[Tuple[Update, CallbackContext]]

Parameters:
  • update (Update)

  • context (CallbackContext)

async handle(update, context)[source]

Catch all buttons clicks.

Parameters:
  • update (Update)

  • context (CallbackContext)

Buttons handler exceptions

exception telegram_bot_discussion.handlers.buttons_handler.exceptions.access_deny.ButtonClassAccessDeny(user_id, button_class)[source]

Bases: Exception

Parameters:
  • user_id (int)

  • button_class (str | Type[Button])

user_id: int
button_class: Union[str, Type[Button]]
exception telegram_bot_discussion.handlers.buttons_handler.exceptions.buttons_map_is_empty.ButtonsMapIsEmpty[source]

Bases: Exception

exception telegram_bot_discussion.handlers.buttons_handler.exceptions.life_time_overflow.ButtonClassLifeTimeOverflow(button_class)[source]

Bases: Exception

Parameters:

button_class (str | Type[Button])

button_class: Union[str, Type[Button]]
exception telegram_bot_discussion.handlers.buttons_handler.exceptions.not_registered.ButtonClassIsNotRegistered(button_class)[source]

Bases: Exception

Parameters:

button_class (str | Type[Button])

button_class: Union[str, Type[Button]]
exception telegram_bot_discussion.handlers.buttons_handler.exceptions.signification_error.ButtonDataSignificationError(user_id, data)[source]

Bases: Exception

Parameters:
  • user_id (int)

  • data (str)

user_id: int
data: str