InlineQuery

class telegram.InlineQuery(id, from_user, query, offset, location=None, chat_type=None, *, api_kwargs=None)[source]

Bases: telegram.TelegramObject

This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their id is equal.

https://core.telegram.org/file/464001466/10e4a/r4FKyQ7gw5g.134366/f2606a53d683374703

Inline queries on Telegram

See also

The telegram.InlineQueryResult classes represent the media the user can choose from (see above figure).

Note

In Python from is a reserved word. Use from_user instead.

Changed in version 20.0: The following are now keyword-only arguments in Bot methods: {read, write, connect, pool}_timeout, answer.api_kwargs, auto_pagination. Use a named argument for those, and notice that some positional arguments changed position as a result.

Parameters:
  • id (str) – Unique identifier for this query.

  • from_user (telegram.User) – Sender.

  • query (str) – Text of the query (up to 256 characters).

  • offset (str) – Offset of the results to be returned, can be controlled by the bot.

  • chat_type (str, optional) –

    Type of the chat, from which the inline query was sent. Can be either 'sender' for a private chat with the inline query sender, 'private', 'group', 'supergroup' or 'channel'. The chat type should be always known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat.

    New in version 13.5.

  • location (telegram.Location, optional) – Sender location, only for bots that request user location.

id[source]

Unique identifier for this query.

Type:

str

from_user[source]

Sender.

Type:

telegram.User

query[source]

Text of the query (up to 256 characters).

Type:

str

offset[source]

Offset of the results to be returned, can be controlled by the bot.

Type:

str

chat_type[source]

Optional. Type of the chat, from which the inline query was sent. Can be either 'sender' for a private chat with the inline query sender, 'private', 'group', 'supergroup' or 'channel'. The chat type should be always known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat.

New in version 13.5.

Type:

str

location[source]

Optional. Sender location, only for bots that request user location.

Type:

telegram.Location

MAX_OFFSET_LENGTH = 64[source]

telegram.constants.InlineQueryLimit.MAX_OFFSET_LENGTH

New in version 20.0.

MAX_QUERY_LENGTH = 256[source]

telegram.constants.InlineQueryLimit.MAX_QUERY_LENGTH

New in version 20.0.

MAX_RESULTS = 50[source]

telegram.constants.InlineQueryLimit.RESULTS

New in version 13.2.

MAX_SWITCH_PM_TEXT_LENGTH = 64[source]

telegram.constants.InlineQueryLimit.MAX_SWITCH_PM_TEXT_LENGTH

New in version 20.0.

MIN_SWITCH_PM_TEXT_LENGTH = 1[source]

telegram.constants.InlineQueryLimit.MIN_SWITCH_PM_TEXT_LENGTH

New in version 20.0.

async answer(results, cache_time=None, is_personal=None, next_offset=None, button=None, *, current_offset=None, auto_pagination=False, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.answer_inline_query(
    update.inline_query.id,
    *args,
    current_offset=self.offset if auto_pagination else None,
    **kwargs
)

For the documentation of the arguments, please see telegram.Bot.answer_inline_query().

Changed in version 20.0: Raises ValueError instead of TypeError.

Keyword Arguments:

auto_pagination (bool, optional) – If set to True, offset will be passed as current_offset to telegram.Bot.answer_inline_query(). Defaults to False.

Raises:

ValueError – If both current_offset and auto_pagination are supplied.

classmethod de_json(data, bot)[source]

See telegram.TelegramObject.de_json().