Hide navigation sidebar
Hide table of contents sidebar
PTB has undergone significant changes in v20. Please read the documentation carefully and also check out the transition guide in the wiki.
Back to top
Toggle table of contents sidebar

# ContextTypes

class telegram.ext.ContextTypes(context=<class 'telegram.ext._callbackcontext.CallbackContext'>, bot_data=<class 'dict'>, chat_data=<class 'dict'>, user_data=<class 'dict'>)

  Bases: `typing.Generic`

  Convenience class to gather customizable types of the `telegram.ext.CallbackContext` interface.

  Examples

  ContextTypes Bot

  Use In

  `telegram.ext.ApplicationBuilder.context_types()`

  Available In

  - `telegram.ext.Application.context_types`

  - `telegram.ext.PicklePersistence.context_types`

  See also

  Architecture Overview, Storing Bot, User and Chat Related Data

  New in version 13.6.

  Parameters:

    - context (`type`, optional) – Determines the type of the `context` argument of all (error-)handler callbacks and job callbacks. Must be a subclass of `telegram.ext.CallbackContext`. Defaults to `telegram.ext.CallbackContext`.

    - bot_data (`type`, optional) – Determines the type of `context.bot_data` of all (error-)handler callbacks and job callbacks. Defaults to `dict`. Must support instantiating without arguments.

    - chat_data (`type`, optional) – Determines the type of `context.chat_data` of all (error-)handler callbacks and job callbacks. Defaults to `dict`. Must support instantiating without arguments.

    - user_data (`type`, optional) – Determines the type of `context.user_data` of all (error-)handler callbacks and job callbacks. Defaults to `dict`. Must support instantiating without arguments.

  DEFAULT_TYPE

    Shortcut for the type annotation for the `context` argument that’s correct for the default settings, i.e. if `telegram.ext.ContextTypes` is not used.

    Example

        async def callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
            ...

    alias of `CallbackContext`[`ExtBot`[`None`], `Dict`[`Any`, `Any`], `Dict`[`Any`, `Any`], `Dict`[`Any`, `Any`]]

  property bot_data

    The type of `context.bot_data` of all (error-)handler callbacks and job callbacks.

  property chat_data

    The type of `context.chat_data` of all (error-)handler callbacks and job callbacks.

  property context

    The type of the `context` argument of all (error-)handler callbacks and job callbacks.

  property user_data

    The type of `context.user_data` of all (error-)handler callbacks and job callbacks.