CallbackQueryHandler

class telegram.ext.CallbackQueryHandler(callback, pattern=None, game_pattern=None, block=True)[source]

Bases: telegram.ext.BaseHandler

Handler class to handle Telegram callback queries. Optionally based on a regex.

Read the documentation of the re module for more information.

Note

Warning

When setting block to False, you cannot rely on adding custom attributes to telegram.ext.CallbackContext. See its docs for more info.

Parameters:
callback[source]

The callback function for this handler.

Type:

coroutine function

pattern[source]

Optional. Regex pattern, callback or type to test telegram.CallbackQuery.data against.

Changed in version 13.6: Added support for arbitrary callback data.

Type:

re.Pattern | callable | type

game_pattern[source]

Optional. Regex pattern to test telegram.CallbackQuery.game_short_name

Type:

re.Pattern

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:

bool

check_update(update)[source]

Determines whether an update should be passed to this handler’s callback.

Parameters:

update (telegram.Update | object) – Incoming update.

Returns:

bool

collect_additional_context(context, update, application, check_result)[source]

Add the result of re.match(pattern, update.callback_query.data) to CallbackContext.matches as list with one element.