Python Telegram Bot
Python Telegram Bot
Release 8.0.0
Leandro Toledo
1 telegram package 3
1.1 telegram.ext package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 telegram.ext.Updater . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 telegram.ext.Dispatcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1.3 telegram.ext.filters Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.1.4 telegram.ext.JobQueue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1.5 telegram.ext.MessageQueue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.1.6 telegram.ext.DelayQueue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.1.7 Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2 telegram.Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.3 telegram.Bot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.4 telegram.CallbackQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
1.5 telegram.Chat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
1.6 telegram.ChatAction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
1.7 telegram.ChatMember . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
1.8 telegram.ChatPhoto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
1.9 telegram.constants Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
1.10 telegram.Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
1.11 telegram.Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
1.12 telegram.error module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
1.13 telegram.File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
1.14 telegram.ForceReply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
1.15 telegram.InlineKeyboardButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
1.16 telegram.InlineKeyboardMarkup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
1.17 telegram.InputFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
1.18 telegram.KeyboardButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
1.19 telegram.Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
1.20 telegram.Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
1.21 telegram.MessageEntity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
1.22 telegram.ParseMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
1.23 telegram.PhotoSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
1.24 telegram.ReplyKeyboardRemove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
1.25 telegram.ReplyKeyboardMarkup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
1.26 telegram.ReplyMarkup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
1.27 telegram.TelegramObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
1.28 telegram.Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
1.29 telegram.User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
1.30 telegram.UserProfilePhotos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
1.31 telegram.Venue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
1.32 telegram.Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
i
1.33 telegram.VideoNote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
1.34 telegram.Voice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
1.35 telegram.WebhookInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
1.36 Stickers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.36.1 telegram.Sticker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.36.2 telegram.StickerSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.36.3 telegram.MaskPosition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.37 Inline Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
1.37.1 telegram.InlineQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
1.37.2 telegram.InlineQueryResult . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
1.37.3 telegram.InlineQueryResultArticle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
1.37.4 telegram.InlineQueryResultAudio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
1.37.5 telegram.InlineQueryResultCachedAudio . . . . . . . . . . . . . . . . . . . . . . . . . 123
1.37.6 telegram.InlineQueryResultCachedDocument . . . . . . . . . . . . . . . . . . . . . . . 124
1.37.7 telegram.InlineQueryResultCachedGif . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
1.37.8 telegram.InlineQueryResultCachedMpeg4Gif . . . . . . . . . . . . . . . . . . . . . . . 126
1.37.9 telegram.InlineQueryResultCachedPhoto . . . . . . . . . . . . . . . . . . . . . . . . . 126
1.37.10 telegram.InlineQueryResultCachedSticker . . . . . . . . . . . . . . . . . . . . . . . . . 127
1.37.11 telegram.InlineQueryResultCachedVideo . . . . . . . . . . . . . . . . . . . . . . . . . 128
1.37.12 telegram.InlineQueryResultCachedVoice . . . . . . . . . . . . . . . . . . . . . . . . . . 129
1.37.13 telegram.InlineQueryResultContact . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
1.37.14 telegram.InlineQueryResultDocument . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
1.37.15 telegram.InlineQueryResultGame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
1.37.16 telegram.InlineQueryResultGif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
1.37.17 telegram.InlineQueryResultLocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
1.37.18 telegram.InlineQueryResultMpeg4Gif . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
1.37.19 telegram.InlineQueryResultPhoto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
1.37.20 telegram.InlineQueryResultVenue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
1.37.21 telegram.InlineQueryResultVideo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
1.37.22 telegram.InlineQueryResultVoice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
1.37.23 telegram.InputMessageContent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
1.37.24 telegram.InputTextMessageContent . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
1.37.25 telegram.InputLocationMessageContent . . . . . . . . . . . . . . . . . . . . . . . . . . 140
1.37.26 telegram.InputVenueMessageContent . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
1.37.27 telegram.InputContactMessageContent . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
1.37.28 telegram.ChosenInlineResult . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
1.38 Payments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
1.38.1 telegram.LabeledPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
1.38.2 telegram.Invoice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
1.38.3 telegram.ShippingAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
1.38.4 telegram.OrderInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
1.38.5 telegram.ShippingOption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
1.38.6 telegram.SuccessfulPayment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
1.38.7 telegram.ShippingQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
1.38.8 telegram.PreCheckoutQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
1.39 Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
1.39.1 telegram.Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
1.39.2 telegram.Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
1.39.3 telegram.Callbackgame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
1.39.4 telegram.GameHighScore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
1.40 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
ii
Python Telegram Bot Documentation, Release 8.0.0
Below you can find the documentation for the python-telegram-bot library. except for the .ext package most of the
objects in the package reflect the types as defined by the telegram bot api.
Contents 1
Python Telegram Bot Documentation, Release 8.0.0
2 Contents
CHAPTER 1
telegram package
1.1.1 telegram.ext.Updater
Parameters
token (str, optional) The bots token given by the @BotFather.
base_url (str, optional) Base_url for the bot.
3
Python Telegram Bot Documentation, Release 8.0.0
workers (int, optional) Amount of threads in the thread pool for functions deco-
rated with @run_async.
bot (telegram.Bot, optional) A pre-initialized bot instance. If a pre-initialized
bot is used, it is the users responsibility to create it using a Request instance with a
large enough connection pool.
user_sig_handler (function, optional) Takes signum, frame as posi-
tional arguments. This will be called when a signal is received, defaults are (SIGINT,
SIGTERM, SIGABRT) setable with idle.
request_kwargs (dict, optional) Keyword args to control the creation of a re-
quest object (ignored if bot argument is used).
Raises ValueError If both token and bot are passed or none of them.
webhook will be started directly on http://listen:port/url_path, so SSL can be handled by another ap-
plication. Else, the webhook will be started on https://listen:port/url_path
Parameters
listen (str, optional) IP-Address to listen on. Default 127.0.0.1.
port (int, optional) Port the bot should be listening on. Default 80.
url_path (str, optional) Path inside url.
cert (str, optional) Path to the SSL certificate file.
key (str, optional) Path to the SSL key file.
clean (bool, optional) Whether to clean any pending updates on Telegram servers
before actually starting the webhook. Default is False.
bootstrap_retries (int, optional) Whether the bootstrapping phase of the
Updater will retry on failures on the Telegram server.
< 0 - retry indefinitely
0 - no retries (default)
> 0 - retry up to X times
webhook_url (str, optional) Explicitly specify the webhook url. Useful behind
NAT, reverse proxy, etc. Default is derived from listen, port & url_path.
allowed_updates (List[str], optional) Passed to telegram.Bot.
set_webhook.
Returns The update queue that can be filled from the main thread.
Return type Queue
stop()
Stops the polling/webhook thread, the dispatcher and the job queue.
1.1.2 telegram.ext.Dispatcher
Parameters
bot (telegram.Bot) The bot object that should be passed to the handlers.
update_queue (Queue) The synchronized queue that will contain the updates.
job_queue (telegram.ext.JobQueue, optional) The telegram.ext.
JobQueue instance to pass onto handler callbacks.
workers (int, optional) Number of maximum concurrent worker threads for the
@run_async decorator. defaults to 4.
add_error_handler(callback)
Registers an error handler in the Dispatcher.
Parameters callback (callable) A function that takes Bot, Update,
TelegramError as arguments.
add_handler(handler, group=0)
Register a handler.
TL;DR: Order and priority counts. 0 or 1 handlers per group will be used.
A handler must be an instance of a subclass of telegram.ext.Handler. All handlers are
organized in groups with a numeric value. The default group is 0. All groups will be evalu-
ated for handling an update, but only 0 or 1 handler per group will be used. If telegram.
DispatcherHandlerStop is raised from one of the handlers, no further handlers (regardless
of the group) will be called.
The priority/order of handlers is determined as follows:
Priority of the group (lower group number == higher priority)
The first handler in a group which should handle an update (see telegram.ext.Handler.
check_update) will be used. Other handlers from the group will not be used. The order in
which handlers were added to the group defines the priority.
Parameters
handler (telegram.ext.Handler) A Handler instance.
group (int, optional) The group identifier. Default is 0.
chat_data = None
dict A dictionary handlers can use to store data for the chat.
dispatch_error(update, error)
Dispatches an error.
Parameters
update (str | telegram.Update | None) The update that caused the error
error (telegram.TelegramError) The Telegram error that was raised.
error_handlers = None
List[callable] A list of errorHandlers.
classmethod get_instance()
Get the singleton instance of this class.
Returns telegram.ext.Dispatcher
Raises RuntimeError
groups = None
List[int] A list with all groups.
handlers = None
Dict[int, List[telegram.ext.Handler]] Holds the handlers per group.
process_update(update)
Processes a single update.
Parameters update (str | telegram.Update | telegram.TelegramError)
The update to process.
remove_error_handler(callback)
Removes an error handler.
Parameters callback (callable) The error handler to remove.
remove_handler(handler, group=0)
Remove a handler from the specified group.
Parameters
handler (telegram.ext.Handler) A Handler instance.
group (object, optional) The group identifier. Default is 0.
run_async(func, *args, **kwargs)
Queue a function (with given args/kwargs) to be run asynchronously.
Parameters
func (callable) The function to run in the thread.
*args (tuple, optional) Arguments to func.
**kwargs (dict, optional) Keyword arguments to func.
Returns Promise
running = None
bool Indicates if this dispatcher is running.
start()
Thread target of thread dispatcher.
Runs in background and processes the update queue.
stop()
Stops the thread.
user_data = None
dict A dictionary handlers can use to store data for the user.
This module contains the Filters for use with the MessageHandler class.
class telegram.ext.filters.BaseFilter
Bases: object
Base class for all Message Filters.
Subclassing from this class filters to be combined using bitwise operators:
And:
Or:
Not:
>>> ~ Filters.command
If you want to create your own filters create a class inheriting from this class and implement a filter method
that returns a boolean: True if the message should be handled, False otherwise. Note that the filters work
only as class instances, not actual class objects (so remember to initialize your filter classes).
By default the filters name (what will get printed when converted to a string for display) will be the class
name. If you want to overwrite this assign a better name to the name class variable.
name
str Name for this filter. Defaults to the type of filter.
filter(message)
This method must be overwritten.
Parameters message (telegram.Message) The message that is tested.
Returns bool
class telegram.ext.filters.Filters
Bases: object
Predefined filters for use as the filter argument of telegram.ext.MessageHandler.
Examples
Examples
MessageHandler(Filters.chat(-1234), callback_method)
Parameters
chat_id (int | List[int], optional) Which chat ID(s) to allow through.
username (str | List[str], optional) Which username(s) to allow through. If
username start swith @ symbol, it will be ignored.
Raises ValueError If chat_id and username are both present, or neither is.
command = Filters.command
Filter Messages starting with /.
contact = Filters.contact
Filter Messages that contain telegram.Contact.
document = Filters.document
Filter Messages that contain telegram.Document.
class entity(entity_type)
Bases: telegram.ext.filters.BaseFilter
Filters messages to only allow those which have a telegram.MessageEntity where their type
matches entity_type.
Examples
Examples
MessageHandler(Filters.language("en"), callback_method)
Parameters lang (str | List[str]) Which language code(s) to allow through. This
will be matched using .startswith meaning that en will match both en_US and
en_GB.
location = Filters.location
Filter Messages that contain telegram.Location.
photo = Filters.photo
Filter Messages that contain telegram.PhotoSize.
private = Filters.private
Filter Messages sent in a private chat.
reply = Filters.reply
Filter Messages that are a reply to another message.
status_update = Filters.status_update
Subset for messages containing a status update.
Examples
left_chat_member
Filter Messages that contain telegram.Message.left_chat_member.
migrate
Filter Messages that contain telegram.Message.migrate_from_chat_id or :attr:
telegram.Message.migrate_from_chat_id.
new_chat_members
Filter Messages that contain telegram.Message.new_chat_member.
new_chat_photo
Filter Messages that contain telegram.Message.new_chat_photo.
new_chat_title
Filter Messages that contain telegram.Message.new_chat_title.
pinned_message
Filter Messages that contain telegram.Message.pinned_message.
sticker = Filters.sticker
Filter Messages that contain telegram.Sticker.
successful_payment = Filters.successful_payment
Filter Messages that confirm a telegram.SuccessfulPayment.
text = Filters.text
Filter Text Messages.
class user(user_id=None, username=None)
Bases: telegram.ext.filters.BaseFilter
Filters messages to allow only those which are from specified user ID.
Examples
MessageHandler(Filters.user(1234), callback_method)
Parameters
user_id (int | List[int], optional) Which user ID(s) to allow through.
username (str | List[str], optional) Which username(s) to allow through. If
username starts with @ symbol, it will be ignored.
Raises ValueError If chat_id and username are both present, or neither is.
venue = Filters.venue
Filter Messages that contain telegram.Venue.
video = Filters.video
Filter Messages that contain telegram.Video.
voice = Filters.voice
Filter Messages that contain telegram.Voice.
class telegram.ext.filters.InvertedFilter(f )
Bases: telegram.ext.filters.BaseFilter
Represents a filter that has been inverted.
Parameters f The filter to invert.
class telegram.ext.filters.MergedFilter(base_filter, and_filter=None, or_filter=None)
Bases: telegram.ext.filters.BaseFilter
Represents a filter consisting of two other filters.
Parameters
1.1.4 telegram.ext.JobQueue
Parameters bot (telegram.Bot) The bot instance that should be passed to the jobs.
Deprecated: prevent_autostart (bool, optional): Thread does not start during initialisation. Use start
method instead.
jobs()
Returns a tuple of all jobs that are currently in the JobQueue.
put(job, next_t=None)
Queue a new job.
Parameters
job (telegram.ext.Job) The Job instance representing the new job.
next_t (int | float | datetime.timedelta | datetime.datetime |
datetime.time, optional) Time in or at which the job should run for the first
time. This parameter will be interpreted depending on its type.
int or float will be interpreted as seconds from now in which the job should
run.
datetime.timedelta will be interpreted as time from now in which the job
should run.
datetime.datetime will be interpreted as a specific date and time at which
the job should run.
datetime.time will be interpreted as a specific time at which the job should
run. This could be either today or, if the time has already passed, tomorrow.
callback (callable) The callback function that should be executed by the new
job. It should take bot, job as parameters, where job is the telegram.ext.
Job instance. It can be used to access its Job.context or change it to a repeating
job.
time (datetime.time) Time of day at which the job should run.
days (Tuple[int], optional) Defines on which days of the week the job should run.
Defaults to EVERY_DAY
context (object, optional) Additional data needed for the callback function.
Can be accessed through job.context in the callback. Defaults to None.
name (str, optional) The name of the new job. Defaults to callback.
__name__.
Returns The new Job instance that has been added to the job queue.
Return type telegram.ext.Job
run_once(callback, when, context=None, name=None)
Creates a new Job that runs once and adds it to the queue.
Parameters
callback (callable) The callback function that should be executed by the new
job. It should take bot, job as parameters, where job is the telegram.ext.
Job instance. It can be used to access its job.context or change it to a repeating
job.
when (int | float | datetime.timedelta | datetime.datetime |
datetime.time) Time in or at which the job should run. This parameter will
be interpreted depending on its type.
int or float will be interpreted as seconds from now in which the job should
run.
datetime.timedelta will be interpreted as time from now in which the job
should run.
datetime.datetime will be interpreted as a specific date and time at which
the job should run.
datetime.time will be interpreted as a specific time of day at which the job
should run. This could be either today or, if the time has already passed, tomorrow.
context (object, optional) Additional data needed for the callback function.
Can be accessed through job.context in the callback. Defaults to None.
name (str, optional) The name of the new job. Defaults to callback.
__name__.
Returns The new Job instance that has been added to the job queue.
Return type telegram.ext.Job
run_repeating(callback, interval, first=None, context=None, name=None)
Creates a new Job that runs once and adds it to the queue.
Parameters
callback (callable) The callback function that should be executed by the new
job. It should take bot, job as parameters, where job is the telegram.ext.
Job instance. It can be used to access its Job.context or change it to a repeating
job.
interval (int | float | datetime.timedelta) The interval in which the
job will run. If it is an int or a float, it will be interpreted as seconds.
1.1.5 telegram.ext.MessageQueue
autostart (bool, optional) If True, processors are started immediately after ob-
jects creation; if False, should be started manually by start method. Defaults to
True.
__call__(promise, is_group_msg=False)
Processes callables in troughput-limiting queues to avoid hitting limits (specified with burst_limit
and time_limit.
Parameters
promise (callable) Mainly the telegram.utils.promise.Promise
(see Notes for other callables), that is processed in delay queues.
is_group_msg (bool, optional) Defines whether promise would be processed
in group*+*all* DelayQueue``s (if set to ``True), or only through all
DelayQueue (if set to False), resulting in needed delays to avoid hitting specified
limits. Defaults to True.
Notes
1.1.6 telegram.ext.DelayQueue
Parameters
queue (Queue, optional) Used to pass callbacks to thread. Creates Queue implicitly
if not provided.
burst_limit (int, optional) Number of maximum callbacks to process per time-
window defined by time_limit_ms. Defaults to 30.
time_limit_ms (int, optional) Defines width of time-window used when each
processing limit is calculated. Defaults to 1000.
exc_route (callable, optional) A callable, accepting 1 positional argument;
used to route exceptions from processor thread to main thread; is called on Exception
subclass exceptions. If not provided, exceptions are routed through dummy handler,
which re-raises them.
autostart (bool, optional) If True, processor is started immediately after objects
creation; if False, should be started manually by start method. Defaults to True.
name (str, optional) Threads name. Defaults to 'DelayQueue-N', where N is
sequential number of object created.
1.1.7 Handlers
telegram.ext.Handler
pass_user_data
bool Optional. Determines whether user_data will be passed to the callback function.
pass_chat_data
bool Optional. Determines whether chat_data will be passed to the callback function.
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pass_user_data (bool, optional) If set to True, a keyword argument called
user_data will be passed to the callback function. Default is False.
pass_chat_data (bool, optional) If set to True, a keyword argument called
chat_data will be passed to the callback function. Default is False.
check_update(update)
This method is called to determine if an update should be handled by this handler instance. It should
always be overridden.
Parameters update (str | telegram.Update) The update to be tested.
Returns bool
collect_optional_args(dispatcher, update=None)
Prepares the optional arguments that are the same for all types of handlers.
Parameters dispatcher (telegram.ext.Dispatcher) The dispatcher.
handle_update(update, dispatcher)
This method is called if it was determined that an update should indeed be handled by this in-
stance. It should also be overridden, but in most cases call self.callback(dispatcher.bot,
update), possibly along with optional arguments. To work with the ConversationHandler,
this method should return the value returned from self.callback
Parameters
update (str | telegram.Update) The update to be handled.
dispatcher (telegram.ext.Dispatcher) The dispatcher to collect op-
tional args.
telegram.ext.CallbackQueryHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pattern (str | Pattern, optional) Regex pattern. If not None, re.match is used
on telegram.CallbackQuery.data to determine if an update should be handled
by this handler.
pass_groups (bool, optional) If the callback should be passed the result of re.
match(pattern, data).groups() as a keyword argument called groups.
Default is False
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.ChosenInlineResultHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.ConversationHandler
entry_points
List[telegram.ext.Handler] A list of Handler objects that can trigger the start of the con-
versation.
states
Dict[object, List[telegram.ext.Handler]] A dict that defines the different states of con-
versation a user can be in and one or more associated Handler objects that should be used in that
state.
fallbacks
List[telegram.ext.Handler] A list of handlers that might be used if the user is in a conversa-
tion, but every handler for their current state returned False on check_update.
allow_reentry
bool Optional. Determines if a user can restart a conversation with an entry point.
run_async_timeout
float Optional. The time-out for run_async decorated Handlers.
timed_out_behavior
List[telegram.ext.Handler] Optional. A list of handlers that might be used if the wait for
run_async timed out.
per_chat
bool Optional. If the conversationkey should contain the Chats ID.
per_user
bool Optional. If the conversationkey should contain the Users ID.
per_message
bool Optional. If the conversationkey should contain the Messages ID.
Parameters
entry_points (List[telegram.ext.Handler]) A list of Handler objects
that can trigger the start of the conversation. The first handler which check_update
method returns True will be used. If all return False, the update is not handled.
states (Dict[object, List[telegram.ext.Handler]]) A dict that de-
fines the different states of conversation a user can be in and one or more associ-
ated Handler objects that should be used in that state. The first handler which
check_update method returns True will be used.
fallbacks (List[telegram.ext.Handler]) A list of handlers that might be
used if the user is in a conversation, but every handler for their current state returned
False on check_update. The first handler which check_update method returns
True will be used. If all return False, the update is not handled.
allow_reentry (bool, optional) If set to True, a user that is currently in a
conversation can restart the conversation by triggering one of the entry points.
run_async_timeout (float, optional) If the previous handler for this user was
running asynchronously using the run_async decorator, it might not be finished when
the next message arrives. This timeout defines how long the conversation handler should
wait for the next state to be computed. The default is None which means it will wait
indefinitely.
timed_out_behavior (List[telegram.ext.Handler], optional) A list of
handlers that might be used if the wait for run_async timed out. The first handler
which check_update method returns True will be used. If all return False, the
update is not handled.
per_chat (bool, optional) If the conversationkey should contain the Chats ID.
Default is True.
per_user (bool, optional) If the conversationkey should contain the Users ID.
Default is True.
per_message (bool, optional) If the conversationkey should contain the Mes-
sages ID. Default is False.
Raises ValueError
END = -1
int Used as a constant to return when a conversation is ended.
check_update(update)
Determines whether an update should be handled by this conversationhandler, and if so in which state
the conversation currently is.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback for the current state and Handler
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.CommandHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
command (str | List[str]) The command or list of commands this handler should
listen for.
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
filters (telegram.ext.BaseFilter, optional) A filter inheriting from
telegram.ext.filters.BaseFilter. Standard filters can be found in
telegram.ext.filters.Filters. Filters can be combined using bitwise op-
erators (& for and, | for or, ~ for not).
allow_edited (bool, optional) Determines whether the handler should also ac-
cept edited messages. Default is False.
pass_args (bool, optional) Determines whether the handler should be passed the
arguments passed to the command as a keyword argument called args. It will contain
a list of strings, which is the text following the command split on single or consecutive
whitespace characters. Default is False
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pass_user_data (bool, optional) If set to True, a keyword argument called
user_data will be passed to the callback function. Default is False.
pass_chat_data (bool, optional) If set to True, a keyword argument called
chat_data will be passed to the callback function. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.InlineQueryHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pattern (str | Pattern, optional) Regex pattern. If not None, re.match
is used on telegram.InlineQuery.query to determine if an update should be
handled by this handler.
pass_groups (bool, optional) If the callback should be passed the result of re.
match(pattern, data).groups() as a keyword argument called groups.
Default is False
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.MessageHandler
allow_edited
bool Optional. If the handler should also accept edited messages. Default is False - Deprecated.
use edited_updates instead.
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
filters (telegram.ext.BaseFilter, optional) A filter inheriting from
telegram.ext.filters.BaseFilter. Standard filters can be found in
telegram.ext.filters.Filters. Filters can be combined using bitwise op-
erators (& for and, | for or, ~ for not).
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pass_user_data (bool, optional) If set to True, a keyword argument called
user_data will be passed to the callback function. Default is False.
pass_chat_data (bool, optional) If set to True, a keyword argument called
chat_data will be passed to the callback function. Default is False.
message_updates (bool, optional) Should normal message updates be han-
dled? Default is True.
channel_post_updates (bool, optional) Should channel posts updates be han-
dled? Default is True.
edited_updates (bool, optional) Should edited message updates be handled?
Default is False.
allow_edited (bool, optional) If the handler should also accept edited messages.
Default is False - Deprecated. use edited_updates instead.
Raises ValueError
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.PreCheckoutQueryHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pass_user_data (bool, optional) If set to True, a keyword argument called
user_data will be passed to the callback function. Default is False.
pass_chat_data (bool, optional) If set to True, a keyword argument called
chat_data will be passed to the callback function. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
telegram.ext.RegexHandler
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
pattern (str | Pattern) The regex pattern.
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_groups (bool, optional) If the callback should be passed the result of re.
match(pattern, data).groups() as a keyword argument called groups.
Default is False
pass_groupdict (bool, optional) If the callback should be passed the result
of re.match(pattern, data).groupdict() as a keyword argument called
groupdict. Default is False
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.ShippingQueryHandler
pass_user_data
bool Optional. Determines whether user_data will be passed to the callback function.
pass_chat_data
bool Optional. Determines whether chat_data will be passed to the callback function.
Note: pass_user_data and pass_chat_data determine whether a dict you can use to keep any
data in will be sent to the callback function.. Related to either the user or the chat that the update was
sent in. For each update from the same user or in the same chat, it will be the same dict.
Parameters
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
pass_user_data (bool, optional) If set to True, a keyword argument called
user_data will be passed to the callback function. Default is False.
pass_chat_data (bool, optional) If set to True, a keyword argument called
chat_data will be passed to the callback function. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
telegram.ext.StringCommandHandler
Note: This handler is not used to handle Telegram telegram.Update, but strings manually put in the
queue. For example to send messages with the bot using command line or API.
command
str The command this handler should listen for.
callback
callable The callback function for this handler.
pass_args
bool Optional. Determines whether the handler should be passed args.
pass_update_queue
bool Optional. Determines whether update_queue will be passed to the callback function.
pass_job_queue
bool Optional. Determines whether job_queue will be passed to the callback function.
Parameters
command (str) The command this handler should listen for.
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that a command
should be processed by this handler.
pass_args (bool, optional) Determines whether the handler should be passed the
arguments passed to the command as a keyword argument called args. It will contain
a list of strings, which is the text following the command split on single or consecutive
whitespace characters. Default is False
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument
called job_queue will be passed to the callback function. It will be a
class:telegram.ext.JobQueue instance created by the telegram.ext.Updater
which can be used to schedule new jobs. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (str) An incomming command.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (str) An incomming command.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
command.
telegram.ext.StringRegexHandler
Read the documentation of the re module for more information. The re.match function is used to
determine if an update should be handled by this handler.
Note: This handler is not used to handle Telegram telegram.Update, but strings manually put in the
queue. For example to send messages with the bot using command line or API.
pattern
str | Pattern The regex pattern.
callback
callable The callback function for this handler.
pass_groups
bool Optional. Determines whether groups will be passed to the callback function.
pass_groupdict
bool Optional. Determines whether groupdict. will be passed to the callback function.
pass_update_queue
bool Optional. Determines whether update_queue will be passed to the callback function.
pass_job_queue
bool Optional. Determines whether job_queue will be passed to the callback function.
Parameters
pattern (str | Pattern) The regex pattern.
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
pass_groups (bool, optional) If the callback should be passed the result of re.
match(pattern, data).groups() as a keyword argument called groups.
Default is False
pass_groupdict (bool, optional) If the callback should be passed the result
of re.match(pattern, data).groupdict() as a keyword argument called
groupdict. Default is False
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (str) An incomming command.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (str) An incomming command.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
command.
telegram.ext.TypeHandler
Parameters
type (type) The type of updates this handler should process, as determined by
isinstance
callback (callable) A function that takes bot, update as positional argu-
ments. It will be called when the check_update has determined that an update
should be processed by this handler.
strict (bool, optional) Use type instead of isinstance. Default is False
pass_update_queue (bool, optional) If set to True, a keyword argument called
update_queue will be passed to the callback function. It will be the Queue instance
used by the telegram.ext.Updater and telegram.ext.Dispatcher that
contains new updates which can be used to insert updates. Default is False.
pass_job_queue (bool, optional) If set to True, a keyword argument called
job_queue will be passed to the callback function. It will be a telegram.ext.
JobQueue instance created by the telegram.ext.Updater which can be used to
schedule new jobs. Default is False.
check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update (telegram.Update) Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
update (telegram.Update) Incoming telegram update.
dispatcher (telegram.ext.Dispatcher) Dispatcher that originated the
Update.
1.2 telegram.Audio
Parameters
file_id (str) Unique identifier for this file.
duration (int) Duration of the audio in seconds as defined by sender.
performer (str, optional) Performer of the audio as defined by sender or by audio
tags.
title (str, optional) Title of the audio as defined by sender or by audio tags.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
1.3 telegram.Bot
1.2. telegram.Audio 33
Python Telegram Bot Documentation, Release 8.0.0
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Sticker set name.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
mask_position (telegram.MaskPosition, optional) Position where the
mask should beplaced on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
add_sticker_to_set(*args, **kwargs)
Use this method to add a new sticker to a set created by the bot.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Sticker set name.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
mask_position (telegram.MaskPosition, optional) Position where the
mask should beplaced on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
answerCallbackQuery(*args, **kwargs)
Use this method to send answers to callback queries sent from inline keyboards. The answer will
be displayed to the user as a notification at the top of the chat screen or as an alert. Alternatively,
the user can be redirected to the specified Game URL. For this option to work, you must first cre-
ate a game for your bot via BotFather and accept the terms. Otherwise, you may use links like
t.me/your_bot?start=XXXX that open your bot with a parameter.
Parameters
callback_query_id (str) Unique identifier for the query to be answered.
text (str, optional) Text of the notification. If not specified, nothing will be
shown to the user, 0-200 characters.
show_alert (bool, optional) If true, an alert will be shown by the client instead
of a notification at the top of the chat screen. Defaults to false.
url (str, optional) URL that will be opened by the users client. If you have
created a Game and accepted the conditions via @Botfather, specify the URL that
opens your game - note that this will only work if the query comes from a callback
game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open
your bot with a parameter.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the callback query may be cached client-side. Defaults to 0.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answerInlineQuery(*args, **kwargs)
Use this method to send answers to an inline query. No more than 50 results per query are allowed.
Parameters
inline_query_id (str) Unique identifier for the answered query.
results (List[telegram.InlineQueryResult) A list of results for the in-
line query.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the inline query may be cached on the server. Defaults to 300.
is_personal (bool, optional) Pass True, if results may be cached on the server
side only for the user that sent the query. By default, results may be returned to any
user who sends the same query.
next_offset (str, optional) Pass the offset that a client should send in the next
query with the same text to receive more results. Pass an empty string if there are no
more results or if you dont support pagination. Offset length cant exceed 64 bytes.
switch_pm_text (str, optional) If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the bot a
start message with the parameter switch_pm_parameter.
switch_pm_parameter (str, optional) Deep-linking parameter for the /start
message sent to the bot when user presses the switch button. 1-64 characters, only
A-Z, a-z, 0-9, _ and - are allowed.
1.3. telegram.Bot 35
Python Telegram Bot Documentation, Release 8.0.0
timeout (int | float, optional) If this value is specified, use it as he read timeout
from the server (instead of the one specified during creation of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Example
An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
to adapt search results accordingly. To do this, it displays a Connect your YouTube account button
above the results, or even before showing any. The user presses the button, switches to a private chat
with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link.
Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where
they wanted to use the bots inline capabilities.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answerPreCheckoutQuery(*args, **kwargs)
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirma-
tion in the form of an Update with the field pre_checkout_query. Use this method to respond to such
pre-checkout queries.
Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
Parameters
pre_checkout_query_id (str) Unique identifier for the query to be an-
swered.
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
answerShippingQuery(*args, **kwargs)
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the
Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to
shipping queries.
Parameters
shipping_query_id (str) Unique identifier for the query to be answered.
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
1.3. telegram.Bot 37
Python Telegram Bot Documentation, Release 8.0.0
is_personal (bool, optional) Pass True, if results may be cached on the server
side only for the user that sent the query. By default, results may be returned to any
user who sends the same query.
next_offset (str, optional) Pass the offset that a client should send in the next
query with the same text to receive more results. Pass an empty string if there are no
more results or if you dont support pagination. Offset length cant exceed 64 bytes.
switch_pm_text (str, optional) If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the bot a
start message with the parameter switch_pm_parameter.
switch_pm_parameter (str, optional) Deep-linking parameter for the /start
message sent to the bot when user presses the switch button. 1-64 characters, only
A-Z, a-z, 0-9, _ and - are allowed.
timeout (int | float, optional) If this value is specified, use it as he read timeout
from the server (instead of the one specified during creation of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Example
An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
to adapt search results accordingly. To do this, it displays a Connect your YouTube account button
above the results, or even before showing any. The user presses the button, switches to a private chat
with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link.
Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where
they wanted to use the bots inline capabilities.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answer_pre_checkout_query(*args, **kwargs)
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirma-
tion in the form of an Update with the field pre_checkout_query. Use this method to respond to such
pre-checkout queries.
Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
Parameters
pre_checkout_query_id (str) Unique identifier for the query to be an-
swered.
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
answer_shipping_query(*args, **kwargs)
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the
Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to
shipping queries.
Parameters
shipping_query_id (str) Unique identifier for the query to be answered.
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
shipping_options (List[telegram.ShippingOption]) Required if ok is
True. A JSON-serialized array of available shipping options.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains why it is impossible to complete the order (e.g. Sorry,
delivery to your desired address is unavailable). Telegram will display this message
to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool; On success, True is returned.
Raises telegram.TelegramError
createNewStickerSet(*args, **kwargs)
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, cant contain consecutive underscores and must end in _by_<bot username>.
<bot_username> is case insensitive. 1-64 characters.
title (str) Sticker set title, 1-64 characters.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
contains_masks (bool, optional) Pass True, if a set of mask stickers should be
created.
1.3. telegram.Bot 39
Python Telegram Bot Documentation, Release 8.0.0
create_new_sticker_set(*args, **kwargs)
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, cant contain consecutive underscores and must end in _by_<bot username>.
<bot_username> is case insensitive. 1-64 characters.
title (str) Sticker set title, 1-64 characters.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
contains_masks (bool, optional) Pass True, if a set of mask stickers should be
created.
mask_position (telegram.MaskPosition, optional) Position where the
mask should be placed on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
deleteChatPhoto(*args, **kwargs)
Use this method to delete a chat photo. Photos cant be changed for private chats. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
deleteMessage(*args, **kwargs)
Use this method to delete a message. A message can only be deleted if it was sent less than 48
hours ago. Any such recently sent outgoing message may be deleted. Additionally, if the bot is an
administrator in a group chat, it can delete any message. If the bot is an administrator in a supergroup,
it can delete messages from any other user and service messages about people joining or leaving the
group (other types of service messages may only be removed by the group creator). In channels, bots
can only remove their own messages.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
message_id (int) Identifier of the message to delete.
timeout (int | float, optional) If this value is specified, use it as
read timeout (the) from the server (instead of the one specified during creation
of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
deleteStickerFromSet(*args, **kwargs)
Use this method to delete a sticker from a set created by the bot.
Parameters
sticker (str) File identifier of the sticker.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
deleteWebhook(*args, **kwargs)
Use this method to remove webhook integration if you decide to switch back to getUpdates. Requires
no parameters.
1.3. telegram.Bot 41
Python Telegram Bot Documentation, Release 8.0.0
Parameters
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
delete_chat_photo(*args, **kwargs)
Use this method to delete a chat photo. Photos cant be changed for private chats. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
delete_message(*args, **kwargs)
Use this method to delete a message. A message can only be deleted if it was sent less than 48
hours ago. Any such recently sent outgoing message may be deleted. Additionally, if the bot is an
administrator in a group chat, it can delete any message. If the bot is an administrator in a supergroup,
it can delete messages from any other user and service messages about people joining or leaving the
group (other types of service messages may only be removed by the group creator). In channels, bots
can only remove their own messages.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
message_id (int) Identifier of the message to delete.
timeout (int | float, optional) If this value is specified, use it as
read timeout (the) from the server (instead of the one specified during creation
of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
delete_sticker_from_set(*args, **kwargs)
Use this method to delete a sticker from a set created by the bot.
Parameters
1.3. telegram.Bot 43
Python Telegram Bot Documentation, Release 8.0.0
1.3. telegram.Bot 45
Python Telegram Bot Documentation, Release 8.0.0
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
from_chat_id (int | str) Unique identifier for the chat where the original
message was sent (or channel username in the format @channelusername).
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
message_id (int) Message identifier in the chat specified in from_chat_id.
timeout (int | float, optional) If this value is specified, use it as
read timeout (the) from the server (instead of the one specified during creation
of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
forward_message(*args, **kwargs)
Use this method to forward messages of any kind.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
from_chat_id (int | str) Unique identifier for the chat where the original
message was sent (or channel username in the format @channelusername).
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
message_id (int) Message identifier in the chat specified in from_chat_id.
timeout (int | float, optional) If this value is specified, use it as
read timeout (the) from the server (instead of the one specified during creation
of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
getChat(*args, **kwargs)
Use this method to get up to date information about the chat (current name of the user for one-on-one
conversations, current username of a user, group or channel, etc.).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.Chat
Raises telegram.TelegramError
1.3. telegram.Bot 47
Python Telegram Bot Documentation, Release 8.0.0
getChatAdministrators(*args, **kwargs)
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember
objects that contains information about all chat administrators except other bots. If the chat is a group
or a supergroup and no administrators were appointed, only the creator will be returned.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.ChatMember]
Raises telegram.TelegramError
getChatMember(*args, **kwargs)
Use this method to get information about a member of a chat.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.ChatMember
Raises telegram.TelegramError
getChatMembersCount(*args, **kwargs)
Use this method to get the number of members in a chat
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns Number of members in the chat.
Return type int
Raises telegram.TelegramError
getFile(*args, **kwargs)
Use this method to get basic info about a file and prepare it for downloading. For the moment, bots
can download files of up to 20MB in size. The file can then be downloaded with telegram.File.
download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a
new one can be requested by calling getFile again.
Parameters
file_id (str) File identifier to get info about.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.File
Raises telegram.TelegramError
getGameHighScores(*args, **kwargs)
Use this method to get data for high score tables. Will return the score of the specified user and several
of his neighbors in a game
Parameters
user_id (int) User identifier.
chat_id (int | str, optional) Required if inline_message_id is not specified.
Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.GameHighScore]
Raises telegram.TelegramError
getMe(*args, **kwargs)
A simple method for testing your bots auth token. Requires no parameters.
Parameters timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Returns A telegram.User instance representing that bot if the credentials are valid,
None otherwise.
Return type telegram.User
Raises telegram.TelegramError
getStickerSet(*args, **kwargs)
Use this method to get a sticker set.
Parameters
name (str) Short name of the sticker set that is used in t.me/addstickers/ URLs
(e.g., animals)
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.StickerSet
Raises telegram.TelegramError
getUpdates(*args, **kwargs)
Use this method to receive incoming updates using long polling.
1.3. telegram.Bot 49
Python Telegram Bot Documentation, Release 8.0.0
Parameters
offset (int, optional) Identifier of the first update to be returned. Must be greater
by one than the highest among the identifiers of previously received updates. By
default, updates starting with the earliest unconfirmed update are returned. An update
is considered confirmed as soon as getUpdates is called with an offset higher than its
update_id. The negative offset can be specified to retrieve updates starting from -offset
update from the end of the updates queue. All previous updates will forgotten.
limit (int, optional) Limits the number of updates to be retrieved. Values be-
tween 1-100 are accepted. Defaults to 100.
timeout (int, optional) Timeout in seconds for long polling. Defaults to 0, i.e.
usual short polling. Should be positive, short polling should be used for testing pur-
poses only.
allowed_updates (List[str]), optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
get_updates, so unwanted updates may be received for a short period of time.
**kwargs (dict) Arbitrary keyword arguments.
Notes
Returns List[telegram.Update]
Raises telegram.TelegramError
getUserProfilePhotos(*args, **kwargs)
Use this method to get a list of profile pictures for a user.
Parameters
user_id (int) Unique identifier of the target user.
offset (int, optional) Sequential number of the first photo to be returned. By
default, all photos are returned.
limit (int, optional) Limits the number of photos to be retrieved. Values between
1-100 are accepted. Defaults to 100.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.UserProfilePhotos
Raises telegram.TelegramError
getWebhookInfo(timeout=None, **kwargs)
Use this method to get current webhook status. Requires no parameters.
If the bot is using getUpdates, will return an object with the url field empty.
Parameters
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.WebhookInfo
get_chat(*args, **kwargs)
Use this method to get up to date information about the chat (current name of the user for one-on-one
conversations, current username of a user, group or channel, etc.).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.Chat
Raises telegram.TelegramError
get_chat_administrators(*args, **kwargs)
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember
objects that contains information about all chat administrators except other bots. If the chat is a group
or a supergroup and no administrators were appointed, only the creator will be returned.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.ChatMember]
Raises telegram.TelegramError
get_chat_member(*args, **kwargs)
Use this method to get information about a member of a chat.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.ChatMember
Raises telegram.TelegramError
get_chat_members_count(*args, **kwargs)
Use this method to get the number of members in a chat
Parameters
1.3. telegram.Bot 51
Python Telegram Bot Documentation, Release 8.0.0
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns Number of members in the chat.
Return type int
Raises telegram.TelegramError
get_file(*args, **kwargs)
Use this method to get basic info about a file and prepare it for downloading. For the moment, bots
can download files of up to 20MB in size. The file can then be downloaded with telegram.File.
download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a
new one can be requested by calling getFile again.
Parameters
file_id (str) File identifier to get info about.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.File
Raises telegram.TelegramError
get_game_high_scores(*args, **kwargs)
Use this method to get data for high score tables. Will return the score of the specified user and several
of his neighbors in a game
Parameters
user_id (int) User identifier.
chat_id (int | str, optional) Required if inline_message_id is not specified.
Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.GameHighScore]
Raises telegram.TelegramError
get_me(*args, **kwargs)
A simple method for testing your bots auth token. Requires no parameters.
Parameters timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Returns A telegram.User instance representing that bot if the credentials are valid,
None otherwise.
Notes
Returns List[telegram.Update]
Raises telegram.TelegramError
get_user_profile_photos(*args, **kwargs)
Use this method to get a list of profile pictures for a user.
Parameters
1.3. telegram.Bot 53
Python Telegram Bot Documentation, Release 8.0.0
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group. Otherwise members may only be removed by the groups
creator or by the member that added them.
kick_chat_member(*args, **kwargs)
Use this method to kick a user from a group or a supergroup. In the case of supergroups, the user will
not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot
must be an administrator in the group for this to work.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
until_date (int | datetime.datetime, optional) Date when the user will
be unbanned, unix time. If user is banned for more than 366 days or less than 30
seconds from the current time they are considered to be banned forever.
**kwargs (dict) Arbitrary keyword arguments.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group. Otherwise members may only be removed by the groups
creator or by the member that added them.
last_name
str Optional. Bots last name.
leaveChat(*args, **kwargs)
Use this method for your bot to leave a group, supergroup or channel.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
leave_chat(*args, **kwargs)
Use this method for your bot to leave a group, supergroup or channel.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
1.3. telegram.Bot 55
Python Telegram Bot Documentation, Release 8.0.0
Raises telegram.TelegramError
name
str Bots @username.
pinChatMessage(*args, **kwargs)
Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
message_id (int) Identifier of a message to pin.
disable_notification (bool, optional) Pass True, if it is not necessary to
send a notification to all group members about the new pinned message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
pin_chat_message(*args, **kwargs)
Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
message_id (int) Identifier of a message to pin.
disable_notification (bool, optional) Pass True, if it is not necessary to
send a notification to all group members about the new pinned message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
promoteChatMember(*args, **kwargs)
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights. Pass False for
all boolean parameters to demote a user
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
user_id (int) Unique identifier of the target user.
can_change_info (bool, optional) Pass True, if the administrator can change
chat title, photo and other settings.
1.3. telegram.Bot 57
Python Telegram Bot Documentation, Release 8.0.0
Note: The audio argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
audio (str | filelike object | telegram.Audio) Audio file to send. Pass a file_id
as String to send an audio file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Audio object to send.
caption (str, optional) Audio caption, 0-200 characters.
duration (int, optional) Duration of sent audio in seconds.
performer (str, optional) Performer.
title (str, optional) Track name.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
1.3. telegram.Bot 59
Python Telegram Bot Documentation, Release 8.0.0
sendChatAction(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bots side. The
status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its
typing status).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
action (telegram.ChatAction | str) Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in telegram.ChatAction
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns True on success.
Return type bool
Raises telegram.TelegramError
sendContact(*args, **kwargs)
Use this method to send phone contacts.
Note: You can either supply contact or phone_number and first_name with optionally
last_name.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
phone_number (str, optional) Contacts phone number.
first_name (str, optional) Contacts first name.
last_name (str, optional) Contacts last name.
contact (telegram.Contact, optional) The contact to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
sendDocument(*args, **kwargs)
Use this method to send general files.
Note: The document argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
document (str | filelike object | telegram.Document) File to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Document object to send.
filename (str, optional) File name that shows in telegram message (it is useful
when you send file generated by temp module, for example). Undocumented.
caption (str, optional) Document caption (may also be used when resending
documents by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendGame(*args, **kwargs)
Use this method to send a game.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
game_short_name (str) Short name of the game, serves as the unique identifier
for the game. Set up your games via Botfather.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
1.3. telegram.Bot 61
Python Telegram Bot Documentation, Release 8.0.0
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of location.
longitude (float, optional) Longitude of location.
location (telegram.Location, optional) The location to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendMessage(*args, **kwargs)
Use this method to send text messages.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
text (str) Text of the message to be sent. Max 4096 characters. Also found as
telegram.constants.MAX_MESSAGE_LENGTH.
parse_mode (str) Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bots message. See the
constants in telegram.ParseMode for the available modes.
1.3. telegram.Bot 63
Python Telegram Bot Documentation, Release 8.0.0
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
photo (str | filelike object | telegram.PhotoSize) Photo to send. Pass a
file_id as String to send a photo that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload
a new photo using multipart/form-data. Lastly you can pass an existing telegram.
PhotoSize object to send.
caption (str, optional) Photo caption (may also be used when resending photos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendSticker(*args, **kwargs)
Use this method to send .webp stickers.
Note: The sticker argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
sticker (str | filelike object telegram.Sticker) Sticker to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Sticker object to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendVenue(*args, **kwargs)
Use this method to send information about a venue.
Note: you can either supply venue, or latitude, longitude, title and address and
optionally foursquare_id.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of venue.
longitude (float, optional) Longitude of venue.
title (str, optional) Name of the venue.
address (str, optional) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
venue (telegram.Venue, optional) The venue to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
1.3. telegram.Bot 65
Python Telegram Bot Documentation, Release 8.0.0
sendVideo(*args, **kwargs)
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent
as Document).
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video (str | filelike object | telegram.Video) Video file to send. Pass a file_id
as String to send an video file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an video file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Video object to send.
duration (int, optional) Duration of sent video in seconds.
width (int, optional) Video width.
height (int, optional) Video height.
caption (str, optional) Video caption (may also be used when resending videos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendVideoNote(*args, **kwargs)
Use this method to send video messages.
Note: The video_note argument can be either a file_id or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video_note (str | filelike object | telegram.VideoNote) Video note to
send. Pass a file_id as String to send a video note that exists on the Telegram servers
(recommended) or upload a new video using multipart/form-data. Or you can pass an
existing telegram.VideoNote object to send. Sending video notes by a URL is
currently unsupported.
duration (int, optional) Duration of sent video in seconds.
length (int, optional) Video width and height
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendVoice(*args, **kwargs)
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice
message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may
be sent as Audio or Document).
Note: The voice argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
voice (str | filelike object | telegram.Voice) Voice file to send. Pass a file_id
as String to send an voice file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an voice file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Voice object to send.
caption (str, optional) Voice message caption, 0-200 characters.
duration (int, optional) Duration of the voice message in seconds.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
1.3. telegram.Bot 67
Python Telegram Bot Documentation, Release 8.0.0
send_audio(*args, **kwargs)
Use this method to send audio files, if you want Telegram clients to display them in the music player.
Your audio must be in the .mp3 format. On success, the sent Message is returned. Bots can currently
send audio files of up to 50 MB in size, this limit may be changed in the future.
For sending voice messages, use the sendVoice method instead.
Note: The audio argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
audio (str | filelike object | telegram.Audio) Audio file to send. Pass a file_id
as String to send an audio file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Audio object to send.
caption (str, optional) Audio caption, 0-200 characters.
duration (int, optional) Duration of sent audio in seconds.
performer (str, optional) Performer.
title (str, optional) Track name.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_chat_action(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bots side. The
status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its
typing status).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
action (telegram.ChatAction | str) Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in telegram.ChatAction
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns True on success.
Return type bool
Raises telegram.TelegramError
send_contact(*args, **kwargs)
Use this method to send phone contacts.
Note: You can either supply contact or phone_number and first_name with optionally
last_name.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
phone_number (str, optional) Contacts phone number.
first_name (str, optional) Contacts first name.
last_name (str, optional) Contacts last name.
contact (telegram.Contact, optional) The contact to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
1.3. telegram.Bot 69
Python Telegram Bot Documentation, Release 8.0.0
send_document(*args, **kwargs)
Use this method to send general files.
Note: The document argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
document (str | filelike object | telegram.Document) File to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Document object to send.
filename (str, optional) File name that shows in telegram message (it is useful
when you send file generated by temp module, for example). Undocumented.
caption (str, optional) Document caption (may also be used when resending
documents by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_game(*args, **kwargs)
Use this method to send a game.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
game_short_name (str) Short name of the game, serves as the unique identifier
for the game. Set up your games via Botfather.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_invoice(*args, **kwargs)
Use this method to send invoices.
Parameters
chat_id (int | str) Unique identifier for the target private chat.
title (str) Product name.
description (str) Product description.
payload (str) Bot-defined invoice payload, 1-128 bytes. This will not be dis-
played to the user, use for your internal processes.
provider_token (str) Payments provider token, obtained via Botfather.
start_parameter (str) Unique deep-linking parameter that can be used to
generate this invoice when used as a start parameter.
currency (str) Three-letter ISO 4217 currency code.
prices (List[telegram.LabeledPrice) Price breakdown, a list of compo-
nents (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
photo_url (str, optional) URL of the product photo for the invoice. Can be a
photo of the goods or a marketing image for a service. People like it better when they
see what they are paying for.
photo_size (str, optional) Photo size.
photo_width (int, optional) Photo width.
photo_height (int, optional) Photo height.
need_name (bool, optional) Pass True, if you require the users full name to
complete the order.
need_phone_number (bool, optional) Pass True, if you require the users
phone number to complete the order.
need_email (bool, optional) Pass True, if you require the users email to com-
plete the order.
need_shipping_address (bool, optional) Pass True, if you require the users
shipping address to complete the order.
is_flexible (bool, optional) Pass True, if the final price depends on the ship-
ping method.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. An inlinekeyboard. If empty, one Pay total price button will be shown. If not
empty, the first button must be a Pay button.
1.3. telegram.Bot 71
Python Telegram Bot Documentation, Release 8.0.0
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_location(*args, **kwargs)
Use this method to send point on the map.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of location.
longitude (float, optional) Longitude of location.
location (telegram.Location, optional) The location to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_message(*args, **kwargs)
Use this method to send text messages.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
text (str) Text of the message to be sent. Max 4096 characters. Also found as
telegram.constants.MAX_MESSAGE_LENGTH.
parse_mode (str) Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bots message. See the
constants in telegram.ParseMode for the available modes.
disable_web_page_preview (bool, optional) Disables link previews for
links in this message.
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
photo (str | filelike object | telegram.PhotoSize) Photo to send. Pass a
file_id as String to send a photo that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload
a new photo using multipart/form-data. Lastly you can pass an existing telegram.
PhotoSize object to send.
caption (str, optional) Photo caption (may also be used when resending photos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_sticker(*args, **kwargs)
Use this method to send .webp stickers.
1.3. telegram.Bot 73
Python Telegram Bot Documentation, Release 8.0.0
Note: The sticker argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
sticker (str | filelike object telegram.Sticker) Sticker to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Sticker object to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_venue(*args, **kwargs)
Use this method to send information about a venue.
Note: you can either supply venue, or latitude, longitude, title and address and
optionally foursquare_id.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of venue.
longitude (float, optional) Longitude of venue.
title (str, optional) Name of the venue.
address (str, optional) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
venue (telegram.Venue, optional) The venue to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
send_video(*args, **kwargs)
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent
as Document).
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video (str | filelike object | telegram.Video) Video file to send. Pass a file_id
as String to send an video file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an video file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Video object to send.
duration (int, optional) Duration of sent video in seconds.
width (int, optional) Video width.
height (int, optional) Video height.
caption (str, optional) Video caption (may also be used when resending videos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_video_note(*args, **kwargs)
Use this method to send video messages.
1.3. telegram.Bot 75
Python Telegram Bot Documentation, Release 8.0.0
Note: The video_note argument can be either a file_id or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video_note (str | filelike object | telegram.VideoNote) Video note to
send. Pass a file_id as String to send a video note that exists on the Telegram servers
(recommended) or upload a new video using multipart/form-data. Or you can pass an
existing telegram.VideoNote object to send. Sending video notes by a URL is
currently unsupported.
duration (int, optional) Duration of sent video in seconds.
length (int, optional) Video width and height
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_voice(*args, **kwargs)
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice
message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may
be sent as Audio or Document).
Note: The voice argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
voice (str | filelike object | telegram.Voice) Voice file to send. Pass a file_id
as String to send an voice file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an voice file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Voice object to send.
caption (str, optional) Voice message caption, 0-200 characters.
duration (int, optional) Duration of the voice message in seconds.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
setChatDescription(*args, **kwargs)
Use this method to change the description of a supergroup or a channel. The bot must be an adminis-
trator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
description (str) New chat description, 1-255 characters.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
setChatPhoto(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos cant be changed for private chats. The bot must be an administrator in the chat for this to work
and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
photo (telegram.InputFile) New chat photo.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
1.3. telegram.Bot 77
Python Telegram Bot Documentation, Release 8.0.0
setChatTitle(*args, **kwargs)
Use this method to change the title of a chat. Titles cant be changed for private chats. The bot must
be an administrator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
title (str) New chat title, 1-255 characters.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
setGameScore(*args, **kwargs)
Use this method to set the score of the specified user in a game. On success, if the message was sent
by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is
not greater than the users current score in the chat and force is False.
Parameters
user_id (int) User identifier.
score (int) New score, must be non-negative.
force (bool, optional) Pass True, if the high score is allowed to decrease. This
can be useful when fixing mistakes or banning cheaters
disable_edit_message (bool, optional) Pass True, if the game message
should not be automatically edited to include the current scoreboard.
chat_id (int|str, optional) Required if inline_message_id is not speci-
fied. Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The edited message, or if the message wasnt sent by the bot , True.
Return type telegram.Message
Raises
telegram.TelegramError If the new score is not greater than the users
current score in the chat and force is False.
setStickerPositionInSet(*args, **kwargs)
Use this method to move a sticker in a set created by the bot to a specific position.
Parameters
sticker (str) File identifier of the sticker.
position (int) New sticker position in the set, zero-based.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
setWebhook(*args, **kwargs)
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever
there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a
JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount
of attempts.
If youd like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bots
token, you can be pretty sure its us.
Note: The certificate argument should be a file from disk open(filename, 'rb').
Parameters
url (str) HTTPS url to send updates to. Use an empty string to remove webhook
integration.
certificate (filelike) Upload your public key certificate so that the root
certificate in use can be checked. See our self-signed guide for details. (https://goo.gl/
rw7w6Y)
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use
lower values to limit the load on your bots server, and higher values to increase your
bots throughput.
allowed_updates (List[str], optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
set_webhook, so unwanted updates may be received for a short period of time.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Note:
1.3. telegram.Bot 79
Python Telegram Bot Documentation, Release 8.0.0
1. You will not be able to receive updates using get_updates for as long as an outgoing webhook is
set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate
parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
set_chat_description(*args, **kwargs)
Use this method to change the description of a supergroup or a channel. The bot must be an adminis-
trator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
description (str) New chat description, 1-255 characters.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
set_chat_photo(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos cant be changed for private chats. The bot must be an administrator in the chat for this to work
and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
photo (telegram.InputFile) New chat photo.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
set_chat_title(*args, **kwargs)
Use this method to change the title of a chat. Titles cant be changed for private chats. The bot must
be an administrator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
title (str) New chat title, 1-255 characters.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
set_game_score(*args, **kwargs)
Use this method to set the score of the specified user in a game. On success, if the message was sent
by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is
not greater than the users current score in the chat and force is False.
Parameters
user_id (int) User identifier.
score (int) New score, must be non-negative.
force (bool, optional) Pass True, if the high score is allowed to decrease. This
can be useful when fixing mistakes or banning cheaters
disable_edit_message (bool, optional) Pass True, if the game message
should not be automatically edited to include the current scoreboard.
chat_id (int|str, optional) Required if inline_message_id is not speci-
fied. Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The edited message, or if the message wasnt sent by the bot , True.
Return type telegram.Message
Raises
telegram.TelegramError If the new score is not greater than the users
current score in the chat and force is False.
set_sticker_position_in_set(*args, **kwargs)
Use this method to move a sticker in a set created by the bot to a specific position.
Parameters
1.3. telegram.Bot 81
Python Telegram Bot Documentation, Release 8.0.0
Note: The certificate argument should be a file from disk open(filename, 'rb').
Parameters
url (str) HTTPS url to send updates to. Use an empty string to remove webhook
integration.
certificate (filelike) Upload your public key certificate so that the root
certificate in use can be checked. See our self-signed guide for details. (https://goo.gl/
rw7w6Y)
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use
lower values to limit the load on your bots server, and higher values to increase your
bots throughput.
allowed_updates (List[str], optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
set_webhook, so unwanted updates may be received for a short period of time.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Note:
1. You will not be able to receive updates using get_updates for as long as an outgoing webhook is
set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate
parameter. Please upload as InputFile, sending a String will not work.
unbanChatMember(*args, **kwargs)
Use this method to unban a previously kicked user in a supergroup.
The user will not return to the group automatically, but will be able to join via link, etc. The bot must
be an administrator in the group for this to work.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
unban_chat_member(*args, **kwargs)
Use this method to unban a previously kicked user in a supergroup.
The user will not return to the group automatically, but will be able to join via link, etc. The bot must
be an administrator in the group for this to work.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
unpinChatMessage(*args, **kwargs)
Use this method to unpin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
1.3. telegram.Bot 83
Python Telegram Bot Documentation, Release 8.0.0
Raises telegram.TelegramError
unpin_chat_message(*args, **kwargs)
Use this method to unpin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
uploadStickerFile(*args, **kwargs)
Use this method to upload a .png file with a sticker for later use in create_new_sticker_set
and add_sticker_to_set methods (can be used multiple times).
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of sticker file owner.
png_sticker (str | filelike object) Png image with the sticker, must be up to 512
kilobytes in size, dimensions must not exceed 512px, and either width or height must
be exactly 512px.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The uploaded File
Return type telegram.File
Raises telegram.TelegramError
upload_sticker_file(*args, **kwargs)
Use this method to upload a .png file with a sticker for later use in create_new_sticker_set
and add_sticker_to_set methods (can be used multiple times).
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of sticker file owner.
png_sticker (str | filelike object) Png image with the sticker, must be up to 512
kilobytes in size, dimensions must not exceed 512px, and either width or height must
be exactly 512px.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The uploaded File
Return type telegram.File
Raises telegram.TelegramError
username
str Bots username.
1.4 telegram.CallbackQuery
Note:
In Python from is a reserved word, use from_user instead.
Exactly one of the fields data or game_short_name will be present.
id
str Unique identifier for this query.
from_user
telegram.User Sender.
message
telegram.Message Optional. Message with the callback button that originated the query.
inline_message_id
str Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
chat_instance
str Optional. Global identifier, uniquely corresponding to the chat to which the message with the
callback button was sent.
data
str Optional. Data associated with the callback button.
game_short_name
str Optional. Short name of a Game to be returned.
Parameters
id (str) Unique identifier for this query.
from_user (telegram.User) Sender.
1.4. telegram.CallbackQuery 85
Python Telegram Bot Documentation, Release 8.0.0
Note: After the user presses an inline button, Telegram clients will display a progress bar until you call
answer. It is, therefore, necessary to react by calling telegram.Bot.answer_callback_query
even if no notification to the user is needed (e.g., without specifying any of the optional parameters).
answer(*args, **kwargs)
Shortcut for:
bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
edit_message_caption(*args, **kwargs)
Shortcut for either:
bot.edit_message_caption(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
*args, **kwargs)
or:
bot.edit_message_caption(inline_message_id=update.callback_query.inline_
message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
edit_message_reply_markup(*args, **kwargs)
Shortcut for either:
bot.edit_message_replyMarkup(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.
message_id,
*args, **kwargs)
or:
bot.edit_message_reply_markup(inline_message_id=update.callback_query.
inline_message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
edit_message_text(*args, **kwargs)
Shortcut for either:
bot.edit_message_text(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
*args, **kwargs)
or:
bot.edit_message_text(inline_message_id=update.callback_query.inline_
message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
1.5 telegram.Chat
1.5. telegram.Chat 87
Python Telegram Bot Documentation, Release 8.0.0
pinned_message
telegram.Message Optional. Pinned message, for supergroups. Returned only in get_chat.
Parameters
id (int) Unique identifier for this chat. This number may be greater than 32 bits and
some programming languages may have difficulty/silent defects in interpreting it. But it
is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe
for storing this identifier.
type (str) Type of chat, can be either private, group, supergroup or channel.
title (str, optional) Title, for supergroups, channels and group chats.
username (str, optional) Username, for private chats, supergroups and channels if
available.
first_name (str, optional) First name of the other party in a private chat.
last_name (str, optional) Last name of the other party in a private chat.
all_members_are_administrators (bool, optional) True if a group has All
Members Are Admins enabled.
photo (telegram.ChatPhoto, optional) Chat photo. Returned only in getChat.
description (str, optional) Description, for supergroups and channel chats. Re-
turned only in get_chat.
invite_link (str, optional) Chat invite link, for supergroups and channel chats.
Returned only in get_chat.
pinned_message (telegram.Message, optional) Pinned message, for super-
groups. Returned only in get_chat.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
CHANNEL = 'channel'
str channel
GROUP = 'group'
str group
PRIVATE = 'private'
str private
SUPERGROUP = 'supergroup'
str supergroup
get_administrators(*args, **kwargs)
Shortcut for:
get_member(*args, **kwargs)
Shortcut for:
Returns telegram.ChatMember
get_members_count(*args, **kwargs)
Shortcut for:
Returns int
kick_member(*args, **kwargs)
Shortcut for:
Note: This method will only work if the All Members Are Admins setting is off in the target group.
Otherwise members may only be removed by the groups creator or by the member that added them.
leave(*args, **kwargs)
Shortcut for:
send_action(*args, **kwargs)
Shortcut for:
unban_member(*args, **kwargs)
Shortcut for:
1.6 telegram.ChatAction
class telegram.ChatAction
Bases: object
Helper class to provide constants for different chatactions.
1.6. telegram.ChatAction 89
Python Telegram Bot Documentation, Release 8.0.0
FIND_LOCATION = 'find_location'
str find_location
RECORD_AUDIO = 'record_audio'
str record_audio
RECORD_VIDEO = 'record_video'
str record_video
RECORD_VIDEO_NOTE = 'record_video_note'
str record_video_note
TYPING = 'typing'
str typing
UPLOAD_AUDIO = 'upload_audio'
str upload_audio
UPLOAD_DOCUMENT = 'upload_document'
str upload_document
UPLOAD_PHOTO = 'upload_photo'
str upload_photo
UPLOAD_VIDEO = 'upload_video'
str upload_video
UPLOAD_VIDEO_NOTE = 'upload_video_note'
str upload_video_note
1.7 telegram.ChatMember
can_delete_messages
bool Optional. If the administrator can delete messages of other users.
can_invite_users
bool Optional. If the administrator can invite new users to the chat.
can_restrict_members
bool Optional. If the administrator can restrict, ban or unban chat members.
can_pin_messages
bool Optional. If the administrator can pin messages.
can_promote_members
bool Optional. If the administrator can add new administrators.
can_send_messages
bool Optional. If the user can send text messages, contacts, locations and venues.
can_send_media_messages
bool Optional. If the user can send media messages, implies can_send_messages.
can_send_other_messages
bool Optional. If the user can send animations, games, stickers and use inline bots, implies
can_send_media_messages.
can_add_web_page_previews
bool Optional. If user may add web page previews to his messages, implies
can_send_media_messages
Parameters
user (telegram.User) Information about the user.
status (str) The members status in the chat. Can be creator, administrator,
member, restricted, left or kicked.
until_date (datetime.datetime, optional) Restricted and kicked only. Date
when restrictions will be lifted for this user.
can_be_edited (bool, optional) Administrators only. True, if the bot is allowed
to edit administrator privileges of that user.
can_change_info (bool, optional) Administrators only. True, if the administra-
tor can change the chat title, photo and other settings.
can_post_messages (bool, optional) Administrators only. True, if the admin-
istrator can post in the channel, channels only.
can_edit_messages (bool, optional) Administrators only. True, if the admin-
istrator can edit messages of other users, channels only.
can_delete_messages (bool, optional) Administrators only. True, if the ad-
ministrator can delete messages of other user.
can_invite_users (bool, optional) Administrators only. True, if the adminis-
trator can invite new users to the chat.
can_restrict_members (bool, optional) Administrators only. True, if the ad-
ministrator can restrict, ban or unban chat members.
can_pin_messages (bool, optional) Administrators only. True, if the adminis-
trator can pin messages, supergroups only.
can_promote_members (bool, optional) Administrators only. True, if the ad-
ministrator can add new administrators with a subset of his own privileges or demote
administrators that he has promoted, directly or indirectly (promoted by administrators
that were appointed by the user).
1.7. telegram.ChatMember 91
Python Telegram Bot Documentation, Release 8.0.0
can_send_messages (bool, optional) Restricted only. True, if the user can send
text messages, contacts, locations and venues.
can_send_media_messages (bool, optional) Restricted only. True, if the
user can send audios, documents, photos, videos, video notes and voice notes, implies
can_send_messages.
can_send_other_messages (bool, optional) Restricted only. True, if
the user can send animations, games, stickers and use inline bots, implies
can_send_media_messages.
can_add_web_page_previews (bool, optional) Restricted only. True, if user
may add web page previews to his messages, implies can_send_media_messages.
ADMINISTRATOR = 'administrator'
str administrator
CREATOR = 'creator'
str creator
KICKED = 'kicked'
str kicked
LEFT = 'left'
str left
MEMBER = 'member'
str member
RESTRICTED = 'restricted'
str restricted
1.8 telegram.ChatPhoto
Parameters
small_file_id (str) Unique file identifier of small (160x160) chat photo. This
file_id can be used only for photo download.
big_file_id (str) Unique file identifier of big (640x640) chat photo. This file_id
can be used only for photo download.
bot (telegram.Bot, optional) The Bot to use for instance methods
**kwargs (dict) Arbitrary keyword arguments.
telegram.constants.MAX_MESSAGE_LENGTH
int 4096
telegram.constants.MAX_CAPTION_LENGTH
int 200
telegram.constants.SUPPORTED_WEBHOOK_PORTS
List[int] [443, 80, 88, 8443]
telegram.constants.MAX_FILESIZE_DOWNLOAD
int In bytes (20MB)
telegram.constants.MAX_FILESIZE_UPLOAD
int In bytes (50MB)
telegram.constants.MAX_MESSAGES_PER_SECOND_PER_CHAT
int 1. Telegram may allow short bursts that go over this limit, but eventually youll begin receiving 429
errors.
telegram.constants.MAX_MESSAGES_PER_SECOND
int 30
telegram.constants.MAX_MESSAGES_PER_MINUTE_PER_GROUP
int 20
telegram.constants.MAX_INLINE_QUERY_RESULTS
int 50
The following constant have been found by experimentation:
telegram.constants.MAX_MESSAGE_ENTITIES
int 100 (Beyond this cap telegram will simply ignore further formatting styles)
1.10 telegram.Contact
Parameters
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
user_id (int, optional) Contacts user identifier in Telegram.
**kwargs (dict) Arbitrary keyword arguments.
1.10. telegram.Contact 93
Python Telegram Bot Documentation, Release 8.0.0
1.11 telegram.Document
Parameters
file_id (str) Unique file identifier
thumb (telegram.PhotoSize, optional) Document thumbnail as defined by
sender.
file_name (str, optional) Original filename as defined by sender.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
exception telegram.error.Unauthorized(message)
Bases: telegram.error.TelegramError
1.13 telegram.File
file_id
str Unique identifier for this file.
file_size
str Optional. File size.
file_path
str Optional. File path. Use download to get the file.
Parameters
file_id (str) Unique identifier for this file.
file_size (int, optional) Optional. File size, if known.
file_path (str, optional) File path. Use download to get the file.
bot (telegram.Bot, optional) Bot to use with shortcut method.
**kwargs (dict) Arbitrary keyword arguments.
Parameters
custom_path (str, optional) Custom path.
out (object, optional) A file-like object. Must be opened in binary mode, if
applicable.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Raises ValueError If both custom_path and out are passed.
1.13. telegram.File 95
Python Telegram Bot Documentation, Release 8.0.0
1.14 telegram.ForceReply
Parameters
selective (bool, optional) Use this parameter if you want to force reply from
specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
**kwargs (dict) Arbitrary keyword arguments.
1.15 telegram.InlineKeyboardButton
Note: You must use exactly one of the optional fields. Mind that callback_game is not working as
expected. Putting a game short name in it might, but is not guaranteed to work.
text
str Label text on the button.
url
str Optional. HTTP url to be opened when button is pressed.
callback_data
str Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.
switch_inline_query
str Optional. Will prompt the user to select one of their chats, open that chat and insert the bots
username and the specified inline query in the input field.
switch_inline_query_current_chat
str Optional. Will insert the bots username and the specified inline query in the current chats
input field.
callback_game
telegram.CallbackGame Optional. Description of the game that will be launched when the
user presses the button.
pay
bool Optional. Specify True, to send a Pay button.
Parameters
text (str) Label text on the button.
url (str) HTTP url to be opened when button is pressed.
callback_data (str, optional) Data to be sent in a callback query to the bot
when button is pressed, 1-64 bytes.
switch_inline_query (str, optional) If set, pressing the button will prompt
the user to select one of their chats, open that chat and insert the bots username and
the specified inline query in the input field. Can be empty, in which case just the bots
username will be inserted. This offers an easy way for users to start using your bot in
inline mode when they are currently in a private chat with it. Especially useful when
combined with switch_pm* actions - in this case the user will be automatically returned
to the chat they switched from, skipping the chat selection screen.
switch_inline_query_current_chat (str, optional) If set, pressing the
button will insert the bots username and the specified inline query in the current chats
input field. Can be empty, in which case only the bots username will be inserted. This
offers a quick way for the user to open your bot in inline mode in the same chat - good
for selecting something from multiple options.
callback_game (telegram.CallbackGame, optional) Description of the
game that will be launched when the user presses the button. This type of button must
always be the first button in the first row.
pay (bool, optional) Specify True, to send a Pay button. This type of button must
always be the first button in the first row.
**kwargs (dict) Arbitrary keyword arguments.
1.16 telegram.InlineKeyboardMarkup
Parameters
inline_keyboard (List[List[telegram.InlineKeyboardButton]]) Ar-
ray of button rows, each represented by an Array of InlineKeyboardButton objects.
**kwargs (dict) Arbitrary keyword arguments.
1.17 telegram.InputFile
class telegram.InputFile(data)
Bases: object
This object represents a Telegram InputFile.
data
dict Data containing an inputfile.
1.16. telegram.InlineKeyboardMarkup 97
Python Telegram Bot Documentation, Release 8.0.0
content_type
str Content type
headers
dict Headers.
static is_image(stream)
Check if the content file is an image by analyzing its headers.
Parameters stream (str) A str representing the content of a file.
Returns The str mime-type of an image.
Return type str
static is_inputfile(data)
Check if the request is a file request.
Parameters data (Dict[str, str]) A dict of (str, str) key/value pairs.
Returns bool
to_form()
Transform the inputfile to multipart/form data.
Returns str
1.18 telegram.KeyboardButton
text
str Text of the button.
request_contact
bool Optional. If the users phone number will be sent.
request_location
bool Optional. If the users current location will be sent.
Parameters
text (str) Text of the button. If none of the optional fields are used, it will be sent
to the bot as a message when the button is pressed.
request_contact (bool, optional) If True, the users phone number will be sent
as a contact when the button is pressed. Available in private chats only.
request_location (bool, optional) If True, the users current location will be
sent when the button is pressed. Available in private chats only.
Note: request_contact and request_location options will only work in Telegram versions
released after 9 April, 2016. Older clients will ignore them.
1.19 telegram.Location
Parameters
longitude (float) Longitude as defined by sender.
latitude (float) Latitude as defined by sender.
**kwargs (dict) Arbitrary keyword arguments.
1.20 telegram.Message
Note:
In Python from is a reserved word, use from_user instead.
message_id
int Unique message identifier inside this chat.
from_user
telegram.User Optional. Sender.
date
datetime.datetime Date the message was sent.
1.19. telegram.Location 99
Python Telegram Bot Documentation, Release 8.0.0
chat
telegram.Chat Conversation the message belongs to.
forward_from
telegram.User Optional. Sender of the original message.
forward_from_chat
telegram.Chat Optional. Information about the original channel.
forward_from_message_id
int Optional. Identifier of the original message in the channel.
forward_date
datetime.datetime Optional. Date the original message was sent.
reply_to_message
telegram.Message Optional. The original message.
edit_date
datetime.datetime Optional. Date the message was last edited.
text
str Optional. The actual UTF-8 text of the message.
entities
List[telegram.MessageEntity] Optional. Special entities like usernames, URLs, bot com-
mands, etc. that appear in the text. See Message.parse_entity and parse_entities meth-
ods for how to use properly.
audio
telegram.Audio Optional. Information about the file.
document
telegram.Document Optional. Information about the file.
game
telegram.Game Optional. Information about the game.
photo
List[telegram.PhotoSize] Optional. Available sizes of the photo.
sticker
telegram.Sticker Optional. Information about the sticker.
video
telegram.Video Optional. Information about the video.
voice
telegram.Voice Optional. Information about the file.
video_note
telegram.VideoNote Optional. Information about the video message.
new_chat_members
List[telegram.User] Optional. Information about new members to the chat. (the bot itself may
be one of these members).
caption
str Optional. Caption for the document, photo or video, 0-200 characters.
contact
telegram.Contact Optional. Information about the contact.
location
telegram.Location Optional. Information about the location.
venue
telegram.Venue Optional. Information about the venue.
left_chat_member
telegram.User Optional. Information about the user that left the group. (this member may be
the bot itself).
new_chat_title
str Optional. A chat title was changed to this value.
new_chat_photo
List[telegram.PhotoSize] Optional. A chat photo was changed to this value.
delete_chat_photo
bool Optional. The chat photo was deleted.
group_chat_created
bool Optional. The group has been created.
supergroup_chat_created
bool Optional. The supergroup has been created.
channel_chat_created
bool Optional. The channel has been created.
migrate_to_chat_id
int Optional. The group has been migrated to a supergroup with the specified identifier.
migrate_from_chat_id
int Optional. The supergroup has been migrated from a group with the specified identifier.
pinned_message
telegram.message Optional. Specified message was pinned.
invoice
telegram.Invoice Optional. Information about the invoice.
successful_payment
telegram.SuccessfulPayment Optional. Information about the payment.
forward_signature
str Optional. Signature of the post author for messages forwarded from channels.
author_signature
str Optional. Signature of the post author for messages in channels.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
message_id (int) Unique message identifier inside this chat.
from_user (telegram.User, optional) Sender, can be empty for messages sent
to channels.
date (datetime.datetime) Date the message was sent in Unix time. Converted
to datetime.datetime.
chat (telegram.Chat) Conversation the message belongs to.
forward_from (telegram.User, optional) For forwarded messages, sender of
the original message.
forward_from_chat (telegram.Chat, optional) For messages forwarded
from a channel, information about the original channel.
forward_from_message_id (int, optional) For forwarded channel posts, iden-
tifier of the original message in the channel.
chat_id
int Shortcut for telegram.Chat.id for chat.
delete(*args, **kwargs)
Shortcut for:
bot.delete_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
edit_caption(*args, **kwargs)
Shortcut for:
bot.edit_message_caption(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods.
edit_reply_markup(*args, **kwargs)
Shortcut for:
bot.edit_message_reply_markup(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods.
edit_text(*args, **kwargs)
Shortcut for:
bot.edit_message_text(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods..
effective_attachment
telegram.Audio or telegram.Contact or telegram.Document or telegram.
Game or telegram.Invoice or telegram.Location or List[telegram.PhotoSize]
or telegram.Sticker or telegram.SuccessfulPayment or telegram.Venue or
telegram.Video or telegram.VideoNote or telegram.Voice: The attachment that this
message was sent with. May be None if no attachment was sent.
forward(chat_id, disable_notification=False)
Shortcut for:
bot.forward_message(chat_id=chat_id,
from_chat_id=update.message.chat_id,
disable_notification=disable_notification,
message_id=update.message.message_id)
new_chat_member
Deprecated
parse_entities(types=None)
Returns a dict that maps telegram.MessageEntity to str. It contains entities from this
message filtered by their telegram.MessageEntity.type attribute as the key, and the text that
each entity belongs to as the value of the dict.
Note: This method should always be used instead of the entities attribute, since it calculates the
correct substring from the message text based on UTF-16 codepoints. See parse_entity for more
info.
parse_entity(entity)
Returns the text from a given telegram.MessageEntity.
Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python dont handle automatically. (That is, you cant just slice
Message.text with the offset and length.)
Parameters
entity (telegram.MessageEntity) The entity to extract the text from. It
must
an entity that belongs to this message. (be)
Returns The text of the given entity
Return type str
reply_audio(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_contact(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_document(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_location(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_photo(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_sticker(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_text(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the message is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
reply_venue(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_video(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_video_note(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_voice(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
text_html
Creates an HTML-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as HTML in the same way
the original message was formatted.
Returns Message text with entities formatted as HTML.
Return type str
text_html_urled
Creates an HTML-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as HTML. This also formats
telegram.MessageEntity.URL as a hyperlink.
Returns Message text with entities formatted as HTML.
Return type str
text_markdown
Creates an Markdown-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as Markdown in the same
way the original message was formatted.
Returns Message text with entities formatted as Markdown.
Return type str
text_markdown_urled
Creates an Markdown-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as Markdown. This also
formats telegram.MessageEntity.URL as a hyperlink.
Returns Message text with entities formatted as Markdown.
Return type str
1.21 telegram.MessageEntity
Parameters
type (str) Type of the entity. Can be mention (@username), hashtag,
bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string),
pre (monowidth block), text_link (for clickable text URLs), text_mention (for users
without usernames).
offset (int) Offset in UTF-16 code units to the start of the entity.
length (int) Length of the entity in UTF-16 code units.
url (str, optional) For text_link only, url that will be opened after usertaps on the
text.
user (telegram.User, optional) For text_mention only, the mentioned user.
1.22 telegram.ParseMode
class telegram.ParseMode
Bases: object
This object represents a Telegram Message Parse Modes.
HTML = 'HTML'
str HTML
MARKDOWN = 'Markdown'
str Markdown
1.23 telegram.PhotoSize
Parameters
file_id (str) Unique identifier for this file.
width (int) Photo width.
height (int) Photo height.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
1.24 telegram.ReplyKeyboardRemove
Example
A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for
that user, while still showing the keyboard with poll options to users who havent voted yet.
Parameters
selective (bool, optional) Use this parameter if you want to remove the keyboard
for specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
**kwargs (dict) Arbitrary keyword arguments.
1.25 telegram.ReplyKeyboardMarkup
Example
A user requests to change the bots language, bot replies to the request with a keyboard to select the new
language. Other users in the group dont see the keyboard.
Parameters
keyboard (List[List[str | telegram.KeyboardButton]]) Array of button
rows, each represented by an Array of telegram.KeyboardButton objects.
resize_keyboard (bool, optional) Requests clients to resize the keyboard ver-
tically for optimal fit (e.g., make the keyboard smaller if there are just two rows of
buttons). Defaults to false, in which case the custom keyboard is always of the same
height as the apps standard keyboard. Defaults to False
one_time_keyboard (bool, optional) Requests clients to hide the keyboard as
soon as its been used. The keyboard will still be available, but clients will automatically
display the usual letter-keyboard in the chat - the user can press a special button in the
input field to see the custom keyboard again. Defaults to False.
selective (bool, optional) Use this parameter if you want to show the keyboard
to specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
Defaults to False.
**kwargs (dict) Arbitrary keyword arguments.
1.26 telegram.ReplyMarkup
class telegram.ReplyMarkup
Bases: telegram.base.TelegramObject
Base class for Telegram ReplyMarkup Objects.
See telegram.ReplyKeyboardMarkup and telegram.InlineKeyboardMarkup for detailed
use.
1.27 telegram.TelegramObject
class telegram.TelegramObject
Bases: object
Base class for most telegram objects.
to_json()
Returns str
1.28 telegram.Update
Note: At most one of the optional parameters can be present in any given update.
update_id
int The updates unique identifier.
message
telegram.Message Optional. New incoming message.
edited_message
telegram.Message Optional. New version of a message.
channel_post
telegram.Message Optional. New incoming channel post.
edited_channel_post
telegram.Message Optional. New version of a channel post.
inline_query
telegram.InlineQuery Optional. New incoming inline query.
chosen_inline_result
telegram.ChosenInlineResult Optional. The result of an inline query that was chosen by
a user.
callback_query
telegram.CallbackQuery Optional. New incoming callback query.
shipping_query
telegram.ShippingQuery Optional. New incoming shipping query.
pre_checkout_query
telegram.PreCheckoutQuery Optional. New incoming pre-checkout query.
Parameters
update_id (int) The updates unique identifier. Update identifiers start from a
certain positive number and increase sequentially. This ID becomes especially handy if
youre using Webhooks, since it allows you to ignore repeated updates or to restore the
correct update sequence, should they get out of order.
1.29 telegram.User
username
str Optional. Users or bots last name.
language_code
str Optional. IETF language tag of the users language.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
id (int) Unique identifier for this user or bot.
is_bot (bool) True, if this user is a bot
first_name (str) Users or bots first name.
last_name (str, optional) Users or bots last name.
username (str, optional) Users or bots username.
language_code (str, optional) IETF language tag of the users language.
bot (telegram.Bot, optional) The Bot to use for instance methods.
mention_html(name=None)
Parameters name (str) If provided, will overwrite the users name.
Returns The inline mention for the user as HTML.
Return type str
mention_markdown(name=None)
Parameters name (str) If provided, will overwrite the users name.
Returns The inline mention for the user as markdown.
Return type str
name
str The users username if available, if not it returns the first name and if present first_name
and last_name.
1.30 telegram.UserProfilePhotos
Parameters
total_count (int) Total number of profile pictures the target user has.
photos (List[List[telegram.PhotoSize]]) Requested profile pictures (in up to
4 sizes each).
1.31 telegram.Venue
Parameters
location (telegram.Location) Venue location.
title (str) Name of the venue.
address (str) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
**kwargs (dict) Arbitrary keyword arguments.
1.32 telegram.Video
Parameters
file_id (str) Unique identifier for this file.
width (int) Video width as defined by sender.
height (int) Video height as defined by sender.
duration (int) Duration of the video in seconds as defined by sender.
thumb (telegram.PhotoSize, optional) Video thumbnail.
mime_type (str, optional) Mime type of a file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
1.33 telegram.VideoNote
Parameters
file_id (str) Unique identifier for this file.
length (int) Video width and height as defined by sender.
duration (int) Duration of the video in seconds as defined by sender.
thumb (telegram.PhotoSize, optional) Video thumbnail.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
1.34 telegram.Voice
mime_type
str Optional. MIME type of the file as defined by sender.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
duration (int, optional) Duration of the audio in seconds as defined by sender.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
1.35 telegram.WebhookInfo
Parameters
url (str) Webhook URL, may be empty if webhook is not set up.
has_custom_certificate (bool) True, if a custom certificate was provided
for webhook certificate checks.
pending_update_count (int) Number of updates awaiting delivery.
last_error_date (int, optional) Unix time for the most recent error that hap-
pened when trying todeliver an update via webhook.
last_error_message (str, optional) Error message in human-readable format
for the most recent error that happened when trying to deliver an update via webhook.
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery.
1.36 Stickers
1.36.1 telegram.Sticker
Parameters
file_id (str) Unique identifier for this file.
width (int) Sticker width.
height (int) Sticker height.
thumb (telegram.PhotoSize, optional) Sticker thumbnail in the .webp or .jpg
format.
emoji (str, optional) Emoji associated with the sticker
set_name (str, optional) Name of the sticker set to which the sticker belongs.
mask_position (telegram.MaskPosition, optional) For mask stickers, the
position where the mask should be placed.
file_size (int, optional) File size.
(obj (**kwargs) dict): Arbitrary keyword arguments.
1.36.2 telegram.StickerSet
Parameters
name (str) Sticker set name.
title (str) Sticker set title.
contains_masks (bool) True, if the sticker set contains masks.
stickers (List[telegram.Sticker]) List of all set stickers.
1.36.3 telegram.MaskPosition
Notes
type should be one of the following: forehead, eyes, mouth or chin. You can use the classconstants for
those.
Parameters
point (str) The part of the face relative to which the mask should be placed.
x_shift (float) Shift by X-axis measured in widths of the mask scaled to the face
size, from left to right. For example, choosing -1.0 will place mask just to the left of the
default mask position.
y_shift (float) Shift by Y-axis measured in heights of the mask scaled to the face
size, from top to bottom. For example, 1.0 will place the mask just below the default
mask position.
scale (float) Mask scaling coefficient. For example, 2.0 means double size.
CHIN = 'chin'
str chin
EYES = 'eyes'
str eyes
FOREHEAD = 'forehead'
str forehead
MOUTH = 'mouth'
str mouth
1.37.1 telegram.InlineQuery
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique identifier for this query.
from_user
telegram.User Sender.
location
telegram.Location Optional. Sender location, only for bots that request user location.
query
str Text of the query (up to 512 characters).
offset
str Offset of the results to be returned, can be controlled by the bot.
Parameters
id (str) Unique identifier for this query.
from_user (telegram.User) Sender.
location (telegram.Location, optional) Sender location, only for bots that
request user location.
query (str) Text of the query (up to 512 characters).
offset (str) Offset of the results to be returned, can be controlled by the bot.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
Parameters
1.37.2 telegram.InlineQueryResult
Parameters
type (str) Type of the result.
id (str) Unique identifier for this result, 1-64 Bytes.
**kwargs (dict) Arbitrary keyword arguments.
1.37.3 telegram.InlineQueryResultArticle
reply_markup
telegram.ReplyMarkup Optional. Inline keyboard attached to the message.
url
str Optional. URL of the result.
hide_url
bool Optional. Pass True, if you dont want the URL to be shown in the message.
description
str Optional. Short description of the result.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 Bytes.
title (str) Title of the result.
input_message_content (telegram.InputMessageContent) Content
of the message to be sent.
reply_markup (telegram.ReplyMarkup, optional) Inline keyboard attached
to the message
url (str, optional) URL of the result.
hide_url (bool, optional) Pass True, if you dont want the URL to be shown in
the message.
description (str, optional) Short description of the result.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
1.37.4 telegram.InlineQueryResultAudio
title
str Title.
performer
str Optional. Caption, 0-200 characters.
audio_duration
str Optional. Performer.
caption
str Optional. Audio duration in seconds.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
audio.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
audio_url (str) A valid URL for the audio file.
title (str) Title.
performer (str, optional) Caption, 0-200 characters.
audio_duration (str, optional) Performer.
caption (str, optional) Audio duration in seconds.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the audio.
**kwargs (dict) Arbitrary keyword arguments.
1.37.5 telegram.InlineQueryResultCachedAudio
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
audio.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
audio_file_id (str) A valid file identifier for the audio file.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the audio.
**kwargs (dict) Arbitrary keyword arguments.
1.37.6 telegram.InlineQueryResultCachedDocument
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
title (str) Title for the result.
document_file_id (str) A valid file identifier for the file.
description (str, optional) Short description of the result.
1.37.7 telegram.InlineQueryResultCachedGif
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
gif_file_id (str) A valid file identifier for the GIF file.
title (str, optional) Title for the result.caption (str, optional):
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the gif.
**kwargs (dict) Arbitrary keyword arguments.
1.37.8 telegram.InlineQueryResultCachedMpeg4Gif
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
mpeg4_file_id (str) A valid file identifier for the MP4 file.
title (str, optional) Title for the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the MPEG-4 file.
**kwargs (dict) Arbitrary keyword arguments.
1.37.9 telegram.InlineQueryResultCachedPhoto
type
str photo.
id
str Unique identifier for this result, 1-64 bytes.
photo_file_id
str A valid file identifier of the photo.
title
str Optional. Title for the result.
description
str Optional. Short description of the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
photo.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
photo_file_id (str) A valid file identifier of the photo.
title (str, optional) Title for the result.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the photo.
**kwargs (dict) Arbitrary keyword arguments.
1.37.10 telegram.InlineQueryResultCachedSticker
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
sticker.
Parameters
id (str)
sticker_file_id (str)
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the sticker.
**kwargs (dict) Arbitrary keyword arguments.
1.37.11 telegram.InlineQueryResultCachedVideo
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
video_file_id (str) A valid file identifier for the video file.
title (str) Title for the result.
description (str, optional) Short description of the result.
1.37.12 telegram.InlineQueryResultCachedVoice
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
voice_file_id (str) A valid file identifier for the voice message.
title (str) Voice message title.
caption (str, optional) Caption, 0-200 characters.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the voice.
**kwargs (dict) Arbitrary keyword arguments.
1.37.13 telegram.InlineQueryResultContact
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the contact.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
1.37.14 telegram.InlineQueryResultDocument
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
title (str) Title for the result.
caption (str, optional) Caption, 0-200 characters
document_url (str) A valid URL for the file.
mime_type (str) Mime type of the content of the file, either application/pdf or
application/zip.
description (str, optional) Short description of the result.
reply_markup (telegram.InlineKeyboardMarkup) Optional. Inline key-
board attached to the message.
1.37.15 telegram.InlineQueryResultGame
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
game_short_name (str) Short name of the game.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
**kwargs (dict) Arbitrary keyword arguments.
1.37.16 telegram.InlineQueryResultGif
gif_height
int Optional. Height of the GIF.
gif_duration
int Optional. Duration of the GIF.
thumb_url
str URL of the static thumbnail for the result (jpeg or gif).
title
str Optional. Title for the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
gif.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
gif_url (str) A valid URL for the GIF file. File size must not exceed 1MB.
gif_width (int, optional) Width of the GIF.
gif_height (int, optional) Height of the GIF.
gif_duration (int, optional) Duration of the GIF
thumb_url (str) URL of the static thumbnail for the result (jpeg or gif).
title (str, optional) Title for the result.caption (str, optional):
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the gif.
**kwargs (dict) Arbitrary keyword arguments.
1.37.17 telegram.InlineQueryResultLocation
longitude
float Location longitude in degrees.
title
str Location title.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
location.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
latitude (float) Location latitude in degrees.
longitude (float) Location longitude in degrees.
title (str) Location title.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the location.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
1.37.18 telegram.InlineQueryResultMpeg4Gif
mpeg4_url
str A valid URL for the MP4 file. File size must not exceed 1MB.
mpeg4_width
int Optional. Video width.
mpeg4_height
int Optional. Video height.
mpeg4_duration
int Optional. Video duration.
thumb_url
str URL of the static thumbnail (jpeg or gif) for the result.
title
str Optional. Title for the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
MPEG-4 file.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
mpeg4_url (str) A valid URL for the MP4 file. File size must not exceed 1MB.
mpeg4_width (int, optional) Video width.
mpeg4_height (int, optional) Video height.
mpeg4_duration (int, optional) Video duration.
thumb_url (str) URL of the static thumbnail (jpeg or gif) for the result.
title (str, optional) Title for the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the MPEG-4 file.
**kwargs (dict) Arbitrary keyword arguments.
1.37.19 telegram.InlineQueryResultPhoto
id
str Unique identifier for this result, 1-64 bytes.
photo_url
str A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.
thumb_url
str URL of the thumbnail for the photo.
photo_width
int Optional. Width of the photo.
photo_height
int Optional. Height of the photo.
title
str Optional. Title for the result.
description
str Optional. Short description of the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
photo.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
photo_url (str) A valid URL of the photo. Photo must be in jpeg format. Photo
size must not exceed 5MB.
thumb_url (str) URL of the thumbnail for the photo.
photo_width (int, optional) Width of the photo.
photo_height (int, optional) Height of the photo.
title (str, optional) Title for the result.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the photo.
**kwargs (dict) Arbitrary keyword arguments.
1.37.20 telegram.InlineQueryResultVenue
Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use
input_message_content to send a message with the specified content instead of the venue.
type
str venue.
id
str Unique identifier for this result, 1-64 Bytes.
latitude
float Latitude of the venue location in degrees.
longitude
float Longitude of the venue location in degrees.
title
str Title of the venue.
address
str Address of the venue.
foursquare_id
str Optional. Foursquare identifier of the venue if known.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
venue.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 Bytes.
latitude (float) Latitude of the venue location in degrees.
longitude (float) Longitude of the venue location in degrees.
title (str) Title of the venue.
address (str) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue if known.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the location.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
1.37.21 telegram.InlineQueryResultVideo
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
video_url (str) A valid URL for the embedded video player or video file.
mime_type (str) Mime type of the content of video url, text/html or
video/mp4.
thumb_url (str) URL of the thumbnail (jpeg only) for the video.
title (str) Title for the result.
caption (str, optional) Caption, 0-200 characters.
video_width (int, optional) Video width.
1.37.22 telegram.InlineQueryResultVoice
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
voice_url (str) A valid URL for the voice recording.
title (str) Voice message title.
caption (str, optional) Caption, 0-200 characters.
voice_duration (int, optional) Recording duration in seconds.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the voice.
1.37.23 telegram.InputMessageContent
class telegram.InputMessageContent
Bases: telegram.base.TelegramObject
Base class for Telegram InputMessageContent Objects.
See: telegram.InputContactMessageContent, telegram.
InputLocationMessageContent, telegram.InputTextMessageContent and
telegram.InputVenueMessageContent for more details.
1.37.24 telegram.InputTextMessageContent
Parameters
message_text (str) Text of the message to be sent, 1-4096 characters. Also
found as telegram.constants.MAX_MESSAGE_LENGTH.
parse_mode (str, optional) Send Markdown or HTML, if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your bots message.
disable_web_page_preview (bool, optional) Disables link previews for links
in the sent message.
**kwargs (dict) Arbitrary keyword arguments.
1.37.25 telegram.InputLocationMessageContent
Parameters
latitude (float) Latitude of the location in degrees.
longitude (float) Longitude of the location in degrees.
**kwargs (dict) Arbitrary keyword arguments.
1.37.26 telegram.InputVenueMessageContent
Parameters
latitude (float) Latitude of the location in degrees.
longitude (float) Longitude of the location in degrees.
title (str) Name of the venue.
address (str) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue, if known.
**kwargs (dict) Arbitrary keyword arguments.
1.37.27 telegram.InputContactMessageContent
Parameters
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
**kwargs (dict) Arbitrary keyword arguments.
1.37.28 telegram.ChosenInlineResult
result_id
str The unique identifier for the result that was chosen.
from_user
telegram.User The user that chose the result.
location
telegram.Location Optional. Sender location.
inline_message_id
str Optional. Identifier of the sent inline message.
query
str The query that was used to obtain the result.
Parameters
result_id (str) The unique identifier for the result that was chosen.
from_user (telegram.User) The user that chose the result.
location (telegram.Location, optional) Sender location, only for bots that
require user location.
inline_message_id (str, optional) Identifier of the sent inline message. Avail-
able only if there is an inline keyboard attached to the message. Will be also received in
callback queries and can be used to edit the message.
query (str) The query that was used to obtain the result.
**kwargs (dict) Arbitrary keyword arguments.
1.38 Payments
1.38.1 telegram.LabeledPrice
Parameters
label (str) Portion label
amount (int) Price of the product in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
**kwargs (dict) Arbitrary keyword arguments.
1.38.2 telegram.Invoice
Parameters
title (str) Product name.
description (str) Product description.
start_parameter (str) Unique bot deep-linking parameter that can be used to
generate this invoice.
currency (str) Three-letter ISO 4217 currency code.
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145.
**kwargs (dict) Arbitrary keyword arguments.
1.38.3 telegram.ShippingAddress
street_line2
str Second line for the address.
post_code
str Address post code.
Parameters
country_code (str) ISO 3166-1 alpha-2 country code.
state (str) State, if applicable.
city (str) City.
street_line1 (str) First line for the address.
street_line2 (str) Second line for the address.
post_code (str) Address post code.
**kwargs (dict) Arbitrary keyword arguments.
1.38.4 telegram.OrderInfo
Parameters
name (str, optional) User name.
phone_number (str, optional) Users phone number.
email (str, optional) User email.
shipping_address (telegram.ShippingAddress, optional) User ship-
ping address.
**kwargs (dict) Arbitrary keyword arguments.
1.38.5 telegram.ShippingOption
prices
List[telegram.LabeledPrice] List of price portions.
Parameters
id (str) Shipping option identifier.
title (str) Option title.
prices (List[telegram.LabeledPrice]) List of price portions.
**kwargs (dict) Arbitrary keyword arguments.
1.38.6 telegram.SuccessfulPayment
Parameters
currency (str) Three-letter ISO 4217 currency code.
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
invoice_payload (str) Bot specified invoice payload.
shipping_option_id (str, optional) Identifier of the shipping option chosen
by the user.
order_info (telegram.OrderInfo, optional) Order info provided by the user
telegram_payment_charge_id (str) Telegram payment identifier.
provider_payment_charge_id (str) Provider payment identifier.
**kwargs (dict) Arbitrary keyword arguments.
1.38.7 telegram.ShippingQuery
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique query identifier.
from_user
telegram.User User who sent the query.
invoice_payload
str Bot specified invoice payload.
shipping_address
telegram.ShippingAddress User specified shipping address.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
id (str) Unique query identifier.
from_user (telegram.User) User who sent the query.
invoice_payload (str) Bot specified invoice payload.
shipping_address (telegram.ShippingAddress) User specified ship-
ping address.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
Parameters
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
shipping_options (List[telegram.ShippingOption], optional) Re-
quired if ok is True. A JSON-serialized array of available shipping options.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains why it is impossible to complete the order (e.g. Sorry,
delivery to your desired address is unavailable). Telegram will display this message
to the user.
1.38.8 telegram.PreCheckoutQuery
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique query identifier.
from_user
telegram.User User who sent the query.
currency
str Three-letter ISO 4217 currency code.
total_amount
int Total price in the smallest units of the currency.
invoice_payload
str Bot specified invoice payload.
shipping_option_id
str Optional. Identifier of the shipping option chosen by the user.
order_info
telegram.OrderInfo Optional. Order info provided by the user.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
id (str) Unique query identifier.
from_user (telegram.User) User who sent the query.
currency (str) Three-letter ISO 4217 currency code
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
invoice_payload (str) Bot specified invoice payload.
shipping_option_id (str, optional) Identifier of the shipping option chosen
by the user.
order_info (telegram.OrderInfo, optional) Order info provided by the user.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args,
**kwargs)
Parameters
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
**kwargs (dict) Arbitrary keyword arguments.
1.39 Games
1.39.1 telegram.Game
Parameters
title (str) Title of the game.
description (str) Description of the game.
photo (List[telegram.PhotoSize]) Photo that will be displayed in the game
message in chats.
text (str, optional) Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls set_game_score, or manually edited using edit_message_text. 0-4096
characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
text_entities (List[telegram.MessageEntity], optional) Special entities
that appear in text, such as usernames, URLs, bot commands, etc.
parse_text_entities(types=None)
Returns a dict that maps telegram.MessageEntity to str. It contains entities from this
message filtered by their type attribute as the key, and the text that each entity belongs to as the value
of the dict.
Note: This method should always be used instead of the text_entities attribute, since
it calculates the correct substring from the message text based on UTF-16 codepoints. See
parse_text_entity for more info.
parse_text_entity(entity)
Returns the text from a given telegram.MessageEntity.
Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python dont handle automatically. (That is, you cant just slice
Message.text with the offset and length.)
1.39.2 telegram.Animation
Parameters
1.39.3 telegram.Callbackgame
class telegram.CallbackGame
Bases: telegram.base.TelegramObject
A placeholder, currently holds no information. Use BotFather to set up your game.
1.39.4 telegram.GameHighScore
Parameters
position (int) Position in high score table for the game.
user (telegram.User) User.
score (int) Score.
mime_type
str Optional. MIME type of the file as defined by sender.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
duration (int) Duration of the audio in seconds as defined by sender.
performer (str, optional) Performer of the audio as defined by sender or by audio
tags.
title (str, optional) Title of the audio as defined by sender or by audio tags.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Bot(token, base_url=None, base_file_url=None, request=None)
Bases: telegram.base.TelegramObject
This object represents a Telegram Bot.
Parameters
token (str) Bots unique authentication.
base_url (str, optional) Telegram Bot API service URL.
base_file_url (str, optional) Telegram Bot API file URL.
request (telegram.utils.Request, optional) Pre initialized telegram.
utils.Request.
addStickerToSet(*args, **kwargs)
Use this method to add a new sticker to a set created by the bot.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Sticker set name.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
mask_position (telegram.MaskPosition, optional) Position where the
mask should beplaced on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Sticker set name.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
mask_position (telegram.MaskPosition, optional) Position where the
mask should beplaced on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
answerCallbackQuery(*args, **kwargs)
Use this method to send answers to callback queries sent from inline keyboards. The answer will
be displayed to the user as a notification at the top of the chat screen or as an alert. Alternatively,
the user can be redirected to the specified Game URL. For this option to work, you must first cre-
ate a game for your bot via BotFather and accept the terms. Otherwise, you may use links like
t.me/your_bot?start=XXXX that open your bot with a parameter.
Parameters
callback_query_id (str) Unique identifier for the query to be answered.
text (str, optional) Text of the notification. If not specified, nothing will be
shown to the user, 0-200 characters.
show_alert (bool, optional) If true, an alert will be shown by the client instead
of a notification at the top of the chat screen. Defaults to false.
url (str, optional) URL that will be opened by the users client. If you have
created a Game and accepted the conditions via @Botfather, specify the URL that
opens your game - note that this will only work if the query comes from a callback
game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open
your bot with a parameter.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the callback query may be cached client-side. Defaults to 0.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answerInlineQuery(*args, **kwargs)
Use this method to send answers to an inline query. No more than 50 results per query are allowed.
Parameters
inline_query_id (str) Unique identifier for the answered query.
results (List[telegram.InlineQueryResult) A list of results for the in-
line query.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the inline query may be cached on the server. Defaults to 300.
is_personal (bool, optional) Pass True, if results may be cached on the server
side only for the user that sent the query. By default, results may be returned to any
user who sends the same query.
next_offset (str, optional) Pass the offset that a client should send in the next
query with the same text to receive more results. Pass an empty string if there are no
more results or if you dont support pagination. Offset length cant exceed 64 bytes.
switch_pm_text (str, optional) If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the bot a
start message with the parameter switch_pm_parameter.
switch_pm_parameter (str, optional) Deep-linking parameter for the /start
message sent to the bot when user presses the switch button. 1-64 characters, only
A-Z, a-z, 0-9, _ and - are allowed.
timeout (int | float, optional) If this value is specified, use it as he read timeout
from the server (instead of the one specified during creation of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Example
An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
to adapt search results accordingly. To do this, it displays a Connect your YouTube account button
above the results, or even before showing any. The user presses the button, switches to a private chat
with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link.
Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where
they wanted to use the bots inline capabilities.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answerPreCheckoutQuery(*args, **kwargs)
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirma-
tion in the form of an Update with the field pre_checkout_query. Use this method to respond to such
pre-checkout queries.
Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
Parameters
pre_checkout_query_id (str) Unique identifier for the query to be an-
swered.
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
answerShippingQuery(*args, **kwargs)
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the
Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to
shipping queries.
Parameters
shipping_query_id (str) Unique identifier for the query to be answered.
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
shipping_options (List[telegram.ShippingOption]) Required if ok is
True. A JSON-serialized array of available shipping options.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains why it is impossible to complete the order (e.g. Sorry,
delivery to your desired address is unavailable). Telegram will display this message
to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool; On success, True is returned.
Raises telegram.TelegramError
answer_callback_query(*args, **kwargs)
Use this method to send answers to callback queries sent from inline keyboards. The answer will
be displayed to the user as a notification at the top of the chat screen or as an alert. Alternatively,
the user can be redirected to the specified Game URL. For this option to work, you must first cre-
ate a game for your bot via BotFather and accept the terms. Otherwise, you may use links like
t.me/your_bot?start=XXXX that open your bot with a parameter.
Parameters
callback_query_id (str) Unique identifier for the query to be answered.
text (str, optional) Text of the notification. If not specified, nothing will be
shown to the user, 0-200 characters.
show_alert (bool, optional) If true, an alert will be shown by the client instead
of a notification at the top of the chat screen. Defaults to false.
url (str, optional) URL that will be opened by the users client. If you have
created a Game and accepted the conditions via @Botfather, specify the URL that
opens your game - note that this will only work if the query comes from a callback
game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open
your bot with a parameter.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the callback query may be cached client-side. Defaults to 0.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answer_inline_query(*args, **kwargs)
Use this method to send answers to an inline query. No more than 50 results per query are allowed.
Parameters
inline_query_id (str) Unique identifier for the answered query.
results (List[telegram.InlineQueryResult) A list of results for the in-
line query.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the inline query may be cached on the server. Defaults to 300.
is_personal (bool, optional) Pass True, if results may be cached on the server
side only for the user that sent the query. By default, results may be returned to any
user who sends the same query.
next_offset (str, optional) Pass the offset that a client should send in the next
query with the same text to receive more results. Pass an empty string if there are no
more results or if you dont support pagination. Offset length cant exceed 64 bytes.
switch_pm_text (str, optional) If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the bot a
start message with the parameter switch_pm_parameter.
switch_pm_parameter (str, optional) Deep-linking parameter for the /start
message sent to the bot when user presses the switch button. 1-64 characters, only
A-Z, a-z, 0-9, _ and - are allowed.
timeout (int | float, optional) If this value is specified, use it as he read timeout
from the server (instead of the one specified during creation of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Example
An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account
to adapt search results accordingly. To do this, it displays a Connect your YouTube account button
above the results, or even before showing any. The user presses the button, switches to a private chat
with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link.
Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where
they wanted to use the bots inline capabilities.
Returns bool On success, True is returned.
Raises telegram.TelegramError
answer_pre_checkout_query(*args, **kwargs)
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirma-
tion in the form of an Update with the field pre_checkout_query. Use this method to respond to such
pre-checkout queries.
Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
Parameters
pre_checkout_query_id (str) Unique identifier for the query to be an-
swered.
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
answer_shipping_query(*args, **kwargs)
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the
Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to
shipping queries.
Parameters
shipping_query_id (str) Unique identifier for the query to be answered.
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
shipping_options (List[telegram.ShippingOption]) Required if ok is
True. A JSON-serialized array of available shipping options.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains why it is impossible to complete the order (e.g. Sorry,
delivery to your desired address is unavailable). Telegram will display this message
to the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, cant contain consecutive underscores and must end in _by_<bot username>.
<bot_username> is case insensitive. 1-64 characters.
title (str) Sticker set title, 1-64 characters.
png_sticker (str | filelike object) Png image with the sticker, must be up to
512 kilobytes in size, dimensions must not exceed 512px, and either width or height
must be exactly 512px. Pass a file_id as a String to send a file that already exists on
the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from
the Internet, or upload a new one using multipart/form-data.
emojis (str) One or more emoji corresponding to the sticker.
contains_masks (bool, optional) Pass True, if a set of mask stickers should be
created.
mask_position (telegram.MaskPosition, optional) Position where the
mask should be placed on faces.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
create_new_sticker_set(*args, **kwargs)
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of created sticker set owner.
name (str) Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, cant contain consecutive underscores and must end in _by_<bot username>.
<bot_username> is case insensitive. 1-64 characters.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
Raises telegram.TelegramError
delete_message(*args, **kwargs)
Use this method to delete a message. A message can only be deleted if it was sent less than 48
hours ago. Any such recently sent outgoing message may be deleted. Additionally, if the bot is an
administrator in a group chat, it can delete any message. If the bot is an administrator in a supergroup,
it can delete messages from any other user and service messages about people joining or leaving the
group (other types of service messages may only be removed by the group creator). In channels, bots
can only remove their own messages.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
message_id (int) Identifier of the message to delete.
timeout (int | float, optional) If this value is specified, use it as
read timeout (the) from the server (instead of the one specified during creation
of the connection pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
delete_sticker_from_set(*args, **kwargs)
Use this method to delete a sticker from a set created by the bot.
Parameters
sticker (str) File identifier of the sticker.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
delete_webhook(*args, **kwargs)
Use this method to remove webhook integration if you decide to switch back to getUpdates. Requires
no parameters.
Parameters
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
editMessageCaption(*args, **kwargs)
Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
getChatMembersCount(*args, **kwargs)
Use this method to get the number of members in a chat
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns Number of members in the chat.
Return type int
Raises telegram.TelegramError
getFile(*args, **kwargs)
Use this method to get basic info about a file and prepare it for downloading. For the moment, bots
can download files of up to 20MB in size. The file can then be downloaded with telegram.File.
download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a
new one can be requested by calling getFile again.
Parameters
file_id (str) File identifier to get info about.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.File
Raises telegram.TelegramError
getGameHighScores(*args, **kwargs)
Use this method to get data for high score tables. Will return the score of the specified user and several
of his neighbors in a game
Parameters
user_id (int) User identifier.
chat_id (int | str, optional) Required if inline_message_id is not specified.
Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.GameHighScore]
Raises telegram.TelegramError
getMe(*args, **kwargs)
A simple method for testing your bots auth token. Requires no parameters.
Parameters timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Returns A telegram.User instance representing that bot if the credentials are valid,
None otherwise.
Return type telegram.User
Raises telegram.TelegramError
getStickerSet(*args, **kwargs)
Use this method to get a sticker set.
Parameters
name (str) Short name of the sticker set that is used in t.me/addstickers/ URLs
(e.g., animals)
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.StickerSet
Raises telegram.TelegramError
getUpdates(*args, **kwargs)
Use this method to receive incoming updates using long polling.
Parameters
offset (int, optional) Identifier of the first update to be returned. Must be greater
by one than the highest among the identifiers of previously received updates. By
default, updates starting with the earliest unconfirmed update are returned. An update
is considered confirmed as soon as getUpdates is called with an offset higher than its
update_id. The negative offset can be specified to retrieve updates starting from -offset
update from the end of the updates queue. All previous updates will forgotten.
limit (int, optional) Limits the number of updates to be retrieved. Values be-
tween 1-100 are accepted. Defaults to 100.
timeout (int, optional) Timeout in seconds for long polling. Defaults to 0, i.e.
usual short polling. Should be positive, short polling should be used for testing pur-
poses only.
allowed_updates (List[str]), optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
get_updates, so unwanted updates may be received for a short period of time.
**kwargs (dict) Arbitrary keyword arguments.
Notes
Returns List[telegram.Update]
Raises telegram.TelegramError
getUserProfilePhotos(*args, **kwargs)
Use this method to get a list of profile pictures for a user.
Parameters
user_id (int) Unique identifier of the target user.
offset (int, optional) Sequential number of the first photo to be returned. By
default, all photos are returned.
limit (int, optional) Limits the number of photos to be retrieved. Values between
1-100 are accepted. Defaults to 100.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.UserProfilePhotos
Raises telegram.TelegramError
getWebhookInfo(timeout=None, **kwargs)
Use this method to get current webhook status. Requires no parameters.
If the bot is using getUpdates, will return an object with the url field empty.
Parameters
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.WebhookInfo
get_chat(*args, **kwargs)
Use this method to get up to date information about the chat (current name of the user for one-on-one
conversations, current username of a user, group or channel, etc.).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.Chat
Raises telegram.TelegramError
get_chat_administrators(*args, **kwargs)
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember
objects that contains information about all chat administrators except other bots. If the chat is a group
or a supergroup and no administrators were appointed, only the creator will be returned.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.ChatMember]
Raises telegram.TelegramError
get_chat_member(*args, **kwargs)
Use this method to get information about a member of a chat.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.ChatMember
Raises telegram.TelegramError
get_chat_members_count(*args, **kwargs)
Use this method to get the number of members in a chat
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns Number of members in the chat.
Return type int
Raises telegram.TelegramError
get_file(*args, **kwargs)
Use this method to get basic info about a file and prepare it for downloading. For the moment, bots
can download files of up to 20MB in size. The file can then be downloaded with telegram.File.
download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a
new one can be requested by calling getFile again.
Parameters
file_id (str) File identifier to get info about.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.File
Raises telegram.TelegramError
get_game_high_scores(*args, **kwargs)
Use this method to get data for high score tables. Will return the score of the specified user and several
of his neighbors in a game
Parameters
user_id (int) User identifier.
chat_id (int | str, optional) Required if inline_message_id is not specified.
Unique identifier for the target chat.
message_id (int, optional) Required if inline_message_id is not specified. Iden-
tifier of the sent message.
inline_message_id (str, optional) Required if chat_id and message_id are
not specified. Identifier of the inline message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns List[telegram.GameHighScore]
Raises telegram.TelegramError
get_me(*args, **kwargs)
A simple method for testing your bots auth token. Requires no parameters.
Parameters timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Returns A telegram.User instance representing that bot if the credentials are valid,
None otherwise.
Return type telegram.User
Raises telegram.TelegramError
get_sticker_set(*args, **kwargs)
Use this method to get a sticker set.
Parameters
name (str) Short name of the sticker set that is used in t.me/addstickers/ URLs
(e.g., animals)
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.StickerSet
Raises telegram.TelegramError
get_updates(*args, **kwargs)
Use this method to receive incoming updates using long polling.
Parameters
offset (int, optional) Identifier of the first update to be returned. Must be greater
by one than the highest among the identifiers of previously received updates. By
default, updates starting with the earliest unconfirmed update are returned. An update
is considered confirmed as soon as getUpdates is called with an offset higher than its
update_id. The negative offset can be specified to retrieve updates starting from -offset
update from the end of the updates queue. All previous updates will forgotten.
limit (int, optional) Limits the number of updates to be retrieved. Values be-
tween 1-100 are accepted. Defaults to 100.
timeout (int, optional) Timeout in seconds for long polling. Defaults to 0, i.e.
usual short polling. Should be positive, short polling should be used for testing pur-
poses only.
allowed_updates (List[str]), optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
get_updates, so unwanted updates may be received for a short period of time.
**kwargs (dict) Arbitrary keyword arguments.
Notes
Returns List[telegram.Update]
Raises telegram.TelegramError
get_user_profile_photos(*args, **kwargs)
Use this method to get a list of profile pictures for a user.
Parameters
user_id (int) Unique identifier of the target user.
offset (int, optional) Sequential number of the first photo to be returned. By
default, all photos are returned.
limit (int, optional) Limits the number of photos to be retrieved. Values between
1-100 are accepted. Defaults to 100.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.UserProfilePhotos
Raises telegram.TelegramError
get_webhook_info(timeout=None, **kwargs)
Use this method to get current webhook status. Requires no parameters.
If the bot is using getUpdates, will return an object with the url field empty.
Parameters
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns telegram.WebhookInfo
id
int Unique identifier for this bot.
kickChatMember(*args, **kwargs)
Use this method to kick a user from a group or a supergroup. In the case of supergroups, the user will
not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot
must be an administrator in the group for this to work.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
user_id (int) Unique identifier of the target user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
until_date (int | datetime.datetime, optional) Date when the user will
be unbanned, unix time. If user is banned for more than 366 days or less than 30
seconds from the current time they are considered to be banned forever.
**kwargs (dict) Arbitrary keyword arguments.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group. Otherwise members may only be removed by the groups
creator or by the member that added them.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group. Otherwise members may only be removed by the groups
creator or by the member that added them.
last_name
str Optional. Bots last name.
leaveChat(*args, **kwargs)
Use this method for your bot to leave a group, supergroup or channel.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
leave_chat(*args, **kwargs)
Use this method for your bot to leave a group, supergroup or channel.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns bool On success, True is returned.
Raises telegram.TelegramError
name
str Bots @username.
pinChatMessage(*args, **kwargs)
Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
message_id (int) Identifier of a message to pin.
disable_notification (bool, optional) Pass True, if it is not necessary to
send a notification to all group members about the new pinned message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
pin_chat_message(*args, **kwargs)
Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for
this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
message_id (int) Identifier of a message to pin.
disable_notification (bool, optional) Pass True, if it is not necessary to
send a notification to all group members about the new pinned message.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
promoteChatMember(*args, **kwargs)
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights. Pass False for
all boolean parameters to demote a user
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
user_id (int) Unique identifier of the target user.
can_change_info (bool, optional) Pass True, if the administrator can change
chat title, photo and other settings.
can_post_messages (bool, optional) Pass True, if the administrator can create
channel posts, channels only.
can_edit_messages (bool, optional) Pass True, if the administrator can edit
messages of other users, channels only.
can_delete_messages (bool, optional) Pass True, if the administrator can
delete messages of other users.
can_invite_users (bool, optional) Pass True, if the administrator can invite
new users to the chat.
can_restrict_members (bool, optional) Pass True, if the administrator can
restrict, ban or unban chat members.
can_pin_messages (bool, optional) Pass True, if the administrator can pin
messages, supergroups only.
can_promote_members (bool, optional) Pass True, if the administrator can
add new administrators with a subset of his own privileges or demote administrators
that he has promoted, directly or indirectly (promoted by administrators that were
appointed by him).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
promote_chat_member(*args, **kwargs)
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights. Pass False for
all boolean parameters to demote a user
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
user_id (int) Unique identifier of the target user.
can_change_info (bool, optional) Pass True, if the administrator can change
chat title, photo and other settings.
can_post_messages (bool, optional) Pass True, if the administrator can create
channel posts, channels only.
can_edit_messages (bool, optional) Pass True, if the administrator can edit
messages of other users, channels only.
can_delete_messages (bool, optional) Pass True, if the administrator can
delete messages of other users.
can_invite_users (bool, optional) Pass True, if the administrator can invite
new users to the chat.
can_restrict_members (bool, optional) Pass True, if the administrator can
restrict, ban or unban chat members.
can_pin_messages (bool, optional) Pass True, if the administrator can pin
messages, supergroups only.
can_promote_members (bool, optional) Pass True, if the administrator can
add new administrators with a subset of his own privileges or demote administrators
that he has promoted, directly or indirectly (promoted by administrators that were
appointed by him).
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
request
restrictChatMember(*args, **kwargs)
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup
for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to
lift restrictions from a user.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
user_id (int) Unique identifier of the target user.
until_date (int | datetime.datetime, optional) Date when restrictions
will be lifted for the user, unix time. If user is restricted for more than 366 days or less
than 30 seconds from the current time, they are considered to be restricted forever.
can_send_messages (bool, optional) Pass True, if the user can send text mes-
sages, contacts, locations and venues.
Note: The audio argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
audio (str | filelike object | telegram.Audio) Audio file to send. Pass a file_id
as String to send an audio file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Audio object to send.
caption (str, optional) Audio caption, 0-200 characters.
duration (int, optional) Duration of sent audio in seconds.
performer (str, optional) Performer.
title (str, optional) Track name.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendChatAction(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bots side. The
status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its
typing status).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
action (telegram.ChatAction | str) Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in telegram.ChatAction
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns True on success.
Return type bool
Raises telegram.TelegramError
sendContact(*args, **kwargs)
Use this method to send phone contacts.
Note: You can either supply contact or phone_number and first_name with optionally
last_name.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
phone_number (str, optional) Contacts phone number.
first_name (str, optional) Contacts first name.
last_name (str, optional) Contacts last name.
contact (telegram.Contact, optional) The contact to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendDocument(*args, **kwargs)
Use this method to send general files.
Note: The document argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
document (str | filelike object | telegram.Document) File to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Document object to send.
filename (str, optional) File name that shows in telegram message (it is useful
when you send file generated by temp module, for example). Undocumented.
caption (str, optional) Document caption (may also be used when resending
documents by file_id), 0-200 characters.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of location.
longitude (float, optional) Longitude of location.
location (telegram.Location, optional) The location to send.
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
photo (str | filelike object | telegram.PhotoSize) Photo to send. Pass a
file_id as String to send a photo that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload
a new photo using multipart/form-data. Lastly you can pass an existing telegram.
PhotoSize object to send.
caption (str, optional) Photo caption (may also be used when resending photos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendSticker(*args, **kwargs)
Use this method to send .webp stickers.
Note: The sticker argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
sticker (str | filelike object telegram.Sticker) Sticker to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Sticker object to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Note: you can either supply venue, or latitude, longitude, title and address and
optionally foursquare_id.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of venue.
longitude (float, optional) Longitude of venue.
title (str, optional) Name of the venue.
address (str, optional) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
venue (telegram.Venue, optional) The venue to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendVideo(*args, **kwargs)
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent
as Document).
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video (str | filelike object | telegram.Video) Video file to send. Pass a file_id
as String to send an video file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an video file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Video object to send.
duration (int, optional) Duration of sent video in seconds.
width (int, optional) Video width.
height (int, optional) Video height.
caption (str, optional) Video caption (may also be used when resending videos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
sendVideoNote(*args, **kwargs)
Use this method to send video messages.
Note: The video_note argument can be either a file_id or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video_note (str | filelike object | telegram.VideoNote) Video note to
send. Pass a file_id as String to send a video note that exists on the Telegram servers
(recommended) or upload a new video using multipart/form-data. Or you can pass an
existing telegram.VideoNote object to send. Sending video notes by a URL is
currently unsupported.
duration (int, optional) Duration of sent video in seconds.
length (int, optional) Video width and height
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Note: The voice argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
voice (str | filelike object | telegram.Voice) Voice file to send. Pass a file_id
as String to send an voice file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an voice file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Voice object to send.
caption (str, optional) Voice message caption, 0-200 characters.
duration (int, optional) Duration of the voice message in seconds.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_audio(*args, **kwargs)
Use this method to send audio files, if you want Telegram clients to display them in the music player.
Your audio must be in the .mp3 format. On success, the sent Message is returned. Bots can currently
send audio files of up to 50 MB in size, this limit may be changed in the future.
For sending voice messages, use the sendVoice method instead.
Note: The audio argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
audio (str | filelike object | telegram.Audio) Audio file to send. Pass a file_id
as String to send an audio file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Audio object to send.
caption (str, optional) Audio caption, 0-200 characters.
duration (int, optional) Duration of sent audio in seconds.
performer (str, optional) Performer.
title (str, optional) Track name.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_chat_action(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bots side. The
status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its
typing status).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
action (telegram.ChatAction | str) Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in telegram.ChatAction
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns True on success.
Return type bool
Raises telegram.TelegramError
send_contact(*args, **kwargs)
Use this method to send phone contacts.
Note: You can either supply contact or phone_number and first_name with optionally
last_name.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
phone_number (str, optional) Contacts phone number.
first_name (str, optional) Contacts first name.
last_name (str, optional) Contacts last name.
contact (telegram.Contact, optional) The contact to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_document(*args, **kwargs)
Use this method to send general files.
Note: The document argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
document (str | filelike object | telegram.Document) File to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Document object to send.
filename (str, optional) File name that shows in telegram message (it is useful
when you send file generated by temp module, for example). Undocumented.
caption (str, optional) Document caption (may also be used when resending
documents by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of location.
longitude (float, optional) Longitude of location.
location (telegram.Location, optional) The location to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
photo (str | filelike object | telegram.PhotoSize) Photo to send. Pass a
file_id as String to send a photo that exists on the Telegram servers (recommended),
pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload
a new photo using multipart/form-data. Lastly you can pass an existing telegram.
PhotoSize object to send.
caption (str, optional) Photo caption (may also be used when resending photos
by file_id), 0-200 characters.
Note: The sticker argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
sticker (str | filelike object telegram.Sticker) Sticker to send. Pass a
file_id as String to send a file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Sticker object to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_venue(*args, **kwargs)
Use this method to send information about a venue.
Note: you can either supply venue, or latitude, longitude, title and address and
optionally foursquare_id.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
latitude (float, optional) Latitude of venue.
longitude (float, optional) Longitude of venue.
title (str, optional) Name of the venue.
address (str, optional) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
venue (telegram.Venue, optional) The venue to send.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_video(*args, **kwargs)
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent
as Document).
Note: The video argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video (str | filelike object | telegram.Video) Video file to send. Pass a file_id
as String to send an video file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an video file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Video object to send.
duration (int, optional) Duration of sent video in seconds.
width (int, optional) Video width.
height (int, optional) Video height.
caption (str, optional) Video caption (may also be used when resending videos
by file_id), 0-200 characters.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
Note: The video_note argument can be either a file_id or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
video_note (str | filelike object | telegram.VideoNote) Video note to
send. Pass a file_id as String to send a video note that exists on the Telegram servers
(recommended) or upload a new video using multipart/form-data. Or you can pass an
existing telegram.VideoNote object to send. Sending video notes by a URL is
currently unsupported.
duration (int, optional) Duration of sent video in seconds.
length (int, optional) Video width and height
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
send_voice(*args, **kwargs)
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice
message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may
be sent as Audio or Document).
Note: The voice argument can be either a file_id, an URL or a file from disk open(filename,
'rb')
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
voice (str | filelike object | telegram.Voice) Voice file to send. Pass a file_id
as String to send an voice file that exists on the Telegram servers (recommended), pass
an HTTP URL as a String for Telegram to get an voice file from the Internet, or upload
a new one using multipart/form-data. Lastly you can pass an existing telegram.
Voice object to send.
caption (str, optional) Voice message caption, 0-200 characters.
duration (int, optional) Duration of the voice message in seconds.
disable_notification (bool, optional) Sends the message silently. Users
will receive a notification with no sound.
reply_to_message_id (int, optional) If the message is a reply, ID of the
original message.
reply_markup (telegram.ReplyMarkup, optional) Additional interface op-
tions. A JSON-serialized object for an inline keyboard, custom reply keyboard, in-
structions to remove reply keyboard or to force a reply from the user.
timeout (int | float, optional) Send file timeout (default: 20 seconds).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, the sent Message is returned.
Return type telegram.Message
Raises telegram.TelegramError
setChatDescription(*args, **kwargs)
Use this method to change the description of a supergroup or a channel. The bot must be an adminis-
trator in the chat for this to work and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
description (str) New chat description, 1-255 characters.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Returns Returns True on success.
Return type bool
Raises telegram.TelegramError
setChatPhoto(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos cant be changed for private chats. The bot must be an administrator in the chat for this to work
and must have the appropriate admin rights.
Parameters
chat_id (int | str) Unique identifier for the target chat or username of the
targetchannel (in the format @channelusername).
photo (telegram.InputFile) New chat photo.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
Note: The certificate argument should be a file from disk open(filename, 'rb').
Parameters
url (str) HTTPS url to send updates to. Use an empty string to remove webhook
integration.
certificate (filelike) Upload your public key certificate so that the root
certificate in use can be checked. See our self-signed guide for details. (https://goo.gl/
rw7w6Y)
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use
lower values to limit the load on your bots server, and higher values to increase your
bots throughput.
Note:
1. You will not be able to receive updates using get_updates for as long as an outgoing webhook is
set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate
parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
Note: In regular groups (non-supergroups), this method will only work if the All Members Are
Admins setting is off in the target group.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The edited message, or if the message wasnt sent by the bot , True.
Return type telegram.Message
Raises
telegram.TelegramError If the new score is not greater than the users
current score in the chat and force is False.
set_sticker_position_in_set(*args, **kwargs)
Use this method to move a sticker in a set created by the bot to a specific position.
Parameters
sticker (str) File identifier of the sticker.
position (int) New sticker position in the set, zero-based.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns On success, True is returned.
Return type bool
Raises telegram.TelegramError
set_webhook(*args, **kwargs)
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever
there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a
JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount
of attempts.
If youd like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bots
token, you can be pretty sure its us.
Note: The certificate argument should be a file from disk open(filename, 'rb').
Parameters
url (str) HTTPS url to send updates to. Use an empty string to remove webhook
integration.
certificate (filelike) Upload your public key certificate so that the root
certificate in use can be checked. See our self-signed guide for details. (https://goo.gl/
rw7w6Y)
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use
lower values to limit the load on your bots server, and higher values to increase your
bots throughput.
allowed_updates (List[str], optional) List the types of updates you want
your bot to receive. For example, specify [message, edited_channel_post, call-
back_query] to only receive updates of these types. See telegram.Update for
a complete list of available update types. Specify an empty list to receive all up-
dates regardless of type (default). If not specified, the previous setting will be used.
Please note that this parameter doesnt affect updates created before the call to the
set_webhook, so unwanted updates may be received for a short period of time.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Note:
1. You will not be able to receive updates using get_updates for as long as an outgoing webhook is
set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate
parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of sticker file owner.
png_sticker (str | filelike object) Png image with the sticker, must be up to 512
kilobytes in size, dimensions must not exceed 512px, and either width or height must
be exactly 512px.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The uploaded File
Note: The png_sticker argument can be either a file_id, an URL or a file from disk
open(filename, 'rb')
Parameters
user_id (int) User identifier of sticker file owner.
png_sticker (str | filelike object) Png image with the sticker, must be up to 512
kilobytes in size, dimensions must not exceed 512px, and either width or height must
be exactly 512px.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
**kwargs (dict) Arbitrary keyword arguments.
Returns The uploaded File
Return type telegram.File
Raises telegram.TelegramError
username
str Bots username.
class telegram.Chat(id, type, title=None, username=None, first_name=None, last_name=None,
all_members_are_administrators=None, bot=None, photo=None, descrip-
tion=None, invite_link=None, pinned_message=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a chat.
id
int Unique identifier for this chat.
type
str Type of chat.
title
str Optional. Title, for supergroups, channels and group chats.
username
str Optional. Username.
first_name
str Optional. First name of the other party in a private chat.
last_name
str Optional. Last name of the other party in a private chat.
all_members_are_administrators
bool Optional.
photo
telegram.ChatPhoto Optional. Chat photo.
description
str Optional. Description, for supergroups and channel chats.
invite_link
str Optional. Chat invite link, for supergroups and channel chats.
pinned_message
telegram.Message Optional. Pinned message, for supergroups. Returned only in get_chat.
Parameters
id (int) Unique identifier for this chat. This number may be greater than 32 bits and
some programming languages may have difficulty/silent defects in interpreting it. But it
is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe
for storing this identifier.
type (str) Type of chat, can be either private, group, supergroup or channel.
title (str, optional) Title, for supergroups, channels and group chats.
username (str, optional) Username, for private chats, supergroups and channels if
available.
first_name (str, optional) First name of the other party in a private chat.
last_name (str, optional) Last name of the other party in a private chat.
all_members_are_administrators (bool, optional) True if a group has All
Members Are Admins enabled.
photo (telegram.ChatPhoto, optional) Chat photo. Returned only in getChat.
description (str, optional) Description, for supergroups and channel chats. Re-
turned only in get_chat.
invite_link (str, optional) Chat invite link, for supergroups and channel chats.
Returned only in get_chat.
pinned_message (telegram.Message, optional) Pinned message, for super-
groups. Returned only in get_chat.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
CHANNEL = 'channel'
GROUP = 'group'
PRIVATE = 'private'
SUPERGROUP = 'supergroup'
classmethod de_json(data, bot)
get_administrators(*args, **kwargs)
Shortcut for:
Returns telegram.ChatMember
get_members_count(*args, **kwargs)
Shortcut for:
Returns int
kick_member(*args, **kwargs)
Shortcut for:
Note: This method will only work if the All Members Are Admins setting is off in the target group.
Otherwise members may only be removed by the groups creator or by the member that added them.
leave(*args, **kwargs)
Shortcut for:
status
str The members status in the chat.
until_date
datetime.datetime Optional. Date when restrictions will be lifted for this user.
can_be_edited
bool Optional. If the bot is allowed to edit administrator privileges of that user.
can_change_info
bool Optional. If the administrator can change the chat title, photo and other settings.
can_post_messages
bool Optional. If the administrator can post in the channel.
can_edit_messages
bool Optional. If the administrator can edit messages of other users.
can_delete_messages
bool Optional. If the administrator can delete messages of other users.
can_invite_users
bool Optional. If the administrator can invite new users to the chat.
can_restrict_members
bool Optional. If the administrator can restrict, ban or unban chat members.
can_pin_messages
bool Optional. If the administrator can pin messages.
can_promote_members
bool Optional. If the administrator can add new administrators.
can_send_messages
bool Optional. If the user can send text messages, contacts, locations and venues.
can_send_media_messages
bool Optional. If the user can send media messages, implies can_send_messages.
can_send_other_messages
bool Optional. If the user can send animations, games, stickers and use inline bots, implies
can_send_media_messages.
can_add_web_page_previews
bool Optional. If user may add web page previews to his messages, implies
can_send_media_messages
Parameters
user (telegram.User) Information about the user.
status (str) The members status in the chat. Can be creator, administrator,
member, restricted, left or kicked.
until_date (datetime.datetime, optional) Restricted and kicked only. Date
when restrictions will be lifted for this user.
can_be_edited (bool, optional) Administrators only. True, if the bot is allowed
to edit administrator privileges of that user.
can_change_info (bool, optional) Administrators only. True, if the administra-
tor can change the chat title, photo and other settings.
can_post_messages (bool, optional) Administrators only. True, if the admin-
istrator can post in the channel, channels only.
can_edit_messages (bool, optional) Administrators only. True, if the admin-
istrator can edit messages of other users, channels only.
result_id
str The unique identifier for the result that was chosen.
from_user
telegram.User The user that chose the result.
location
telegram.Location Optional. Sender location.
inline_message_id
str Optional. Identifier of the sent inline message.
query
str The query that was used to obtain the result.
Parameters
result_id (str) The unique identifier for the result that was chosen.
from_user (telegram.User) The user that chose the result.
location (telegram.Location, optional) Sender location, only for bots that
require user location.
inline_message_id (str, optional) Identifier of the sent inline message. Avail-
able only if there is an inline keyboard attached to the message. Will be also received in
callback queries and can be used to edit the message.
query (str) The query that was used to obtain the result.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
to_dict()
class telegram.CallbackQuery(id, from_user, chat_instance, message=None, data=None, in-
line_message_id=None, game_short_name=None, bot=None,
**kwargs)
Bases: telegram.base.TelegramObject
This object represents an incoming callback query from a callback button in an inline keyboard.
If the button that originated the query was attached to a message sent by the bot, the field message
will be present. If the button was attached to a message sent via the bot (in inline mode), the field
inline_message_id will be present.
Note:
In Python from is a reserved word, use from_user instead.
Exactly one of the fields data or game_short_name will be present.
id
str Unique identifier for this query.
from_user
telegram.User Sender.
message
telegram.Message Optional. Message with the callback button that originated the query.
inline_message_id
str Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
chat_instance
str Optional. Global identifier, uniquely corresponding to the chat to which the message with the
callback button was sent.
data
str Optional. Data associated with the callback button.
game_short_name
str Optional. Short name of a Game to be returned.
Parameters
id (str) Unique identifier for this query.
from_user (telegram.User) Sender.
message (telegram.Message, optional) Message with the callback button that
originated the query. Note that message content and message date will not be available
if the message is too old.
inline_message_id (str, optional) Identifier of the message sent via the bot in
inline mode, that originated the query.
chat_instance (str, optional) Global identifier, uniquely corresponding to the
chat to which the message with the callback button was sent. Useful for high scores in
games.
data (str, optional) Data associated with the callback button. Be aware that a bad
client can send arbitrary data in this field.
game_short_name (str, optional) Short name of a Game to be returned, serves
as the unique identifier for the game
Note: After the user presses an inline button, Telegram clients will display a progress bar until you call
answer. It is, therefore, necessary to react by calling telegram.Bot.answer_callback_query
even if no notification to the user is needed (e.g., without specifying any of the optional parameters).
answer(*args, **kwargs)
Shortcut for:
bot.edit_message_caption(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
*args, **kwargs)
or:
bot.edit_message_caption(inline_message_id=update.callback_query.inline_
message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
edit_message_reply_markup(*args, **kwargs)
Shortcut for either:
bot.edit_message_replyMarkup(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.
message_id,
*args, **kwargs)
or:
bot.edit_message_reply_markup(inline_message_id=update.callback_query.
inline_message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
edit_message_text(*args, **kwargs)
Shortcut for either:
bot.edit_message_text(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
*args, **kwargs)
or:
bot.edit_message_text(inline_message_id=update.callback_query.inline_
message_id,
*args, **kwargs)
Returns On success, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type telegram.Message
to_dict()
class telegram.Contact(phone_number, first_name, last_name=None, user_id=None,
**kwargs)
Bases: telegram.base.TelegramObject
This object represents a phone contact.
phone_number
str Contacts phone number.
first_name
str Contacts first name.
last_name
str Optional. Contacts last name.
user_id
int Optional. Contacts user identifier in Telegram.
Parameters
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
user_id (int, optional) Contacts user identifier in Telegram.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Document(file_id, thumb=None, file_name=None, mime_type=None,
file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a general file (as opposed to photos, voice messages and audio files).
file_id
str Unique file identifier.
thumb
telegram.PhotoSize Optional. Document thumbnail.
file_name
str Original filename.
mime_type
str Optional. MIME type of the file.
file_size
int Optional. File size.
Parameters
file_id (str) Unique file identifier
thumb (telegram.PhotoSize, optional) Document thumbnail as defined by
sender.
file_name (str, optional) Original filename as defined by sender.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.File(file_id, bot=None, file_size=None, file_path=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a file ready to be downloaded. The file can be downloaded with download. It is
guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested
by calling getFile.
file_id
str Unique identifier for this file.
file_size
str Optional. File size.
file_path
str Optional. File path. Use download to get the file.
Parameters
file_id (str) Unique identifier for this file.
file_size (int, optional) Optional. File size, if known.
file_path (str, optional) File path. Use download to get the file.
bot (telegram.Bot, optional) Bot to use with shortcut method.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
download(custom_path=None, out=None, timeout=None)
Download this file. By default, the file is saved in the current working directory with its original
filename as reported by Telegram. If a custom_path is supplied, it will be saved to that path
instead. If out is defined, the file contents will be saved to that object using the out.write method.
Parameters
custom_path (str, optional) Custom path.
out (object, optional) A file-like object. Must be opened in binary mode, if
applicable.
timeout (int | float, optional) If this value is specified, use it as the read
timeout from the server (instead of the one specified during creation of the connection
pool).
Raises ValueError If both custom_path and out are passed.
class telegram.ForceReply(force_reply=True, selective=False, **kwargs)
Bases: telegram.replymarkup.ReplyMarkup
Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as
if the user has selected the bots message and tapped Reply). This can be extremely useful if you want to
create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
force_reply
True Shows reply interface to the user.
selective
bool Optional. Force reply from specific users only.
Parameters
selective (bool, optional) Use this parameter if you want to force reply from
specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineKeyboardButton(text, url=None, callback_data=None,
switch_inline_query=None,
switch_inline_query_current_chat=None, call-
back_game=None, pay=None, **kwargs)
Bases: telegram.base.TelegramObject
Note: You must use exactly one of the optional fields. Mind that callback_game is not working as
expected. Putting a game short name in it might, but is not guaranteed to work.
text
str Label text on the button.
url
str Optional. HTTP url to be opened when button is pressed.
callback_data
str Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.
switch_inline_query
str Optional. Will prompt the user to select one of their chats, open that chat and insert the bots
username and the specified inline query in the input field.
switch_inline_query_current_chat
str Optional. Will insert the bots username and the specified inline query in the current chats
input field.
callback_game
telegram.CallbackGame Optional. Description of the game that will be launched when the
user presses the button.
pay
bool Optional. Specify True, to send a Pay button.
Parameters
text (str) Label text on the button.
url (str) HTTP url to be opened when button is pressed.
callback_data (str, optional) Data to be sent in a callback query to the bot
when button is pressed, 1-64 bytes.
switch_inline_query (str, optional) If set, pressing the button will prompt
the user to select one of their chats, open that chat and insert the bots username and
the specified inline query in the input field. Can be empty, in which case just the bots
username will be inserted. This offers an easy way for users to start using your bot in
inline mode when they are currently in a private chat with it. Especially useful when
combined with switch_pm* actions - in this case the user will be automatically returned
to the chat they switched from, skipping the chat selection screen.
switch_inline_query_current_chat (str, optional) If set, pressing the
button will insert the bots username and the specified inline query in the current chats
input field. Can be empty, in which case only the bots username will be inserted. This
offers a quick way for the user to open your bot in inline mode in the same chat - good
for selecting something from multiple options.
callback_game (telegram.CallbackGame, optional) Description of the
game that will be launched when the user presses the button. This type of button must
always be the first button in the first row.
pay (bool, optional) Specify True, to send a Pay button. This type of button must
always be the first button in the first row.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineKeyboardMarkup(inline_keyboard, **kwargs)
Bases: telegram.replymarkup.ReplyMarkup
This object represents an inline keyboard that appears right next to the message it belongs to.
inline_keyboard
List[List[telegram.InlineKeyboardButton]] Array of button rows, each represented by an
Array of InlineKeyboardButton objects.
Parameters
inline_keyboard (List[List[telegram.InlineKeyboardButton]]) Ar-
ray of button rows, each represented by an Array of InlineKeyboardButton objects.
**kwargs (dict) Arbitrary keyword arguments.
to_dict()
class telegram.InlineQuery(id, from_user, query, offset, location=None, bot=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents an incoming inline query. When the user sends an empty query, your bot could return
some default or trending results.
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique identifier for this query.
from_user
telegram.User Sender.
location
telegram.Location Optional. Sender location, only for bots that request user location.
query
str Text of the query (up to 512 characters).
offset
str Offset of the results to be returned, can be controlled by the bot.
Parameters
id (str) Unique identifier for this query.
from_user (telegram.User) Sender.
location (telegram.Location, optional) Sender location, only for bots that
request user location.
query (str) Text of the query (up to 512 characters).
offset (str) Offset of the results to be returned, can be controlled by the bot.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
Parameters
results (List[telegram.InlineQueryResult]) A list of results for the
inline query.
cache_time (int, optional) The maximum amount of time in seconds that the
result of the inline query may be cached on the server. Defaults to 300.
is_personal (bool, optional) Pass True, if results may be cached on the server
side only for the user that sent the query. By default, results may be returned to any
user who sends the same query.
next_offset (str, optional) Pass the offset that a client should send in the next
query with the same text to receive more results. Pass an empty string if there are no
more results or if you dont support pagination. Offset length cant exceed 64 bytes.
switch_pm_text (str, optional) If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the bot a
start message with the parameter switch_pm_parameter.
switch_pm_parameter (str, optional) Deep-linking parameter for the /start
message sent to the bot when user presses the switch button. 1-64 characters, only
A-Z, a-z, 0-9, _ and - are allowed.
classmethod de_json(data, bot)
to_dict()
class telegram.InlineQueryResult(type, id, **kwargs)
Bases: telegram.base.TelegramObject
Baseclass for the InlineQueryResult* classes.
type
str Type of the result.
id
str Unique identifier for this result, 1-64 Bytes.
Parameters
type (str) Type of the result.
id (str) Unique identifier for this result, 1-64 Bytes.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResult(type, id, **kwargs)
Bases: telegram.base.TelegramObject
Baseclass for the InlineQueryResult* classes.
type
str Type of the result.
id
str Unique identifier for this result, 1-64 Bytes.
Parameters
type (str) Type of the result.
id (str) Unique identifier for this result, 1-64 Bytes.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultArticle(id, title, input_message_content,
reply_markup=None, url=None,
hide_url=None, description=None,
thumb_url=None, thumb_width=None,
thumb_height=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
This object represents a Telegram InlineQueryResultArticle.
type
str article.
id
str Unique identifier for this result, 1-64 Bytes.
title
str Title of the result.
input_message_content
telegram.InputMessageContent Content of the message to be sent.
reply_markup
telegram.ReplyMarkup Optional. Inline keyboard attached to the message.
url
str Optional. URL of the result.
hide_url
bool Optional. Pass True, if you dont want the URL to be shown in the message.
description
str Optional. Short description of the result.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 Bytes.
title (str) Title of the result.
input_message_content (telegram.InputMessageContent) Content
of the message to be sent.
reply_markup (telegram.ReplyMarkup, optional) Inline keyboard attached
to the message
url (str, optional) URL of the result.
hide_url (bool, optional) Pass True, if you dont want the URL to be shown in
the message.
description (str, optional) Short description of the result.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultAudio(id, audio_url, title, performer=None,
audio_duration=None, cap-
tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you
can use input_message_content to send a message with the specified content instead of the audio.
type
str audio.
id
str Unique identifier for this result, 1-64 bytes.
audio_url
str A valid URL for the audio file.
title
str Title.
performer
str Optional. Caption, 0-200 characters.
audio_duration
str Optional. Performer.
caption
str Optional. Audio duration in seconds.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
audio.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
audio_url (str) A valid URL for the audio file.
title (str) Title.
performer (str, optional) Caption, 0-200 characters.
audio_duration (str, optional) Performer.
caption (str, optional) Audio duration in seconds.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the audio.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedAudio(id, audio_file_id, caption=None,
reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent
by the user. Alternatively, you can use input_message_content to send amessage with the specified
content instead of the audio.
type
str audio.
id
str Unique identifier for this result, 1-64 bytes.
audio_file_id
str A valid file identifier for the audio file.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
audio.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
audio_file_id (str) A valid file identifier for the audio file.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the audio.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedDocument(id, title, document_file_id, de-
scription=None, caption=None,
reply_markup=None, in-
put_message_content=None,
**kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with
an optional caption. Alternatively, you can use input_message_content to send a message with the
specified content instead of the file.
type
str document.
id
str Unique identifier for this result, 1-64 bytes.
title
str Title for the result.
document_file_id
str A valid file identifier for the file.
description
str Optional. Short description of the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
file.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
title (str) Title for the result.
document_file_id (str) A valid file identifier for the file.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
gif_file_id (str) A valid file identifier for the GIF file.
title (str, optional) Title for the result.caption (str, optional):
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the gif.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedMpeg4Gif(id, mpeg4_file_id, title=None, cap-
tion=None, reply_markup=None,
input_message_content=None,
**kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram
servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alterna-
tively, you can use input_message_content to send a message with the specified content instead of
the animation.
type
str mpeg4_gif.
id
str Unique identifier for this result, 1-64 bytes.
mpeg4_file_id
str A valid file identifier for the MP4 file.
title
str Optional. Title for the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
MPEG-4 file.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
mpeg4_file_id (str) A valid file identifier for the MP4 file.
title (str, optional) Title for the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the MPEG-4 file.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedPhoto(id, photo_file_id, title=None, de-
scription=None, caption=None,
reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user
with an optional caption. Alternatively, you can use input_message_content to send a message with
the specified content instead of the photo.
type
str photo.
id
str Unique identifier for this result, 1-64 bytes.
photo_file_id
str A valid file identifier of the photo.
title
str Optional. Title for the result.
description
str Optional. Short description of the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
photo.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
photo_file_id (str) A valid file identifier of the photo.
title (str, optional) Title for the result.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the photo.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedSticker(id, sticker_file_id, re-
ply_markup=None, in-
put_message_content=None,
**kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user.
Alternatively, you can use input_message_content to send a message with the specified content
instead of the sticker.
type
str sticker.
id
str Unique identifier for this result, 1-64 bytes.
sticker_file_id
str A valid file identifier of the sticker.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
sticker.
Parameters
id (str)
sticker_file_id (str)
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the sticker.
**kwargs (dict) Arbitrary keyword arguments.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
video_file_id (str) A valid file identifier for the video file.
title (str) Title for the result.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the video.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedVoice(id, voice_file_id, title, cap-
tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a voice message stored on the Telegram servers. By default, this voice message will
be sent by the user. Alternatively, you can use input_message_content to send a message with the
specified content instead of the voice message.
type
str voice.
id
str Unique identifier for this result, 1-64 bytes.
voice_file_id
str A valid file identifier for the voice message.
title
str Voice message title.
caption
str Optional. Caption, 0-200 characters.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
voice.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
voice_file_id (str) A valid file identifier for the voice message.
title (str) Voice message title.
caption (str, optional) Caption, 0-200 characters.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the voice.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultContact(id, phone_number, first_name,
last_name=None, reply_markup=None,
input_message_content=None,
thumb_url=None, thumb_width=None,
thumb_height=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively,
you can use input_message_content to send a message with the specified content instead of the
contact.
type
str contact.
id
str Unique identifier for this result, 1-64 bytes.
phone_number
str Contacts phone number.
first_name
str Contacts first name.
last_name
str Optional. Contacts last name.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
contact.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the contact.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultDocument(id, document_url, title, mime_type,
caption=None, description=None,
reply_markup=None, in-
put_message_content=None,
thumb_url=None, thumb_width=None,
thumb_height=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively,
you can use input_message_content to send a message with the specified content instead of the file.
Currently, only .PDF and .ZIP files can be sent using this method.
type
str document.
id
str Unique identifier for this result, 1-64 bytes.
title
str Title for the result.
caption
str Optional. Caption, 0-200 characters
document_url
str A valid URL for the file.
mime_type
str Mime type of the content of the file, either application/pdf or application/zip.
description
str Optional. Short description of the result.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
file.
thumb_url
str Optional. URL of the thumbnail (jpeg only) for the file.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
title (str) Title for the result.
caption (str, optional) Caption, 0-200 characters
document_url (str) A valid URL for the file.
mime_type (str) Mime type of the content of the file, either application/pdf or
application/zip.
description (str, optional) Short description of the result.
reply_markup (telegram.InlineKeyboardMarkup) Optional. Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent) Op-
tional. Content of the message to be sent instead of the file.
thumb_url (str, optional) URL of the thumbnail (jpeg only) for the file.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultGif(id, gif_url, thumb_url, gif_width=None,
gif_height=None, title=None, caption=None, re-
ply_markup=None, input_message_content=None,
gif_duration=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with
optional caption. Alternatively, you can use input_message_content to send a message with the
specified content instead of the animation.
type
str gif.
id
str Unique identifier for this result, 1-64 bytes.
gif_url
str A valid URL for the GIF file. File size must not exceed 1MB.
gif_width
int Optional. Width of the GIF.
gif_height
int Optional. Height of the GIF.
gif_duration
int Optional. Duration of the GIF.
thumb_url
str URL of the static thumbnail for the result (jpeg or gif).
title
str Optional. Title for the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
gif.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
gif_url (str) A valid URL for the GIF file. File size must not exceed 1MB.
gif_width (int, optional) Width of the GIF.
gif_height (int, optional) Height of the GIF.
gif_duration (int, optional) Duration of the GIF
thumb_url (str) URL of the static thumbnail for the result (jpeg or gif).
title (str, optional) Title for the result.caption (str, optional):
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the gif.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultLocation(id, latitude, longitude, ti-
tle, reply_markup=None, in-
put_message_content=None,
thumb_url=None, thumb_width=None,
thumb_height=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use
input_message_content to send a message with the specified content instead of the location.
type
str location.
id
str Unique identifier for this result, 1-64 bytes.
latitude
float Location latitude in degrees.
longitude
float Location longitude in degrees.
title
str Location title.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
location.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
latitude (float) Location latitude in degrees.
longitude (float) Location longitude in degrees.
title (str) Location title.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the location.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultMpeg4Gif(id, mpeg4_url, thumb_url,
mpeg4_width=None, mpeg4_height=None,
title=None, caption=None,
reply_markup=None, in-
put_message_content=None,
mpeg4_duration=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this
animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use
input_message_content to send a message with the specified content instead of the animation.
type
str mpeg4_gif.
id
str Unique identifier for this result, 1-64 bytes.
mpeg4_url
str A valid URL for the MP4 file. File size must not exceed 1MB.
mpeg4_width
int Optional. Video width.
mpeg4_height
int Optional. Video height.
mpeg4_duration
int Optional. Video duration.
thumb_url
str URL of the static thumbnail (jpeg or gif) for the result.
title
str Optional. Title for the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
MPEG-4 file.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
mpeg4_url (str) A valid URL for the MP4 file. File size must not exceed 1MB.
mpeg4_width (int, optional) Video width.
mpeg4_height (int, optional) Video height.
mpeg4_duration (int, optional) Video duration.
thumb_url (str) URL of the static thumbnail (jpeg or gif) for the result.
title (str, optional) Title for the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the MPEG-4 file.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultPhoto(id, photo_url, thumb_url, photo_width=None,
photo_height=None, title=None, descrip-
tion=None, caption=None, reply_markup=None,
input_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alterna-
tively, you can use input_message_content to send a message with the specified content instead of
the photo.
type
str photo.
id
str Unique identifier for this result, 1-64 bytes.
photo_url
str A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.
thumb_url
str URL of the thumbnail for the photo.
photo_width
int Optional. Width of the photo.
photo_height
int Optional. Height of the photo.
title
str Optional. Title for the result.
description
str Optional. Short description of the result.
caption
str Optional. Caption, 0-200 characters
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
photo.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
photo_url (str) A valid URL of the photo. Photo must be in jpeg format. Photo
size must not exceed 5MB.
thumb_url (str) URL of the thumbnail for the photo.
photo_width (int, optional) Width of the photo.
photo_height (int, optional) Height of the photo.
title (str, optional) Title for the result.
description (str, optional) Short description of the result.
caption (str, optional) Caption, 0-200 characters
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the photo.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultVenue(id, latitude, longitude, title, address,
foursquare_id=None, reply_markup=None,
input_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use
input_message_content to send a message with the specified content instead of the venue.
type
str venue.
id
str Unique identifier for this result, 1-64 Bytes.
latitude
float Latitude of the venue location in degrees.
longitude
float Longitude of the venue location in degrees.
title
str Title of the venue.
address
str Address of the venue.
foursquare_id
str Optional. Foursquare identifier of the venue if known.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
venue.
thumb_url
str Optional. Url of the thumbnail for the result.
thumb_width
int Optional. Thumbnail width.
thumb_height
int Optional. Thumbnail height.
Parameters
id (str) Unique identifier for this result, 1-64 Bytes.
latitude (float) Latitude of the venue location in degrees.
longitude (float) Longitude of the venue location in degrees.
title (str) Title of the venue.
address (str) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue if known.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the location.
thumb_url (str, optional) Url of the thumbnail for the result.
thumb_width (int, optional) Thumbnail width.
thumb_height (int, optional) Thumbnail height.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultVideo(id, video_url, mime_type, thumb_url, ti-
tle, caption=None, video_width=None,
video_height=None, video_duration=None,
description=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a page containing an embedded video player or a video file. By default, this video file
will be sent by the user with an optional caption. Alternatively, you can use input_message_content
to send a message with the specified content instead of the video.
type
str video.
id
str Unique identifier for this result, 1-64 bytes.
video_url
str A valid URL for the embedded video player or video file.
mime_type
str Mime type of the content of video url, text/html or video/mp4.
thumb_url
str URL of the thumbnail (jpeg only) for the video.
title
str Title for the result.
caption
str Optional. Caption, 0-200 characters
video_width
int Optional. Video width.
video_height
int Optional. Video height.
video_duration
int Optional. Video duration in seconds.
description
str Optional. Short description of the result.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
video.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
video_url (str) A valid URL for the embedded video player or video file.
mime_type (str) Mime type of the content of video url, text/html or
video/mp4.
thumb_url (str) URL of the thumbnail (jpeg only) for the video.
title (str) Title for the result.
caption (str, optional) Caption, 0-200 characters.
video_width (int, optional) Video width.
video_height (int, optional) Video height.
video_duration (int, optional) Video duration in seconds.
description (str, optional) Short description of the result.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the video.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultVoice(id, voice_url, title, voice_duration=None,
caption=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice
recording will be sent by the user. Alternatively, you can use input_message_content to send a
message with the specified content instead of the the voice message.
type
str voice.
id
str Unique identifier for this result, 1-64 bytes.
voice_url
str A valid URL for the voice recording.
title
str Voice message title.
caption
str Optional. Caption, 0-200 characters.
voice_duration
int Optional. Recording duration in seconds.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
input_message_content
telegram.InputMessageContent Optional. Content of the message to be sent instead of the
voice.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
voice_url (str) A valid URL for the voice recording.
title (str) Voice message title.
caption (str, optional) Caption, 0-200 characters.
voice_duration (int, optional) Recording duration in seconds.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
input_message_content (telegram.InputMessageContent, optional)
Content of the message to be sent instead of the voice.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InlineQueryResultGame(id, game_short_name, reply_markup=None,
**kwargs)
Bases: telegram.inline.inlinequeryresult.InlineQueryResult
Represents a Game.
type
str game.
id
str Unique identifier for this result, 1-64 bytes.
game_short_name
str Short name of the game.
reply_markup
telegram.InlineKeyboardMarkup Optional. Inline keyboard attached to the message.
Parameters
id (str) Unique identifier for this result, 1-64 bytes.
game_short_name (str) Short name of the game.
reply_markup (telegram.InlineKeyboardMarkup, optional) Inline key-
board attached to the message.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InputContactMessageContent(phone_number, first_name,
last_name=None, **kwargs)
Bases: telegram.inline.inputmessagecontent.InputMessageContent
Represents the content of a contact message to be sent as the result of an inline query.
phone_number
str Contacts phone number.
first_name
str Contacts first name.
last_name
str Optional. Contacts last name.
Parameters
phone_number (str) Contacts phone number.
first_name (str) Contacts first name.
last_name (str, optional) Contacts last name.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InputFile(data)
Bases: object
This object represents a Telegram InputFile.
data
dict Data containing an inputfile.
Parameters
Parameters
message_text (str) Text of the message to be sent, 1-4096 characters. Also
found as telegram.constants.MAX_MESSAGE_LENGTH.
parse_mode (str, optional) Send Markdown or HTML, if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your bots message.
disable_web_page_preview (bool, optional) Disables link previews for links
in the sent message.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.InputVenueMessageContent(latitude, longitude, title, address,
foursquare_id=None, **kwargs)
Bases: telegram.inline.inputmessagecontent.InputMessageContent
Represents the content of a venue message to be sent as the result of an inline query.
latitude
float Latitude of the location in degrees.
longitude
float Longitude of the location in degrees.
title
str Name of the venue.
address
str Address of the venue.
foursquare_id
str Optional. Foursquare identifier of the venue, if known.
Parameters
latitude (float) Latitude of the location in degrees.
longitude (float) Longitude of the location in degrees.
text
str Text of the button.
request_contact
bool Optional. If the users phone number will be sent.
request_location
bool Optional. If the users current location will be sent.
Parameters
text (str) Text of the button. If none of the optional fields are used, it will be sent
to the bot as a message when the button is pressed.
request_contact (bool, optional) If True, the users phone number will be sent
as a contact when the button is pressed. Available in private chats only.
request_location (bool, optional) If True, the users current location will be
sent when the button is pressed. Available in private chats only.
Note: request_contact and request_location options will only work in Telegram versions
released after 9 April, 2016. Older clients will ignore them.
Parameters
longitude (float) Longitude as defined by sender.
latitude (float) Latitude as defined by sender.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
Note:
In Python from is a reserved word, use from_user instead.
message_id
int Unique message identifier inside this chat.
from_user
telegram.User Optional. Sender.
date
datetime.datetime Date the message was sent.
chat
telegram.Chat Conversation the message belongs to.
forward_from
telegram.User Optional. Sender of the original message.
forward_from_chat
telegram.Chat Optional. Information about the original channel.
forward_from_message_id
int Optional. Identifier of the original message in the channel.
forward_date
datetime.datetime Optional. Date the original message was sent.
reply_to_message
telegram.Message Optional. The original message.
edit_date
datetime.datetime Optional. Date the message was last edited.
text
str Optional. The actual UTF-8 text of the message.
entities
List[telegram.MessageEntity] Optional. Special entities like usernames, URLs, bot com-
mands, etc. that appear in the text. See Message.parse_entity and parse_entities meth-
ods for how to use properly.
audio
telegram.Audio Optional. Information about the file.
document
telegram.Document Optional. Information about the file.
game
telegram.Game Optional. Information about the game.
photo
List[telegram.PhotoSize] Optional. Available sizes of the photo.
sticker
telegram.Sticker Optional. Information about the sticker.
video
telegram.Video Optional. Information about the video.
voice
telegram.Voice Optional. Information about the file.
video_note
telegram.VideoNote Optional. Information about the video message.
new_chat_members
List[telegram.User] Optional. Information about new members to the chat. (the bot itself may
be one of these members).
caption
str Optional. Caption for the document, photo or video, 0-200 characters.
contact
telegram.Contact Optional. Information about the contact.
location
telegram.Location Optional. Information about the location.
venue
telegram.Venue Optional. Information about the venue.
left_chat_member
telegram.User Optional. Information about the user that left the group. (this member may be
the bot itself).
new_chat_title
str Optional. A chat title was changed to this value.
new_chat_photo
List[telegram.PhotoSize] Optional. A chat photo was changed to this value.
delete_chat_photo
bool Optional. The chat photo was deleted.
group_chat_created
bool Optional. The group has been created.
supergroup_chat_created
bool Optional. The supergroup has been created.
channel_chat_created
bool Optional. The channel has been created.
migrate_to_chat_id
int Optional. The group has been migrated to a supergroup with the specified identifier.
migrate_from_chat_id
int Optional. The supergroup has been migrated from a group with the specified identifier.
pinned_message
telegram.message Optional. Specified message was pinned.
invoice
telegram.Invoice Optional. Information about the invoice.
successful_payment
telegram.SuccessfulPayment Optional. Information about the payment.
forward_signature
str Optional. Signature of the post author for messages forwarded from channels.
author_signature
str Optional. Signature of the post author for messages in channels.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
message_id (int) Unique message identifier inside this chat.
from_user (telegram.User, optional) Sender, can be empty for messages sent
to channels.
date (datetime.datetime) Date the message was sent in Unix time. Converted
to datetime.datetime.
chat (telegram.Chat) Conversation the message belongs to.
forward_from (telegram.User, optional) For forwarded messages, sender of
the original message.
forward_from_chat (telegram.Chat, optional) For messages forwarded
from a channel, information about the original channel.
forward_from_message_id (int, optional) For forwarded channel posts, iden-
tifier of the original message in the channel.
forward_date (datetime.datetime, optional) For forwarded messages, date
the original message was sent in Unix time. Converted to datetime.datetime.
reply_to_message (telegram.Message, optional) For replies, the origi-
nal message. Note that the Message object in this field will not contain further
reply_to_message fields even if it itself is a reply.
edit_date (datetime.datetime, optional) Date the message was last edited
in Unix time. Converted to datetime.datetime.
text (str, optional) For text messages, the actual UTF-8 text of
the message, 0-4096 characters. Also found as telegram.constants.
MAX_MESSAGE_LENGTH.
entities (List[telegram.MessageEntity], optional) For text messages,
special entities like usernames, URLs, bot commands, etc. that appear in the text. See
attr:parse_entity and attr:parse_entities methods for how to use properly.
audio (telegram.Audio, optional) Message is an audio file, information about
the file.
document (telegram.Document, optional) Message is a general file, informa-
tion about the file.
game (telegram.Game, optional) Message is a game, information about the game.
photo (List[telegram.PhotoSize], optional) Message is a photo, available
sizes of the photo.
sticker (telegram.Sticker, optional) Message is a sticker, information about
the sticker.
video (telegram.Video, optional) Message is a video, information about the
video.
bot.delete_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
bot.edit_message_caption(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods.
bot.edit_message_reply_markup(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods.
bot.edit_message_text(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)
Note: You can only edit messages that the bot sent itself, therefore this method can only be used on
the return value of the bot.send_* family of methods..
bot.forward_message(chat_id=chat_id,
from_chat_id=update.message.chat_id,
disable_notification=disable_notification,
message_id=update.message.message_id)
Note: This method should always be used instead of the entities attribute, since it calculates the
correct substring from the message text based on UTF-16 codepoints. See parse_entity for more
info.
Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python dont handle automatically. (That is, you cant just slice
Parameters
entity (telegram.MessageEntity) The entity to extract the text from. It
must
an entity that belongs to this message. (be)
Returns The text of the given entity
Return type str
reply_audio(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_contact(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_document(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_location(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_photo(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_sticker(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_text(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the message is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
reply_venue(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_video(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_video_note(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
reply_voice(*args, **kwargs)
Shortcut for:
Keyword Arguments quote (bool, optional) If set to True, the photo is sent as an
actual reply to this message. If reply_to_message_id is passed in kwargs, this
parameter will be ignored. Default: True in group chats and False in private chats.
Returns On success, instance representing the message posted.
Return type telegram.Message
text_html
Creates an HTML-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as HTML in the same way
the original message was formatted.
Returns Message text with entities formatted as HTML.
Return type str
text_html_urled
Creates an HTML-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as HTML. This also formats
telegram.MessageEntity.URL as a hyperlink.
Returns Message text with entities formatted as HTML.
Return type str
text_markdown
Creates an Markdown-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as Markdown in the same
way the original message was formatted.
Returns Message text with entities formatted as Markdown.
Return type str
text_markdown_urled
Creates an Markdown-formatted string from the markup entities found in the message.
Use this if you want to retrieve the message text with the entities formatted as Markdown. This also
formats telegram.MessageEntity.URL as a hyperlink.
Returns Message text with entities formatted as Markdown.
Return type str
to_dict()
class telegram.MessageEntity(type, offset, length, url=None, user=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
type
str Type of the entity.
offset
int Offset in UTF-16 code units to the start of the entity.
length
int Length of the entity in UTF-16 code units.
url
str Optional. Url that will be opened after user taps on the text.
user
telegram.User Optional. The mentioned user.
Parameters
type (str) Type of the entity. Can be mention (@username), hashtag,
bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string),
pre (monowidth block), text_link (for clickable text URLs), text_mention (for users
without usernames).
offset (int) Offset in UTF-16 code units to the start of the entity.
length (int) Length of the entity in UTF-16 code units.
url (str, optional) For text_link only, url that will be opened after usertaps on the
text.
user (telegram.User, optional) For text_mention only, the mentioned user.
ALL_TYPES = ['mention', 'hashtag', 'bot_command', 'url', 'email', 'bold', 'italic',
BOLD = 'bold'
BOT_COMMAND = 'bot_command'
CODE = 'code'
EMAIL = 'email'
HASHTAG = 'hashtag'
ITALIC = 'italic'
MENTION = 'mention'
PRE = 'pre'
TEXT_LINK = 'text_link'
TEXT_MENTION = 'text_mention'
URL = 'url'
classmethod de_json(data, bot)
classmethod de_list(data, bot)
class telegram.ParseMode
Bases: object
This object represents a Telegram Message Parse Modes.
HTML = 'HTML'
MARKDOWN = 'Markdown'
class telegram.PhotoSize(file_id, width, height, file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents one size of a photo or a file/sticker thumbnail.
file_id
str Unique identifier for this file.
width
int Photo width.
height
int Photo height.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
width (int) Photo width.
height (int) Photo height.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
class telegram.ReplyKeyboardRemove(selective=False, **kwargs)
Bases: telegram.replymarkup.ReplyMarkup
Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and
display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent
by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a
button (see telegram.ReplyKeyboardMarkup).
remove_keyboard
True Requests clients to remove the custom keyboard.
selective
bool Optional. Use this parameter if you want to remove the keyboard for specific users only.
Example
A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for
that user, while still showing the keyboard with poll options to users who havent voted yet.
Parameters
selective (bool, optional) Use this parameter if you want to remove the keyboard
for specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
**kwargs (dict) Arbitrary keyword arguments.
class telegram.ReplyKeyboardMarkup(keyboard, resize_keyboard=False,
one_time_keyboard=False, selective=False,
**kwargs)
Bases: telegram.replymarkup.ReplyMarkup
This object represents a custom keyboard with reply options.
keyboard
List[List[telegram.KeyboardButton | str]] Array of button rows.
resize_keyboard
bool Optional. Requests clients to resize the keyboard.
one_time_keyboard
bool Optional. Requests clients to hide the keyboard as soon as its been used.
selective
bool Optional. Show the keyboard to specific users only.
Example
A user requests to change the bots language, bot replies to the request with a keyboard to select the new
language. Other users in the group dont see the keyboard.
Parameters
keyboard (List[List[str | telegram.KeyboardButton]]) Array of button
rows, each represented by an Array of telegram.KeyboardButton objects.
resize_keyboard (bool, optional) Requests clients to resize the keyboard ver-
tically for optimal fit (e.g., make the keyboard smaller if there are just two rows of
buttons). Defaults to false, in which case the custom keyboard is always of the same
height as the apps standard keyboard. Defaults to False
one_time_keyboard (bool, optional) Requests clients to hide the keyboard as
soon as its been used. The keyboard will still be available, but clients will automatically
display the usual letter-keyboard in the chat - the user can press a special button in the
input field to see the custom keyboard again. Defaults to False.
selective (bool, optional) Use this parameter if you want to show the keyboard
to specific users only. Targets:
1. users that are @mentioned in the text of the Message object
2. if the bots message is a reply (has reply_to_message_id), sender of the original mes-
sage.
Defaults to False.
**kwargs (dict) Arbitrary keyword arguments.
to_dict()
class telegram.ReplyMarkup
Bases: telegram.base.TelegramObject
Base class for Telegram ReplyMarkup Objects.
See telegram.ReplyKeyboardMarkup and telegram.InlineKeyboardMarkup for detailed
use.
class telegram.Sticker(file_id, width, height, thumb=None, emoji=None, file_size=None,
set_name=None, mask_position=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a sticker.
file_id
str Unique identifier for this file.
width
int Sticker width.
height
int Sticker height.
thumb
telegram.PhotoSize Optional. Sticker thumbnail in the .webp or .jpg format.
emoji
str Optional. Emoji associated with the sticker.
set_name
str Optional. Name of the sticker set to which the sticker belongs.
mask_position
telegram.MaskPosition Optional. For mask stickers, the position where the mask should be
placed.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
width (int) Sticker width.
height (int) Sticker height.
thumb (telegram.PhotoSize, optional) Sticker thumbnail in the .webp or .jpg
format.
emoji (str, optional) Emoji associated with the sticker
set_name (str, optional) Name of the sticker set to which the sticker belongs.
mask_position (telegram.MaskPosition, optional) For mask stickers, the
position where the mask should be placed.
file_size (int, optional) File size.
(obj (**kwargs) dict): Arbitrary keyword arguments.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
exception telegram.TelegramError(message)
Bases: exceptions.Exception
class telegram.TelegramObject
Bases: object
Base class for most telegram objects.
classmethod de_json(data, bot)
to_dict()
to_json()
Returns str
class telegram.Update(update_id, message=None, edited_message=None, chan-
nel_post=None, edited_channel_post=None, inline_query=None, cho-
sen_inline_result=None, callback_query=None, shipping_query=None,
pre_checkout_query=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents an incoming update.
Note: At most one of the optional parameters can be present in any given update.
update_id
int The updates unique identifier.
message
telegram.Message Optional. New incoming message.
edited_message
telegram.Message Optional. New version of a message.
channel_post
telegram.Message Optional. New incoming channel post.
edited_channel_post
telegram.Message Optional. New version of a channel post.
inline_query
telegram.InlineQuery Optional. New incoming inline query.
chosen_inline_result
telegram.ChosenInlineResult Optional. The result of an inline query that was chosen by
a user.
callback_query
telegram.CallbackQuery Optional. New incoming callback query.
shipping_query
telegram.ShippingQuery Optional. New incoming shipping query.
pre_checkout_query
telegram.PreCheckoutQuery Optional. New incoming pre-checkout query.
Parameters
update_id (int) The updates unique identifier. Update identifiers start from a
certain positive number and increase sequentially. This ID becomes especially handy if
youre using Webhooks, since it allows you to ignore repeated updates or to restore the
correct update sequence, should they get out of order.
message (telegram.Message, optional) New incoming message of any kind -
text, photo, sticker, etc.
edited_message (telegram.Message, optional) New version of a message
that is known to the bot and was edited.
channel_post (telegram.Message, optional) New incoming channel post of
any kind - text, photo, sticker, etc.
edited_channel_post (telegram.Message, optional) New version of a
channel post that is known to the bot and was edited.
inline_query (telegram.InlineQuery, optional) New incoming inline
query.
chosen_inline_result (telegram.ChosenInlineResult, optional)
The result of an inline query that was chosen by a user and sent to their chat partner.
callback_query (telegram.CallbackQuery, optional) New incoming
callback query.
shipping_query (telegram.ShippingQuery, optional) New incoming
shipping query. Only for invoices with flexible price.
pre_checkout_query (telegram.PreCheckoutQuery, optional) New in-
coming pre-checkout query. Contains full information about checkout
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
effective_chat
telegram.Chat The chat that this update was sent in, no matter what kind of update this is.
Parameters
id (int) Unique identifier for this user or bot.
is_bot (bool) True, if this user is a bot
first_name (str) Users or bots first name.
last_name (str, optional) Users or bots last name.
username (str, optional) Users or bots username.
language_code (str, optional) IETF language tag of the users language.
bot (telegram.Bot, optional) The Bot to use for instance methods.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
get_profile_photos(*args, **kwargs)
Shortcut for:
mention_html(name=None)
Parameters name (str) If provided, will overwrite the users name.
Returns The inline mention for the user as HTML.
Return type str
mention_markdown(name=None)
Parameters name (str) If provided, will overwrite the users name.
Returns The inline mention for the user as markdown.
Return type str
name
str The users username if available, if not it returns the first name and if present first_name
and last_name.
class telegram.UserProfilePhotos(total_count, photos, **kwargs)
Bases: telegram.base.TelegramObject
This object represent a users profile pictures.
total_count
int Total number of profile pictures.
photos
List[List[telegram.PhotoSize]] Requested profile pictures.
Parameters
total_count (int) Total number of profile pictures the target user has.
photos (List[List[telegram.PhotoSize]]) Requested profile pictures (in up to
4 sizes each).
classmethod de_json(data, bot)
to_dict()
class telegram.Venue(location, title, address, foursquare_id=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a venue.
location
telegram.Location Venue location.
title
str Name of the venue.
address
str Address of the venue.
foursquare_id
str Optional. Foursquare identifier of the venue.
Parameters
location (telegram.Location) Venue location.
title (str) Name of the venue.
address (str) Address of the venue.
foursquare_id (str, optional) Foursquare identifier of the venue.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Video(file_id, width, height, duration, thumb=None, mime_type=None,
file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a video file.
file_id
str Unique identifier for this file.
width
int Video width as defined by sender.
height
int Video height as defined by sender.
duration
int Duration of the video in seconds as defined by sender.
thumb
telegram.PhotoSize Optional. Video thumbnail.
mime_type
str Optional. Mime type of a file as defined by sender.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
width (int) Video width as defined by sender.
height (int) Video height as defined by sender.
duration (int) Duration of the video in seconds as defined by sender.
thumb (telegram.PhotoSize, optional) Video thumbnail.
mime_type (str, optional) Mime type of a file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Voice(file_id, duration, mime_type=None, file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a voice note.
file_id
str Unique identifier for this file.
duration
int Duration of the audio in seconds as defined by sender.
mime_type
str Optional. MIME type of the file as defined by sender.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
duration (int, optional) Duration of the audio in seconds as defined by sender.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
Parameters
url (str) Webhook URL, may be empty if webhook is not set up.
has_custom_certificate (bool) True, if a custom certificate was provided
for webhook certificate checks.
pending_update_count (int) Number of updates awaiting delivery.
last_error_date (int, optional) Unix time for the most recent error that hap-
pened when trying todeliver an update via webhook.
last_error_message (str, optional) Error message in human-readable format
for the most recent error that happened when trying to deliver an update via webhook.
max_connections (int, optional) Maximum allowed number of simultaneous
HTTPS connections to the webhook for update delivery.
allowed_updates (List[str], optional) A list of update types the bot is sub-
scribed to. Defaults to all update types.
classmethod de_json(data, bot)
class telegram.Animation(file_id, thumb=None, file_name=None, mime_type=None,
file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents an animation file to be displayed in the message containing a game.
file_id
str Unique file identifier.
thumb
telegram.PhotoSize Optional. Animation thumbnail as defined by sender.
file_name
str Optional. Original animation filename as defined by sender.
mime_type
str Optional. MIME type of the file as defined by sender.
file_size
int Optional. File size.
Parameters
file_id (str) Unique file identifier.
thumb (telegram.PhotoSize, optional) Animation thumbnail as defined by
sender.
file_name (str, optional) Original animation filename as defined by sender.
mime_type (str, optional) MIME type of the file as defined by sender.
file_size (int, optional) File size.
classmethod de_json(data, bot)
class telegram.Game(title, description, photo, text=None, text_entities=None, animation=None,
**kwargs)
Bases: telegram.base.TelegramObject
This object represents a game. Use BotFather to create and edit games, their short names will act as unique
identifiers.
title
str Title of the game.
description
str Description of the game.
photo
List[telegram.PhotoSize] Photo that will be displayed in the game message in chats.
text
str Optional. Brief description of the game or high scores included in the game message. Can be
automatically edited to include current high scores for the game when the bot calls set_game_score,
or manually edited using edit_message_text.
text_entities
List[telegram.MessageEntity] Optional. Special entities that appear in text, such as user-
names, URLs, bot commands, etc.
animation
telegram.Animation Optional. Animation that will be displayed in the game message in chats.
Upload via BotFather.
Parameters
title (str) Title of the game.
description (str) Description of the game.
photo (List[telegram.PhotoSize]) Photo that will be displayed in the game
message in chats.
text (str, optional) Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls set_game_score, or manually edited using edit_message_text. 0-4096
characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
text_entities (List[telegram.MessageEntity], optional) Special entities
that appear in text, such as usernames, URLs, bot commands, etc.
animation (telegram.Animation, optional) Animation that will be displayed
in the game message in chats. Upload via BotFather.
classmethod de_json(data, bot)
parse_text_entities(types=None)
Returns a dict that maps telegram.MessageEntity to str. It contains entities from this
message filtered by their type attribute as the key, and the text that each entity belongs to as the value
of the dict.
Note: This method should always be used instead of the text_entities attribute, since
it calculates the correct substring from the message text based on UTF-16 codepoints. See
parse_text_entity for more info.
Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python dont handle automatically. (That is, you cant just slice
Message.text with the offset and length.)
Parameters
position (int) Position in high score table for the game.
user (telegram.User) User.
score (int) Score.
classmethod de_json(data, bot)
class telegram.VideoNote(file_id, length, duration, thumb=None, file_size=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a video message (available in Telegram apps as of v.4.0).
file_id
str Unique identifier for this file.
length
int Video width and height as defined by sender.
duration
int Duration of the video in seconds as defined by sender.
thumb
telegram.PhotoSize Optional. Video thumbnail.
file_size
int Optional. File size.
Parameters
file_id (str) Unique identifier for this file.
length (int) Video width and height as defined by sender.
duration (int) Duration of the video in seconds as defined by sender.
thumb (telegram.PhotoSize, optional) Video thumbnail.
file_size (int, optional) File size.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.LabeledPrice(label, amount, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a portion of the price for goods or services.
label
str Portion label.
amount
int Price of the product in the smallest units of the currency.
Parameters
label (str) Portion label
amount (int) Price of the product in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
**kwargs (dict) Arbitrary keyword arguments.
class telegram.SuccessfulPayment(currency, total_amount, invoice_payload, tele-
gram_payment_charge_id, provider_payment_charge_id,
shipping_option_id=None, order_info=None, **kwargs)
Bases: telegram.base.TelegramObject
This object contains basic information about a successful payment.
currency
str Three-letter ISO 4217 currency code.
total_amount
int Total price in the smallest units of the currency.
invoice_payload
str Bot specified invoice payload.
shipping_option_id
str Optional. Identifier of the shipping option chosen by the user.
order_info
telegram.OrderInfo Optional. Order info provided by the user.
telegram_payment_charge_id
str Telegram payment identifier.
provider_payment_charge_id
str Provider payment identifier.
Parameters
currency (str) Three-letter ISO 4217 currency code.
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
invoice_payload (str) Bot specified invoice payload.
shipping_option_id (str, optional) Identifier of the shipping option chosen
by the user.
order_info (telegram.OrderInfo, optional) Order info provided by the user
telegram_payment_charge_id (str) Telegram payment identifier.
provider_payment_charge_id (str) Provider payment identifier.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.ShippingOption(id, title, prices, **kwargs)
Bases: telegram.base.TelegramObject
This object represents one shipping option.
id
str Shipping option identifier.
title
str Option title.
prices
List[telegram.LabeledPrice] List of price portions.
Parameters
id (str) Shipping option identifier.
title (str) Option title.
prices (List[telegram.LabeledPrice]) List of price portions.
**kwargs (dict) Arbitrary keyword arguments.
to_dict()
class telegram.ShippingAddress(country_code, state, city, street_line1, street_line2,
post_code, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a Telegram ShippingAddress.
country_code
str ISO 3166-1 alpha-2 country code.
state
str State, if applicable.
city
str City.
street_line1
str First line for the address.
street_line2
str Second line for the address.
post_code
str Address post code.
Parameters
country_code (str) ISO 3166-1 alpha-2 country code.
state (str) State, if applicable.
city (str) City.
street_line1 (str) First line for the address.
street_line2 (str) Second line for the address.
post_code (str) Address post code.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.PreCheckoutQuery(id, from_user, currency, total_amount, invoice_payload,
shipping_option_id=None, order_info=None, bot=None,
**kwargs)
Bases: telegram.base.TelegramObject
This object contains information about an incoming pre-checkout query.
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique query identifier.
from_user
telegram.User User who sent the query.
currency
str Three-letter ISO 4217 currency code.
total_amount
int Total price in the smallest units of the currency.
invoice_payload
str Bot specified invoice payload.
shipping_option_id
str Optional. Identifier of the shipping option chosen by the user.
order_info
telegram.OrderInfo Optional. Order info provided by the user.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
id (str) Unique query identifier.
from_user (telegram.User) User who sent the query.
currency (str) Three-letter ISO 4217 currency code
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp
parameter in currencies.json, it shows the number of digits past the decimal point for
each currency (2 for the majority of currencies).
invoice_payload (str) Bot specified invoice payload.
shipping_option_id (str, optional) Identifier of the shipping option chosen
by the user.
order_info (telegram.OrderInfo, optional) Order info provided by the user.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args,
**kwargs)
Parameters
ok (bool) Specify True if everything is alright (goods are available, etc.) and the
bot is ready to proceed with the order. Use False if there are any problems.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains the reason for failure to proceed with the checkout (e.g.
Sorry, somebody just bought the last of our amazing black T-shirts while you were
busy filling out your payment details. Please choose a different color or garment!).
Telegram will display this message to the user.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
to_dict()
class telegram.OrderInfo(name=None, phone_number=None, email=None, ship-
ping_address=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents information about an order.
name
str Optional. User name.
phone_number
str Optional. Users phone number.
email
str Optional. User email.
shipping_address
telegram.ShippingAddress Optional. User shipping address.
Parameters
name (str, optional) User name.
phone_number (str, optional) Users phone number.
Parameters
title (str) Product name.
description (str) Product description.
start_parameter (str) Unique bot deep-linking parameter that can be used to
generate this invoice.
currency (str) Three-letter ISO 4217 currency code.
total_amount (int) Total price in the smallest units of the currency (integer, not
float/double). For example, for a price of US$ 1.45 pass amount = 145.
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.ShippingQuery(id, from_user, invoice_payload, shipping_address, bot=None,
**kwargs)
Bases: telegram.base.TelegramObject
This object contains information about an incoming shipping query.
Note:
In Python from is a reserved word, use from_user instead.
id
str Unique query identifier.
from_user
telegram.User User who sent the query.
invoice_payload
str Bot specified invoice payload.
shipping_address
telegram.ShippingAddress User specified shipping address.
bot
telegram.Bot Optional. The Bot to use for instance methods.
Parameters
id (str) Unique query identifier.
from_user (telegram.User) User who sent the query.
invoice_payload (str) Bot specified invoice payload.
shipping_address (telegram.ShippingAddress) User specified ship-
ping address.
bot (telegram.Bot, optional) The Bot to use for instance methods.
**kwargs (dict) Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:
Parameters
ok (bool) Specify True if delivery to the specified address is possible and False if
there are any problems (for example, if delivery to the specified address is not possi-
ble).
shipping_options (List[telegram.ShippingOption], optional) Re-
quired if ok is True. A JSON-serialized array of available shipping options.
error_message (str, optional) Required if ok is False. Error message in human
readable form that explains why it is impossible to complete the order (e.g. Sorry,
delivery to your desired address is unavailable). Telegram will display this message
to the user.
classmethod de_json(data, bot)
to_dict()
class telegram.ChatPhoto(small_file_id, big_file_id, bot=None, **kwargs)
Bases: telegram.base.TelegramObject
This object represents a chat photo.
small_file_id
str Unique file identifier of small (160x160) chat photo.
big_file_id
str Unique file identifier of big (640x640) chat photo.
Parameters
small_file_id (str) Unique file identifier of small (160x160) chat photo. This
file_id can be used only for photo download.
big_file_id (str) Unique file identifier of big (640x640) chat photo. This file_id
can be used only for photo download.
bot (telegram.Bot, optional) The Bot to use for instance methods
**kwargs (dict) Arbitrary keyword arguments.
classmethod de_json(data, bot)
Parameters
name (str) Sticker set name.
title (str) Sticker set title.
contains_masks (bool) True, if the sticker set contains masks.
stickers (List[telegram.Sticker]) List of all set stickers.
static de_json(data, bot)
to_dict()
class telegram.MaskPosition(point, x_shift, y_shift, scale, **kwargs)
Bases: telegram.base.TelegramObject
This object describes the position on faces where a mask should be placed by default.
point
str The part of the face relative to which the mask should be placed.
x_shift
float Shift by X-axis measured in widths of the mask scaled to the face size, from left to right.
y_shift
float Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom.
scale
float Mask scaling coefficient. For example, 2.0 means double size.
Notes
type should be one of the following: forehead, eyes, mouth or chin. You can use the classconstants for
those.
Parameters
point (str) The part of the face relative to which the mask should be placed.
x_shift (float) Shift by X-axis measured in widths of the mask scaled to the face
size, from left to right. For example, choosing -1.0 will place mask just to the left of the
default mask position.
y_shift (float) Shift by Y-axis measured in heights of the mask scaled to the face
size, from top to bottom. For example, 1.0 will place the mask just below the default
mask position.
scale (float) Mask scaling coefficient. For example, 2.0 means double size.
CHIN = 'chin'
EYES = 'eyes'
FOREHEAD = 'forehead'
MOUTH = 'mouth'
classmethod de_json(data, bot)
class telegram.CallbackGame
Bases: telegram.base.TelegramObject
A placeholder, currently holds no information. Use BotFather to set up your game.
genindex
modindex
search
263
Python Telegram Bot Documentation, Release 8.0.0
t
telegram.constants, 92
telegram.error, 94
telegram.ext.filters, 7
265
Python Telegram Bot Documentation, Release 8.0.0
267
Python Telegram Bot Documentation, Release 8.0.0
268 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 269
Python Telegram Bot Documentation, Release 8.0.0
270 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 271
Python Telegram Bot Documentation, Release 8.0.0
272 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 273
Python Telegram Bot Documentation, Release 8.0.0
274 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 275
Python Telegram Bot Documentation, Release 8.0.0
276 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 277
Python Telegram Bot Documentation, Release 8.0.0
R reply_markup (telegram.InlineQueryResultCachedGif
RECORD_AUDIO (telegram.ChatAction attribute), 90 attribute), 218
RECORD_VIDEO (telegram.ChatAction attribute), 90 reply_markup (telegram.InlineQueryResultCachedMpeg4Gif
RECORD_VIDEO_NOTE (telegram.ChatAction at- attribute), 219
tribute), 90 reply_markup (telegram.InlineQueryResultCachedPhoto
RegexHandler (class in telegram.ext), 27 attribute), 219
remove_error_handler() (telegram.ext.Dispatcher reply_markup (telegram.InlineQueryResultCachedSticker
method), 6 attribute), 220
remove_handler() (telegram.ext.Dispatcher method), 7 reply_markup (telegram.InlineQueryResultCachedVideo
remove_keyboard (ReplyKeyboardRemove attribute), attribute), 221
110 reply_markup (telegram.InlineQueryResultCachedVoice
remove_keyboard (telegram.ReplyKeyboardRemove attribute), 222
attribute), 245 reply_markup (telegram.InlineQueryResultContact at-
reply (telegram.ext.filters.Filters attribute), 9 tribute), 222
reply_audio() (telegram.Message method), 105 reply_markup (telegram.InlineQueryResultDocument
reply_contact() (telegram.Message method), 105 attribute), 223
reply_document() (telegram.Message method), 106 reply_markup (telegram.InlineQueryResultGame at-
reply_location() (telegram.Message method), 106 tribute), 231
reply_markup (InlineQueryResultArticle attribute), 122 reply_markup (telegram.InlineQueryResultGif at-
reply_markup (InlineQueryResultAudio attribute), 123 tribute), 225
reply_markup (InlineQueryResultCachedAudio at- reply_markup (telegram.InlineQueryResultLocation at-
tribute), 123 tribute), 225
reply_markup (InlineQueryResultCachedDocument at- reply_markup (telegram.InlineQueryResultMpeg4Gif
tribute), 124 attribute), 227
reply_markup (InlineQueryResultCachedGif attribute), reply_markup (telegram.InlineQueryResultPhoto at-
125 tribute), 228
reply_markup (InlineQueryResultCachedMpeg4Gif at- reply_markup (telegram.InlineQueryResultVenue at-
tribute), 126 tribute), 228
reply_markup (InlineQueryResultCachedPhoto at- reply_markup (telegram.InlineQueryResultVideo at-
tribute), 127 tribute), 230
reply_markup (InlineQueryResultCachedSticker reply_markup (telegram.InlineQueryResultVoice at-
attribute), 127 tribute), 231
reply_markup (InlineQueryResultCachedVideo at- reply_photo() (telegram.Message method), 106
tribute), 128 reply_sticker() (telegram.Message method), 106
reply_markup (InlineQueryResultCachedVoice at- reply_text() (telegram.Message method), 106
tribute), 129 reply_to_message (Message attribute), 100
reply_markup (InlineQueryResultContact attribute), reply_to_message (telegram.Message attribute), 235
130 reply_venue() (telegram.Message method), 107
reply_markup (InlineQueryResultDocument attribute), reply_video() (telegram.Message method), 107
131 reply_video_note() (telegram.Message method), 107
reply_markup (InlineQueryResultGame attribute), 132 reply_voice() (telegram.Message method), 107
reply_markup (InlineQueryResultGif attribute), 133 ReplyKeyboardMarkup (class in telegram), 111
reply_markup (InlineQueryResultLocation attribute), ReplyKeyboardRemove (class in telegram), 110
134 ReplyMarkup (class in telegram), 111
reply_markup (InlineQueryResultMpeg4Gif attribute), request_contact (KeyboardButton attribute), 98
135 request_contact (telegram.KeyboardButton attribute),
reply_markup (InlineQueryResultPhoto attribute), 136 234
reply_markup (InlineQueryResultVenue attribute), 137 request_location (KeyboardButton attribute), 98
reply_markup (InlineQueryResultVideo attribute), 138 request_location (telegram.KeyboardButton attribute),
reply_markup (InlineQueryResultVoice attribute), 139 234
reply_markup (telegram.InlineQueryResultArticle at- resize_keyboard (ReplyKeyboardMarkup attribute),
tribute), 215 111
reply_markup (telegram.InlineQueryResultAudio at- resize_keyboard (telegram.ReplyKeyboardMarkup at-
tribute), 216 tribute), 245
reply_markup (telegram.InlineQueryResultCachedAudio restrict_chat_member() (telegram.Bot method), 58
attribute), 216 restrictChatMember() (telegram.Bot method), 58
reply_markup (telegram.InlineQueryResultCachedDocument RESTRICTED (telegram.ChatMember attribute), 92
attribute), 217 result_id (ChosenInlineResult attribute), 142
278 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 279
Python Telegram Bot Documentation, Release 8.0.0
280 Index
Python Telegram Bot Documentation, Release 8.0.0
Index 281
Python Telegram Bot Documentation, Release 8.0.0
282 Index
Python Telegram Bot Documentation, Release 8.0.0
W
WebhookInfo (class in telegram), 117
width (PhotoSize attribute), 110
width (Sticker attribute), 118
width (telegram.PhotoSize attribute), 245
width (telegram.Sticker attribute), 246
width (telegram.Video attribute), 251
width (Video attribute), 115
workers (Dispatcher attribute), 5
X
x_shift (MaskPosition attribute), 119
x_shift (telegram.MaskPosition attribute), 261
Y
y_shift (MaskPosition attribute), 119
y_shift (telegram.MaskPosition attribute), 261
Index 283