Toggle table of contents sidebar
CallbackContext¶This is a context object passed to the callback called by telegram.ext.BaseHandler
or by the telegram.ext.Application
in an error handler added by telegram.ext.Application.add_error_handler
or to the callback of a telegram.ext.Job
.
Note
telegram.ext.Application
will create a single context for an entire update. This means that if you got 2 handlers in different groups and they both get called, they will receive the same CallbackContext
object (of course with proper attributes like matches
differing). This allows you to add custom attributes in a lower handler group callback, and then subsequently access those attributes in a higher handler group callback. Note that the attributes on CallbackContext
might change in the future, so make sure to use a fairly unique name for the attributes.
This class is a Generic
class and accepts four type variables:
The type of bot
. Must be telegram.Bot
or a subclass of that class.
application (telegram.ext.Application
) – The application associated with this context.
The ID of the chat associated with this object. Used to provide chat_data
.
Added in version 20.0.
The ID of the user associated with this object. Used to provide user_data
.
Added in version 20.0.
Optional. Only present in error handlers if the error was caused by an awaitable run with Application.create_task()
or a handler callback with block=False
.
Optional. If the associated update originated from a filters.Regex
, this will contain a list of match objects for every pattern where re.search(pattern, string)
returned a match. Note that filters short circuit, so combined regex filters will not always be evaluated.
list[re.Match
]
Optional. Arguments passed to a command if the associated update is handled by telegram.ext.CommandHandler
, telegram.ext.PrefixHandler
or telegram.ext.StringCommandHandler
. It contains a list of the words in the text after the command, using any whitespace string as a delimiter.
list[str
]
Optional. The error that was raised. Only present when passed to an error handler registered with telegram.ext.Application.add_error_handler
.
Optional. The job which originated this callback. Only present when passed to the callback of telegram.ext.Job
or in error handlers if the error is caused by a job.
Changed in version 20.0: job
is now also present in error handlers if the error is caused by a job.
The application associated with this context.
The bot associated with this context.
Optional. An object that can be used to keep any data in. For each update it will be the same ContextTypes.bot_data
. Defaults to dict
.
Optional. An object that can be used to keep any data in. For each update from the same chat id it will be the same ContextTypes.chat_data
. Defaults to dict
.
Warning
When a group chat migrates to a supergroup, its chat id will change and the chat_data
needs to be transferred. For details see our wiki page.
Changed in version 20.0: The chat data is now also present in error handlers if the error is caused by a job.
Deletes the cached data for the specified callback query.
Added in version 13.6.
Note
Will not raise exceptions in case the data is not found in the cache. Will raise KeyError
in case the callback query can not be found in the cache.
callback_query (telegram.CallbackQuery
) – The callback query.
KeyError | RuntimeError – KeyError
, if the callback query can not be found in the cache and RuntimeError
, if the bot doesn’t allow for arbitrary callback data.
Constructs an instance of telegram.ext.CallbackContext
to be passed to the error handlers.
Changed in version 20.0: Removed arguments async_args
and async_kwargs
.
update (object
| telegram.Update
) – The update associated with the error. May be None
, e.g. for errors in job callbacks.
application (telegram.ext.Application
) – The application associated with this context.
job (telegram.ext.Job
, optional) –
The job associated with the error.
Added in version 20.0.
coroutine (awaitable, optional) –
The awaitable associated with this error if the error was caused by a coroutine run with Application.create_task()
or a handler callback with block=False
.
Added in version 20.0.
Changed in version 20.2: Accepts asyncio.Future
and generator-based coroutine functions.
Constructs an instance of telegram.ext.CallbackContext
to be passed to a job callback.
job (telegram.ext.Job
) – The job.
application (telegram.ext.Application
) – The application associated with this context.
Constructs an instance of telegram.ext.CallbackContext
to be passed to the handlers.
update (object
| telegram.Update
) – The update.
application (telegram.ext.Application
) – The application associated with this context.
The JobQueue
used by the telegram.ext.Application
.
The first match from matches
. Useful if you are only filtering using a single regex filter. Returns None
if matches
is empty.
If application
uses persistence, calls telegram.ext.BasePersistence.refresh_bot_data()
on bot_data
, telegram.ext.BasePersistence.refresh_chat_data()
on chat_data
and telegram.ext.BasePersistence.refresh_user_data()
on user_data
, if appropriate.
Will be called by telegram.ext.Application.process_update()
and telegram.ext.Job.run()
.
Added in version 13.6.
Updates self.__slots__
with the passed data.
The asyncio.Queue
instance used by the telegram.ext.Application
and (usually) the telegram.ext.Updater
associated with this context.
Optional. An object that can be used to keep any data in. For each update from the same user it will be the same ContextTypes.user_data
. Defaults to dict
.
Changed in version 20.0: The user data is now also present in error handlers if the error is caused by a job.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4