InlineQueryHandler¶
- class telegram.ext.InlineQueryHandler(callback, pattern=None, block=True, chat_types=None)[source]¶
Bases:
telegram.ext.BaseHandlerBaseHandler class to handle Telegram updates that contain a
telegram.Update.inline_query. Optionally based on a regex. Read the documentation of theremodule for more information.Warning
When setting
blocktoFalse, you cannot rely on adding custom attributes totelegram.ext.CallbackContext. See its docs for more info.telegram.InlineQuery.chat_typewill not be set for inline queries from secret chats and may not be set for inline queries coming from third-party clients. These updates won’t be handled, ifchat_typesis passed.
Examples
Available In
- Parameters:
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.pattern (
str|re.Pattern, optional) – Regex pattern. If notNone,re.match()is used ontelegram.InlineQuery.queryto determine if an update should be handled by this handler.block (
bool, optional) –Determines whether the return value of the callback should be awaited before processing the next handler in
telegram.ext.Application.process_update(). Defaults toTrue.See also
chat_types (list[
str], optional) –List of allowed chat types. If passed, will only handle inline queries with the appropriate
telegram.InlineQuery.chat_type.Added in version 13.5.
- pattern[source]¶
Optional. Regex pattern to test
telegram.InlineQuery.queryagainst.- Type:
str|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|re.match
- collect_additional_context(context, update, application, check_result)[source]¶
Add the result of
re.match(pattern, update.inline_query.query)toCallbackContext.matchesas list with one element.