Skip to content
Back to top
View this page

# ExtBot

class telegram.ext.ExtBot(token, base_url='https://api.telegram.org/bot', base_file_url='https://api.telegram.org/file/bot', request=None, get_updates_request=None, private_key=None, private_key_password=None, defaults=None, arbitrary_callback_data=False, local_mode=False, rate_limiter=None)

  Bases: `telegram.Bot`, `typing.Generic`

  This object represents a Telegram Bot with convenience extensions.

  Warning

  Not to be confused with `telegram.Bot`.

  For the documentation of the arguments, methods and attributes, please see `telegram.Bot`.

  All API methods of this class have an additional keyword argument `rate_limit_args`. This can be used to pass additional information to the rate limiter, specifically to `telegram.ext.BaseRateLimiter.process_request.rate_limit_args`.

  This class is a `Generic` class and accepts one type variable that specifies the generic type of the `rate_limiter` used by the bot. Use `None` if no rate limiter is used.

  Warning

  - The keyword argument `rate_limit_args` can not be used, if `rate_limiter` is `None`.

  - The method `get_updates()` is the only method that does not have the additional argument, as this method will never be rate limited.

  Examples

  Arbitrary Callback Data Bot

  See also

  Arbitrary callback_data

  Use In

  `telegram.ext.ApplicationBuilder.bot()`

  Available In

  - `telegram.ext.Application.bot`

  - `telegram.ext.CallbackContext.bot`

  - `telegram.ext.CallbackDataCache.bot`

  - `telegram.ext.Updater.bot`

  Returned In

  - `telegram.ext.Application.builder()`

  - `telegram.ext.ApplicationBuilder.rate_limiter()`

  Added in version 13.6.

  Changed in version 20.0: Removed the attribute `arbitrary_callback_data`. You can instead use `bot.callback_data_cache.maxsize` to access the size of the cache.

  Changed in version 20.5: Removed deprecated methods `set_sticker_set_thumb` and `setStickerSetThumb`.

  Parameters:

    - defaults (`telegram.ext.Defaults`, optional) – An object containing default values to be used if not set explicitly in the bot methods.

    - arbitrary_callback_data (`bool` | `int`, optional) –

      Whether to allow arbitrary objects as callback data for `telegram.InlineKeyboardButton`. Pass an integer to specify the maximum number of objects cached in memory. Defaults to `False`.

      See also

      Arbitrary callback_data

    - rate_limiter (`telegram.ext.BaseRateLimiter`, optional) –

      A rate limiter to use for limiting the number of requests made by the bot per time interval.

      Added in version 20.0.

  property callback_data_cache

    Optional. The cache for objects passed as callback data for `telegram.InlineKeyboardButton`.

    Examples

    Arbitrary Callback Data Bot

    Changed in version 20.0: * This property is now read-only. * This property is now optional and can be `None` if `arbitrary_callback_data` is set to `False`.

    Type:

      `telegram.ext.CallbackDataCache`

  property defaults

    The `telegram.ext.Defaults` used by this bot, if any.

  async initialize()

    See `telegram.Bot.initialize()`. Also initializes the `ExtBot.rate_limiter` (if set) by calling `telegram.ext.BaseRateLimiter.initialize()`.

  insert_callback_data(update)

    If this bot allows for arbitrary callback data, this inserts the cached data into all corresponding buttons within this update.

    Note

    Checks `telegram.Message.via_bot` and `telegram.Message.from_user` to figure out if a) a reply markup exists and b) it was actually sent by this bot. If not, the message will be returned unchanged.

    Note that this will fail for channel posts, as `telegram.Message.from_user` is `None` for those! In the corresponding reply markups, the callback data will be replaced by `telegram.ext.InvalidCallbackData`.

    Warning

    In place, i.e. the passed `telegram.Message` will be changed!

    Parameters:

      update (`telegram.Update`) – The update.

  property rate_limiter

    The `telegram.ext.BaseRateLimiter` used by this bot, if any.

    Added in version 20.0.

  async shutdown()

    See `telegram.Bot.shutdown()`. Also shuts down the `ExtBot.rate_limiter` (if set) by calling `telegram.ext.BaseRateLimiter.shutdown()`.