telegram.ext.MessageHandler¶
- class telegram.ext.MessageHandler(filters, callback, block=True)[source]¶
Bases:
telegram.ext.BaseHandler
BaseHandler class to handle Telegram messages. They might contain text, media or status updates.
Warning
When setting
block
toFalse
, you cannot rely on adding custom attributes totelegram.ext.CallbackContext
. See its docs for more info.- Parameters
filters (
telegram.ext.filters.BaseFilter
) – A filter inheriting fromtelegram.ext.filters.BaseFilter
. Standard filters can be found intelegram.ext.filters
. Filters can be combined using bitwise operators (& for and, | for or, ~ for not). This defaults to all message updates being:telegram.Update.message
,telegram.Update.edited_message
,telegram.Update.channel_post
andtelegram.Update.edited_channel_post
. If you don’t want or need any of those pass~filters.UpdateType.*
in the filter argument.callback (coroutine function) –
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
telegram.ext.ConversationHandler
.block (
bool
, optional) – Determines whether the return value of the callback should be awaited before processing the next handler intelegram.ext.Application.process_update()
. Defaults toTrue
.
- filters[source]¶
Only allow updates with these Filters. See
telegram.ext.filters
for a full list of all available filters.
- block[source]¶
Determines whether the return value of the callback should be awaited before processing the next handler in
telegram.ext.Application.process_update()
.- Type
- check_update(update)[source]¶
Determines whether an update should be passed to this handler’s
callback
.- Parameters
update (
telegram.Update
|object
) – Incoming update.- Returns
- collect_additional_context(context, update, application, check_result)[source]¶
Adds possible output of data filters to the
CallbackContext
.