- class telegram.ext.Handler(callback, block=True)#
The base class for all update handlers. Create custom handlers by inheriting from it.
This class is a
Genericclass and accepts two type variables:
The type of the second argument of
callback. Must coincide with the type of the parameters
collect_additional_context.contextas well as the second argument of
callback. Must be either
CallbackContextor a subclass of that class.
Changed in version 20.0: The attribute
The callback function for this handler. Will be called when
check_update()has determined that an update should be processed by this handler. Callback signature:
async def callback(update: Update, context: CallbackContext)
The return value of the callback is usually ignored except for the special case of
- abstract check_update(update)#
This method is called to determine if an update should be handled by this handler instance. It should always be overridden.
Custom updates types can be handled by the application. Therefore, an implementation of this method should always check the type of
- collect_additional_context(context, update, application, check_result)#
Prepares additional arguments for the context. Override if needed.
- async handle_update(update, application, check_result, context)#
This method is called if it was determined that an update should indeed be handled by this instance. Calls
callbackalong with its respectful arguments. To work with the
telegram.ext.ConversationHandler, this method returns the value returned from
callback. Note that it can be overridden if needed by the subclassing handler.