0% found this document useful (0 votes)
1K views305 pages

Python Telegram Bot

This document provides documentation for the Python Telegram Bot library. It describes the telegram package which includes utilities and an extensions package for building bots. The extensions package contains classes for managing updates, dispatching messages, and scheduling jobs. The document also outlines the Telegram object classes for representing common bot entities like messages, users and chats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views305 pages

Python Telegram Bot

This document provides documentation for the Python Telegram Bot library. It describes the telegram package which includes utilities and an extensions package for building bots. The extensions package contains classes for managing updates, dispatching messages, and scheduling jobs. The document also outlines the Telegram object classes for representing common bot entities like messages, users and chats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Telegram Bot Documentation

Release 9.0.0

Leandro Toledo

Dec 08, 2017


Contents

1 telegram package 3
1.1 [Link] Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 [Link] package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.2 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.3 [Link] Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.4 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.5 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.6 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.2.7 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.2.8 Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.3 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.4 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.5 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
1.6 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
1.7 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
1.8 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
1.9 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
1.10 [Link] Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
1.11 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
1.12 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
1.13 [Link] module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
1.14 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
1.15 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
1.16 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
1.17 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
1.18 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
1.19 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
1.20 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
1.21 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
1.22 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
1.23 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
1.24 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
1.25 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
1.26 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
1.27 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
1.28 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.29 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
1.30 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.31 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

i
1.32 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
1.33 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
1.34 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
1.35 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
1.36 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
1.37 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
1.38 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
1.39 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
1.40 Stickers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
1.40.1 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
1.40.2 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
1.40.3 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
1.41 Inline Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
1.41.1 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
1.41.2 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
1.41.3 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
1.41.4 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
1.41.5 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . 131
1.41.6 [Link] . . . . . . . . . . . . . . . . . . . . . . . 132
1.41.7 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
1.41.8 telegram.InlineQueryResultCachedMpeg4Gif . . . . . . . . . . . . . . . . . . . . . . . 133
1.41.9 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . 134
1.41.10 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . 135
1.41.11 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . 136
1.41.12 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . 136
1.41.13 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
1.41.14 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
1.41.15 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
1.41.16 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
1.41.17 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
1.41.18 telegram.InlineQueryResultMpeg4Gif . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
1.41.19 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
1.41.20 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
1.41.21 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
1.41.22 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
1.41.23 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
1.41.24 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
1.41.25 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . 148
1.41.26 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
1.41.27 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
1.41.28 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
1.42 Payments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
1.42.1 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
1.42.2 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
1.42.3 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
1.42.4 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
1.42.5 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
1.42.6 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
1.42.7 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
1.42.8 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
1.43 Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
1.43.1 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
1.43.2 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
1.43.3 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
1.43.4 [Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
1.44 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

2 Changelog 277

ii
3 Indices and tables 279

Python Module Index 281

iii
iv
Python Telegram Bot Documentation, Release 9.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 9.0.0

2 Contents
CHAPTER 1

telegram package

1.1 [Link] Module

This module contains helper functions.


[Link].escape_markdown(text)
Helper function to escape telegram markup symbols.
[Link].from_timestamp(unixtime)
Parameters unixtime (int) –
Returns
Return type [Link]
[Link].mention_html(user_id, name)
Parameters
• user_id (int) –
• name (str) –
Returns The inline mention for the user as html.
Return type str
[Link].mention_markdown(user_id, name)
Parameters
• user_id (int) –
• name (str) –
Returns The inline mention for the user as markdown.
Return type str
[Link].to_timestamp(dt_obj)
Parameters dt_obj ([Link]) –
Returns
Return type int

3
Python Telegram Bot Documentation, Release 9.0.0

1.2 [Link] package

1.2.1 [Link]

class [Link](token=None, base_url=None, workers=4, bot=None,


user_sig_handler=None, request_kwargs=None)
Bases: object
This class, which employs the [Link], provides a frontend to [Link]
to the programmer, so they can focus on coding the bot. Its purpose is to receive the updates from Telegram
and to deliver them to said dispatcher. It also runs in a separate thread, so the user can interact with the bot,
for example on the command line. The dispatcher supports handlers for different kinds of data: Updates
from Telegram, basic text commands and even arbitrary types. The updater can be started as a polling
service or, for production, use a webhook to receive updates. This is achieved using the WebhookServer
and WebhookHandler classes.
bot
[Link] – The bot used with this Updater.
user_sig_handler
signal – signals the updater will respond to.
update_queue
Queue – Queue for the updates.
job_queue
[Link] – Jobqueue for the updater.
dispatcher
[Link] – Dispatcher that handles the updates and dispatches them to the
handlers.
running
bool – Indicates if the updater is running.

Parameters
• token (str, optional) – The bot’s token given by the @BotFather.
• base_url (str, optional) – Base_url for the bot.
• workers (int, optional) – Amount of threads in the thread pool for functions deco-
rated with @run_async.
• bot ([Link], optional) – A pre-initialized bot instance. If a pre-initialized
bot is used, it is the user’s 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 [Link] object (ignored if bot argument is used). The re-
quest_kwargs are very useful for the advanced users who would like to control the
default timeouts and/or control the proxy used for http communication.

Note: You must supply either a bot or a token argument.

Raises ValueError – If both token and bot are passed or none of them.

4 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

idle(stop_signals=(2, 15, 6))


Blocks until one of the signals are received and stops the updater.
Parameters stop_signals (iterable) – Iterable containing signals from the signal
module that should be subscribed to. [Link]() will be called on receiving one of
those signals. Defaults to (SIGINT, SIGTERM, SIGABRT).
start_polling(poll_interval=0.0, timeout=10, network_delay=None, clean=False, boot-
strap_retries=0, read_latency=2.0, allowed_updates=None)
Starts polling updates from Telegram.
Parameters
• poll_interval (float, optional) – Time to wait between polling updates from
Telegram in seconds. Default is 0.0.
• timeout (float, optional) – Passed to [Link].get_updates.
• clean (bool, optional) – Whether to clean any pending updates on Telegram servers
before actually starting to poll. 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
• allowed_updates (List[str], optional) – Passed to [Link].
get_updates.
• read_latency (float | int, optional) – Grace time in seconds for receiving the
reply from server. Will be added to the timeout value and used as the read timeout
from server (Default: 2).
• network_delay – Deprecated. Will be honoured as read_latency for a while
but will be removed in the future.
Returns The update queue that can be filled from the main thread.
Return type Queue
start_webhook(listen=‘[Link]’, port=80, url_path=’‘, cert=None, key=None, clean=False,
bootstrap_retries=0, webhook_url=None, allowed_updates=None)
Starts a small http server to listen for updates via webhook. If cert and key are not provided, the
webhook will be started directly on [Link] so SSL can be handled by another ap-
plication. Else, the webhook will be started on [Link]
Parameters
• listen (str, optional) – IP-Address to listen on. Default [Link].
• 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)

1.2. [Link] package 5


Python Telegram Bot Documentation, Release 9.0.0

– > 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 [Link].
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.2.2 [Link]

class [Link](bot, update_queue, workers=4, exception_event=None,


job_queue=None)
Bases: object
This class dispatches all kinds of updates to its registered handlers.
bot
[Link] – The bot object that should be passed to the handlers.
update_queue
Queue – The synchronized queue that will contain the updates.
job_queue
[Link] – Optional. The [Link] instance to pass onto
handler callbacks.
workers
int – Number of maximum concurrent worker threads for the @run_async decorator.

Parameters
• bot ([Link]) – The bot object that should be passed to the handlers.
• update_queue (Queue) – The synchronized queue that will contain the updates.
• job_queue ([Link], optional) – The [Link].
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 [Link]. 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:

6 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• Priority of the group (lower group number == higher priority)


• The first handler in a group which should handle an update (see [Link].
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 ([Link]) – 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 | [Link] | None) – The update that caused the error
• error ([Link]) – 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 [Link]
Raises RuntimeError
groups = None
List[int] – A list with all groups.
handlers = None
Dict[int, List[[Link]]] – Holds the handlers per group.
process_update(update)
Processes a single update.
Parameters update (str | [Link] | [Link]) –
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 ([Link]) – 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

1.2. [Link] package 7


Python Telegram Bot Documentation, Release 9.0.0

running = None
bool – Indicates if this dispatcher is running.
start(ready=None)
Thread target of thread ‘dispatcher’.
Runs in background and processes the update queue.
Parameters ready ([Link], optional) – If specified, the event will be set
once the dispatcher is ready.
stop()
Stops the thread.
user_data = None
dict – A dictionary handlers can use to store data for the user.

1.2.3 [Link] Module

This module contains the Filters for use with the MessageHandler class.
class [Link]
Bases: object
Base class for all Message Filters.
Subclassing from this class filters to be combined using bitwise operators:
And:

>>> ([Link] & [Link](MENTION))

Or:

>>> ([Link] | [Link])

Not:

>>> ~ [Link]

Also works with more than two filters:

>>> ([Link] & ([Link](URL) | [Link](TEXT_LINK)))


>>> [Link] & (~ [Link])

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 ([Link]) – The message that is tested.
Returns bool
class [Link]
Bases: object
Predefined filters for use as the filter argument of [Link].

8 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Examples

Use MessageHandler([Link], callback_method) to filter all video messages. Use


MessageHandler([Link], callback_method) for all contacts. etc.
all = [Link]
Filter – All Messages.
audio = [Link]
Filter – Messages that contain [Link].
class chat(chat_id=None, username=None)
Bases: [Link]
Filters messages to allow only those which are from specified chat ID.

Examples

MessageHandler([Link](-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 = [Link]
Filter – Messages starting with /.
contact = [Link]
Filter – Messages that contain [Link].
document = [Link]
Filter – Messages that contain [Link].
class entity(entity_type)
Bases: [Link]
Filters messages to only allow those which have a [Link] where their type
matches entity_type.

Examples

Example MessageHandler([Link]("hashtag"), callback_method)


Parameters entity_type – Entity type to check for. All types can be found as constants
in [Link].
forwarded = [Link]
Filter – Messages that are forwarded.
game = [Link]
Filter – Messages that contain [Link].
group = [Link]
Filter – Messages sent in a group chat.
invoice = [Link]
Filter – Messages that contain [Link].

1.2. [Link] package 9


Python Telegram Bot Documentation, Release 9.0.0

class language(lang)
Bases: [Link]
Filters messages to only allow those which are from users with a certain language code.
Note: According to telegrams documentation, every single user does not have the language_code
attribute.

Examples

MessageHandler([Link]("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 = [Link]
Filter – Messages that contain [Link].
photo = [Link]
Filter – Messages that contain [Link].
private = [Link]
Filter – Messages sent in a private chat.
reply = [Link]
Filter – Messages that are a reply to another message.
status_update = Filters.status_update
Subset for messages containing a status update.

Examples

Use these filters like: Filters.status_update.new_chat_member etc. Or use just


Filters.status_update for all status update messages.
chat_created
Filter – Messages that contain [Link].group_chat_created,
[Link].supergroup_chat_created or [Link].
channel_chat_created.
delete_chat_photo
Filter – Messages that contain [Link].delete_chat_photo.
left_chat_member
Filter – Messages that contain [Link].left_chat_member.
migrate
Filter – Messages that contain [Link].migrate_from_chat_id or :attr:
[Link].migrate_from_chat_id.
new_chat_members
Filter – Messages that contain [Link].new_chat_member.
new_chat_photo
Filter – Messages that contain [Link].new_chat_photo.
new_chat_title
Filter – Messages that contain [Link].new_chat_title.
pinned_message
Filter – Messages that contain [Link].pinned_message.
sticker = [Link]
Filter – Messages that contain [Link].

10 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

successful_payment = Filters.successful_payment
Filter – Messages that confirm a [Link].
text = [Link]
Filter – Text Messages.
class user(user_id=None, username=None)
Bases: [Link]
Filters messages to allow only those which are from specified user ID.

Examples

MessageHandler([Link](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 = [Link]
Filter – Messages that contain [Link].
video = [Link]
Filter – Messages that contain [Link].
voice = [Link]
Filter – Messages that contain [Link].
class [Link](f )
Bases: [Link]
Represents a filter that has been inverted.
Parameters f – The filter to invert.
class [Link](base_filter, and_filter=None, or_filter=None)
Bases: [Link]
Represents a filter consisting of two other filters.
Parameters
• base_filter – Filter 1 of the merged filter
• and_filter – Optional filter to “and” with base_filter. Mutually exclusive with
or_filter.
• or_filter – Optional filter to “or” with base_filter. Mutually exclusive with
and_filter.

1.2.4 [Link]

class [Link](callback, interval=None, repeat=True, context=None, days=(0, 1, 2, 3, 4, 5,


6), name=None, job_queue=None)
Bases: object
This class encapsulates a Job.
callback
callable – The callback function that should be executed by the new job.

1.2. [Link] package 11


Python Telegram Bot Documentation, Release 9.0.0

context
object – Optional. Additional data needed for the callback function.
name
str – Optional. The name of the new job.

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 [Link]
instance. It can be used to access it’s context or change it to a repeating job.
• interval (int | float | [Link], optional) – The interval in
which the job will run. If it is an int or a float, it will be interpreted as seconds. If
you don’t set this value, you must set repeat to False and specify next_t when
you put the job into the job queue.
• repeat (bool, optional) – If this job should be periodically execute its callback func-
tion (True) or only once (False). Defaults to True.
• context (object, optional) – Additional data needed for the callback function. Can
be accessed through [Link] in the callback. Defaults to None.
• name (str, optional) – The name of the new job. Defaults to callback.__name__.
• days (Tuple[int], optional) – Defines on which days of the week the job should run.
Defaults to Days.EVERY_DAY
• job_queue ([Link], optional) – The JobQueue this job be-
longs to. Only optional for backward compatibility with [Link]().

days
Tuple[int] – Optional. Defines on which days of the week the job should run.
enabled
bool – Whether this job is enabled.
interval
int | float | [Link] – Optional. The interval in which the job will run.
interval_seconds
int – The interval for this job in seconds.
job_queue
[Link] – Optional. The JobQueue this job belongs to.
removed
bool – Whether this job is due to be removed.
repeat
bool – Optional. If this job should periodically execute its callback function.
run(bot)
Executes the callback function.
schedule_removal()
Schedules this job for removal from the JobQueue. It will be removed without executing its callback
function again.

1.2.5 [Link]

class [Link](bot, prevent_autostart=None)


Bases: object
This class allows you to periodically perform tasks with the bot.

12 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

queue
PriorityQueue – The queue that holds the Jobs.
bot
[Link] – Bot that’s send to the handlers.

Parameters bot ([Link]) – 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.

Note: This method is deprecated. Please use: run_once, run_daily or run_repeating


instead.

Parameters
• job ([Link]) – The Job instance representing the new job.
• next_t (int | float | [Link] | [Link] |
[Link], 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.
– [Link] will be interpreted as “time from now” in which the job
should run.
– [Link] will be interpreted as a specific date and time at which
the job should run.
– [Link] 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.

run_daily(callback, time, days=(0, 1, 2, 3, 4, 5, 6), 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 [Link].
Job instance. It can be used to access it’s [Link] or change it to a repeating
job.
• time ([Link]) – 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 [Link] 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 [Link]

1.2. [Link] package 13


Python Telegram Bot Documentation, Release 9.0.0

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 [Link].
Job instance. It can be used to access it’s [Link] or change it to a repeating
job.
• when (int | float | [Link] | [Link] |
[Link]) – 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.
– [Link] will be interpreted as “time from now” in which the job
should run.
– [Link] will be interpreted as a specific date and time at which
the job should run.
– [Link] 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 [Link] 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 [Link]
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 [Link].
Job instance. It can be used to access it’s [Link] or change it to a repeating
job.
• interval (int | float | [Link]) – The interval in which the
job will run. If it is an int or a float, it will be interpreted as seconds.
• first (int | float | [Link] | [Link] |
[Link], optional) – Time in or at which the job should run. This pa-
rameter will be interpreted depending on its type.
– int or float will be interpreted as “seconds from now” in which the job should
run.
– [Link] will be interpreted as “time from now” in which the job
should run.
– [Link] will be interpreted as a specific date and time at which
the job should run.
– [Link] 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.
Defaults to interval
• context (object, optional) – Additional data needed for the callback function.
Can be accessed through [Link] in the callback. Defaults to None.

14 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
start()
Starts the job_queue thread.
stop()
Stops the thread.
tick()
Run all jobs that are due and re-enqueue them with their interval.

1.2.6 [Link]

class [Link](all_burst_limit=30, all_time_limit_ms=1000,


group_burst_limit=20, group_time_limit_ms=60000,
exc_route=None, autostart=True)
Bases: object
Implements callback processing with proper delays to avoid hitting Telegram’s message limits. Contains
two DelayQueue, for group and for all messages, interconnected in delay chain. Callables are processed
through group DelayQueue, then through all DelayQueue for group-type messages. For non-group
messages, only the all DelayQueue is used.
Parameters
• all_burst_limit (int, optional) – Number of maximum all-type callbacks to
process per time-window defined by all_time_limit_ms. Defaults to 30.
• all_time_limit_ms (int, optional) – Defines width of all-type time-window used
when each processing limit is calculated. Defaults to 1000 ms.
• group_burst_limit (int, optional) – Number of maximum group-type callbacks
to process per time-window defined by group_time_limit_ms. Defaults to 20.
• group_time_limit_ms (int, optional) – Defines width of group-type time-
window used when each processing limit is calculated. Defaults to 60000 ms.
• exc_route (callable, optional) – A callable, accepting one positional argu-
ment; used to route exceptions from processor threads 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, processors are started immediately after ob-
ject’s 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 [Link]
(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.

1.2. [Link] package 15


Python Telegram Bot Documentation, Release 9.0.0

Notes

Method is designed to accept [Link] as promise argument,


but other callables could be used too. For example, lambdas or simple functions could be used to wrap
original func to be called with needed args. In that case, be sure that either wrapper func does not raise
outside exceptions or the proper exc_route handler is provided.
Returns Used as promise argument.
Return type callable
__weakref__
list of weak references to the object (if defined)
start()
Method is used to manually start the MessageQueue processing.
stop(timeout=None)
Used to gently stop processor and shutdown its thread.
Parameters timeout (float) – Indicates maximum time to wait for processor to stop
and its thread to exit. If timeout exceeds and processor has not stopped, method silently
returns. is_alive could be used afterwards to check the actual status. timeout set
to None, blocks until processor is shut down. Defaults to None.

1.2.7 [Link]

class [Link](queue=None, burst_limit=30, time_limit_ms=1000,


exc_route=None, autostart=True, name=None)
Bases: [Link]
Processes callbacks from queue with specified throughput limits. Creates a separate thread to process call-
backs with delays.
burst_limit
int – Number of maximum callbacks to process per time-window.
time_limit
int – Defines width of time-window used when each processing limit is calculated.
exc_route
callable – A callable, accepting 1 positional argument; used to route exceptions from processor
thread to main thread;
name
str – Thread’s name.

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 object’s
creation; if False, should be started manually by start method. Defaults to True.

16 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• name (str, optional) – Thread’s name. Defaults to 'DelayQueue-N', where N is


sequential number of object created.

__call__(func, *args, **kwargs)


Used to process callbacks in throughput-limiting thread through queue.
Parameters
• func (callable) – The actual function (or any callable) that is processed through
queue.
• *args (list) – Variable-length func arguments.
• **kwargs (dict) – Arbitrary keyword-arguments to func.
run()
Do not use the method except for unthreaded testing purposes, the method normally is automatically
called by autostart argument.
stop(timeout=None)
Used to gently stop processor and shutdown its thread.
Parameters timeout (float) – Indicates maximum time to wait for processor to stop
and its thread to exit. If timeout exceeds and processor has not stopped, method silently
returns. is_alive could be used afterwards to check the actual status. timeout set
to None, blocks until processor is shut down. Defaults to None.

1.2.8 Handlers

[Link]

class [Link](callback, pass_update_queue=False, pass_job_queue=False,


pass_user_data=False, pass_chat_data=False)
Bases: object
The base class for all update handlers. Create custom handlers by inheriting from it.
callback
callable – The callback function for this handler.
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.
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.

1.2. [Link] package 17


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 | [Link]) – 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 ([Link]) – 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 [Link]([Link],
update), possibly along with optional arguments. To work with the ConversationHandler,
this method should return the value returned from [Link]
Parameters
• update (str | [Link]) – The update to be handled.
• dispatcher ([Link]) – The dispatcher to collect op-
tional args.

[Link]

class [Link](callback, pass_update_queue=False,


pass_job_queue=False, pattern=None,
pass_groups=False, pass_groupdict=False,
pass_user_data=False, pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram callback queries. Optionally based on a regex.
Read the documentation of the re module for more information.
callback
callable – The callback function for this handler.
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.
pattern
str | Pattern – Optional. Regex pattern to test [Link] against.

18 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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_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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] which can be used to
schedule new jobs. Default is False.
• pattern (str | Pattern, optional) – Regex pattern. If not None, [Link] is used
on [Link] 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
• pass_groupdict (bool, optional) – If the callback should be passed the result
of [Link](pattern, data).groupdict() as a keyword argument called
groupdict. 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.

1.2. [Link] package 19


Python Telegram Bot Documentation, Release 9.0.0

• dispatcher ([Link]) – Dispatcher that originated the


Update.

[Link]

class [Link](callback, pass_update_queue=False,


pass_job_queue=False,
pass_user_data=False,
pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram updates that contain a chosen inline result.
callback
callable – The callback function for this handler.
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.
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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.

20 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](entry_points, states, fallbacks, al-


low_reentry=False, run_async_timeout=None,
timed_out_behavior=None, per_chat=True,
per_user=True, per_message=False)
Bases: [Link]
A handler to hold a conversation with a single user by managing four collections of other handlers. Note that
neither posts in Telegram Channels, nor group interactions with multiple users are managed by instances of
this class.
The first collection, a list named entry_points, is used to initiate the conversation, for example with
a [Link] or [Link].
The second collection, a dict named states, contains the different conversation steps and one or more
associated handlers that should be used if the user sends a message when the conversation with them is cur-
rently in that state. You will probably use mostly [Link] and telegram.
[Link] here.
The third collection, a list named fallbacks, is used if the user is currently in a conversation but the
state has either no associated handler or the handler that is associated to the state is inappropriate for the
update, for example if the update contains a command, but a regular text message is expected. You could
use this for a /cancel command or to let the user know their message was not recognized.
The fourth, optional collection of handlers, a list named timed_out_behavior is used if the wait
for run_async takes longer than defined in run_async_timeout. For example, you can let the user
know that they should wait for a bit before they can continue.
To change the state of conversation, the callback function of a handler must return the new state after
responding to the user. If it does not return anything (returning None by default), the state will not change.
To end the conversation, the callback function must return :attr‘END‘ or -1.
entry_points
List[[Link]] – A list of Handler objects that can trigger the start of the con-
versation.
states
Dict[object, List[[Link]]] – 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[[Link]] – 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[[Link]] – 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 Chat’s ID.

1.2. [Link] package 21


Python Telegram Bot Documentation, Release 9.0.0

per_user
bool – Optional. If the conversationkey should contain the User’s ID.
per_message
bool – Optional. If the conversationkey should contain the Message’s ID.

Parameters
• entry_points (List[[Link]]) – 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[[Link]]]) – 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[[Link]]) – 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[[Link]], 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 Chat’s ID.
Default is True.
• per_user (bool, optional) – If the conversationkey should contain the User’s ID.
Default is True.
• per_message (bool, optional) – If the conversationkey should contain the Mes-
sage’s 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback for the current state and Handler
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

22 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

[Link]

class [Link](command, callback, filters=None, allow_edited=False,


pass_args=False, pass_update_queue=False,
pass_job_queue=False, pass_user_data=False,
pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram commands.
Commands are Telegram messages that start with /, optionally followed by an @ and the bot’s name and/or
some additional text.
command
str | List[str] – The command or list of commands this handler should listen for.
callback
callable – The callback function for this handler.
filters
[Link] – Optional. Only allow updates with these Filters.
allow_edited
bool – Optional. Determines Whether the handler should also accept edited messages.
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.
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
• 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 ([Link], optional) – A filter inheriting from
[Link]. Standard filters can be found in
[Link]. 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

1.2. [Link] package 23


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](callback, pass_update_queue=False,


pass_job_queue=False, pattern=None,
pass_groups=False, pass_groupdict=False,
pass_user_data=False, pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram inline queries. Optionally based on a regex. Read the documentation of
the re module for more information.
callback
callable – The callback function for this handler.
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.
pattern
str | Pattern – Optional. Regex pattern to test [Link] against.
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_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.

24 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] which can be used to
schedule new jobs. Default is False.
• pattern (str | Pattern, optional) – Regex pattern. If not None, [Link]
is used on [Link] 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
• pass_groupdict (bool, optional) – If the callback should be passed the result
of [Link](pattern, data).groupdict() as a keyword argument called
groupdict. 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](filters, callback, allow_edited=False,


pass_update_queue=False, pass_job_queue=False,
pass_user_data=False, pass_chat_data=False, mes-
sage_updates=True, channel_post_updates=True,
edited_updates=False)
Bases: [Link]

1.2. [Link] package 25


Python Telegram Bot Documentation, Release 9.0.0

Handler class to handle telegram messages. They might contain text, media or status updates.
filters
Filter – Only allow updates with these Filters. See [Link] for a full list of
all available filters.
callback
callable – The callback function for this handler.
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.
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.
message_updates
bool – Optional. Should “normal” message updates be handled? Default is True.
channel_post_updates
bool – Optional. Should channel posts updates be handled? 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.

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 ([Link], optional) – A filter inheriting from
[Link]. Standard filters can be found in
[Link]. 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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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.

26 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](callback, pass_update_queue=False,


pass_job_queue=False,
pass_user_data=False,
pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram PreCheckout callback queries.
callback
callable – The callback function for this handler.
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.
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.

1.2. [Link] package 27


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](pattern, callback, pass_groups=False, pass_groupdict=False,


pass_update_queue=False, pass_job_queue=False,
pass_user_data=False, pass_chat_data=False, al-
low_edited=False, message_updates=True, chan-
nel_post_updates=False, edited_updates=False)
Bases: [Link]
Handler class to handle Telegram updates based on a regex.
It uses a regular expression to check text messages. Read the documentation of the re module for more
information. The [Link] function is used to determine if an update should be handled by this handler.
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.
pass_user_data
bool – Optional. Determines whether user_data will be passed to the callback function.

28 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
• 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 [Link](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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.

1.2. [Link] package 29


Python Telegram Bot Documentation, Release 9.0.0

• dispatcher ([Link]) – Dispatcher that originated the


Update.

[Link]

class [Link](callback, pass_update_queue=False,


pass_job_queue=False, pass_user_data=False,
pass_chat_data=False)
Bases: [Link]
Handler class to handle Telegram shipping callback queries.
callback
callable – The callback function for this handler.
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.
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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters

30 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• update ([Link]) – Incoming telegram update.


• dispatcher ([Link]) – Dispatcher that originated the
Update.

[Link]

class [Link](command, callback, pass_args=False,


pass_update_queue=False,
pass_job_queue=False)
Bases: [Link]
Handler class to handle string commands. Commands are string updates that start with /.

Note: This handler is not used to handle Telegram [Link], 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 [Link] and [Link] 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:[Link] instance created by the [Link]
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.

1.2. [Link] package 31


Python Telegram Bot Documentation, Release 9.0.0

Parameters
• update (str) – An incomming command.
• dispatcher ([Link]) – Dispatcher that originated the
command.

[Link]

class [Link](pattern, callback, pass_groups=False,


pass_groupdict=False, pass_update_queue=False,
pass_job_queue=False)
Bases: [Link]
Handler class to handle string updates based on a regex which checks the update content.
Read the documentation of the re module for more information. The [Link] function is used to
determine if an update should be handled by this handler.

Note: This handler is not used to handle Telegram [Link], 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 [Link](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 [Link] and [Link] that
contains new updates which can be used to insert updates. Default is False.

32 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link].
JobQueue instance created by the [Link] 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 ([Link]) – Dispatcher that originated the
command.

[Link]

class [Link](type, callback, strict=False, pass_update_queue=False,


pass_job_queue=False)
Bases: [Link]
Handler class to handle updates of custom types.
type
type – The type of updates this handler should process.
callback
callable – The callback function for this handler.
strict
bool – Optional. Use type instead of isinstance. Default is False
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
• 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 [Link] and [Link] 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 [Link].
JobQueue instance created by the [Link] which can be used to
schedule new jobs. Default is False.

1.2. [Link] package 33


Python Telegram Bot Documentation, Release 9.0.0

check_update(update)
Determines whether an update should be passed to this handlers callback.
Parameters update ([Link]) – Incoming telegram update.
Returns bool
handle_update(update, dispatcher)
Send the update to the callback.
Parameters
• update ([Link]) – Incoming telegram update.
• dispatcher ([Link]) – Dispatcher that originated the
Update.

1.3 [Link]

class [Link](file_id, duration, performer=None, title=None, mime_type=None,


file_size=None, **kwargs)
Bases: [Link]
This object represents an audio file to be treated as music by the Telegram clients.
file_id
str – Unique identifier for this file.
duration
int – Duration of the audio in seconds.
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.

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.4 [Link]

class [Link](token, base_url=None, base_file_url=None, request=None)


Bases: [Link]

34 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

This object represents a Telegram Bot.


Parameters
• token (str) – Bot’s unique authentication.
• base_url (str, optional) – Telegram Bot API service URL.
• base_file_url (str, optional) – Telegram Bot API file URL.
• request ([Link], optional) – Pre initialized
[Link].
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 ([Link], 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 [Link]

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.

1.4. [Link] 35
Python Telegram Bot Documentation, Release 9.0.0

• emojis (str) – One or more emoji corresponding to the sticker.


• mask_position ([Link], 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 [Link]

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
[Link]/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 user’s 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 [Link]/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 [Link]
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[[Link]) – 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.

36 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 don’t support pagination. Offset length can’t 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 bot’s inline capabilities.
Returns bool On success, True is returned.
Raises [Link]
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 [Link]

1.4. [Link] 37
Python Telegram Bot Documentation, Release 9.0.0

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[[Link]]) – 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 [Link]
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
[Link]/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 user’s 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 [Link]/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 [Link]
answer_inline_query(*args, **kwargs)
Use this method to send answers to an inline query. No more than 50 results per query are allowed.

38 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Parameters
• inline_query_id (str) – Unique identifier for the answered query.
• results (List[[Link]) – 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 don’t support pagination. Offset length can’t 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 bot’s inline capabilities.
Returns bool On success, True is returned.
Raises [Link]
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

1.4. [Link] 39
Python Telegram Bot Documentation, Release 9.0.0

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 [Link]

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[[Link]]) – 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 [Link]
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 [Link]/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, can’t 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.

40 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 ([Link], 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 [Link]

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 [Link]/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, can’t 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 ([Link], 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.

1.4. [Link] 41
Python Telegram Bot Documentation, Release 9.0.0

Return type bool


Raises [Link]

deleteChatPhoto(*args, **kwargs)
Use this method to delete a chat photo. Photos can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]

deleteChatStickerSet(*args, **kwargs)
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• 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
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

42 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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 [Link]
deleteWebhook(*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 [Link]
delete_chat_photo(*args, **kwargs)
Use this method to delete a chat photo. Photos can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]

1.4. [Link] 43
Python Telegram Bot Documentation, Release 9.0.0

delete_chat_sticker_set(*args, **kwargs)
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• 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
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 [Link]
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 [Link]
delete_webhook(*args, **kwargs)
Use this method to remove webhook integration if you decide to switch back to getUpdates. Requires
no parameters.

44 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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 [Link]
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
target‘channel (in the format @channelusername).
• 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.
• caption (str, optional) – New caption of the message.
• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
editMessageLiveLocation(*args, **kwargs)
Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A
location can be edited until its live_period expires or editing is explicitly disabled by a call to
stop_message_live_location.

Note: You can either supply a latitude and longitude or a location.

Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• latitude (float, optional) – Latitude of location.
• longitude (float, optional) – Longitude of location.
• location ([Link], optional) – The location to send.

1.4. [Link] 45
Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]

editMessageReplyMarkup(*args, **kwargs)
Use this method to edit only the reply markup 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
target‘channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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, if edited message is sent by the bot, the editedMessage is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
editMessageText(*args, **kwargs)
Use this method to edit text and game 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 target
channel (in the format @channelusername).
• 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.
• text (str) – New text of the message.
• parse_mode (str) – Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bot’s message. See the
constants in [Link] for the available modes.
• reply_markup ([Link], 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.

46 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_caption(*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
target‘channel (in the format @channelusername).
• 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.
• caption (str, optional) – New caption of the message.
• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_live_location(*args, **kwargs)
Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A
location can be edited until its live_period expires or editing is explicitly disabled by a call to
stop_message_live_location.

Note: You can either supply a latitude and longitude or a location.

Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• latitude (float, optional) – Latitude of location.
• longitude (float, optional) – Longitude of location.

1.4. [Link] 47
Python Telegram Bot Documentation, Release 9.0.0

• location ([Link], optional) – The location to send.


• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]

edit_message_reply_markup(*args, **kwargs)
Use this method to edit only the reply markup 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
target‘channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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, if edited message is sent by the bot, the editedMessage is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_text(*args, **kwargs)
Use this method to edit text and game 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 target
channel (in the format @channelusername).
• 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.
• text (str) – New text of the message.
• parse_mode (str) – Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bot’s message. See the
constants in [Link] for the available modes.
• reply_markup ([Link], 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.

48 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
exportChatInviteLink(*args, **kwargs)
Use this method to export an invite link to 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.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the
target‘channel (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 Exported invite link on success.
Return type str
Raises [Link]
export_chat_invite_link(*args, **kwargs)
Use this method to export an invite link to 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.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the
target‘channel (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 Exported invite link on success.
Return type str
Raises [Link]
first_name
str – Bot’s first name.
forwardMessage(*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.

1.4. [Link] 49
Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
Raises [Link]
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 [Link]
Raises [Link]
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
target‘channel (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 [Link]
Raises [Link]
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
target‘channel (in the format @channelusername).

50 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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 List[[Link]]
Raises [Link]
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
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 [Link]
Raises [Link]
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
target‘channel (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 [Link]
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 [Link].
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 [Link]
Raises [Link]

1.4. [Link] 51
Python Telegram Bot Documentation, Release 9.0.0

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[[Link]]
Raises [Link]
getMe(*args, **kwargs)
A simple method for testing your bot’s 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 [Link] instance representing that bot if the credentials are valid,
None otherwise.
Return type [Link]
Raises [Link]
getStickerSet(*args, **kwargs)
Use this method to get a sticker set.
Parameters
• name (str) – Short name of the sticker set that is used in [Link]/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 [Link]
Raises [Link]
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.

52 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] 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 doesn’t 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

1. This method will not work if an outgoing webhook is set up.


2. In order to avoid getting duplicate updates, recalculate offset after each server response.
3. To take full advantage of this library take a look at [Link]

Returns List[[Link]]
Raises [Link]

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 [Link]
Raises [Link]
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 [Link]

1.4. [Link] 53
Python Telegram Bot Documentation, Release 9.0.0

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
target‘channel (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 [Link]
Raises [Link]
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
target‘channel (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[[Link]]
Raises [Link]
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
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 [Link]
Raises [Link]
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
target‘channel (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).

54 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns Number of members in the chat.
Return type int
Raises [Link]
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 [Link].
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 [Link]
Raises [Link]
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[[Link]]
Raises [Link]
get_me(*args, **kwargs)
A simple method for testing your bot’s 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 [Link] instance representing that bot if the credentials are valid,
None otherwise.
Return type [Link]
Raises [Link]
get_sticker_set(*args, **kwargs)
Use this method to get a sticker set.

1.4. [Link] 55
Python Telegram Bot Documentation, Release 9.0.0

Parameters
• name (str) – Short name of the sticker set that is used in [Link]/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 [Link]
Raises [Link]
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 [Link] 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 doesn’t 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

1. This method will not work if an outgoing webhook is set up.


2. In order to avoid getting duplicate updates, recalculate offset after each server response.
3. To take full advantage of this library take a look at [Link]

Returns List[[Link]]
Raises [Link]

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.

56 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
Raises [Link]
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 [Link]
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 | [Link], 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 group’s
creator or by the member that added them.

Returns bool On success, True is returned.


Raises [Link]

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

1.4. [Link] 57
Python Telegram Bot Documentation, Release 9.0.0

• 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 | [Link], 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 group’s
creator or by the member that added them.

Returns bool On success, True is returned.


Raises [Link]

last_name
str – Optional. Bot’s 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
target‘channel (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 [Link]
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
target‘channel (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 [Link]
name
str – Bot’s @username.

58 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
target‘channel (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 [Link]
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
target‘channel (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 [Link]
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.

1.4. [Link] 59
Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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).

60 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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 Returns True on success.
Return type bool
Raises [Link]
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 | [Link], 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.
• can_send_media_messages (bool, optional) – Pass 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) – Pass 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) – Pass True, if the user may
add web page previews to their messages, implies can_send_media_messages.
• 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 [Link]
restrict_chat_member(*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 | [Link], 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.

1.4. [Link] 61
Python Telegram Bot Documentation, Release 9.0.0

• can_send_messages (bool, optional) – Pass True, if the user can send text mes-
sages, contacts, locations and venues.
• can_send_media_messages (bool, optional) – Pass 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) – Pass 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) – Pass True, if the user may
add web page previews to their messages, implies can_send_media_messages.
• 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 [Link]
sendAudio(*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 | [Link]) – 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 ([Link], 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.

62 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, the sent Message is returned.


Return type [Link]
Raises [Link]

sendChatAction(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bot’s 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 ([Link] | str) – Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in [Link]
• 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 [Link]
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) – Contact’s phone number.
• first_name (str, optional) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• contact ([Link], 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 ([Link], 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.

1.4. [Link] 63
Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]

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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

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.

64 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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 [Link]
Raises [Link]
sendInvoice(*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[[Link]) – Price breakdown, a list of compo-
nents (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
• provider_data (str | object, optional) – JSON-encoded data about the in-
voice, which will be shared with the payment provider. A detailed description of re-
quired fields should be provided by the payment provider. When an object is passed,
it will be encoded as JSON.
• 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 user’s full name to
complete the order.
• need_phone_number (bool, optional) – Pass True, if you require the user’s
phone number to complete the order.
• need_email (bool, optional) – Pass True, if you require the user’s email to com-
plete the order.
• need_shipping_address (bool, optional) – Pass True, if you require the user’s
shipping address to complete the order.
• is_flexible (bool, optional) – Pass True, if the final price depends on the ship-
ping method.

1.4. [Link] 65
Python Telegram Bot Documentation, Release 9.0.0

• 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 ([Link], 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.
• 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 [Link]
Raises [Link]
sendLocation(*args, **kwargs)
Use this method to send point on the map.

Note: You can either supply a latitude and longitude or a location.

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 ([Link], optional) – The location to send.
• live_period (int, optional) – Period in seconds for which the location will be
updated, should be between 60 and 86400.
• 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 ([Link], 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 [Link]
Raises [Link]

sendMediaGroup(*args, **kwargs)
Use this method to send a group of photos or videos as an album.
Parameters

66 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• media (List[[Link]]) – An array describing photos and videos
to be sent, must include 2–10 items.
• 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.
• timeout (int | float, optional) – Send file timeout (default: 20 seconds).
• **kwargs (dict) – Arbitrary keyword arguments.
Returns An array of the sent Messages.
Return type List[[Link]]
Raises [Link]
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
[Link].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 bot’s message. See the
constants in [Link] for the available modes.
• disable_web_page_preview (bool, optional) – Disables link previews for
links in this message.
• 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 ([Link], 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 [Link]
Raises [Link]
sendPhoto(*args, **kwargs)
Use this method to send photos.

Note: The photo argument can be either a file_id, an URL or a file from disk open(filename,
'rb')

1.4. [Link] 67
Python Telegram Bot Documentation, Release 9.0.0

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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

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 [Link]) – 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 ([Link], 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.

68 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]

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 ([Link], 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 ([Link], 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 [Link]
Raises [Link]

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 | [Link]) – 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

1.4. [Link] 69
Python Telegram Bot Documentation, Release 9.0.0

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 ([Link], 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 [Link]
Raises [Link]

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 | [Link]) – 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 [Link] 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 ([Link], 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.

70 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]

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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

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).

1.4. [Link] 71
Python Telegram Bot Documentation, Release 9.0.0

• audio (str | filelike object | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

send_chat_action(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bot’s 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 ([Link] | str) – Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in [Link]
• 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 [Link]
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

72 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• phone_number (str, optional) – Contact’s phone number.
• first_name (str, optional) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• contact ([Link], 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 ([Link], 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 [Link]
Raises [Link]

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 | [Link]) – 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 ([Link], 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).

1.4. [Link] 73
Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns On success, the sent Message is returned.
Return type [Link]
Raises [Link]

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 ([Link], 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 [Link]
Raises [Link]
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[[Link]) – Price breakdown, a list of compo-
nents (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
• provider_data (str | object, optional) – JSON-encoded data about the in-
voice, which will be shared with the payment provider. A detailed description of re-
quired fields should be provided by the payment provider. When an object is passed,
it will be encoded as JSON.

74 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 user’s full name to
complete the order.
• need_phone_number (bool, optional) – Pass True, if you require the user’s
phone number to complete the order.
• need_email (bool, optional) – Pass True, if you require the user’s email to com-
plete the order.
• need_shipping_address (bool, optional) – Pass True, if you require the user’s
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 ([Link], 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.
• 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 [Link]
Raises [Link]
send_location(*args, **kwargs)
Use this method to send point on the map.

Note: You can either supply a latitude and longitude or a location.

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 ([Link], optional) – The location to send.
• live_period (int, optional) – Period in seconds for which the location will be
updated, should be between 60 and 86400.
• disable_notification (bool, optional) – Sends the message silently. Users
will receive a notification with no sound.

1.4. [Link] 75
Python Telegram Bot Documentation, Release 9.0.0

• reply_to_message_id (int, optional) – If the message is a reply, ID of the


original message.
• reply_markup ([Link], 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 [Link]
Raises [Link]

send_media_group(*args, **kwargs)
Use this method to send a group of photos or videos as an album.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• media (List[[Link]]) – An array describing photos and videos
to be sent, must include 2–10 items.
• 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.
• timeout (int | float, optional) – Send file timeout (default: 20 seconds).
• **kwargs (dict) – Arbitrary keyword arguments.
Returns An array of the sent Messages.
Return type List[[Link]]
Raises [Link]
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
[Link].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 bot’s message. See the
constants in [Link] for the available modes.
• disable_web_page_preview (bool, optional) – Disables link previews for
links in this message.
• 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.

76 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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 [Link]
Raises [Link]
send_photo(*args, **kwargs)
Use this method to send photos.

Note: The photo 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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

send_sticker(*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

1.4. [Link] 77
Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• sticker (str | filelike object [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

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 ([Link], 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 ([Link], 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.

78 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, the sent Message is returned.


Return type [Link]
Raises [Link]

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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]

send_video_note(*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).

1.4. [Link] 79
Python Telegram Bot Documentation, Release 9.0.0

• video_note (str | filelike object | [Link]) – 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 [Link] 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 ([Link], 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 [Link]
Raises [Link]

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 | [Link]) – 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 ([Link], 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.

80 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, the sent Message is returned.


Return type [Link]
Raises [Link]

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
target‘channel (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 [Link]
setChatPhoto(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos can’t 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
target‘channel (in the format @channelusername).
• photo ([Link]) – 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.

Returns Returns True on success.


Return type bool
Raises [Link]

setChatStickerSet(*args, **kwargs)
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).

1.4. [Link] 81
Python Telegram Bot Documentation, Release 9.0.0

• sticker_set_name (str) – Name of the sticker set to be set as the group sticker
set.
• 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
setChatTitle(*args, **kwargs)
Use this method to change the title of a chat. Titles can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]

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 user’s 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.

82 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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 The edited message, or if the message wasn’t sent by the bot , True.
Return type [Link]
Raises
• [Link] – If the new score is not greater than the user’s
• 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 [Link]
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 you’d like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. [Link] Since nobody else knows your bot’s
token, you can be pretty sure it’s 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. ([Link]
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 bot’s server, and higher values to increase your
bot’s 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 [Link] for

1.4. [Link] 83
Python Telegram Bot Documentation, Release 9.0.0

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 doesn’t 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.

Returns bool On success, True is returned.


Raises [Link]

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
target‘channel (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 [Link]
set_chat_photo(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos can’t 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
target‘channel (in the format @channelusername).
• photo ([Link]) – 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

84 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.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.

Returns Returns True on success.


Return type bool
Raises [Link]

set_chat_sticker_set(*args, **kwargs)
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• sticker_set_name (str) – Name of the sticker set to be set as the group sticker
set.
• 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
set_chat_title(*args, **kwargs)
Use this method to change the title of a chat. Titles can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]

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 user’s current score in the chat and force is False.

1.4. [Link] 85
Python Telegram Bot Documentation, Release 9.0.0

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 wasn’t sent by the bot , True.
Return type [Link]
Raises
• [Link] – If the new score is not greater than the user’s
• 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 [Link]
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 you’d like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. [Link] Since nobody else knows your bot’s
token, you can be pretty sure it’s us.

Note: The certificate argument should be a file from disk open(filename, 'rb').

86 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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. ([Link]
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 bot’s server, and higher values to increase your
bot’s 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 [Link] 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 doesn’t 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.

Returns bool On success, True is returned.


Raises [Link]

stopMessageLiveLocation(*args, **kwargs)
Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots)
before live_period expires.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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).

1.4. [Link] 87
Python Telegram Bot Documentation, Release 9.0.0

Returns On success the edited message.


Return type [Link]
stop_message_live_location(*args, **kwargs)
Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots)
before live_period expires.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]
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 [Link]
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).

88 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns bool On success, True is returned.
Raises [Link]
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
target‘channel (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 [Link]
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
target‘channel (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 [Link]
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.

1.4. [Link] 89
Python Telegram Bot Documentation, Release 9.0.0

Returns The uploaded File


Return type [Link]
Raises [Link]

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 [Link]
Raises [Link]

username
str – Bot’s username.

1.5 [Link]

class [Link](id, from_user, chat_instance, message=None, data=None, in-


line_message_id=None, game_short_name=None, bot=None,
**kwargs)
Bases: [Link]
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
[Link] – Sender.

90 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

message
[Link] – 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 ([Link]) – Sender.
• message ([Link], 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 [Link].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)

Returns On success, True is returned.


Return type bool

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:

1.5. [Link] 91
Python Telegram Bot Documentation, Release 9.0.0

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 [Link]

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 [Link]

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 [Link]

1.6 [Link]

class [Link](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, sticker_set_name=None,
can_set_sticker_set=None, **kwargs)
Bases: [Link]
This object represents a chat.
id
int – Unique identifier for this chat.

92 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – 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
[Link] – Optional. Pinned message, for supergroups. Returned only in get_chat.
sticker_set_name
str – Optional. For supergroups, name of Group sticker set.
can_set_sticker_set
bool – Optional. True, if the bot can change group the sticker set.

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 ([Link], 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 ([Link], optional) – Pinned message, for super-
groups. Returned only in get_chat.
• bot ([Link], optional) – The Bot to use for instance methods.

1.6. [Link] 93
Python Telegram Bot Documentation, Release 9.0.0

• sticker_set_name (str, optional) – For supergroups, name of Group sticker set.


Returned only in get_chat.
• can_set_sticker_set (bool, optional) – True, if the bot can change group the
sticker set. Returned only in get_chat.
• **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:
bot.get_chat_administrators([Link], *args, **kwargs)

Returns A list of administrators in a chat. An Array of [Link] 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
Return type List[[Link]]

get_member(*args, **kwargs)
Shortcut for:
bot.get_chat_member([Link], *args, **kwargs)

Returns [Link]

get_members_count(*args, **kwargs)
Shortcut for:
bot.get_chat_members_count([Link], *args, **kwargs)

Returns int

kick_member(*args, **kwargs)
Shortcut for:
bot.kick_chat_member([Link], *args, **kwargs)

Returns If the action was sent succesfully.


Return type bool

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 group’s creator or by the member that added them.

leave(*args, **kwargs)
Shortcut for:

94 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

bot.leave_chat([Link], *args, **kwargs)

Returns bool If the action was sent successfully.

send_action(*args, **kwargs)
Shortcut for:

bot.send_chat_action([Link], *args, **kwargs)

Returns If the action was sent successfully.


Return type bool

unban_member(*args, **kwargs)
Shortcut for:

bot.unban_chat_member([Link], *args, **kwargs)

Returns If the action was sent successfully.


Return type bool

1.7 [Link]

class [Link]
Bases: object
Helper class to provide constants for different chatactions.
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. [Link] 95
Python Telegram Bot Documentation, Release 9.0.0

1.8 [Link]

class [Link](user, status, until_date=None, can_be_edited=None,


can_change_info=None, can_post_messages=None,
can_edit_messages=None, can_delete_messages=None,
can_invite_users=None, can_restrict_members=None,
can_pin_messages=None, can_promote_members=None,
can_send_messages=None, can_send_media_messages=None,
can_send_other_messages=None, can_add_web_page_previews=None,
**kwargs)
Bases: [Link]
This object contains information about one member of the chat.
user
[Link] – Information about the user.
status
str – The member’s status in the chat.
until_date
[Link] – 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 ([Link]) – Information about the user.

96 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• status (str) – The member’s status in the chat. Can be ‘creator’, ‘administrator’,
‘member’, ‘restricted’, ‘left’ or ‘kicked’.
• until_date ([Link], 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).
• 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. [Link] 97
Python Telegram Bot Documentation, Release 9.0.0

1.9 [Link]

class [Link](small_file_id, big_file_id, bot=None, **kwargs)


Bases: [Link]
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 ([Link], optional) – The Bot to use for instance methods
• **kwargs (dict) – Arbitrary keyword arguments.

1.10 [Link] Module

Constants in the Telegram network.


The following constants were extracted from the Telegram Bots FAQ.
[Link].MAX_MESSAGE_LENGTH
int – 4096
[Link].MAX_CAPTION_LENGTH
int – 200
[Link].SUPPORTED_WEBHOOK_PORTS
List[int] – [443, 80, 88, 8443]
[Link].MAX_FILESIZE_DOWNLOAD
int – In bytes (20MB)
[Link].MAX_FILESIZE_UPLOAD
int – In bytes (50MB)
[Link].MAX_MESSAGES_PER_SECOND_PER_CHAT
int – 1. Telegram may allow short bursts that go over this limit, but eventually you’ll begin receiving 429
errors.
[Link].MAX_MESSAGES_PER_SECOND
int – 30
[Link].MAX_MESSAGES_PER_MINUTE_PER_GROUP
int – 20
[Link].MAX_INLINE_QUERY_RESULTS
int – 50
The following constant have been found by experimentation:
[Link].MAX_MESSAGE_ENTITIES
int – 100 (Beyond this cap telegram will simply ignore further formatting styles)

98 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

1.11 [Link]

class [Link](phone_number, first_name, last_name=None, user_id=None, **kwargs)


Bases: [Link]
This object represents a phone contact.
phone_number
str – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.
user_id
int – Optional. Contact’s user identifier in Telegram.

Parameters
• phone_number (str) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• user_id (int, optional) – Contact’s user identifier in Telegram.
• **kwargs (dict) – Arbitrary keyword arguments.

1.12 [Link]

class [Link](file_id, thumb=None, file_name=None, mime_type=None, file_size=None,


**kwargs)
Bases: [Link]
This object represents a general file (as opposed to photos, voice messages and audio files).
file_id
str – Unique file identifier.
thumb
[Link] – 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 ([Link], 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.

1.11. [Link] 99
Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.

1.13 [Link] module

This module contains an object that represents Telegram errors.


exception [Link](message)
Bases: [Link]
exception [Link](new_chat_id)
Bases: [Link]
Parameters new_chat_id (int) –
exception [Link]
Bases: [Link]
exception [Link](message)
Bases: [Link]
exception [Link](retry_after)
Bases: [Link]
Parameters retry_after (int) –
exception [Link](message)
Bases: [Link]
exception [Link]
Bases: [Link]
exception [Link](message)
Bases: [Link]

1.14 [Link]

class [Link](file_id, bot=None, file_size=None, file_path=None, **kwargs)


Bases: [Link]
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.

Note: Maximum file size to download is 20 MB

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.

100 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• bot ([Link], optional) – Bot to use with shortcut method.


• **kwargs (dict) – Arbitrary keyword arguments.

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 [Link] method.

Note: custom_path and out are mutually exclusive.

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.15 [Link]

class [Link](force_reply=True, selective=False, **kwargs)


Bases: [Link]
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 bot’s 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 bot’s message is a reply (has reply_to_message_id), sender of the original mes-
sage.
• **kwargs (dict) – Arbitrary keyword arguments.

1.16 [Link]

class [Link](text, url=None, callback_data=None,


switch_inline_query=None,
switch_inline_query_current_chat=None, call-
back_game=None, pay=None, **kwargs)
Bases: [Link]
This object represents one button of an inline keyboard.

1.15. [Link] 101


Python Telegram Bot Documentation, Release 9.0.0

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 bot’s
username and the specified inline query in the input field.
switch_inline_query_current_chat
str – Optional. Will insert the bot’s username and the specified inline query in the current chat’s
input field.
callback_game
[Link] – 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 bot’s username and
the specified inline query in the input field. Can be empty, in which case just the bot’s
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 bot’s username and the specified inline query in the current chat’s
input field. Can be empty, in which case only the bot’s 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 ([Link], 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.

102 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

1.17 [Link]

class [Link](inline_keyboard, **kwargs)


Bases: [Link]
This object represents an inline keyboard that appears right next to the message it belongs to.
inline_keyboard
List[List[[Link]]] – Array of button rows, each represented by an
Array of InlineKeyboardButton objects.

Parameters
• inline_keyboard (List[List[[Link]]]) – Ar-
ray of button rows, each represented by an Array of InlineKeyboardButton objects.
• **kwargs (dict) – Arbitrary keyword arguments.

1.18 [Link]

class [Link](data)
Bases: object
This object represents a Telegram InputFile.
data
dict – Data containing an inputfile.

Parameters data (dict) – Data containing an inputfile.


Raises TelegramError

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.17. [Link] 103


Python Telegram Bot Documentation, Release 9.0.0

1.19 [Link]

class [Link]
Bases: [Link]
Base class for Telegram InputMedia Objects.
See [Link] and [Link] for detailed use.

1.20 [Link]

class [Link](media, caption=None)


Bases: [Link]
Represents a photo to be sent.
type
str – photo.
media
str – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing
[Link] object to send.
caption
str – Optional. Caption of the photo to be sent, 0-200 characters.

Parameters
• media (str) – File to send. Pass a file_id to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
Lastly you can pass an existing [Link] object to send.
• caption (str, optional) – Caption of the photo to be sent, 0-200 characters.

Note: At the moment using a new file is not yet supported.

1.21 [Link]

class [Link](media, caption=None, width=None, height=None, dura-


tion=None)
Bases: [Link]
Represents a video to be sent.
type
str – video.
media
str – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing
[Link] object to send.
caption
str – Optional. Caption of the video to be sent, 0-200 characters.
width
int – Optional. Video width.

104 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

height
int – Optional. Video height.
duration
int – Optional. Video duration.

Parameters
• media (str) – File to send. Pass a file_id to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
Lastly you can pass an existing [Link] object to send.
• caption (str, optional) – Caption of the video to be sent, 0-200 characters.
• width (int, optional) – Video width.
• height (int, optional) – Video height.
• duration (int, optional) – Video duration.

Note: When using a [Link] for the media attribute. It will take the width, height and
duration from that video, unless otherwise specified with the optional arguments. At the moment using a
new file is not yet supported.

1.22 [Link]

class [Link](text, request_contact=None, request_location=None, **kwargs)


Bases: [Link]
This object represents one button of the reply keyboard. For simple text buttons String can be used instead
of this object to specify text of the button.

Note: Optional fields are mutually exclusive.

text
str – Text of the button.
request_contact
bool – Optional. If the user’s phone number will be sent.
request_location
bool – Optional. If the user’s 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 user’s 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 user’s 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.22. [Link] 105


Python Telegram Bot Documentation, Release 9.0.0

1.23 [Link]

class [Link](longitude, latitude, **kwargs)


Bases: [Link]
This object represents a point on the map.
longitude
float – Longitude as defined by sender.
latitude
float – Latitude as defined by sender.

Parameters
• longitude (float) – Longitude as defined by sender.
• latitude (float) – Latitude as defined by sender.
• **kwargs (dict) – Arbitrary keyword arguments.

1.24 [Link]

class [Link](message_id, from_user, date, chat, forward_from=None, for-


ward_from_chat=None, forward_from_message_id=None, for-
ward_date=None, reply_to_message=None, edit_date=None, text=None,
entities=None, caption_entities=None, audio=None, document=None,
game=None, photo=None, sticker=None, video=None, voice=None,
video_note=None, new_chat_members=None, caption=None, con-
tact=None, location=None, venue=None, new_chat_member=None,
left_chat_member=None, new_chat_title=None, new_chat_photo=None,
delete_chat_photo=False, group_chat_created=False, su-
pergroup_chat_created=False, channel_chat_created=False,
migrate_to_chat_id=None, migrate_from_chat_id=None,
pinned_message=None, invoice=None, successful_payment=None, for-
ward_signature=None, author_signature=None, media_group_id=None,
bot=None, **kwargs)
Bases: [Link]
This object represents a message.

Note:
• In Python from is a reserved word, use from_user instead.

message_id
int – Unique message identifier inside this chat.
from_user
[Link] – Optional. Sender.
date
[Link] – Date the message was sent.
chat
[Link] – Conversation the message belongs to.
forward_from
[Link] – Optional. Sender of the original message.

106 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

forward_from_chat
[Link] – Optional. Information about the original channel.
forward_from_message_id
int – Optional. Identifier of the original message in the channel.
forward_date
[Link] – Optional. Date the original message was sent.
reply_to_message
[Link] – Optional. The original message.
edit_date
[Link] – Optional. Date the message was last edited.
media_group_id
str – Optional. The unique identifier of a media message group this message belongs to.
text
str – Optional. The actual UTF-8 text of the message.
entities
List[[Link]] – 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.
caption_entities
List[[Link]] – Optional. Special entities like usernames, URLs, bot
commands, etc. that appear in the caption. See Message.parse_caption_entity and
parse_caption_entities methods for how to use properly.
audio
[Link] – Optional. Information about the file.
document
[Link] – Optional. Information about the file.
game
[Link] – Optional. Information about the game.
photo
List[[Link]] – Optional. Available sizes of the photo.
sticker
[Link] – Optional. Information about the sticker.
video
[Link] – Optional. Information about the video.
voice
[Link] – Optional. Information about the file.
video_note
[Link] – Optional. Information about the video message.
new_chat_members
List[[Link]] – 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
[Link] – Optional. Information about the contact.
location
[Link] – Optional. Information about the location.

1.24. [Link] 107


Python Telegram Bot Documentation, Release 9.0.0

venue
[Link] – Optional. Information about the venue.
left_chat_member
[Link] – 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[[Link]] – 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
[Link] – Optional. Specified message was pinned.
invoice
[Link] – Optional. Information about the invoice.
successful_payment
[Link] – 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
[Link] – Optional. The Bot to use for instance methods.

Deprecated: 6.0 new_chat_member ([Link]): Replaced with new_chat_members

Parameters
• message_id (int) – Unique message identifier inside this chat.
• from_user ([Link], optional) – Sender, can be empty for messages sent
to channels.
• date ([Link]) – Date the message was sent in Unix time. Converted
to [Link].
• chat ([Link]) – Conversation the message belongs to.
• forward_from ([Link], optional) – For forwarded messages, sender of
the original message.
• forward_from_chat ([Link], optional) – For messages forwarded
from a channel, information about the original channel.

108 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• forward_from_message_id (int, optional) – For forwarded channel posts, iden-


tifier of the original message in the channel.
• forward_date ([Link], optional) – For forwarded messages, date
the original message was sent in Unix time. Converted to [Link].
• reply_to_message ([Link], 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 ([Link], optional) – Date the message was last edited
in Unix time. Converted to [Link].
• media_group_id (str, optional) – The unique identifier of a media message group
this message belongs to.
• text (str, optional) – For text messages, the actual UTF-8 text of
the message, 0-4096 characters. Also found as [Link].
MAX_MESSAGE_LENGTH.
• entities (List[[Link]], 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.
• caption_entities (List[[Link]]) – Optional. For Mes-
sages with a Caption. Special entities like usernames, URLs, bot commands,
etc. that appear in the caption. See Message.parse_caption_entity and
parse_caption_entities methods for how to use properly.
• audio ([Link], optional) – Message is an audio file, information about
the file.
• document ([Link], optional) – Message is a general file, informa-
tion about the file.
• game ([Link], optional) – Message is a game, information about the game.
• photo (List[[Link]], optional) – Message is a photo, available
sizes of the photo.
• sticker ([Link], optional) – Message is a sticker, information about
the sticker.
• video ([Link], optional) – Message is a video, information about the
video.
• voice ([Link], optional) – Message is a voice message, information
about the file.
• video_note ([Link], optional) – Message is a video note, infor-
mation about the video message.
• new_chat_members (List[[Link]], optional) – New members that were
added to the group or supergroup and information about them (the bot itself may be one
of these members).
• caption (str, optional) – Caption for the document, photo or video, 0-200 charac-
ters.
• contact ([Link], optional) – Message is a shared contact, informa-
tion about the contact.
• location ([Link], optional) – Message is a shared location, infor-
mation about the location.
• venue ([Link], optional) – Message is a venue, information about the
venue.

1.24. [Link] 109


Python Telegram Bot Documentation, Release 9.0.0

• left_chat_member ([Link], optional) – A member was removed from


the group, information about them (this member may be the bot itself).
• new_chat_title (str, optional) – A chat title was changed to this value.
• new_chat_photo (List[[Link]], optional) – A chat photo was
change to this value.
• delete_chat_photo (bool, optional) – Service message: The chat photo was
deleted.
• group_chat_created (bool, optional) – Service message: The group has been
created.
• supergroup_chat_created (bool, optional) – Service message: The super-
group has been created. This field can’t be received in a message coming through
updates, because bot can’t be a member of a supergroup when it is created. It can
only be found in reply_to_message if someone replies to a very first message in a
directly created supergroup.
• channel_chat_created (bool, optional) – Service message: The channel has
been created. This field can’t be received in a message coming through updates, be-
cause bot can’t be a member of a channel when it is created. It can only be found in
attr:reply_to_message if someone replies to a very first message in a channel.
• migrate_to_chat_id (int, optional) – The group has been migrated to a super-
group with the specified identifier. 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.
• migrate_from_chat_id (int, optional) – The supergroup has been migrated
from a group with the specified identifier. 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.
• pinned_message ([Link], optional) – Specified message was
pinned. Note that the Message object in this field will not contain further
attr:reply_to_message fields even if it is itself a reply.
• invoice ([Link], optional) – Message is an invoice for a payment,
information about the invoice.
• successful_payment ([Link], optional) – Mes-
sage is a service message about a successful payment, 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.

chat_id
int – Shortcut for [Link] for chat.
delete(*args, **kwargs)
Shortcut for:

bot.delete_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)

Returns On success, True is returned.

110 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type bool

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.

Returns On success, instance representing the edited message.


Return type [Link]

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.

Returns On success, instance representing the edited message.


Return type [Link]

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..

Returns On success, instance representing the edited message.


Return type [Link]

effective_attachment
[Link] or [Link] or [Link] or telegram.
Game or [Link] or [Link] or List[[Link]]
or [Link] or [Link] or [Link] or
[Link] or [Link] or [Link]: The attachment that this
message was sent with. May be None if no attachment was sent.
forward(chat_id, disable_notification=False)
Shortcut for:

1.24. [Link] 111


Python Telegram Bot Documentation, Release 9.0.0

bot.forward_message(chat_id=chat_id,
from_chat_id=[Link].chat_id,
disable_notification=disable_notification,
message_id=[Link].message_id)

Returns On success, instance representing the message forwarded.


Return type [Link]

new_chat_member
Deprecated
parse_caption_entities(types=None)
Returns a dict that maps [Link] to str. It contains entities from this
message’s caption filtered by their [Link] 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 caption_entities attribute,
since it calculates the correct substring from the message text based on UTF-16 codepoints. See
parse_entity for more info.

Parameters types (List[str], optional) – List of [Link] types


as strings. If the type attribute of an entity is contained in this list, it will be returned.
Defaults to a list of all types. All types can be found as constants in telegram.
MessageEntity.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]

parse_caption_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters
• entity ([Link]) – 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

parse_entities(types=None)
Returns a dict that maps [Link] to str. It contains entities from this
message filtered by their [Link] 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.

112 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Parameters types (List[str], optional) – List of [Link] types


as strings. If the type attribute of an entity is contained in this list, it will be returned.
Defaults to a list of all types. All types can be found as constants in telegram.
MessageEntity.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]

parse_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters
• entity ([Link]) – 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:

bot.send_audio([Link].chat_id, *args, **kwargs)

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 [Link]

reply_contact(*args, **kwargs)
Shortcut for:

bot.send_contact([Link].chat_id, *args, **kwargs)

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 [Link]

reply_document(*args, **kwargs)
Shortcut for:

bot.send_document([Link].chat_id, *args, **kwargs)

1.24. [Link] 113


Python Telegram Bot Documentation, Release 9.0.0

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 [Link]

reply_location(*args, **kwargs)
Shortcut for:

bot.send_location([Link].chat_id, *args, **kwargs)

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 [Link]

reply_photo(*args, **kwargs)
Shortcut for:

bot.send_photo([Link].chat_id, *args, **kwargs)

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 [Link]

reply_sticker(*args, **kwargs)
Shortcut for:

bot.send_sticker([Link].chat_id, *args, **kwargs)

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 [Link]

reply_text(*args, **kwargs)
Shortcut for:

bot.send_message([Link].chat_id, *args, **kwargs)

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:

bot.send_venue([Link].chat_id, *args, **kwargs)

114 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 [Link]

reply_video(*args, **kwargs)
Shortcut for:

bot.send_video([Link].chat_id, *args, **kwargs)

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 [Link]

reply_video_note(*args, **kwargs)
Shortcut for:

bot.send_video_note([Link].chat_id, *args, **kwargs)

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 [Link]

reply_voice(*args, **kwargs)
Shortcut for:

bot.send_voice([Link].chat_id, *args, **kwargs)

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 [Link]

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
[Link] as a hyperlink.
Returns Message text with entities formatted as HTML.

1.24. [Link] 115


Python Telegram Bot Documentation, Release 9.0.0

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 [Link] as a hyperlink.
Returns Message text with entities formatted as Markdown.
Return type str

1.25 [Link]

class [Link](type, offset, length, url=None, user=None, **kwargs)


Bases: [Link]
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
[Link] – 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 ([Link], optional) – For “text_mention” only, the mentioned user.

ALL_TYPES = [’mention’, ‘hashtag’, ‘bot_command’, ‘url’, ‘email’, ‘bold’, ‘italic’, ‘code’, ‘pre’, ‘text_link’, ‘text_men
List[str] – List of all the types.
BOLD = ‘bold’
str – ‘bold’

116 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

BOT_COMMAND = ‘bot_command’
str – ‘bot_command’
CODE = ‘code’
str – ‘code’
EMAIL = ‘email’
str – ‘email’
HASHTAG = ‘hashtag’
str – ‘hashtag’
ITALIC = ‘italic’
str – ‘italic’
MENTION = ‘mention’
str – ‘mention’
PRE = ‘pre’
str – ‘pre’
TEXT_LINK = ‘text_link’
str – ‘text_link’
TEXT_MENTION = ‘text_mention’
str – ‘text_mention’
URL = ‘url’
str – ‘url’

1.26 [Link]

class [Link]
Bases: object
This object represents a Telegram Message Parse Modes.
HTML = ‘HTML’
str – ‘HTML’
MARKDOWN = ‘Markdown’
str – ‘Markdown’

1.27 [Link]

class [Link](file_id, width, height, file_size=None, **kwargs)


Bases: [Link]
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

1.26. [Link] 117


Python Telegram Bot Documentation, Release 9.0.0

• 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.28 [Link]

class [Link](selective=False, **kwargs)


Bases: [Link]
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 [Link]).
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 haven’t 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 bot’s message is a reply (has reply_to_message_id), sender of the original mes-
sage.
• **kwargs (dict) – Arbitrary keyword arguments.

1.29 [Link]

class [Link](keyboard, resize_keyboard=False,


one_time_keyboard=False, selective=False, **kwargs)
Bases: [Link]
This object represents a custom keyboard with reply options.
keyboard
List[List[[Link] | 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 it’s been used.
selective
bool – Optional. Show the keyboard to specific users only.

118 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Example

A user requests to change the bot’s language, bot replies to the request with a keyboard to select the new
language. Other users in the group don’t see the keyboard.
Parameters
• keyboard (List[List[str | [Link]]]) – Array of button
rows, each represented by an Array of [Link] 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 app’s standard keyboard. Defaults to False
• one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as
soon as it’s 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 bot’s message is a reply (has reply_to_message_id), sender of the original mes-
sage.
Defaults to False.
• **kwargs (dict) – Arbitrary keyword arguments.

1.30 [Link]

class [Link]
Bases: [Link]
Base class for Telegram ReplyMarkup Objects.
See [Link] and [Link] for detailed
use.

1.31 [Link]

class [Link]
Bases: object
Base class for most telegram objects.
to_json()
Returns str

1.32 [Link]

class [Link](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: [Link]

1.30. [Link] 119


Python Telegram Bot Documentation, Release 9.0.0

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 update’s unique identifier.
message
[Link] – Optional. New incoming message.
edited_message
[Link] – Optional. New version of a message.
channel_post
[Link] – Optional. New incoming channel post.
edited_channel_post
[Link] – Optional. New version of a channel post.
inline_query
[Link] – Optional. New incoming inline query.
chosen_inline_result
[Link] – Optional. The result of an inline query that was chosen by
a user.
callback_query
[Link] – Optional. New incoming callback query.
shipping_query
[Link] – Optional. New incoming shipping query.
pre_checkout_query
[Link] – Optional. New incoming pre-checkout query.

Parameters
• update_id (int) – The update’s unique identifier. Update identifiers start from a
certain positive number and increase sequentially. This ID becomes especially handy if
you’re using Webhooks, since it allows you to ignore repeated updates or to restore the
correct update sequence, should they get out of order.
• message ([Link], optional) – New incoming message of any kind -
text, photo, sticker, etc.
• edited_message ([Link], optional) – New version of a message
that is known to the bot and was edited.
• channel_post ([Link], optional) – New incoming channel post of
any kind - text, photo, sticker, etc.
• edited_channel_post ([Link], optional) – New version of a
channel post that is known to the bot and was edited.
• inline_query ([Link], optional) – New incoming inline
query.
• chosen_inline_result ([Link], optional) –
The result of an inline query that was chosen by a user and sent to their chat partner.
• callback_query ([Link], optional) – New incoming
callback query.
• shipping_query ([Link], optional) – New incoming
shipping query. Only for invoices with flexible price.

120 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• pre_checkout_query ([Link], optional) – New in-


coming pre-checkout query. Contains full information about checkout
• **kwargs (dict) – Arbitrary keyword arguments.

classmethod de_json(data, bot)


effective_chat
[Link] – The chat that this update was sent in, no matter what kind of update this is.
Will be None for inline_query, chosen_inline_result, callback_query from inline
messages, shipping_query and pre_checkout_query.
effective_message
[Link] – The message included in this update, no matter what kind of update this is.
Will be None for inline_query, chosen_inline_result, callback_query from inline
messages, shipping_query and pre_checkout_query.
effective_user
[Link] – The user that sent this update, no matter what kind of update this is. Will be
None for channel_post.

1.33 [Link]

class [Link](id, first_name, is_bot, last_name=None, username=None, lan-


guage_code=None, bot=None, **kwargs)
Bases: [Link]
This object represents a Telegram user or bot.
id
int – Unique identifier for this user or bot.
is_bot
bool – True, if this user is a bot
first_name
str – User’s or bot’s first name.
last_name
str – Optional. User’s or bot’s last name.
username
str – Optional. User’s or bot’s username.
language_code
str – Optional. IETF language tag of the user’s language.
bot
[Link] – 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) – User’s or bot’s first name.
• last_name (str, optional) – User’s or bot’s last name.
• username (str, optional) – User’s or bot’s username.
• language_code (str, optional) – IETF language tag of the user’s language.
• bot ([Link], optional) – The Bot to use for instance methods.

1.33. [Link] 121


Python Telegram Bot Documentation, Release 9.0.0

classmethod de_json(data, bot)


classmethod de_list(data, bot)
get_profile_photos(*args, **kwargs)
Shortcut for:

bot.get_user_profile_photos([Link].from_user.id, *args, **kwargs)

mention_html(name=None)
Parameters name (str) – If provided, will overwrite the user’s 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 user’s 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.34 [Link]

class [Link](total_count, photos, **kwargs)


Bases: [Link]
This object represent a user’s profile pictures.
total_count
int – Total number of profile pictures.
photos
List[List[[Link]]] – Requested profile pictures.

Parameters
• total_count (int) – Total number of profile pictures the target user has.
• photos (List[List[[Link]]]) – Requested profile pictures (in up to
4 sizes each).

1.35 [Link]

class [Link](location, title, address, foursquare_id=None, **kwargs)


Bases: [Link]
This object represents a venue.
location
[Link] – Venue location.
title
str – Name of the venue.
address
str – Address of the venue.

122 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

foursquare_id
str – Optional. Foursquare identifier of the venue.

Parameters
• location ([Link]) – 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.36 [Link]

class [Link](file_id, width, height, duration, thumb=None, mime_type=None,


file_size=None, **kwargs)
Bases: [Link]
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
[Link] – 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 ([Link], 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.36. [Link] 123


Python Telegram Bot Documentation, Release 9.0.0

1.37 [Link]

class [Link](file_id, length, duration, thumb=None, file_size=None, **kwargs)


Bases: [Link]
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
[Link] – 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 ([Link], optional) – Video thumbnail.
• file_size (int, optional) – File size.
• **kwargs (dict) – Arbitrary keyword arguments.

1.38 [Link]

class [Link](file_id, duration, mime_type=None, file_size=None, **kwargs)


Bases: [Link]
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.

124 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

1.39 [Link]

class [Link](url, has_custom_certificate, pending_update_count,


last_error_date=None, last_error_message=None,
max_connections=None, allowed_updates=None, **kwargs)
Bases: [Link]
This object represents a Telegram WebhookInfo.
Contains information about the current status of a webhook.
url
str – Webhook URL.
has_custom_certificate
bool – If a custom certificate was provided for webhook.
pending_update_count
int – Number of updates awaiting delivery.
last_error_date
int – Optional. Unix time for the most recent error that happened.
last_error_message
str – Optional. Error message in human-readable format.
max_connections
int – Optional. Maximum allowed number of simultaneous HTTPS connections.
allowed_updates
List[str] – Optional. A list of update types the bot is subscribed to.

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.

1.40 Stickers

1.40.1 [Link]

class [Link](file_id, width, height, thumb=None, emoji=None, file_size=None,


set_name=None, mask_position=None, **kwargs)
Bases: [Link]
This object represents a sticker.
file_id
str – Unique identifier for this file.

1.39. [Link] 125


Python Telegram Bot Documentation, Release 9.0.0

width
int – Sticker width.
height
int – Sticker height.
thumb
[Link] – 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
[Link] – 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 ([Link], 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 ([Link], 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.40.2 [Link]

class [Link](name, title, contains_masks, stickers, bot=None, **kwargs)


Bases: [Link]
This object represents a sticker set.
name
str – Sticker set name.
title
str – Sticker set title.
contains_masks
bool – True, if the sticker set contains masks.
stickers
List[[Link]] – List of all set stickers.

Parameters
• name (str) – Sticker set name.
• title (str) – Sticker set title.

126 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• contains_masks (bool) – True, if the sticker set contains masks.


• stickers (List[[Link]]) – List of all set stickers.

1.40.3 [Link]

class [Link](point, x_shift, y_shift, scale, **kwargs)


Bases: [Link]
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’
str – ‘chin’
EYES = ‘eyes’
str – ‘eyes’
FOREHEAD = ‘forehead’
str – ‘forehead’
MOUTH = ‘mouth’
str – ‘mouth’

1.41 Inline Mode

1.41.1 [Link]

class [Link](id, from_user, query, offset, location=None, bot=None, **kwargs)


Bases: [Link]

1.41. Inline Mode 127


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Sender.
location
[Link] – 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 ([Link]) – Sender.
• location ([Link], 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 ([Link], optional) – The Bot to use for instance methods.
• **kwargs (dict) – Arbitrary keyword arguments.

answer(*args, **kwargs)
Shortcut for:

bot.answer_inline_query(update.inline_query.id, *args, **kwargs)

Parameters
• results (List[[Link]]) – 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 don’t support pagination. Offset length can’t 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.

128 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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.41.2 [Link]

class [Link](type, id, **kwargs)


Bases: [Link]
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.

1.41.3 [Link]

class [Link](id, title, input_message_content, re-


ply_markup=None, url=None, hide_url=None,
description=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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
[Link] – Content of the message to be sent.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
url
str – Optional. URL of the result.
hide_url
bool – Optional. Pass True, if you don’t 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.

1.41. Inline Mode 129


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link]) – Content
of the message to be sent.
• reply_markup ([Link], optional) – Inline keyboard attached
to the message
• url (str, optional) – URL of the result.
• hide_url (bool, optional) – Pass True, if you don’t 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.41.4 [Link]

class [Link](id, audio_url, title, performer=None, au-


dio_duration=None, caption=None, re-
ply_markup=None, input_message_content=None,
**kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
audio.

130 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the audio.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.5 [Link]

class [Link](id, audio_file_id, caption=None,


reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the audio.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41. Inline Mode 131


Python Telegram Bot Documentation, Release 9.0.0

1.41.6 [Link]

class [Link](id, title, document_file_id, de-


scription=None, caption=None,
reply_markup=None, in-
put_message_content=None,
**kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the file.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.7 [Link]

class [Link](id, gif_file_id, title=None, cap-


tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]

132 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file
will be sent by the user with an optional caption. Alternatively, you can use input_message_content
to send a message with specified content instead of the animation.
type
str – ‘gif’.
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, 0-200 characters
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
gif.

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 [Link] (str, optional):
• caption (str, optional) – Caption, 0-200 characters
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the gif.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.8 telegram.InlineQueryResultCachedMpeg4Gif

class telegram.InlineQueryResultCachedMpeg4Gif(id, mpeg4_file_id, title=None, cap-


tion=None, reply_markup=None,
input_message_content=None,
**kwargs)
Bases: [Link]
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.

1.41. Inline Mode 133


Python Telegram Bot Documentation, Release 9.0.0

title
str – Optional. Title for the result.
caption
str – Optional. Caption, 0-200 characters
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the MPEG-4 file.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.9 [Link]

class [Link](id, photo_file_id, title=None, de-


scription=None, caption=None,
reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
photo.

134 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the photo.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.10 [Link]

class [Link](id, sticker_file_id, reply_markup=None,


input_message_content=None,
**kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
sticker.

Parameters
• id (str) –
• sticker_file_id (str) –
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the sticker.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41. Inline Mode 135


Python Telegram Bot Documentation, Release 9.0.0

1.41.11 [Link]

class [Link](id, video_file_id, title, description=None,


caption=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
Represents a link to a video file stored on the Telegram servers. 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_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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
video.

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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the video.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.12 [Link]

class [Link](id, voice_file_id, title, cap-


tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
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.

136 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the voice.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.13 [Link]

class [Link](id, phone_number, first_name,


last_name=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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 – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.

1.41. Inline Mode 137


Python Telegram Bot Documentation, Release 9.0.0

reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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.41.14 [Link]

class [Link](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: [Link]
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

138 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link]) – Optional. Inline key-
board attached to the message.
• input_message_content ([Link]) – 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.

1.41.15 [Link]

class [Link](id, game_short_name, reply_markup=None,


**kwargs)
Bases: [Link]
Represents a Game.
type
str – ‘game’.
id
str – Unique identifier for this result, 1-64 bytes.

1.41. Inline Mode 139


Python Telegram Bot Documentation, Release 9.0.0

game_short_name
str – Short name of the game.
reply_markup
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.16 [Link]

class [Link](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: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
gif.

Parameters
• id (str) – Unique identifier for this result, 1-64 bytes.

140 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] (str, optional):
• caption (str, optional) – Caption, 0-200 characters
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the gif.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.17 [Link]

class [Link](id, latitude, longitude, title,


live_period=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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.
live_period
int – Optional. Period in seconds for which the location can be updated, should be between 60 and
86400.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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.

1.41. Inline Mode 141


Python Telegram Bot Documentation, Release 9.0.0

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.
• live_period (int, optional) – Period in seconds for which the location can be
updated, should be between 60 and 86400.
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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.41.18 telegram.InlineQueryResultMpeg4Gif

class telegram.InlineQueryResultMpeg4Gif(id, mpeg4_url, thumb_url, mpeg4_width=None,


mpeg4_height=None, title=None, cap-
tion=None, reply_markup=None,
input_message_content=None,
mpeg4_duration=None, **kwargs)
Bases: [Link]
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

142 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the MPEG-4 file.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.19 [Link]

class [Link](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: [Link]
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.

1.41. Inline Mode 143


Python Telegram Bot Documentation, Release 9.0.0

caption
str – Optional. Caption, 0-200 characters
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the photo.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.20 [Link]

class [Link](id, latitude, longitude, title, address,


foursquare_id=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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.

144 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

foursquare_id
str – Optional. Foursquare identifier of the venue if known.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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.41.21 [Link]

class [Link](id, video_url, mime_type, thumb_url, title, cap-


tion=None, video_width=None, video_height=None,
video_duration=None, description=None, re-
ply_markup=None, input_message_content=None,
**kwargs)
Bases: [Link]
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.

1.41. Inline Mode 145


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the video.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.22 [Link]

class [Link](id, voice_url, title, voice_duration=None,


caption=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]

146 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the voice.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.23 [Link]

class [Link]
Bases: [Link]
Base class for Telegram InputMessageContent Objects.
See: [Link], telegram.
InputLocationMessageContent, [Link] and
[Link] for more details.

1.41.24 [Link]

class [Link](message_text, parse_mode=None, dis-


able_web_page_preview=None, **kwargs)
Bases: [Link]

1.41. Inline Mode 147


Python Telegram Bot Documentation, Release 9.0.0

Represents the content of a text message to be sent as the result of an inline query.
message_text
str – Text of the message to be sent, 1-4096 characters.
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 bot’s message.
disable_web_page_preview
bool – Optional. Disables link previews for links in the sent message.

Parameters
• message_text (str) – Text of the message to be sent, 1-4096 characters. Also
found as [Link].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 bot’s message.
• disable_web_page_preview (bool, optional) – Disables link previews for links
in the sent message.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.25 [Link]

class [Link](latitude, longitude, live_period=None,


**kwargs)
Bases: [Link]
Represents the content of a location 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.

Parameters
• latitude (float) – Latitude of the location in degrees.
• longitude (float) – Longitude of the location in degrees.
• live_period (int, optional) – Period in seconds for which the location can be
updated, should be between 60 and 86400.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.26 [Link]

class [Link](latitude, longitude, title, address,


foursquare_id=None, **kwargs)
Bases: [Link]
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.

148 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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.
• 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.41.27 [Link]

class [Link](phone_number, first_name, last_name=None,


**kwargs)
Bases: [Link]
Represents the content of a contact message to be sent as the result of an inline query.
phone_number
str – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.

Parameters
• phone_number (str) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• **kwargs (dict) – Arbitrary keyword arguments.

1.41.28 [Link]

class [Link](result_id, from_user, query, location=None, in-


line_message_id=None, **kwargs)
Bases: [Link]
Represents a result of an inline query that was chosen by the user and sent to their chat partner.

Note: In Python from is a reserved word, use from_user instead.

result_id
str – The unique identifier for the result that was chosen.
from_user
[Link] – The user that chose the result.
location
[Link] – Optional. Sender location.

1.41. Inline Mode 149


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link]) – The user that chose the result.
• location ([Link], 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.42 Payments

1.42.1 [Link]

class [Link](label, amount, **kwargs)


Bases: [Link]
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 [Link], 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.42.2 [Link]

class [Link](title, description, start_parameter, currency, total_amount, **kwargs)


Bases: [Link]
This object contains basic information about an invoice.
title
str – Product name.
description
str – Product description.
start_parameter
str – Unique bot deep-linking parameter.

150 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

currency
str – Three-letter ISO 4217 currency code.
total_amount
int – Total price in the smallest units of the currency.

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.42.3 [Link]

class [Link](country_code, state, city, street_line1, street_line2, post_code,


**kwargs)
Bases: [Link]
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.

1.42. Payments 151


Python Telegram Bot Documentation, Release 9.0.0

1.42.4 [Link]

class [Link](name=None, phone_number=None, email=None, ship-


ping_address=None, **kwargs)
Bases: [Link]
This object represents information about an order.
name
str – Optional. User name.
phone_number
str – Optional. User’s phone number.
email
str – Optional. User email.
shipping_address
[Link] – Optional. User shipping address.

Parameters
• name (str, optional) – User name.
• phone_number (str, optional) – User’s phone number.
• email (str, optional) – User email.
• shipping_address ([Link], optional) – User ship-
ping address.
• **kwargs (dict) – Arbitrary keyword arguments.

1.42.5 [Link]

class [Link](id, title, prices, **kwargs)


Bases: [Link]
This object represents one shipping option.
id
str – Shipping option identifier.
title
str – Option title.
prices
List[[Link]] – List of price portions.

Parameters
• id (str) – Shipping option identifier.
• title (str) – Option title.
• prices (List[[Link]]) – List of price portions.
• **kwargs (dict) – Arbitrary keyword arguments.

1.42.6 [Link]

class [Link](currency, total_amount, invoice_payload, tele-


gram_payment_charge_id, provider_payment_charge_id,
shipping_option_id=None, order_info=None, **kwargs)
Bases: [Link]

152 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – 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 [Link], 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 ([Link], 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.42.7 [Link]

class [Link](id, from_user, invoice_payload, shipping_address, bot=None,


**kwargs)
Bases: [Link]
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
[Link] – User who sent the query.
invoice_payload
str – Bot specified invoice payload.

1.42. Payments 153


Python Telegram Bot Documentation, Release 9.0.0

shipping_address
[Link] – User specified shipping address.
bot
[Link] – Optional. The Bot to use for instance methods.

Parameters
• id (str) – Unique query identifier.
• from_user ([Link]) – User who sent the query.
• invoice_payload (str) – Bot specified invoice payload.
• shipping_address ([Link]) – User specified ship-
ping address.
• bot ([Link], optional) – The Bot to use for instance methods.
• **kwargs (dict) – Arbitrary keyword arguments.

answer(*args, **kwargs)
Shortcut for:

bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)

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[[Link]], 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.42.8 [Link]

class [Link](id, from_user, currency, total_amount, invoice_payload,


shipping_option_id=None, order_info=None, bot=None,
**kwargs)
Bases: [Link]
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
[Link] – 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.

154 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

invoice_payload
str – Bot specified invoice payload.
shipping_option_id
str – Optional. Identifier of the shipping option chosen by the user.
order_info
[Link] – Optional. Order info provided by the user.
bot
[Link] – Optional. The Bot to use for instance methods.

Parameters
• id (str) – Unique query identifier.
• from_user ([Link]) – 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 [Link], 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 ([Link], optional) – Order info provided by the user.
• bot ([Link], 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.43 Games

1.43.1 [Link]

class [Link](title, description, photo, text=None, text_entities=None, animation=None,


**kwargs)
Bases: [Link]

1.43. Games 155


Python Telegram Bot Documentation, Release 9.0.0

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[[Link]] – 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[[Link]] – Optional. Special entities that appear in text, such as user-
names, URLs, bot commands, etc.
animation
[Link] – 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[[Link]]) – 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 [Link].MAX_MESSAGE_LENGTH.
• text_entities (List[[Link]], optional) – Special entities
that appear in text, such as usernames, URLs, bot commands, etc.
• animation ([Link], optional) – Animation that will be displayed
in the game message in chats. Upload via BotFather.

parse_text_entities(types=None)
Returns a dict that maps [Link] 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.

Parameters types (List[str], optional) – List of MessageEntity types as strings. If


the type attribute of an entity is contained in this list, it will be returned. Defaults to
[Link].ALL_TYPES.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]

156 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

parse_text_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters entity ([Link]) – The entity to extract the text


from. It must be an entity that belongs to this message.
Returns The text of the given entity.
Return type str

1.43.2 [Link]

class [Link](file_id, thumb=None, file_name=None, mime_type=None,


file_size=None, **kwargs)
Bases: [Link]
This object represents an animation file to be displayed in the message containing a game.
file_id
str – Unique file identifier.
thumb
[Link] – 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 ([Link], 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.

1.43.3 [Link]

class [Link]
Bases: [Link]
A placeholder, currently holds no information. Use BotFather to set up your game.

1.43. Games 157


Python Telegram Bot Documentation, Release 9.0.0

1.43.4 [Link]

class [Link](position, user, score)


Bases: [Link]
This object represents one row of the high scores table for a game.
position
int – Position in high score table for the game.
user
[Link] – User.
score
int – Score.

Parameters
• position (int) – Position in high score table for the game.
• user ([Link]) – User.
• score (int) – Score.

1.44 Module contents

A library that provides a Python interface to the Telegram Bot API


class [Link](file_id, duration, performer=None, title=None, mime_type=None,
file_size=None, **kwargs)
Bases: [Link]
This object represents an audio file to be treated as music by the Telegram clients.
file_id
str – Unique identifier for this file.
duration
int – Duration of the audio in seconds.
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.

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.

158 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

classmethod de_json(data, bot)


class [Link](token, base_url=None, base_file_url=None, request=None)
Bases: [Link]
This object represents a Telegram Bot.
Parameters
• token (str) – Bot’s unique authentication.
• base_url (str, optional) – Telegram Bot API service URL.
• base_file_url (str, optional) – Telegram Bot API file URL.
• request ([Link], optional) – Pre initialized
[Link].
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 ([Link], 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 [Link]
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.

1.44. Module contents 159


Python Telegram Bot Documentation, Release 9.0.0

• 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 ([Link], 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 [Link]
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
[Link]/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 user’s 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 [Link]/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 [Link]
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[[Link]) – A list of results for the in-
line query.

160 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 don’t support pagination. Offset length can’t 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 bot’s inline capabilities.
Returns bool On success, True is returned.
Raises [Link]
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.

1.44. Module contents 161


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, True is returned.


Return type bool
Raises [Link]
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[[Link]]) – 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 [Link]
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
[Link]/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 user’s 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 [Link]/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.

162 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns bool On success, True is returned.


Raises [Link]
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[[Link]) – 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 don’t support pagination. Offset length can’t 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 bot’s inline capabilities.
Returns bool On success, True is returned.
Raises [Link]
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.

1.44. Module contents 163


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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[[Link]]) – 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 [Link]
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 [Link]/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a

164 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

letter, can’t 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 ([Link], 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 [Link]
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 [Link]/addstickers/ URLs (e.g.,
animals). Can contain only english letters, digits and underscores. Must begin with a
letter, can’t 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 ([Link], 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).

1.44. Module contents 165


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns On success, True is returned.
Return type bool
Raises [Link]
deleteChatPhoto(*args, **kwargs)
Use this method to delete a chat photo. Photos can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]
deleteChatStickerSet(*args, **kwargs)
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• 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
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.

166 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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 [Link]
deleteWebhook(*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 [Link]
delete_chat_photo(*args, **kwargs)
Use this method to delete a chat photo. Photos can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool

1.44. Module contents 167


Python Telegram Bot Documentation, Release 9.0.0

Raises [Link]
delete_chat_sticker_set(*args, **kwargs)
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• 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
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 [Link]
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 [Link]

168 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 [Link]
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
target‘channel (in the format @channelusername).
• 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.
• caption (str, optional) – New caption of the message.
• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
editMessageLiveLocation(*args, **kwargs)
Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A
location can be edited until its live_period expires or editing is explicitly disabled by a call to
stop_message_live_location.

Note: You can either supply a latitude and longitude or a location.

Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• latitude (float, optional) – Latitude of location.

1.44. Module contents 169


Python Telegram Bot Documentation, Release 9.0.0

• longitude (float, optional) – Longitude of location.


• location ([Link], optional) – The location to send.
• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]
editMessageReplyMarkup(*args, **kwargs)
Use this method to edit only the reply markup 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
target‘channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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, if edited message is sent by the bot, the editedMessage is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
editMessageText(*args, **kwargs)
Use this method to edit text and game 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 target
channel (in the format @channelusername).
• 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.
• text (str) – New text of the message.
• parse_mode (str) – Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bot’s message. See the
constants in [Link] for the available modes.

170 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_caption(*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
target‘channel (in the format @channelusername).
• 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.
• caption (str, optional) – New caption of the message.
• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_live_location(*args, **kwargs)
Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A
location can be edited until its live_period expires or editing is explicitly disabled by a call to
stop_message_live_location.

Note: You can either supply a latitude and longitude or a location.

Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.

1.44. Module contents 171


Python Telegram Bot Documentation, Release 9.0.0

• latitude (float, optional) – Latitude of location.


• longitude (float, optional) – Longitude of location.
• location ([Link], optional) – The location to send.
• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]
edit_message_reply_markup(*args, **kwargs)
Use this method to edit only the reply markup 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
target‘channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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, if edited message is sent by the bot, the editedMessage is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
edit_message_text(*args, **kwargs)
Use this method to edit text and game 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 target
channel (in the format @channelusername).
• 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.
• text (str) – New text of the message.
• parse_mode (str) – Send Markdown or HTML, if you want Telegram apps to
show bold, italic, fixed-width text or inline URLs in your bot’s message. See the
constants in [Link] for the available modes.

172 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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, if edited message is sent by the bot, the edited Message is returned,
otherwise True is returned.
Return type [Link]
Raises [Link]
exportChatInviteLink(*args, **kwargs)
Use this method to export an invite link to 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.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the
target‘channel (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 Exported invite link on success.
Return type str
Raises [Link]
export_chat_invite_link(*args, **kwargs)
Use this method to export an invite link to 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.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the
target‘channel (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 Exported invite link on success.
Return type str
Raises [Link]
first_name
str – Bot’s first name.
forwardMessage(*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).

1.44. Module contents 173


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
Raises [Link]
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 [Link]
Raises [Link]
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
target‘channel (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 [Link]
Raises [Link]
getChatAdministrators(*args, **kwargs)
Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember

174 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
target‘channel (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[[Link]]
Raises [Link]
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
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 [Link]
Raises [Link]
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
target‘channel (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 [Link]
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 [Link].
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).

1.44. Module contents 175


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns [Link]
Raises [Link]
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[[Link]]
Raises [Link]
getMe(*args, **kwargs)
A simple method for testing your bot’s 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 [Link] instance representing that bot if the credentials are valid,
None otherwise.
Return type [Link]
Raises [Link]
getStickerSet(*args, **kwargs)
Use this method to get a sticker set.
Parameters
• name (str) – Short name of the sticker set that is used in [Link]/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 [Link]
Raises [Link]
getUpdates(*args, **kwargs)
Use this method to receive incoming updates using long polling.
Parameters

176 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link] 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 doesn’t 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

1. This method will not work if an outgoing webhook is set up.


2. In order to avoid getting duplicate updates, recalculate offset after each server response.
3. To take full advantage of this library take a look at [Link]

Returns List[[Link]]
Raises [Link]
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 [Link]
Raises [Link]
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

1.44. Module contents 177


Python Telegram Bot Documentation, Release 9.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 [Link]
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
target‘channel (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 [Link]
Raises [Link]
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
target‘channel (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[[Link]]
Raises [Link]
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
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 [Link]
Raises [Link]
get_chat_members_count(*args, **kwargs)
Use this method to get the number of members in a chat
Parameters

178 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the
target‘channel (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 [Link]
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 [Link].
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 [Link]
Raises [Link]
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[[Link]]
Raises [Link]
get_me(*args, **kwargs)
A simple method for testing your bot’s 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 [Link] instance representing that bot if the credentials are valid,
None otherwise.

1.44. Module contents 179


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]
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 [Link]/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 [Link]
Raises [Link]
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 [Link] 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 doesn’t 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

1. This method will not work if an outgoing webhook is set up.


2. In order to avoid getting duplicate updates, recalculate offset after each server response.
3. To take full advantage of this library take a look at [Link]

Returns List[[Link]]
Raises [Link]
get_user_profile_photos(*args, **kwargs)
Use this method to get a list of profile pictures for a user.
Parameters

180 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
Raises [Link]
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 [Link]
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 | [Link], 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 group’s
creator or by the member that added them.

Returns bool On success, True is returned.


Raises [Link]

1.44. Module contents 181


Python Telegram Bot Documentation, Release 9.0.0

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 | [Link], 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 group’s
creator or by the member that added them.

Returns bool On success, True is returned.


Raises [Link]
last_name
str – Optional. Bot’s 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
target‘channel (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 [Link]
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
target‘channel (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 [Link]

182 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

name
str – Bot’s @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
target‘channel (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 [Link]
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
target‘channel (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 [Link]
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.44. Module contents 183


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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.

184 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 [Link]
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 | [Link], 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.
• can_send_media_messages (bool, optional) – Pass 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) – Pass 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) – Pass True, if the user may
add web page previews to their messages, implies can_send_media_messages.
• 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 [Link]
restrict_chat_member(*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).

1.44. Module contents 185


Python Telegram Bot Documentation, Release 9.0.0

• user_id (int) – Unique identifier of the target user.


• until_date (int | [Link], 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.
• can_send_media_messages (bool, optional) – Pass 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) – Pass 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) – Pass True, if the user may
add web page previews to their messages, implies can_send_media_messages.
• 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 [Link]
sendAudio(*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 | [Link]) – 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.

186 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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 [Link]
Raises [Link]
sendChatAction(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bot’s 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 ([Link] | str) – Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in [Link]
• 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 [Link]
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) – Contact’s phone number.
• first_name (str, optional) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• contact ([Link], 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 ([Link], 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.44. Module contents 187


Python Telegram Bot Documentation, Release 9.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 [Link]
Raises [Link]
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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
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.

188 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_to_message_id (int, optional) – If the message is a reply, ID of the


original message.
• reply_markup ([Link], 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 [Link]
Raises [Link]
sendInvoice(*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[[Link]) – Price breakdown, a list of compo-
nents (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
• provider_data (str | object, optional) – JSON-encoded data about the in-
voice, which will be shared with the payment provider. A detailed description of re-
quired fields should be provided by the payment provider. When an object is passed,
it will be encoded as JSON.
• 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 user’s full name to
complete the order.
• need_phone_number (bool, optional) – Pass True, if you require the user’s
phone number to complete the order.
• need_email (bool, optional) – Pass True, if you require the user’s email to com-
plete the order.
• need_shipping_address (bool, optional) – Pass True, if you require the user’s
shipping address to complete the order.

1.44. Module contents 189


Python Telegram Bot Documentation, Release 9.0.0

• 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 ([Link], 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.
• 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 [Link]
Raises [Link]
sendLocation(*args, **kwargs)
Use this method to send point on the map.

Note: You can either supply a latitude and longitude or a location.

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 ([Link], optional) – The location to send.
• live_period (int, optional) – Period in seconds for which the location will be
updated, should be between 60 and 86400.
• 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 ([Link], 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 [Link]
Raises [Link]
sendMediaGroup(*args, **kwargs)
Use this method to send a group of photos or videos as an album.

190 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• media (List[[Link]]) – An array describing photos and videos
to be sent, must include 2–10 items.
• 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.
• timeout (int | float, optional) – Send file timeout (default: 20 seconds).
• **kwargs (dict) – Arbitrary keyword arguments.
Returns An array of the sent Messages.
Return type List[[Link]]
Raises [Link]
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
[Link].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 bot’s message. See the
constants in [Link] for the available modes.
• disable_web_page_preview (bool, optional) – Disables link previews for
links in this message.
• 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 ([Link], 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 [Link]
Raises [Link]
sendPhoto(*args, **kwargs)
Use this method to send photos.

Note: The photo argument can be either a file_id, an URL or a file from disk open(filename,
'rb')

1.44. Module contents 191


Python Telegram Bot Documentation, Release 9.0.0

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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
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 [Link]) – 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 ([Link], 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.

192 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]
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 ([Link], 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 ([Link], 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 [Link]
Raises [Link]
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 | [Link]) – 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

1.44. Module contents 193


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link], 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 [Link]
Raises [Link]
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 | [Link]) – 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 [Link] 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 ([Link], 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.

194 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]
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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
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).

1.44. Module contents 195


Python Telegram Bot Documentation, Release 9.0.0

• audio (str | filelike object | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
send_chat_action(*args, **kwargs)
Use this method when you need to tell the user that something is happening on the bot’s 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 ([Link] | str) – Type of action to broadcast. Choose
one, depending on what the user is about to receive. For convenience look at the
constants in [Link]
• 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 [Link]
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

196 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• phone_number (str, optional) – Contact’s phone number.
• first_name (str, optional) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• contact ([Link], 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 ([Link], 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 [Link]
Raises [Link]
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 | [Link]) – 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 ([Link], 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).

1.44. Module contents 197


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns On success, the sent Message is returned.
Return type [Link]
Raises [Link]
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 ([Link], 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 [Link]
Raises [Link]
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[[Link]) – Price breakdown, a list of compo-
nents (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
• provider_data (str | object, optional) – JSON-encoded data about the in-
voice, which will be shared with the payment provider. A detailed description of re-
quired fields should be provided by the payment provider. When an object is passed,
it will be encoded as JSON.

198 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• 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 user’s full name to
complete the order.
• need_phone_number (bool, optional) – Pass True, if you require the user’s
phone number to complete the order.
• need_email (bool, optional) – Pass True, if you require the user’s email to com-
plete the order.
• need_shipping_address (bool, optional) – Pass True, if you require the user’s
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 ([Link], 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.
• 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 [Link]
Raises [Link]
send_location(*args, **kwargs)
Use this method to send point on the map.

Note: You can either supply a latitude and longitude or a location.

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 ([Link], optional) – The location to send.
• live_period (int, optional) – Period in seconds for which the location will be
updated, should be between 60 and 86400.
• disable_notification (bool, optional) – Sends the message silently. Users
will receive a notification with no sound.

1.44. Module contents 199


Python Telegram Bot Documentation, Release 9.0.0

• reply_to_message_id (int, optional) – If the message is a reply, ID of the


original message.
• reply_markup ([Link], 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 [Link]
Raises [Link]
send_media_group(*args, **kwargs)
Use this method to send a group of photos or videos as an album.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• media (List[[Link]]) – An array describing photos and videos
to be sent, must include 2–10 items.
• 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.
• timeout (int | float, optional) – Send file timeout (default: 20 seconds).
• **kwargs (dict) – Arbitrary keyword arguments.
Returns An array of the sent Messages.
Return type List[[Link]]
Raises [Link]
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
[Link].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 bot’s message. See the
constants in [Link] for the available modes.
• disable_web_page_preview (bool, optional) – Disables link previews for
links in this message.
• 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.

200 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• reply_markup ([Link], 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 [Link]
Raises [Link]
send_photo(*args, **kwargs)
Use this method to send photos.

Note: The photo 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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
send_sticker(*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

1.44. Module contents 201


Python Telegram Bot Documentation, Release 9.0.0

• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• sticker (str | filelike object [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
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 ([Link], 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 ([Link], 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.

202 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, the sent Message is returned.


Return type [Link]
Raises [Link]
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 | [Link]) – 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 ([Link], 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 [Link]
Raises [Link]
send_video_note(*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).

1.44. Module contents 203


Python Telegram Bot Documentation, Release 9.0.0

• video_note (str | filelike object | [Link]) – 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 [Link] 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 ([Link], 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 [Link]
Raises [Link]
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 | [Link]) – 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 ([Link], 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.

204 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, the sent Message is returned.


Return type [Link]
Raises [Link]
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
target‘channel (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 [Link]
setChatPhoto(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos can’t 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
target‘channel (in the format @channelusername).
• photo ([Link]) – 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.

Returns Returns True on success.


Return type bool
Raises [Link]
setChatStickerSet(*args, **kwargs)
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).

1.44. Module contents 205


Python Telegram Bot Documentation, Release 9.0.0

• sticker_set_name (str) – Name of the sticker set to be set as the group sticker
set.
• 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
setChatTitle(*args, **kwargs)
Use this method to change the title of a chat. Titles can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]
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 user’s 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).

206 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


Returns The edited message, or if the message wasn’t sent by the bot , True.
Return type [Link]
Raises
• [Link] – If the new score is not greater than the user’s
• 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 [Link]
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 you’d like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. [Link] Since nobody else knows your bot’s
token, you can be pretty sure it’s 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. ([Link]
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 bot’s server, and higher values to increase your
bot’s 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 [Link] 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 doesn’t affect updates created before the call to the
set_webhook, so unwanted updates may be received for a short period of time.

1.44. Module contents 207


Python Telegram Bot Documentation, Release 9.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.

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.

Returns bool On success, True is returned.


Raises [Link]
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
target‘channel (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 [Link]
set_chat_photo(*args, **kwargs)
Use this method to set a new profile photo for the chat.
Photos can’t 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
target‘channel (in the format @channelusername).
• photo ([Link]) – 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.

208 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns Returns True on success.


Return type bool
Raises [Link]
set_chat_sticker_set(*args, **kwargs)
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights. Use the field telegram.
Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can
use this method.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
supergroup (in the format @supergroupusername).
• sticker_set_name (str) – Name of the sticker set to be set as the group sticker
set.
• 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
set_chat_title(*args, **kwargs)
Use this method to change the title of a chat. Titles can’t 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
target‘channel (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.

Returns Returns True on success.


Return type bool
Raises [Link]
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 user’s current score in the chat and force is False.
Parameters
• user_id (int) – User identifier.
• score (int) – New score, must be non-negative.

1.44. Module contents 209


Python Telegram Bot Documentation, Release 9.0.0

• 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 wasn’t sent by the bot , True.
Return type [Link]
Raises
• [Link] – If the new score is not greater than the user’s
• 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 [Link]
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 you’d like to make sure that the Webhook request comes from Telegram, we recommend using a
secret path in the URL, e.g. [Link] Since nobody else knows your bot’s
token, you can be pretty sure it’s 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.

210 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• certificate (filelike) – Upload your public key certificate so that the root
certificate in use can be checked. See our self-signed guide for details. ([Link]
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 bot’s server, and higher values to increase your
bot’s 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 [Link] 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 doesn’t 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.

Returns bool On success, True is returned.


Raises [Link]
stopMessageLiveLocation(*args, **kwargs)
Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots)
before live_period expires.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]

1.44. Module contents 211


Python Telegram Bot Documentation, Release 9.0.0

stop_message_live_location(*args, **kwargs)
Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots)
before live_period expires.
Parameters
• chat_id (int | str) – Unique identifier for the target chat or username of the target
channel (in the format @channelusername).
• 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.
• reply_markup ([Link], 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).
Returns On success the edited message.
Return type [Link]
to_dict()
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 [Link]
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.

212 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns bool On success, True is returned.


Raises [Link]
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
target‘channel (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 [Link]
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
target‘channel (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 [Link]
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

1.44. Module contents 213


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


Raises [Link]
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 [Link]
Raises [Link]
username
str – Bot’s username.
class [Link](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, sticker_set_name=None,
can_set_sticker_set=None, **kwargs)
Bases: [Link]
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
[Link] – Optional. Chat photo.

214 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

description
str – Optional. Description, for supergroups and channel chats.
invite_link
str – Optional. Chat invite link, for supergroups and channel chats.
pinned_message
[Link] – Optional. Pinned message, for supergroups. Returned only in get_chat.
sticker_set_name
str – Optional. For supergroups, name of Group sticker set.
can_set_sticker_set
bool – Optional. True, if the bot can change group the sticker set.

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 ([Link], 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 ([Link], optional) – Pinned message, for super-
groups. Returned only in get_chat.
• bot ([Link], optional) – The Bot to use for instance methods.
• sticker_set_name (str, optional) – For supergroups, name of Group sticker set.
Returned only in get_chat.
• can_set_sticker_set (bool, optional) – True, if the bot can change group the
sticker set. Returned only in get_chat.
• **kwargs (dict) – Arbitrary keyword arguments.
CHANNEL = ‘channel’
GROUP = ‘group’
PRIVATE = ‘private’
SUPERGROUP = ‘supergroup’
classmethod de_json(data, bot)
get_administrators(*args, **kwargs)
Shortcut for:

1.44. Module contents 215


Python Telegram Bot Documentation, Release 9.0.0

bot.get_chat_administrators([Link], *args, **kwargs)

Returns A list of administrators in a chat. An Array of [Link] 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
Return type List[[Link]]
get_member(*args, **kwargs)
Shortcut for:

bot.get_chat_member([Link], *args, **kwargs)

Returns [Link]
get_members_count(*args, **kwargs)
Shortcut for:

bot.get_chat_members_count([Link], *args, **kwargs)

Returns int
kick_member(*args, **kwargs)
Shortcut for:

bot.kick_chat_member([Link], *args, **kwargs)

Returns If the action was sent succesfully.


Return type bool

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 group’s creator or by the member that added them.

leave(*args, **kwargs)
Shortcut for:

bot.leave_chat([Link], *args, **kwargs)

Returns bool If the action was sent successfully.


send_action(*args, **kwargs)
Shortcut for:

bot.send_chat_action([Link], *args, **kwargs)

Returns If the action was sent successfully.


Return type bool
unban_member(*args, **kwargs)
Shortcut for:

bot.unban_chat_member([Link], *args, **kwargs)

Returns If the action was sent successfully.


Return type bool

216 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

class [Link](user, status, until_date=None, can_be_edited=None,


can_change_info=None, can_post_messages=None,
can_edit_messages=None, can_delete_messages=None,
can_invite_users=None, can_restrict_members=None,
can_pin_messages=None, can_promote_members=None,
can_send_messages=None, can_send_media_messages=None,
can_send_other_messages=None, can_add_web_page_previews=None,
**kwargs)
Bases: [Link]
This object contains information about one member of the chat.
user
[Link] – Information about the user.
status
str – The member’s status in the chat.
until_date
[Link] – 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 ([Link]) – Information about the user.
• status (str) – The member’s status in the chat. Can be ‘creator’, ‘administrator’,
‘member’, ‘restricted’, ‘left’ or ‘kicked’.

1.44. Module contents 217


Python Telegram Bot Documentation, Release 9.0.0

• until_date ([Link], 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).
• 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’
CREATOR = ‘creator’
KICKED = ‘kicked’
LEFT = ‘left’
MEMBER = ‘member’
RESTRICTED = ‘restricted’
classmethod de_json(data, bot)
to_dict()
class [Link]
Bases: object
Helper class to provide constants for different chatactions.
FIND_LOCATION = ‘find_location’
RECORD_AUDIO = ‘record_audio’

218 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

RECORD_VIDEO = ‘record_video’
RECORD_VIDEO_NOTE = ‘record_video_note’
TYPING = ‘typing’
UPLOAD_AUDIO = ‘upload_audio’
UPLOAD_DOCUMENT = ‘upload_document’
UPLOAD_PHOTO = ‘upload_photo’
UPLOAD_VIDEO = ‘upload_video’
UPLOAD_VIDEO_NOTE = ‘upload_video_note’
class [Link](result_id, from_user, query, location=None, in-
line_message_id=None, **kwargs)
Bases: [Link]
Represents a result of an inline query that was chosen by the user and sent to their chat partner.

Note: In Python from is a reserved word, use from_user instead.

result_id
str – The unique identifier for the result that was chosen.
from_user
[Link] – The user that chose the result.
location
[Link] – 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 ([Link]) – The user that chose the result.
• location ([Link], 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 [Link](id, from_user, chat_instance, message=None, data=None, in-
line_message_id=None, game_short_name=None, bot=None,
**kwargs)
Bases: [Link]
This object represents an incoming callback query from a callback button in an inline keyboard.

1.44. Module contents 219


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Sender.
message
[Link] – 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 ([Link]) – Sender.
• message ([Link], 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 [Link].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:

220 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

bot.answer_callback_query(update.callback_query.id, *args, **kwargs)

Returns On success, True is returned.


Return type bool
classmethod de_json(data, bot)
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 [Link]
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 [Link]
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 [Link]

1.44. Module contents 221


Python Telegram Bot Documentation, Release 9.0.0

to_dict()
class [Link](phone_number, first_name, last_name=None, user_id=None, **kwargs)
Bases: [Link]
This object represents a phone contact.
phone_number
str – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.
user_id
int – Optional. Contact’s user identifier in Telegram.

Parameters
• phone_number (str) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• user_id (int, optional) – Contact’s user identifier in Telegram.
• **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class [Link](file_id, thumb=None, file_name=None, mime_type=None, file_size=None,
**kwargs)
Bases: [Link]
This object represents a general file (as opposed to photos, voice messages and audio files).
file_id
str – Unique file identifier.
thumb
[Link] – 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 ([Link], 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)

222 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

class [Link](file_id, bot=None, file_size=None, file_path=None, **kwargs)


Bases: [Link]
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.

Note: Maximum file size to download is 20 MB

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 ([Link], 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 [Link] method.

Note: custom_path and out are mutually exclusive.

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 [Link](force_reply=True, selective=False, **kwargs)
Bases: [Link]
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 bot’s 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.

1.44. Module contents 223


Python Telegram Bot Documentation, Release 9.0.0

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 bot’s message is a reply (has reply_to_message_id), sender of the original mes-
sage.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](text, url=None, callback_data=None,
switch_inline_query=None,
switch_inline_query_current_chat=None, call-
back_game=None, pay=None, **kwargs)
Bases: [Link]
This object represents one button of an inline keyboard.

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 bot’s
username and the specified inline query in the input field.
switch_inline_query_current_chat
str – Optional. Will insert the bot’s username and the specified inline query in the current chat’s
input field.
callback_game
[Link] – 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 bot’s username and
the specified inline query in the input field. Can be empty, in which case just the bot’s
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 bot’s username and the specified inline query in the current chat’s

224 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

input field. Can be empty, in which case only the bot’s 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 ([Link], 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 [Link](inline_keyboard, **kwargs)
Bases: [Link]
This object represents an inline keyboard that appears right next to the message it belongs to.
inline_keyboard
List[List[[Link]]] – Array of button rows, each represented by an
Array of InlineKeyboardButton objects.

Parameters
• inline_keyboard (List[List[[Link]]]) – Ar-
ray of button rows, each represented by an Array of InlineKeyboardButton objects.
• **kwargs (dict) – Arbitrary keyword arguments.
to_dict()
class [Link](id, from_user, query, offset, location=None, bot=None, **kwargs)
Bases: [Link]
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
[Link] – Sender.
location
[Link] – 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 ([Link]) – Sender.
• location ([Link], 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.

1.44. Module contents 225


Python Telegram Bot Documentation, Release 9.0.0

• bot ([Link], optional) – The Bot to use for instance methods.


• **kwargs (dict) – Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:

bot.answer_inline_query(update.inline_query.id, *args, **kwargs)

Parameters
• results (List[[Link]]) – 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 don’t support pagination. Offset length can’t 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 [Link](type, id, **kwargs)
Bases: [Link]
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 [Link](type, id, **kwargs)
Bases: [Link]
Baseclass for the InlineQueryResult* classes.
type
str – Type of the result.
id
str – Unique identifier for this result, 1-64 Bytes.

Parameters

226 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• type (str) – Type of the result.


• id (str) – Unique identifier for this result, 1-64 Bytes.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, title, input_message_content, re-
ply_markup=None, url=None, hide_url=None,
description=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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
[Link] – Content of the message to be sent.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
url
str – Optional. URL of the result.
hide_url
bool – Optional. Pass True, if you don’t 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 ([Link]) – Content
of the message to be sent.
• reply_markup ([Link], optional) – Inline keyboard attached
to the message
• url (str, optional) – URL of the result.
• hide_url (bool, optional) – Pass True, if you don’t 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.

1.44. Module contents 227


Python Telegram Bot Documentation, Release 9.0.0

• thumb_height (int, optional) – Thumbnail height.


• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, audio_url, title, performer=None, au-
dio_duration=None, caption=None, re-
ply_markup=None, input_message_content=None,
**kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the audio.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, audio_file_id, caption=None,
reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]

228 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the audio.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, title, document_file_id, de-
scription=None, caption=None,
reply_markup=None, in-
put_message_content=None,
**kwargs)
Bases: [Link]
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

1.44. Module contents 229


Python Telegram Bot Documentation, Release 9.0.0

reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the file.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, gif_file_id, title=None, cap-
tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file
will be sent by the user with an optional caption. Alternatively, you can use input_message_content
to send a message with specified content instead of the animation.
type
str – ‘gif’.
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, 0-200 characters
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
gif.

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 [Link] (str, optional):
• caption (str, optional) – Caption, 0-200 characters
• reply_markup ([Link], optional) – Inline key-
board attached to the message.

230 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• input_message_content ([Link], 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: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the MPEG-4 file.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, photo_file_id, title=None, de-
scription=None, caption=None,
reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
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’.

1.44. Module contents 231


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the photo.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, sticker_file_id, reply_markup=None,
input_message_content=None,
**kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
sticker.

Parameters

232 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• id (str) –
• sticker_file_id (str) –
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the sticker.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, video_file_id, title, description=None,
caption=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
Represents a link to a video file stored on the Telegram servers. 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_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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – Optional. Content of the message to be sent instead of the
video.

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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the video.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, voice_file_id, title, cap-
tion=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]

1.44. Module contents 233


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the voice.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, phone_number, first_name,
last_name=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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 – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.

234 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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 [Link](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: [Link]
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”.

1.44. Module contents 235


Python Telegram Bot Documentation, Release 9.0.0

description
str – Optional. Short description of the result.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link]) – Optional. Inline key-
board attached to the message.
• input_message_content ([Link]) – 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 [Link](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: [Link]
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.

236 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 [Link] (str, optional):
• caption (str, optional) – Caption, 0-200 characters
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the gif.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, latitude, longitude, title,
live_period=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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.

1.44. Module contents 237


Python Telegram Bot Documentation, Release 9.0.0

title
str – Location title.
live_period
int – Optional. Period in seconds for which the location can be updated, should be between 60 and
86400.
reply_markup
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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.
• live_period (int, optional) – Period in seconds for which the location can be
updated, should be between 60 and 86400.
• reply_markup ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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, cap-
tion=None, reply_markup=None,
input_message_content=None,
mpeg4_duration=None, **kwargs)
Bases: [Link]
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.

238 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the MPEG-4 file.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](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: [Link]
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.

1.44. Module contents 239


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the photo.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, latitude, longitude, title, address,
foursquare_id=None, reply_markup=None, in-
put_message_content=None, thumb_url=None,
thumb_width=None, thumb_height=None,
**kwargs)
Bases: [Link]
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.

240 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], 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 [Link](id, video_url, mime_type, thumb_url, title, cap-
tion=None, video_width=None, video_height=None,
video_duration=None, description=None, re-
ply_markup=None, input_message_content=None,
**kwargs)
Bases: [Link]
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’.

1.44. Module contents 241


Python Telegram Bot Documentation, Release 9.0.0

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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the video.
• **kwargs (dict) – Arbitrary keyword arguments.

242 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

class [Link](id, voice_url, title, voice_duration=None,


caption=None, reply_markup=None, in-
put_message_content=None, **kwargs)
Bases: [Link]
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
[Link] – Optional. Inline keyboard attached to the message.
input_message_content
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• input_message_content ([Link], optional) –
Content of the message to be sent instead of the voice.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](id, game_short_name, reply_markup=None,
**kwargs)
Bases: [Link]
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.

1.44. Module contents 243


Python Telegram Bot Documentation, Release 9.0.0

reply_markup
[Link] – 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 ([Link], optional) – Inline key-
board attached to the message.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](phone_number, first_name, last_name=None,
**kwargs)
Bases: [Link]
Represents the content of a contact message to be sent as the result of an inline query.
phone_number
str – Contact’s phone number.
first_name
str – Contact’s first name.
last_name
str – Optional. Contact’s last name.

Parameters
• phone_number (str) – Contact’s phone number.
• first_name (str) – Contact’s first name.
• last_name (str, optional) – Contact’s last name.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link](data)
Bases: object
This object represents a Telegram InputFile.
data
dict – Data containing an inputfile.

Parameters data (dict) – Data containing an inputfile.


Raises TelegramError
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.

244 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Returns bool
to_form()
Transform the inputfile to multipart/form data.
Returns str
class [Link](latitude, longitude, live_period=None,
**kwargs)
Bases: [Link]
Represents the content of a location 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.

Parameters
• latitude (float) – Latitude of the location in degrees.
• longitude (float) – Longitude of the location in degrees.
• live_period (int, optional) – Period in seconds for which the location can be
updated, should be between 60 and 86400.
• **kwargs (dict) – Arbitrary keyword arguments.
class [Link]
Bases: [Link]
Base class for Telegram InputMessageContent Objects.
See: [Link], telegram.
InputLocationMessageContent, [Link] and
[Link] for more details.
class [Link](message_text, parse_mode=None, dis-
able_web_page_preview=None, **kwargs)
Bases: [Link]
Represents the content of a text message to be sent as the result of an inline query.
message_text
str – Text of the message to be sent, 1-4096 characters.
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 bot’s message.
disable_web_page_preview
bool – Optional. Disables link previews for links in the sent message.

Parameters
• message_text (str) – Text of the message to be sent, 1-4096 characters. Also
found as [Link].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 bot’s message.
• disable_web_page_preview (bool, optional) – Disables link previews for links
in the sent message.
• **kwargs (dict) – Arbitrary keyword arguments.

1.44. Module contents 245


Python Telegram Bot Documentation, Release 9.0.0

class [Link](latitude, longitude, title, address,


foursquare_id=None, **kwargs)
Bases: [Link]
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.
• 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.
class [Link](text, request_contact=None, request_location=None, **kwargs)
Bases: [Link]
This object represents one button of the reply keyboard. For simple text buttons String can be used instead
of this object to specify text of the button.

Note: Optional fields are mutually exclusive.

text
str – Text of the button.
request_contact
bool – Optional. If the user’s phone number will be sent.
request_location
bool – Optional. If the user’s 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 user’s 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 user’s 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.

246 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

class [Link](longitude, latitude, **kwargs)


Bases: [Link]
This object represents a point on the map.
longitude
float – Longitude as defined by sender.
latitude
float – Latitude as defined by sender.

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)
class [Link](message_id, from_user, date, chat, forward_from=None, for-
ward_from_chat=None, forward_from_message_id=None, for-
ward_date=None, reply_to_message=None, edit_date=None, text=None,
entities=None, caption_entities=None, audio=None, document=None,
game=None, photo=None, sticker=None, video=None, voice=None,
video_note=None, new_chat_members=None, caption=None, con-
tact=None, location=None, venue=None, new_chat_member=None,
left_chat_member=None, new_chat_title=None, new_chat_photo=None,
delete_chat_photo=False, group_chat_created=False, su-
pergroup_chat_created=False, channel_chat_created=False,
migrate_to_chat_id=None, migrate_from_chat_id=None,
pinned_message=None, invoice=None, successful_payment=None, for-
ward_signature=None, author_signature=None, media_group_id=None,
bot=None, **kwargs)
Bases: [Link]
This object represents a message.

Note:
• In Python from is a reserved word, use from_user instead.

message_id
int – Unique message identifier inside this chat.
from_user
[Link] – Optional. Sender.
date
[Link] – Date the message was sent.
chat
[Link] – Conversation the message belongs to.
forward_from
[Link] – Optional. Sender of the original message.
forward_from_chat
[Link] – Optional. Information about the original channel.
forward_from_message_id
int – Optional. Identifier of the original message in the channel.
forward_date
[Link] – Optional. Date the original message was sent.

1.44. Module contents 247


Python Telegram Bot Documentation, Release 9.0.0

reply_to_message
[Link] – Optional. The original message.
edit_date
[Link] – Optional. Date the message was last edited.
media_group_id
str – Optional. The unique identifier of a media message group this message belongs to.
text
str – Optional. The actual UTF-8 text of the message.
entities
List[[Link]] – 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.
caption_entities
List[[Link]] – Optional. Special entities like usernames, URLs, bot
commands, etc. that appear in the caption. See Message.parse_caption_entity and
parse_caption_entities methods for how to use properly.
audio
[Link] – Optional. Information about the file.
document
[Link] – Optional. Information about the file.
game
[Link] – Optional. Information about the game.
photo
List[[Link]] – Optional. Available sizes of the photo.
sticker
[Link] – Optional. Information about the sticker.
video
[Link] – Optional. Information about the video.
voice
[Link] – Optional. Information about the file.
video_note
[Link] – Optional. Information about the video message.
new_chat_members
List[[Link]] – 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
[Link] – Optional. Information about the contact.
location
[Link] – Optional. Information about the location.
venue
[Link] – Optional. Information about the venue.
left_chat_member
[Link] – 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.

248 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

new_chat_photo
List[[Link]] – 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
[Link] – Optional. Specified message was pinned.
invoice
[Link] – Optional. Information about the invoice.
successful_payment
[Link] – 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
[Link] – Optional. The Bot to use for instance methods.

Deprecated: 6.0 new_chat_member ([Link]): Replaced with new_chat_members

Parameters
• message_id (int) – Unique message identifier inside this chat.
• from_user ([Link], optional) – Sender, can be empty for messages sent
to channels.
• date ([Link]) – Date the message was sent in Unix time. Converted
to [Link].
• chat ([Link]) – Conversation the message belongs to.
• forward_from ([Link], optional) – For forwarded messages, sender of
the original message.
• forward_from_chat ([Link], 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 ([Link], optional) – For forwarded messages, date
the original message was sent in Unix time. Converted to [Link].
• reply_to_message ([Link], 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.

1.44. Module contents 249


Python Telegram Bot Documentation, Release 9.0.0

• edit_date ([Link], optional) – Date the message was last edited


in Unix time. Converted to [Link].
• media_group_id (str, optional) – The unique identifier of a media message group
this message belongs to.
• text (str, optional) – For text messages, the actual UTF-8 text of
the message, 0-4096 characters. Also found as [Link].
MAX_MESSAGE_LENGTH.
• entities (List[[Link]], 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.
• caption_entities (List[[Link]]) – Optional. For Mes-
sages with a Caption. Special entities like usernames, URLs, bot commands,
etc. that appear in the caption. See Message.parse_caption_entity and
parse_caption_entities methods for how to use properly.
• audio ([Link], optional) – Message is an audio file, information about
the file.
• document ([Link], optional) – Message is a general file, informa-
tion about the file.
• game ([Link], optional) – Message is a game, information about the game.
• photo (List[[Link]], optional) – Message is a photo, available
sizes of the photo.
• sticker ([Link], optional) – Message is a sticker, information about
the sticker.
• video ([Link], optional) – Message is a video, information about the
video.
• voice ([Link], optional) – Message is a voice message, information
about the file.
• video_note ([Link], optional) – Message is a video note, infor-
mation about the video message.
• new_chat_members (List[[Link]], optional) – New members that were
added to the group or supergroup and information about them (the bot itself may be one
of these members).
• caption (str, optional) – Caption for the document, photo or video, 0-200 charac-
ters.
• contact ([Link], optional) – Message is a shared contact, informa-
tion about the contact.
• location ([Link], optional) – Message is a shared location, infor-
mation about the location.
• venue ([Link], optional) – Message is a venue, information about the
venue.
• left_chat_member ([Link], optional) – A member was removed from
the group, information about them (this member may be the bot itself).
• new_chat_title (str, optional) – A chat title was changed to this value.
• new_chat_photo (List[[Link]], optional) – A chat photo was
change to this value.
• delete_chat_photo (bool, optional) – Service message: The chat photo was
deleted.

250 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• group_chat_created (bool, optional) – Service message: The group has been


created.
• supergroup_chat_created (bool, optional) – Service message: The super-
group has been created. This field can’t be received in a message coming through
updates, because bot can’t be a member of a supergroup when it is created. It can
only be found in reply_to_message if someone replies to a very first message in a
directly created supergroup.
• channel_chat_created (bool, optional) – Service message: The channel has
been created. This field can’t be received in a message coming through updates, be-
cause bot can’t be a member of a channel when it is created. It can only be found in
attr:reply_to_message if someone replies to a very first message in a channel.
• migrate_to_chat_id (int, optional) – The group has been migrated to a super-
group with the specified identifier. 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.
• migrate_from_chat_id (int, optional) – The supergroup has been migrated
from a group with the specified identifier. 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.
• pinned_message ([Link], optional) – Specified message was
pinned. Note that the Message object in this field will not contain further
attr:reply_to_message fields even if it is itself a reply.
• invoice ([Link], optional) – Message is an invoice for a payment,
information about the invoice.
• successful_payment ([Link], optional) – Mes-
sage is a service message about a successful payment, 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.
chat_id
int – Shortcut for [Link] for chat.
classmethod de_json(data, bot)
delete(*args, **kwargs)
Shortcut for:

bot.delete_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)

Returns On success, True is returned.


Return type bool
edit_caption(*args, **kwargs)
Shortcut for:

bot.edit_message_caption(chat_id=message.chat_id,
message_id=message.message_id,

1.44. Module contents 251


Python Telegram Bot Documentation, Release 9.0.0

*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.

Returns On success, instance representing the edited message.


Return type [Link]
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.

Returns On success, instance representing the edited message.


Return type [Link]
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..

Returns On success, instance representing the edited message.


Return type [Link]
effective_attachment
[Link] or [Link] or [Link] or telegram.
Game or [Link] or [Link] or List[[Link]]
or [Link] or [Link] or [Link] or
[Link] or [Link] or [Link]: 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=[Link].chat_id,
disable_notification=disable_notification,
message_id=[Link].message_id)

Returns On success, instance representing the message forwarded.

252 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Return type [Link]


new_chat_member
Deprecated
parse_caption_entities(types=None)
Returns a dict that maps [Link] to str. It contains entities from this
message’s caption filtered by their [Link] 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 caption_entities attribute,
since it calculates the correct substring from the message text based on UTF-16 codepoints. See
parse_entity for more info.

Parameters types (List[str], optional) – List of [Link] types


as strings. If the type attribute of an entity is contained in this list, it will be returned.
Defaults to a list of all types. All types can be found as constants in telegram.
MessageEntity.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]
parse_caption_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters
• entity ([Link]) – 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
parse_entities(types=None)
Returns a dict that maps [Link] to str. It contains entities from this
message filtered by their [Link] 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.

Parameters types (List[str], optional) – List of [Link] types


as strings. If the type attribute of an entity is contained in this list, it will be returned.
Defaults to a list of all types. All types can be found as constants in telegram.
MessageEntity.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]

1.44. Module contents 253


Python Telegram Bot Documentation, Release 9.0.0

parse_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters
• entity ([Link]) – 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:

bot.send_audio([Link].chat_id, *args, **kwargs)

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 [Link]
reply_contact(*args, **kwargs)
Shortcut for:

bot.send_contact([Link].chat_id, *args, **kwargs)

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 [Link]
reply_document(*args, **kwargs)
Shortcut for:

bot.send_document([Link].chat_id, *args, **kwargs)

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 [Link]
reply_location(*args, **kwargs)
Shortcut for:

bot.send_location([Link].chat_id, *args, **kwargs)

254 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

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 [Link]
reply_photo(*args, **kwargs)
Shortcut for:
bot.send_photo([Link].chat_id, *args, **kwargs)

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 [Link]
reply_sticker(*args, **kwargs)
Shortcut for:
bot.send_sticker([Link].chat_id, *args, **kwargs)

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 [Link]
reply_text(*args, **kwargs)
Shortcut for:
bot.send_message([Link].chat_id, *args, **kwargs)

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:
bot.send_venue([Link].chat_id, *args, **kwargs)

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 [Link]
reply_video(*args, **kwargs)
Shortcut for:
bot.send_video([Link].chat_id, *args, **kwargs)

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.

1.44. Module contents 255


Python Telegram Bot Documentation, Release 9.0.0

Returns On success, instance representing the message posted.


Return type [Link]
reply_video_note(*args, **kwargs)
Shortcut for:

bot.send_video_note([Link].chat_id, *args, **kwargs)

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 [Link]
reply_voice(*args, **kwargs)
Shortcut for:

bot.send_voice([Link].chat_id, *args, **kwargs)

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 [Link]
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
[Link] 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 [Link] as a hyperlink.
Returns Message text with entities formatted as Markdown.
Return type str

256 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

to_dict()
class [Link](type, offset, length, url=None, user=None, **kwargs)
Bases: [Link]
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
[Link] – 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 ([Link], optional) – For “text_mention” only, the mentioned user.
ALL_TYPES = [’mention’, ‘hashtag’, ‘bot_command’, ‘url’, ‘email’, ‘bold’, ‘italic’, ‘code’, ‘pre’, ‘text_link’, ‘text_men
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 [Link]
Bases: object
This object represents a Telegram Message Parse Modes.
HTML = ‘HTML’

1.44. Module contents 257


Python Telegram Bot Documentation, Release 9.0.0

MARKDOWN = ‘Markdown’
class [Link](file_id, width, height, file_size=None, **kwargs)
Bases: [Link]
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 [Link](selective=False, **kwargs)
Bases: [Link]
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 [Link]).
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 haven’t 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 bot’s message is a reply (has reply_to_message_id), sender of the original mes-
sage.
• **kwargs (dict) – Arbitrary keyword arguments.

258 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

class [Link](keyboard, resize_keyboard=False,


one_time_keyboard=False, selective=False, **kwargs)
Bases: [Link]
This object represents a custom keyboard with reply options.
keyboard
List[List[[Link] | 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 it’s been used.
selective
bool – Optional. Show the keyboard to specific users only.

Example

A user requests to change the bot’s language, bot replies to the request with a keyboard to select the new
language. Other users in the group don’t see the keyboard.
Parameters
• keyboard (List[List[str | [Link]]]) – Array of button
rows, each represented by an Array of [Link] 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 app’s standard keyboard. Defaults to False
• one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as
soon as it’s 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 bot’s 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 [Link]
Bases: [Link]
Base class for Telegram ReplyMarkup Objects.
See [Link] and [Link] for detailed
use.
class [Link](file_id, width, height, thumb=None, emoji=None, file_size=None,
set_name=None, mask_position=None, **kwargs)
Bases: [Link]
This object represents a sticker.
file_id
str – Unique identifier for this file.

1.44. Module contents 259


Python Telegram Bot Documentation, Release 9.0.0

width
int – Sticker width.
height
int – Sticker height.
thumb
[Link] – 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
[Link] – 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 ([Link], 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 ([Link], 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 [Link](message)
Bases: [Link]
class [Link]
Bases: object
Base class for most telegram objects.
classmethod de_json(data, bot)
to_dict()
to_json()
Returns str
class [Link](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: [Link]
This object represents an incoming update.

260 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

Note: At most one of the optional parameters can be present in any given update.

update_id
int – The update’s unique identifier.
message
[Link] – Optional. New incoming message.
edited_message
[Link] – Optional. New version of a message.
channel_post
[Link] – Optional. New incoming channel post.
edited_channel_post
[Link] – Optional. New version of a channel post.
inline_query
[Link] – Optional. New incoming inline query.
chosen_inline_result
[Link] – Optional. The result of an inline query that was chosen by
a user.
callback_query
[Link] – Optional. New incoming callback query.
shipping_query
[Link] – Optional. New incoming shipping query.
pre_checkout_query
[Link] – Optional. New incoming pre-checkout query.

Parameters
• update_id (int) – The update’s unique identifier. Update identifiers start from a
certain positive number and increase sequentially. This ID becomes especially handy if
you’re using Webhooks, since it allows you to ignore repeated updates or to restore the
correct update sequence, should they get out of order.
• message ([Link], optional) – New incoming message of any kind -
text, photo, sticker, etc.
• edited_message ([Link], optional) – New version of a message
that is known to the bot and was edited.
• channel_post ([Link], optional) – New incoming channel post of
any kind - text, photo, sticker, etc.
• edited_channel_post ([Link], optional) – New version of a
channel post that is known to the bot and was edited.
• inline_query ([Link], optional) – New incoming inline
query.
• chosen_inline_result ([Link], optional) –
The result of an inline query that was chosen by a user and sent to their chat partner.
• callback_query ([Link], optional) – New incoming
callback query.
• shipping_query ([Link], optional) – New incoming
shipping query. Only for invoices with flexible price.
• pre_checkout_query ([Link], optional) – New in-
coming pre-checkout query. Contains full information about checkout

1.44. Module contents 261


Python Telegram Bot Documentation, Release 9.0.0

• **kwargs (dict) – Arbitrary keyword arguments.


classmethod de_json(data, bot)
effective_chat
[Link] – The chat that this update was sent in, no matter what kind of update this is.
Will be None for inline_query, chosen_inline_result, callback_query from inline
messages, shipping_query and pre_checkout_query.
effective_message
[Link] – The message included in this update, no matter what kind of update this is.
Will be None for inline_query, chosen_inline_result, callback_query from inline
messages, shipping_query and pre_checkout_query.
effective_user
[Link] – The user that sent this update, no matter what kind of update this is. Will be
None for channel_post.
class [Link](id, first_name, is_bot, last_name=None, username=None, lan-
guage_code=None, bot=None, **kwargs)
Bases: [Link]
This object represents a Telegram user or bot.
id
int – Unique identifier for this user or bot.
is_bot
bool – True, if this user is a bot
first_name
str – User’s or bot’s first name.
last_name
str – Optional. User’s or bot’s last name.
username
str – Optional. User’s or bot’s username.
language_code
str – Optional. IETF language tag of the user’s language.
bot
[Link] – 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) – User’s or bot’s first name.
• last_name (str, optional) – User’s or bot’s last name.
• username (str, optional) – User’s or bot’s username.
• language_code (str, optional) – IETF language tag of the user’s language.
• bot ([Link], 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:

bot.get_user_profile_photos([Link].from_user.id, *args, **kwargs)

262 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

mention_html(name=None)
Parameters name (str) – If provided, will overwrite the user’s 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 user’s 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 [Link](total_count, photos, **kwargs)
Bases: [Link]
This object represent a user’s profile pictures.
total_count
int – Total number of profile pictures.
photos
List[List[[Link]]] – Requested profile pictures.

Parameters
• total_count (int) – Total number of profile pictures the target user has.
• photos (List[List[[Link]]]) – Requested profile pictures (in up to
4 sizes each).
classmethod de_json(data, bot)
to_dict()
class [Link](location, title, address, foursquare_id=None, **kwargs)
Bases: [Link]
This object represents a venue.
location
[Link] – 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 ([Link]) – 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)

1.44. Module contents 263


Python Telegram Bot Documentation, Release 9.0.0

class [Link](file_id, width, height, duration, thumb=None, mime_type=None,


file_size=None, **kwargs)
Bases: [Link]
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
[Link] – 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 ([Link], 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 [Link](file_id, duration, mime_type=None, file_size=None, **kwargs)
Bases: [Link]
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.

264 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• file_size (int, optional) – File size.


• **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class [Link](url, has_custom_certificate, pending_update_count,
last_error_date=None, last_error_message=None,
max_connections=None, allowed_updates=None, **kwargs)
Bases: [Link]
This object represents a Telegram WebhookInfo.
Contains information about the current status of a webhook.
url
str – Webhook URL.
has_custom_certificate
bool – If a custom certificate was provided for webhook.
pending_update_count
int – Number of updates awaiting delivery.
last_error_date
int – Optional. Unix time for the most recent error that happened.
last_error_message
str – Optional. Error message in human-readable format.
max_connections
int – Optional. Maximum allowed number of simultaneous HTTPS connections.
allowed_updates
List[str] – Optional. A list of update types the bot is subscribed to.

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 [Link](file_id, thumb=None, file_name=None, mime_type=None,
file_size=None, **kwargs)
Bases: [Link]
This object represents an animation file to be displayed in the message containing a game.
file_id
str – Unique file identifier.
thumb
[Link] – Optional. Animation thumbnail as defined by sender.

1.44. Module contents 265


Python Telegram Bot Documentation, Release 9.0.0

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 ([Link], 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 [Link](title, description, photo, text=None, text_entities=None, animation=None,
**kwargs)
Bases: [Link]
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[[Link]] – 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[[Link]] – Optional. Special entities that appear in text, such as user-
names, URLs, bot commands, etc.
animation
[Link] – 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[[Link]]) – 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 [Link].MAX_MESSAGE_LENGTH.
• text_entities (List[[Link]], optional) – Special entities
that appear in text, such as usernames, URLs, bot commands, etc.

266 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

• animation ([Link], 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 [Link] 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.

Parameters types (List[str], optional) – List of MessageEntity types as strings. If


the type attribute of an entity is contained in this list, it will be returned. Defaults to
[Link].ALL_TYPES.
Returns A dictionary of entities mapped to the text that belongs to them, calculated based
on UTF-16 codepoints.
Return type Dict[[Link], str]
parse_text_entity(entity)
Returns the text from a given [Link].

Note: This method is present because Telegram calculates the offset and length in UTF-16 code-
point pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice
[Link] with the offset and length.)

Parameters entity ([Link]) – The entity to extract the text


from. It must be an entity that belongs to this message.
Returns The text of the given entity.
Return type str
to_dict()
class [Link](position, user, score)
Bases: [Link]
This object represents one row of the high scores table for a game.
position
int – Position in high score table for the game.
user
[Link] – User.
score
int – Score.

Parameters
• position (int) – Position in high score table for the game.
• user ([Link]) – User.
• score (int) – Score.
classmethod de_json(data, bot)

1.44. Module contents 267


Python Telegram Bot Documentation, Release 9.0.0

class [Link](file_id, length, duration, thumb=None, file_size=None, **kwargs)


Bases: [Link]
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
[Link] – 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 ([Link], optional) – Video thumbnail.
• file_size (int, optional) – File size.
• **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class [Link](label, amount, **kwargs)
Bases: [Link]
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 [Link], 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 [Link](currency, total_amount, invoice_payload, tele-
gram_payment_charge_id, provider_payment_charge_id,
shipping_option_id=None, order_info=None, **kwargs)
Bases: [Link]
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.

268 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

invoice_payload
str – Bot specified invoice payload.
shipping_option_id
str – Optional. Identifier of the shipping option chosen by the user.
order_info
[Link] – 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 [Link], 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 ([Link], 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 [Link](id, title, prices, **kwargs)
Bases: [Link]
This object represents one shipping option.
id
str – Shipping option identifier.
title
str – Option title.
prices
List[[Link]] – List of price portions.

Parameters
• id (str) – Shipping option identifier.
• title (str) – Option title.
• prices (List[[Link]]) – List of price portions.
• **kwargs (dict) – Arbitrary keyword arguments.
to_dict()
class [Link](country_code, state, city, street_line1, street_line2, post_code,
**kwargs)
Bases: [Link]
This object represents a Telegram ShippingAddress.

1.44. Module contents 269


Python Telegram Bot Documentation, Release 9.0.0

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 [Link](id, from_user, currency, total_amount, invoice_payload,
shipping_option_id=None, order_info=None, bot=None,
**kwargs)
Bases: [Link]
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
[Link] – 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
[Link] – Optional. Order info provided by the user.

270 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

bot
[Link] – Optional. The Bot to use for instance methods.

Parameters
• id (str) – Unique query identifier.
• from_user ([Link]) – 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 [Link], 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 ([Link], optional) – Order info provided by the user.
• bot ([Link], 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 [Link](name=None, phone_number=None, email=None, ship-
ping_address=None, **kwargs)
Bases: [Link]
This object represents information about an order.
name
str – Optional. User name.
phone_number
str – Optional. User’s phone number.
email
str – Optional. User email.
shipping_address
[Link] – Optional. User shipping address.

Parameters

1.44. Module contents 271


Python Telegram Bot Documentation, Release 9.0.0

• name (str, optional) – User name.


• phone_number (str, optional) – User’s phone number.
• email (str, optional) – User email.
• shipping_address ([Link], optional) – User ship-
ping address.
• **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class [Link](title, description, start_parameter, currency, total_amount, **kwargs)
Bases: [Link]
This object contains basic information about an invoice.
title
str – Product name.
description
str – Product description.
start_parameter
str – Unique bot deep-linking parameter.
currency
str – Three-letter ISO 4217 currency code.
total_amount
int – Total price in the smallest units of the currency.

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 [Link](id, from_user, invoice_payload, shipping_address, bot=None,
**kwargs)
Bases: [Link]
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
[Link] – User who sent the query.
invoice_payload
str – Bot specified invoice payload.

272 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

shipping_address
[Link] – User specified shipping address.
bot
[Link] – Optional. The Bot to use for instance methods.

Parameters
• id (str) – Unique query identifier.
• from_user ([Link]) – User who sent the query.
• invoice_payload (str) – Bot specified invoice payload.
• shipping_address ([Link]) – User specified ship-
ping address.
• bot ([Link], optional) – The Bot to use for instance methods.
• **kwargs (dict) – Arbitrary keyword arguments.
answer(*args, **kwargs)
Shortcut for:

bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)

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[[Link]], 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 [Link](small_file_id, big_file_id, bot=None, **kwargs)
Bases: [Link]
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 ([Link], optional) – The Bot to use for instance methods
• **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)

1.44. Module contents 273


Python Telegram Bot Documentation, Release 9.0.0

class [Link](name, title, contains_masks, stickers, bot=None, **kwargs)


Bases: [Link]
This object represents a sticker set.
name
str – Sticker set name.
title
str – Sticker set title.
contains_masks
bool – True, if the sticker set contains masks.
stickers
List[[Link]] – List of all set stickers.

Parameters
• name (str) – Sticker set name.
• title (str) – Sticker set title.
• contains_masks (bool) – True, if the sticker set contains masks.
• stickers (List[[Link]]) – List of all set stickers.
static de_json(data, bot)
to_dict()
class [Link](point, x_shift, y_shift, scale, **kwargs)
Bases: [Link]
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’

274 Chapter 1. telegram package


Python Telegram Bot Documentation, Release 9.0.0

EYES = ‘eyes’
FOREHEAD = ‘forehead’
MOUTH = ‘mouth’
classmethod de_json(data, bot)
class [Link]
Bases: [Link]
A placeholder, currently holds no information. Use BotFather to set up your game.
class [Link]
Bases: [Link]
Base class for Telegram InputMedia Objects.
See [Link] and [Link] for detailed use.
class [Link](media, caption=None)
Bases: [Link]
Represents a photo to be sent.
type
str – photo.
media
str – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing
[Link] object to send.
caption
str – Optional. Caption of the photo to be sent, 0-200 characters.

Parameters
• media (str) – File to send. Pass a file_id to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
Lastly you can pass an existing [Link] object to send.
• caption (str, optional) – Caption of the photo to be sent, 0-200 characters.

Note: At the moment using a new file is not yet supported.

class [Link](media, caption=None, width=None, height=None, dura-


tion=None)
Bases: [Link]
Represents a video to be sent.
type
str – video.
media
str – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing
[Link] object to send.
caption
str – Optional. Caption of the video to be sent, 0-200 characters.
width
int – Optional. Video width.

1.44. Module contents 275


Python Telegram Bot Documentation, Release 9.0.0

height
int – Optional. Video height.
duration
int – Optional. Video duration.

Parameters
• media (str) – File to send. Pass a file_id to send a file that exists on the Telegram
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
Lastly you can pass an existing [Link] object to send.
• caption (str, optional) – Caption of the video to be sent, 0-200 characters.
• width (int, optional) – Video width.
• height (int, optional) – Video height.
• duration (int, optional) – Video duration.

Note: When using a [Link] for the media attribute. It will take the width, height and
duration from that video, unless otherwise specified with the optional arguments. At the moment using a
new file is not yet supported.

276 Chapter 1. telegram package


CHAPTER 2

Changelog

277
Python Telegram Bot Documentation, Release 9.0.0

278 Chapter 2. Changelog


CHAPTER 3

Indices and tables

• genindex
• modindex
• search

279
Python Telegram Bot Documentation, Release 9.0.0

280 Chapter 3. Indices and tables


Python Module Index

t
[Link], 98
[Link], 100
[Link], 8
[Link], 3

281
Python Telegram Bot Documentation, Release 9.0.0

282 Python Module Index


Index

Symbols answer_pre_checkout_query() ([Link] method),


__call__() ([Link] method), 17 39
__call__() ([Link] method), 15 answer_shipping_query() ([Link] method), 40
__weakref__ ([Link] attribute), answerCallbackQuery() ([Link] method), 36
16 answerInlineQuery() ([Link] method), 36
answerPreCheckoutQuery() ([Link] method), 37
A answerShippingQuery() ([Link] method), 37
add_error_handler() ([Link] method), Audio (class in telegram), 34
6 audio (Message attribute), 107
add_handler() ([Link] method), 6 audio ([Link] attribute), 9
add_sticker_to_set() ([Link] method), 35 audio ([Link] attribute), 248
address (InlineQueryResultVenue attribute), 144 audio_duration (InlineQueryResultAudio attribute),
address (InputVenueMessageContent attribute), 148 130
address ([Link] attribute), audio_duration ([Link] at-
241 tribute), 228
address ([Link] at- audio_file_id (InlineQueryResultCachedAudio at-
tribute), 246 tribute), 131
address ([Link] attribute), 263 audio_file_id ([Link]
address (Venue attribute), 122 attribute), 229
addStickerToSet() ([Link] method), 35 audio_url (InlineQueryResultAudio attribute), 130
ADMINISTRATOR ([Link] attribute), audio_url ([Link] attribute),
97 228
all ([Link] attribute), 9 author_signature (Message attribute), 108
all_members_are_administrators (Chat attribute), 93 author_signature ([Link] attribute), 249
all_members_are_administrators ([Link]
attribute), 214 B
ALL_TYPES ([Link] attribute), 116 BadRequest, 100
allow_edited (CommandHandler attribute), 23 BaseFilter (class in [Link]), 8
allow_edited (MessageHandler attribute), 26 big_file_id (ChatPhoto attribute), 98
allow_reentry (ConversationHandler attribute), 21 big_file_id ([Link] attribute), 273
allowed_updates ([Link] attribute), BOLD ([Link] attribute), 116
265 Bot (class in telegram), 34
allowed_updates (WebhookInfo attribute), 125 bot (Dispatcher attribute), 6
amount (LabeledPrice attribute), 150 bot (JobQueue attribute), 13
amount ([Link] attribute), 268 bot (Message attribute), 108
Animation (class in telegram), 157 bot (PreCheckoutQuery attribute), 155
animation (Game attribute), 156 bot (ShippingQuery attribute), 154
animation ([Link] attribute), 266 bot ([Link] attribute), 249
answer() ([Link] method), 91 bot ([Link] attribute), 270
answer() ([Link] method), 128 bot ([Link] attribute), 273
answer() ([Link] method), 155 bot ([Link] attribute), 262
answer() ([Link] method), 154 bot (Updater attribute), 4
answer_callback_query() ([Link] method), 38 bot (User attribute), 121
answer_inline_query() ([Link] method), 38

283
Python Telegram Bot Documentation, Release 9.0.0

BOT_COMMAND ([Link] attribute), can_send_media_messages (ChatMember attribute), 96


116 can_send_media_messages ([Link] at-
burst_limit (DelayQueue attribute), 16 tribute), 217
can_send_messages (ChatMember attribute), 96
C can_send_messages ([Link] attribute),
callback (CallbackQueryHandler attribute), 18 217
callback (ChosenInlineResultHandler attribute), 20 can_send_other_messages (ChatMember attribute), 96
callback (CommandHandler attribute), 23 can_send_other_messages ([Link] at-
callback (Handler attribute), 17 tribute), 217
callback (InlineQueryHandler attribute), 24 can_set_sticker_set (Chat attribute), 93
callback (Job attribute), 11 can_set_sticker_set ([Link] attribute), 215
callback (MessageHandler attribute), 26 caption (InlineQueryResultAudio attribute), 130
callback (PreCheckoutQueryHandler attribute), 27 caption (InlineQueryResultCachedAudio attribute), 131
callback (RegexHandler attribute), 28 caption (InlineQueryResultCachedDocument attribute),
callback (ShippingQueryHandler attribute), 30 132
callback (StringCommandHandler attribute), 31 caption (InlineQueryResultCachedGif attribute), 133
callback (StringRegexHandler attribute), 32 caption (InlineQueryResultCachedMpeg4Gif attribute),
callback (TypeHandler attribute), 33 134
callback_data (InlineKeyboardButton attribute), 102 caption (InlineQueryResultCachedPhoto attribute), 134
callback_data ([Link] at- caption (InlineQueryResultCachedVideo attribute), 136
tribute), 224 caption (InlineQueryResultCachedVoice attribute), 137
callback_game (InlineKeyboardButton attribute), 102 caption (InlineQueryResultDocument attribute), 138
callback_game ([Link] caption (InlineQueryResultGif attribute), 140
attribute), 224 caption (InlineQueryResultMpeg4Gif attribute), 142
callback_query ([Link] attribute), 261 caption (InlineQueryResultPhoto attribute), 143
callback_query (Update attribute), 120 caption (InlineQueryResultVideo attribute), 146
CallbackGame (class in telegram), 157 caption (InlineQueryResultVoice attribute), 147
CallbackQuery (class in telegram), 90 caption (InputMediaPhoto attribute), 104
CallbackQueryHandler (class in [Link]), 18 caption (InputMediaVideo attribute), 104
can_add_web_page_previews (ChatMember attribute), caption (Message attribute), 107
96 caption ([Link] attribute),
can_add_web_page_previews ([Link] 228
attribute), 217 caption ([Link] at-
can_be_edited (ChatMember attribute), 96 tribute), 229
can_be_edited ([Link] attribute), 217 caption ([Link]
can_change_info (ChatMember attribute), 96 attribute), 229
can_change_info ([Link] attribute), caption ([Link] at-
217 tribute), 230
can_delete_messages (ChatMember attribute), 96 caption (telegram.InlineQueryResultCachedMpeg4Gif
can_delete_messages ([Link] at- attribute), 231
tribute), 217 caption ([Link] at-
can_edit_messages (ChatMember attribute), 96 tribute), 232
can_edit_messages ([Link] attribute), caption ([Link] at-
217 tribute), 233
can_invite_users (ChatMember attribute), 96 caption ([Link] at-
can_invite_users ([Link] attribute), 217 tribute), 234
can_pin_messages (ChatMember attribute), 96 caption ([Link] at-
can_pin_messages ([Link] attribute), tribute), 235
217 caption ([Link] attribute), 237
can_post_messages (ChatMember attribute), 96 caption (telegram.InlineQueryResultMpeg4Gif at-
can_post_messages ([Link] attribute), tribute), 239
217 caption ([Link] attribute),
can_promote_members (ChatMember attribute), 96 240
can_promote_members ([Link] at- caption ([Link] attribute),
tribute), 217 242
can_restrict_members (ChatMember attribute), 96 caption ([Link] attribute),
can_restrict_members ([Link] at- 243
tribute), 217 caption ([Link] attribute), 275

284 Index
Python Telegram Bot Documentation, Release 9.0.0

caption ([Link] attribute), 275 18


caption ([Link] attribute), 248 command (CommandHandler attribute), 23
caption_entities (Message attribute), 107 command (StringCommandHandler attribute), 31
caption_entities ([Link] attribute), 248 command ([Link] attribute), 9
CHANNEL ([Link] attribute), 94 CommandHandler (class in [Link]), 23
channel_chat_created (Message attribute), 108 Contact (class in telegram), 99
channel_chat_created ([Link] attribute), contact (Message attribute), 107
249 contact ([Link] attribute), 9
channel_post ([Link] attribute), 261 contact ([Link] attribute), 248
channel_post (Update attribute), 120 contains_masks (StickerSet attribute), 126
channel_post_updates (MessageHandler attribute), 26 contains_masks ([Link] attribute), 274
Chat (class in telegram), 92 content_type ([Link] attribute), 103
chat (Message attribute), 106 context (Job attribute), 11
chat ([Link] attribute), 247 ConversationHandler (class in [Link]), 21
chat_created ([Link] attribute), 10 country_code (ShippingAddress attribute), 151
chat_data ([Link] attribute), 7 country_code ([Link] attribute),
chat_id ([Link] attribute), 110 269
chat_instance (CallbackQuery attribute), 91 create_new_sticker_set() ([Link] method), 41
chat_instance ([Link] attribute), 220 createNewStickerSet() ([Link] method), 40
ChatAction (class in telegram), 95 CREATOR ([Link] attribute), 97
ChatMember (class in telegram), 96 currency (Invoice attribute), 150
ChatMigrated, 100 currency (PreCheckoutQuery attribute), 154
ChatPhoto (class in telegram), 98 currency (SuccessfulPayment attribute), 153
check_update() ([Link] currency ([Link] attribute), 272
method), 19 currency ([Link] attribute), 270
check_update() (tele- currency ([Link] attribute), 268
[Link]
method), 20 D
check_update() ([Link] data (CallbackQuery attribute), 91
method), 24 data (InputFile attribute), 103
check_update() ([Link] data ([Link] attribute), 220
method), 22 data ([Link] attribute), 244
check_update() ([Link] method), 18 date (Message attribute), 106
check_update() ([Link] date ([Link] attribute), 247
method), 25 days ([Link] attribute), 12
check_update() ([Link] de_json() ([Link] class method), 121
method), 27 de_json() ([Link] class method), 121
check_update() (tele- de_list() ([Link] class method), 122
[Link] DelayQueue (class in [Link]), 16
method), 28 delete() ([Link] method), 110
check_update() ([Link] method), delete_chat_photo (Message attribute), 108
29 delete_chat_photo ([Link] at-
check_update() ([Link] tribute), 10
method), 30 delete_chat_photo ([Link] attribute), 249
check_update() ([Link] delete_chat_photo() ([Link] method), 43
method), 31 delete_chat_sticker_set() ([Link] method), 44
check_update() ([Link] delete_message() ([Link] method), 44
method), 33 delete_sticker_from_set() ([Link] method), 44
check_update() ([Link] method), 33 delete_webhook() ([Link] method), 44
CHIN ([Link] attribute), 127 deleteChatPhoto() ([Link] method), 42
chosen_inline_result ([Link] attribute), 261 deleteChatStickerSet() ([Link] method), 42
chosen_inline_result (Update attribute), 120 deleteMessage() ([Link] method), 42
ChosenInlineResult (class in telegram), 149 deleteStickerFromSet() ([Link] method), 43
ChosenInlineResultHandler (class in [Link]), 20 deleteWebhook() ([Link] method), 43
city (ShippingAddress attribute), 151 description (Chat attribute), 93
city ([Link] attribute), 270 description (Game attribute), 156
CODE ([Link] attribute), 117 description (InlineQueryResultArticle attribute), 129
collect_optional_args() ([Link] method),

Index 285
Python Telegram Bot Documentation, Release 9.0.0

description (InlineQueryResultCachedDocument at- duration (VideoNote attribute), 124


tribute), 132 duration (Voice attribute), 124
description (InlineQueryResultCachedPhoto attribute),
134 E
description (InlineQueryResultCachedVideo attribute), edit_caption() ([Link] method), 111
136 edit_date (Message attribute), 107
description (InlineQueryResultDocument attribute), edit_date ([Link] attribute), 248
139 edit_message_caption() ([Link] method), 47
description (InlineQueryResultPhoto attribute), 143 edit_message_caption() ([Link]
description (InlineQueryResultVideo attribute), 146 method), 91
description (Invoice attribute), 150 edit_message_live_location() ([Link] method),
description ([Link] attribute), 214 47
description ([Link] attribute), 266 edit_message_reply_markup() ([Link] method),
description ([Link] at- 48
tribute), 227 edit_message_reply_markup() (tele-
description ([Link] [Link] method), 92
attribute), 229 edit_message_text() ([Link] method), 48
description ([Link] edit_message_text() ([Link] method),
attribute), 232 92
description ([Link] edit_reply_markup() ([Link] method), 111
attribute), 233 edit_text() ([Link] method), 111
description ([Link] at- edited_channel_post ([Link] attribute), 261
tribute), 235 edited_channel_post (Update attribute), 120
description ([Link] at- edited_message ([Link] attribute), 261
tribute), 240 edited_message (Update attribute), 120
description ([Link] at- edited_updates (MessageHandler attribute), 26
tribute), 242 editMessageCaption() ([Link] method), 45
description ([Link] attribute), 272 editMessageLiveLocation() ([Link] method), 45
disable_web_page_preview (InputTextMessageContent editMessageReplyMarkup() ([Link] method), 46
attribute), 148 editMessageText() ([Link] method), 46
disable_web_page_preview (tele- effective_attachment ([Link] attribute), 111
[Link] attribute), effective_chat ([Link] attribute), 121
245 effective_message ([Link] attribute), 121
dispatch_error() ([Link] method), 7 effective_user ([Link] attribute), 121
Dispatcher (class in [Link]), 6 email (OrderInfo attribute), 152
dispatcher (Updater attribute), 4 EMAIL ([Link] attribute), 117
Document (class in telegram), 99 email ([Link] attribute), 271
document (Message attribute), 107 emoji (Sticker attribute), 126
document ([Link] attribute), 9 emoji ([Link] attribute), 260
document ([Link] attribute), 248 enabled ([Link] attribute), 12
document_file_id (InlineQueryResultCachedDocument END ([Link] attribute), 22
attribute), 132 entities (Message attribute), 107
document_file_id (tele- entities ([Link] attribute), 248
[Link] entry_points (ConversationHandler attribute), 21
attribute), 229 error_handlers ([Link] attribute), 7
document_url (InlineQueryResultDocument attribute), escape_markdown() (in module [Link]),
138 3
document_url ([Link] exc_route (DelayQueue attribute), 16
attribute), 235 export_chat_invite_link() ([Link] method), 49
download() ([Link] method), 101 exportChatInviteLink() ([Link] method), 49
duration (Audio attribute), 34 EYES ([Link] attribute), 127
duration (InputMediaVideo attribute), 105
duration ([Link] attribute), 158 F
duration ([Link] attribute), 276 fallbacks (ConversationHandler attribute), 21
duration ([Link] attribute), 264 File (class in telegram), 100
duration ([Link] attribute), 268 file_id (Animation attribute), 157
duration ([Link] attribute), 264 file_id (Audio attribute), 34
duration (Video attribute), 123 file_id (Document attribute), 99

286 Index
Python Telegram Bot Documentation, Release 9.0.0

file_id (File attribute), 100 first_name ([Link] at-


file_id (PhotoSize attribute), 117 tribute), 244
file_id (Sticker attribute), 125 first_name ([Link] attribute), 262
file_id ([Link] attribute), 265 first_name (User attribute), 121
file_id ([Link] attribute), 158 force_reply (ForceReply attribute), 101
file_id ([Link] attribute), 222 force_reply ([Link] attribute), 223
file_id ([Link] attribute), 223 ForceReply (class in telegram), 101
file_id ([Link] attribute), 258 FOREHEAD ([Link] attribute), 127
file_id ([Link] attribute), 259 forward() ([Link] method), 111
file_id ([Link] attribute), 264 forward_date (Message attribute), 107
file_id ([Link] attribute), 268 forward_date ([Link] attribute), 247
file_id ([Link] attribute), 264 forward_from (Message attribute), 106
file_id (Video attribute), 123 forward_from ([Link] attribute), 247
file_id (VideoNote attribute), 124 forward_from_chat (Message attribute), 106
file_id (Voice attribute), 124 forward_from_chat ([Link] attribute), 247
file_name (Animation attribute), 157 forward_from_message_id (Message attribute), 107
file_name (Document attribute), 99 forward_from_message_id ([Link] at-
file_name ([Link] attribute), 265 tribute), 247
file_name ([Link] attribute), 222 forward_message() ([Link] method), 50
file_path (File attribute), 100 forward_signature (Message attribute), 108
file_path ([Link] attribute), 223 forward_signature ([Link] attribute), 249
file_size (Animation attribute), 157 forwarded ([Link] attribute), 9
file_size (Audio attribute), 34 forwardMessage() ([Link] method), 49
file_size (Document attribute), 99 foursquare_id (InlineQueryResultVenue attribute), 144
file_size (File attribute), 100 foursquare_id (InputVenueMessageContent attribute),
file_size (PhotoSize attribute), 117 149
file_size (Sticker attribute), 126 foursquare_id ([Link] at-
file_size ([Link] attribute), 266 tribute), 241
file_size ([Link] attribute), 158 foursquare_id ([Link]
file_size ([Link] attribute), 222 attribute), 246
file_size ([Link] attribute), 223 foursquare_id ([Link] attribute), 263
file_size ([Link] attribute), 258 foursquare_id (Venue attribute), 122
file_size ([Link] attribute), 260 from_timestamp() (in module [Link]), 3
file_size ([Link] attribute), 264 from_user (CallbackQuery attribute), 90
file_size ([Link] attribute), 268 from_user (ChosenInlineResult attribute), 149
file_size ([Link] attribute), 264 from_user (InlineQuery attribute), 128
file_size (Video attribute), 123 from_user (Message attribute), 106
file_size (VideoNote attribute), 124 from_user (PreCheckoutQuery attribute), 154
file_size (Voice attribute), 124 from_user (ShippingQuery attribute), 153
filter() ([Link] method), 8 from_user ([Link] attribute), 220
Filters (class in [Link]), 8 from_user ([Link] attribute), 219
filters (CommandHandler attribute), 23 from_user ([Link] attribute), 225
filters (MessageHandler attribute), 26 from_user ([Link] attribute), 247
[Link] (class in [Link]), 9 from_user ([Link] attribute), 270
[Link] (class in [Link]), 9 from_user ([Link] attribute), 272
[Link] (class in [Link]), 9
[Link] (class in [Link]), 11 G
FIND_LOCATION ([Link] attribute), 95 Game (class in telegram), 155
first_name (Chat attribute), 93 game (Message attribute), 107
first_name (Contact attribute), 99 game ([Link] attribute), 9
first_name (InlineQueryResultContact attribute), 137 game ([Link] attribute), 248
first_name (InputContactMessageContent attribute), game_short_name (CallbackQuery attribute), 91
149 game_short_name (InlineQueryResultGame attribute),
first_name ([Link] attribute), 49 139
first_name ([Link] attribute), 214 game_short_name ([Link] attribute),
first_name ([Link] attribute), 222 220
first_name ([Link] at- game_short_name ([Link]
tribute), 234 attribute), 243

Index 287
Python Telegram Bot Documentation, Release 9.0.0

GameHighScore (class in telegram), 158 handle_update() ([Link]


get_administrators() ([Link] method), 94 method), 22
get_chat() ([Link] method), 53 handle_update() ([Link] method), 18
get_chat_administrators() ([Link] method), 54 handle_update() ([Link]
get_chat_member() ([Link] method), 54 method), 25
get_chat_members_count() ([Link] method), 54 handle_update() ([Link]
get_file() ([Link] method), 55 method), 27
get_game_high_scores() ([Link] method), 55 handle_update() (tele-
get_instance() ([Link] class method), [Link]
7 method), 28
get_me() ([Link] method), 55 handle_update() ([Link] method),
get_member() ([Link] method), 94 29
get_members_count() ([Link] method), 94 handle_update() ([Link]
get_profile_photos() ([Link] method), 122 method), 30
get_sticker_set() ([Link] method), 55 handle_update() ([Link]
get_updates() ([Link] method), 56 method), 31
get_user_profile_photos() ([Link] method), 56 handle_update() ([Link]
get_webhook_info() ([Link] method), 57 method), 33
getChat() ([Link] method), 50 handle_update() ([Link] method),
getChatAdministrators() ([Link] method), 50 34
getChatMember() ([Link] method), 51 Handler (class in [Link]), 17
getChatMembersCount() ([Link] method), 51 handlers ([Link] attribute), 7
getFile() ([Link] method), 51 has_custom_certificate ([Link] at-
getGameHighScores() ([Link] method), 51 tribute), 265
getMe() ([Link] method), 52 has_custom_certificate (WebhookInfo attribute), 125
getStickerSet() ([Link] method), 52 HASHTAG ([Link] attribute), 117
getUpdates() ([Link] method), 52 headers ([Link] attribute), 103
getUserProfilePhotos() ([Link] method), 53 height (InputMediaVideo attribute), 104
getWebhookInfo() ([Link] method), 53 height (PhotoSize attribute), 117
gif_duration (InlineQueryResultGif attribute), 140 height (Sticker attribute), 126
gif_duration ([Link] attribute), height ([Link] attribute), 275
237 height ([Link] attribute), 258
gif_file_id (InlineQueryResultCachedGif attribute), height ([Link] attribute), 260
133 height ([Link] attribute), 264
gif_file_id ([Link] at- height (Video attribute), 123
tribute), 230 hide_url (InlineQueryResultArticle attribute), 129
gif_height (InlineQueryResultGif attribute), 140 hide_url ([Link] attribute),
gif_height ([Link] attribute), 227
236 HTML ([Link] attribute), 117
gif_url (InlineQueryResultGif attribute), 140
gif_url ([Link] attribute), 236 I
gif_width (InlineQueryResultGif attribute), 140 id (CallbackQuery attribute), 90
gif_width ([Link] attribute), id (Chat attribute), 92
236 id (InlineQuery attribute), 128
GROUP ([Link] attribute), 94 id (InlineQueryResult attribute), 129
group ([Link] attribute), 9 id (InlineQueryResultArticle attribute), 129
group_chat_created (Message attribute), 108 id (InlineQueryResultAudio attribute), 130
group_chat_created ([Link] attribute), 249 id (InlineQueryResultCachedAudio attribute), 131
groups ([Link] attribute), 7 id (InlineQueryResultCachedDocument attribute), 132
id (InlineQueryResultCachedGif attribute), 133
H id (InlineQueryResultCachedMpeg4Gif attribute), 133
handle_update() ([Link] id (InlineQueryResultCachedPhoto attribute), 134
method), 19 id (InlineQueryResultCachedSticker attribute), 135
handle_update() (tele- id (InlineQueryResultCachedVideo attribute), 136
[Link] id (InlineQueryResultCachedVoice attribute), 137
method), 20 id (InlineQueryResultContact attribute), 137
handle_update() ([Link] id (InlineQueryResultDocument attribute), 138
method), 24 id (InlineQueryResultGame attribute), 139

288 Index
Python Telegram Bot Documentation, Release 9.0.0

id (InlineQueryResultGif attribute), 140 inline_message_id ([Link] attribute),


id (InlineQueryResultLocation attribute), 141 220
id (InlineQueryResultMpeg4Gif attribute), 142 inline_message_id ([Link] at-
id (InlineQueryResultPhoto attribute), 143 tribute), 219
id (InlineQueryResultVenue attribute), 144 inline_query ([Link] attribute), 261
id (InlineQueryResultVideo attribute), 145 inline_query (Update attribute), 120
id (InlineQueryResultVoice attribute), 147 InlineKeyboardButton (class in telegram), 101
id (PreCheckoutQuery attribute), 154 InlineKeyboardMarkup (class in telegram), 103
id (ShippingOption attribute), 152 InlineQuery (class in telegram), 127
id (ShippingQuery attribute), 153 InlineQueryHandler (class in [Link]), 24
id ([Link] attribute), 57 InlineQueryResult (class in telegram), 129
id ([Link] attribute), 220 InlineQueryResultArticle (class in telegram), 129
id ([Link] attribute), 214 InlineQueryResultAudio (class in telegram), 130
id ([Link] attribute), 225 InlineQueryResultCachedAudio (class in telegram),
id ([Link] attribute), 226 131
id ([Link] attribute), 227 InlineQueryResultCachedDocument (class in tele-
id ([Link] attribute), 228 gram), 132
id ([Link] attribute), InlineQueryResultCachedGif (class in telegram), 132
229 InlineQueryResultCachedMpeg4Gif (class in tele-
id ([Link] at- gram), 133
tribute), 229 InlineQueryResultCachedPhoto (class in telegram), 134
id ([Link] attribute), InlineQueryResultCachedSticker (class in telegram),
230 135
id (telegram.InlineQueryResultCachedMpeg4Gif at- InlineQueryResultCachedVideo (class in telegram),
tribute), 231 136
id ([Link] attribute), InlineQueryResultCachedVoice (class in telegram), 136
231 InlineQueryResultContact (class in telegram), 137
id ([Link] at- InlineQueryResultDocument (class in telegram), 138
tribute), 232 InlineQueryResultGame (class in telegram), 139
id ([Link] attribute), InlineQueryResultGif (class in telegram), 140
233 InlineQueryResultLocation (class in telegram), 141
id ([Link] attribute), InlineQueryResultMpeg4Gif (class in telegram), 142
234 InlineQueryResultPhoto (class in telegram), 143
id ([Link] attribute), 234 InlineQueryResultVenue (class in telegram), 144
id ([Link] attribute), InlineQueryResultVideo (class in telegram), 145
235 InlineQueryResultVoice (class in telegram), 146
id ([Link] attribute), 243 input_message_content (InlineQueryResultArticle at-
id ([Link] attribute), 236 tribute), 129
id ([Link] attribute), 237 input_message_content (InlineQueryResultAudio at-
id (telegram.InlineQueryResultMpeg4Gif attribute), tribute), 130
238 input_message_content (InlineQueryResultCachedAu-
id ([Link] attribute), 239 dio attribute), 131
id ([Link] attribute), 240 input_message_content (InlineQueryResultCached-
id ([Link] attribute), 241 Document attribute), 132
id ([Link] attribute), 243 input_message_content (InlineQueryResultCachedGif
id ([Link] attribute), 270 attribute), 133
id ([Link] attribute), 269 input_message_content (InlineQueryResultCachedM-
id ([Link] attribute), 272 peg4Gif attribute), 134
id ([Link] attribute), 262 input_message_content (InlineQueryResultCached-
id (User attribute), 121 Photo attribute), 134
idle() ([Link] method), 4 input_message_content (InlineQueryResultCached-
inline_keyboard (InlineKeyboardMarkup attribute), Sticker attribute), 135
103 input_message_content (InlineQueryResultCached-
inline_keyboard ([Link] at- Video attribute), 136
tribute), 225 input_message_content (InlineQueryResultCached-
inline_message_id (CallbackQuery attribute), 91 Voice attribute), 137
inline_message_id (ChosenInlineResult attribute), 149 input_message_content (InlineQueryResultContact at-
tribute), 138

Index 289
Python Telegram Bot Documentation, Release 9.0.0

input_message_content (InlineQueryResultDocument input_message_content (tele-


attribute), 139 gram.InlineQueryResultMpeg4Gif attribute),
input_message_content (InlineQueryResultGif at- 239
tribute), 140 input_message_content (tele-
input_message_content (InlineQueryResultLocation at- [Link] attribute),
tribute), 141 240
input_message_content (InlineQueryResultMpeg4Gif input_message_content (tele-
attribute), 143 [Link] attribute),
input_message_content (InlineQueryResultPhoto at- 241
tribute), 144 input_message_content (tele-
input_message_content (InlineQueryResultVenue at- [Link] attribute),
tribute), 145 242
input_message_content (InlineQueryResultVideo at- input_message_content (tele-
tribute), 146 [Link] attribute),
input_message_content (InlineQueryResultVoice at- 243
tribute), 147 InputContactMessageContent (class in telegram), 149
input_message_content (tele- InputFile (class in telegram), 103
[Link] attribute), InputLocationMessageContent (class in telegram), 148
227 InputMedia (class in telegram), 104
input_message_content (tele- InputMediaPhoto (class in telegram), 104
[Link] attribute), InputMediaVideo (class in telegram), 104
228 InputMessageContent (class in telegram), 147
input_message_content (tele- InputTextMessageContent (class in telegram), 147
[Link] InputVenueMessageContent (class in telegram), 148
attribute), 229 interval ([Link] attribute), 12
input_message_content (tele- interval_seconds ([Link] attribute), 12
[Link] InvalidToken, 100
attribute), 230 InvertedFilter (class in [Link]), 11
input_message_content (tele- invite_link (Chat attribute), 93
[Link] attribute), invite_link ([Link] attribute), 215
230 Invoice (class in telegram), 150
input_message_content (tele- invoice (Message attribute), 108
gram.InlineQueryResultCachedMpeg4Gif invoice ([Link] attribute), 9
attribute), 231 invoice ([Link] attribute), 249
input_message_content (tele- invoice_payload (PreCheckoutQuery attribute), 155
[Link] at- invoice_payload (ShippingQuery attribute), 153
tribute), 232 invoice_payload (SuccessfulPayment attribute), 153
input_message_content (tele- invoice_payload ([Link] at-
[Link] tribute), 270
attribute), 232 invoice_payload ([Link] attribute),
input_message_content (tele- 272
[Link] at- invoice_payload ([Link] at-
tribute), 233 tribute), 268
input_message_content (tele- is_bot ([Link] attribute), 262
[Link] at- is_bot (User attribute), 121
tribute), 234 is_image() ([Link] static method), 103
input_message_content (tele- is_inputfile() ([Link] static method), 103
[Link] attribute), ITALIC ([Link] attribute), 117
235
input_message_content (tele- J
[Link] attribute), Job (class in [Link]), 11
236 job_queue (Dispatcher attribute), 6
input_message_content (tele- job_queue ([Link] attribute), 12
[Link] attribute), job_queue (Updater attribute), 4
237 JobQueue (class in [Link]), 12
input_message_content (tele- jobs() ([Link] method), 13
[Link] attribute),
238

290 Index
Python Telegram Bot Documentation, Release 9.0.0

K length ([Link] attribute), 257


keyboard (ReplyKeyboardMarkup attribute), 118 length ([Link] attribute), 268
keyboard ([Link] attribute), length (VideoNote attribute), 124
259 live_period (InlineQueryResultLocation attribute), 141
KeyboardButton (class in telegram), 105 live_period ([Link] at-
kick_chat_member() ([Link] method), 57 tribute), 238
kick_member() ([Link] method), 94 location (ChosenInlineResult attribute), 149
kickChatMember() ([Link] method), 57 Location (class in telegram), 106
KICKED ([Link] attribute), 97 location (InlineQuery attribute), 128
location (Message attribute), 107
L location ([Link] attribute), 219
location ([Link] attribute), 10
label (LabeledPrice attribute), 150
location ([Link] attribute), 225
label ([Link] attribute), 268
location ([Link] attribute), 248
LabeledPrice (class in telegram), 150
location ([Link] attribute), 263
language_code ([Link] attribute), 262
location (Venue attribute), 122
language_code (User attribute), 121
longitude (InlineQueryResultLocation attribute), 141
last_error_date ([Link] attribute), 265
longitude (InlineQueryResultVenue attribute), 144
last_error_date (WebhookInfo attribute), 125
longitude (InputLocationMessageContent attribute),
last_error_message ([Link] attribute),
148
265
longitude (InputVenueMessageContent attribute), 148
last_error_message (WebhookInfo attribute), 125
longitude (Location attribute), 106
last_name (Chat attribute), 93
longitude ([Link] at-
last_name (Contact attribute), 99
tribute), 237
last_name (InlineQueryResultContact attribute), 137
longitude ([Link] attribute),
last_name (InputContactMessageContent attribute),
240
149
longitude ([Link] at-
last_name ([Link] attribute), 58
tribute), 245
last_name ([Link] attribute), 214
longitude ([Link]
last_name ([Link] attribute), 222
attribute), 246
last_name ([Link] at-
longitude ([Link] attribute), 247
tribute), 234
last_name ([Link] at-
tribute), 244
M
last_name ([Link] attribute), 262 MARKDOWN ([Link] attribute), 117
last_name (User attribute), 121 mask_position (Sticker attribute), 126
latitude (InlineQueryResultLocation attribute), 141 mask_position ([Link] attribute), 260
latitude (InlineQueryResultVenue attribute), 144 MaskPosition (class in telegram), 127
latitude (InputLocationMessageContent attribute), 148 MAX_CAPTION_LENGTH (in module tele-
latitude (InputVenueMessageContent attribute), 148 [Link]), 98
latitude (Location attribute), 106 max_connections ([Link] attribute),
latitude ([Link] at- 265
tribute), 237 max_connections (WebhookInfo attribute), 125
latitude ([Link] attribute), MAX_FILESIZE_DOWNLOAD (in module tele-
240 [Link]), 98
latitude ([Link] at- MAX_FILESIZE_UPLOAD (in module tele-
tribute), 245 [Link]), 98
latitude ([Link] at- MAX_INLINE_QUERY_RESULTS (in module tele-
tribute), 246 [Link]), 98
latitude ([Link] attribute), 247 MAX_MESSAGE_ENTITIES (in module tele-
leave() ([Link] method), 94 [Link]), 98
leave_chat() ([Link] method), 58 MAX_MESSAGE_LENGTH (in module tele-
leaveChat() ([Link] method), 58 [Link]), 98
LEFT ([Link] attribute), 97 MAX_MESSAGES_PER_MINUTE_PER_GROUP
left_chat_member (Message attribute), 108 (in module [Link]), 98
left_chat_member ([Link] at- MAX_MESSAGES_PER_SECOND (in module tele-
tribute), 10 [Link]), 98
left_chat_member ([Link] attribute), 248 MAX_MESSAGES_PER_SECOND_PER_CHAT (in
length (MessageEntity attribute), 116 module [Link]), 98

Index 291
Python Telegram Bot Documentation, Release 9.0.0

media (InputMediaPhoto attribute), 104 mpeg4_file_id (InlineQueryResultCachedMpeg4Gif at-


media (InputMediaVideo attribute), 104 tribute), 133
media ([Link] attribute), 275 mpeg4_file_id (telegram.InlineQueryResultCachedMpeg4Gif
media ([Link] attribute), 275 attribute), 231
media_group_id (Message attribute), 107 mpeg4_height (InlineQueryResultMpeg4Gif attribute),
media_group_id ([Link] attribute), 248 142
MEMBER ([Link] attribute), 97 mpeg4_height (telegram.InlineQueryResultMpeg4Gif
MENTION ([Link] attribute), 117 attribute), 239
mention_html() (in module [Link]), 3 mpeg4_url (InlineQueryResultMpeg4Gif attribute),
mention_html() ([Link] method), 122 142
mention_markdown() (in module tele- mpeg4_url (telegram.InlineQueryResultMpeg4Gif at-
[Link]), 3 tribute), 238
mention_markdown() ([Link] method), 122 mpeg4_width (InlineQueryResultMpeg4Gif attribute),
MergedFilter (class in [Link]), 11 142
message (CallbackQuery attribute), 90 mpeg4_width (telegram.InlineQueryResultMpeg4Gif
Message (class in telegram), 106 attribute), 238
message ([Link] attribute), 220
message ([Link] attribute), 261 N
message (Update attribute), 120 name (DelayQueue attribute), 16
message_id (Message attribute), 106 name (Job attribute), 12
message_id ([Link] attribute), 247 name (OrderInfo attribute), 152
message_text (InputTextMessageContent attribute), name (StickerSet attribute), 126
148 name ([Link] attribute), 58
message_text ([Link] at- name ([Link] attribute), 8
tribute), 245 name ([Link] attribute), 271
message_updates (MessageHandler attribute), 26 name ([Link] attribute), 274
MessageEntity (class in telegram), 116 name ([Link] attribute), 122
MessageHandler (class in [Link]), 25 NetworkError, 100
MessageQueue (class in [Link]), 15 new_chat_member ([Link] attribute), 112
migrate ([Link] attribute), 10 new_chat_members (Message attribute), 107
migrate_from_chat_id (Message attribute), 108 new_chat_members ([Link] at-
migrate_from_chat_id ([Link] attribute), tribute), 10
249 new_chat_members ([Link] attribute), 248
migrate_to_chat_id (Message attribute), 108 new_chat_photo (Message attribute), 108
migrate_to_chat_id ([Link] attribute), 249 new_chat_photo ([Link] attribute),
mime_type (Animation attribute), 157 10
mime_type (Audio attribute), 34 new_chat_photo ([Link] attribute), 248
mime_type (Document attribute), 99 new_chat_title (Message attribute), 108
mime_type (InlineQueryResultDocument attribute), new_chat_title ([Link] attribute), 10
139 new_chat_title ([Link] attribute), 248
mime_type (InlineQueryResultVideo attribute), 145
mime_type ([Link] attribute), 266 O
mime_type ([Link] attribute), 158 offset (InlineQuery attribute), 128
mime_type ([Link] attribute), 222 offset (MessageEntity attribute), 116
mime_type ([Link] at- offset ([Link] attribute), 225
tribute), 235 offset ([Link] attribute), 257
mime_type ([Link] at- one_time_keyboard (ReplyKeyboardMarkup attribute),
tribute), 242 118
mime_type ([Link] attribute), 264 one_time_keyboard ([Link]
mime_type ([Link] attribute), 264 attribute), 259
mime_type (Video attribute), 123 order_info (PreCheckoutQuery attribute), 155
mime_type (Voice attribute), 124 order_info (SuccessfulPayment attribute), 153
MOUTH ([Link] attribute), 127 order_info ([Link] attribute), 270
mpeg4_duration (InlineQueryResultMpeg4Gif at- order_info ([Link] attribute), 269
tribute), 142 OrderInfo (class in telegram), 152
mpeg4_duration (tele-
gram.InlineQueryResultMpeg4Gif attribute), P
239
parse_caption_entities() ([Link] method),

292 Index
Python Telegram Bot Documentation, Release 9.0.0

112 pass_update_queue (ShippingQueryHandler attribute),


parse_caption_entity() ([Link] method), 30
112 pass_update_queue (StringCommandHandler at-
parse_entities() ([Link] method), 112 tribute), 31
parse_entity() ([Link] method), 113 pass_update_queue (StringRegexHandler attribute), 32
parse_mode (InputTextMessageContent attribute), 148 pass_update_queue (TypeHandler attribute), 33
parse_mode ([Link] at- pass_user_data (CallbackQueryHandler attribute), 19
tribute), 245 pass_user_data (ChosenInlineResultHandler attribute),
parse_text_entities() ([Link] method), 156 20
parse_text_entity() ([Link] method), 156 pass_user_data (CommandHandler attribute), 23
ParseMode (class in telegram), 117 pass_user_data (Handler attribute), 17
pass_args (CommandHandler attribute), 23 pass_user_data (InlineQueryHandler attribute), 24
pass_args (StringCommandHandler attribute), 31 pass_user_data (MessageHandler attribute), 26
pass_chat_data (CallbackQueryHandler attribute), 19 pass_user_data (PreCheckoutQueryHandler attribute),
pass_chat_data (ChosenInlineResultHandler attribute), 27
20 pass_user_data (RegexHandler attribute), 28
pass_chat_data (CommandHandler attribute), 23 pass_user_data (ShippingQueryHandler attribute), 30
pass_chat_data (Handler attribute), 17 pattern (CallbackQueryHandler attribute), 18
pass_chat_data (InlineQueryHandler attribute), 24 pattern (InlineQueryHandler attribute), 24
pass_chat_data (MessageHandler attribute), 26 pattern (RegexHandler attribute), 28
pass_chat_data (PreCheckoutQueryHandler attribute), pattern (StringRegexHandler attribute), 32
27 pay (InlineKeyboardButton attribute), 102
pass_chat_data (RegexHandler attribute), 29 pay ([Link] attribute), 224
pass_chat_data (ShippingQueryHandler attribute), 30 pending_update_count ([Link] at-
pass_groupdict (CallbackQueryHandler attribute), 19 tribute), 265
pass_groupdict (InlineQueryHandler attribute), 24 pending_update_count (WebhookInfo attribute), 125
pass_groupdict (RegexHandler attribute), 28 per_chat (ConversationHandler attribute), 21
pass_groupdict (StringRegexHandler attribute), 32 per_message (ConversationHandler attribute), 22
pass_groups (CallbackQueryHandler attribute), 18 per_user (ConversationHandler attribute), 21
pass_groups (InlineQueryHandler attribute), 24 performer (Audio attribute), 34
pass_groups (RegexHandler attribute), 28 performer (InlineQueryResultAudio attribute), 130
pass_groups (StringRegexHandler attribute), 32 performer ([Link] attribute), 158
pass_job_queue (CallbackQueryHandler attribute), 18 performer ([Link] at-
pass_job_queue (ChosenInlineResultHandler attribute), tribute), 228
20 phone_number (Contact attribute), 99
pass_job_queue (CommandHandler attribute), 23 phone_number (InlineQueryResultContact attribute),
pass_job_queue (Handler attribute), 17 137
pass_job_queue (InlineQueryHandler attribute), 24 phone_number (InputContactMessageContent at-
pass_job_queue (MessageHandler attribute), 26 tribute), 149
pass_job_queue (PreCheckoutQueryHandler attribute), phone_number (OrderInfo attribute), 152
27 phone_number ([Link] attribute), 222
pass_job_queue (RegexHandler attribute), 28 phone_number ([Link] at-
pass_job_queue (ShippingQueryHandler attribute), 30 tribute), 234
pass_job_queue (StringCommandHandler attribute), 31 phone_number ([Link]
pass_job_queue (StringRegexHandler attribute), 32 attribute), 244
pass_job_queue (TypeHandler attribute), 33 phone_number ([Link] attribute), 271
pass_update_queue (CallbackQueryHandler attribute), photo (Chat attribute), 93
18 photo (Game attribute), 156
pass_update_queue (ChosenInlineResultHandler photo (Message attribute), 107
attribute), 20 photo ([Link] attribute), 214
pass_update_queue (CommandHandler attribute), 23 photo ([Link] attribute), 10
pass_update_queue (Handler attribute), 17 photo ([Link] attribute), 266
pass_update_queue (InlineQueryHandler attribute), 24 photo ([Link] attribute), 248
pass_update_queue (MessageHandler attribute), 26 photo_file_id (InlineQueryResultCachedPhoto at-
pass_update_queue (PreCheckoutQueryHandler tribute), 134
attribute), 27 photo_file_id ([Link]
pass_update_queue (RegexHandler attribute), 28 attribute), 232
photo_height (InlineQueryResultPhoto attribute), 143

Index 293
Python Telegram Bot Documentation, Release 9.0.0

photo_height ([Link] remove_handler() ([Link] method), 7


attribute), 240 remove_keyboard (ReplyKeyboardRemove attribute),
photo_url (InlineQueryResultPhoto attribute), 143 118
photo_url ([Link] attribute), remove_keyboard ([Link]
239 attribute), 258
photo_width (InlineQueryResultPhoto attribute), 143 removed ([Link] attribute), 12
photo_width ([Link] at- repeat ([Link] attribute), 12
tribute), 240 reply ([Link] attribute), 10
photos ([Link] attribute), 263 reply_audio() ([Link] method), 113
photos (UserProfilePhotos attribute), 122 reply_contact() ([Link] method), 113
PhotoSize (class in telegram), 117 reply_document() ([Link] method), 113
pin_chat_message() ([Link] method), 59 reply_location() ([Link] method), 114
pinChatMessage() ([Link] method), 58 reply_markup (InlineQueryResultArticle attribute), 129
pinned_message (Chat attribute), 93 reply_markup (InlineQueryResultAudio attribute), 130
pinned_message (Message attribute), 108 reply_markup (InlineQueryResultCachedAudio at-
pinned_message ([Link] attribute), 215 tribute), 131
pinned_message ([Link] attribute), reply_markup (InlineQueryResultCachedDocument at-
10 tribute), 132
pinned_message ([Link] attribute), 249 reply_markup (InlineQueryResultCachedGif attribute),
point (MaskPosition attribute), 127 133
point ([Link] attribute), 274 reply_markup (InlineQueryResultCachedMpeg4Gif at-
position (GameHighScore attribute), 158 tribute), 134
position ([Link] attribute), 267 reply_markup (InlineQueryResultCachedPhoto at-
post_code (ShippingAddress attribute), 151 tribute), 134
post_code ([Link] attribute), 270 reply_markup (InlineQueryResultCachedSticker
PRE ([Link] attribute), 117 attribute), 135
pre_checkout_query ([Link] attribute), 261 reply_markup (InlineQueryResultCachedVideo at-
pre_checkout_query (Update attribute), 120 tribute), 136
PreCheckoutQuery (class in telegram), 154 reply_markup (InlineQueryResultCachedVoice at-
PreCheckoutQueryHandler (class in [Link]), 27 tribute), 137
prices (ShippingOption attribute), 152 reply_markup (InlineQueryResultContact attribute),
prices ([Link] attribute), 269 137
PRIVATE ([Link] attribute), 94 reply_markup (InlineQueryResultDocument attribute),
private ([Link] attribute), 10 139
process_update() ([Link] method), 7 reply_markup (InlineQueryResultGame attribute), 140
promote_chat_member() ([Link] method), 60 reply_markup (InlineQueryResultGif attribute), 140
promoteChatMember() ([Link] method), 59 reply_markup (InlineQueryResultLocation attribute),
provider_payment_charge_id (SuccessfulPayment at- 141
tribute), 153 reply_markup (InlineQueryResultMpeg4Gif attribute),
provider_payment_charge_id (tele- 142
[Link] attribute), 269 reply_markup (InlineQueryResultPhoto attribute), 144
put() ([Link] method), 13 reply_markup (InlineQueryResultVenue attribute), 145
reply_markup (InlineQueryResultVideo attribute), 146
Q reply_markup (InlineQueryResultVoice attribute), 147
query (ChosenInlineResult attribute), 150 reply_markup ([Link] at-
query (InlineQuery attribute), 128 tribute), 227
query ([Link] attribute), 219 reply_markup ([Link] at-
query ([Link] attribute), 225 tribute), 228
queue (JobQueue attribute), 12 reply_markup ([Link]
attribute), 229
R reply_markup ([Link]
RECORD_AUDIO ([Link] attribute), 95 attribute), 229
RECORD_VIDEO ([Link] attribute), 95 reply_markup ([Link]
RECORD_VIDEO_NOTE ([Link] at- attribute), 230
tribute), 95 reply_markup (telegram.InlineQueryResultCachedMpeg4Gif
RegexHandler (class in [Link]), 28 attribute), 231
remove_error_handler() ([Link] reply_markup ([Link]
method), 7 attribute), 232

294 Index
Python Telegram Bot Documentation, Release 9.0.0

reply_markup ([Link] run_daily() ([Link] method), 13


attribute), 232 run_once() ([Link] method), 13
reply_markup ([Link] run_repeating() ([Link] method), 14
attribute), 233 running ([Link] attribute), 7
reply_markup ([Link] running (Updater attribute), 4
attribute), 234
reply_markup ([Link] at- S
tribute), 234 scale (MaskPosition attribute), 127
reply_markup ([Link] scale ([Link] attribute), 274
attribute), 236 schedule_removal() ([Link] method), 12
reply_markup ([Link] at- score (GameHighScore attribute), 158
tribute), 243 score ([Link] attribute), 267
reply_markup ([Link] at- selective (ForceReply attribute), 101
tribute), 237 selective (ReplyKeyboardMarkup attribute), 118
reply_markup ([Link] at- selective (ReplyKeyboardRemove attribute), 118
tribute), 238 selective ([Link] attribute), 223
reply_markup (telegram.InlineQueryResultMpeg4Gif selective ([Link] attribute),
attribute), 239 259
reply_markup ([Link] at- selective ([Link] attribute),
tribute), 240 258
reply_markup ([Link] at- send_action() ([Link] method), 95
tribute), 241 send_audio() ([Link] method), 71
reply_markup ([Link] at- send_chat_action() ([Link] method), 72
tribute), 242 send_contact() ([Link] method), 72
reply_markup ([Link] at- send_document() ([Link] method), 73
tribute), 243 send_game() ([Link] method), 74
reply_photo() ([Link] method), 114 send_invoice() ([Link] method), 74
reply_sticker() ([Link] method), 114 send_location() ([Link] method), 75
reply_text() ([Link] method), 114 send_media_group() ([Link] method), 76
reply_to_message (Message attribute), 107 send_message() ([Link] method), 76
reply_to_message ([Link] attribute), 247 send_photo() ([Link] method), 77
reply_venue() ([Link] method), 114 send_sticker() ([Link] method), 77
reply_video() ([Link] method), 115 send_venue() ([Link] method), 78
reply_video_note() ([Link] method), 115 send_video() ([Link] method), 79
reply_voice() ([Link] method), 115 send_video_note() ([Link] method), 79
ReplyKeyboardMarkup (class in telegram), 118 send_voice() ([Link] method), 80
ReplyKeyboardRemove (class in telegram), 118 sendAudio() ([Link] method), 62
ReplyMarkup (class in telegram), 119 sendChatAction() ([Link] method), 63
request_contact (KeyboardButton attribute), 105 sendContact() ([Link] method), 63
request_contact ([Link] attribute), sendDocument() ([Link] method), 64
246 sendGame() ([Link] method), 64
request_location (KeyboardButton attribute), 105 sendInvoice() ([Link] method), 65
request_location ([Link] attribute), sendLocation() ([Link] method), 66
246 sendMediaGroup() ([Link] method), 66
resize_keyboard (ReplyKeyboardMarkup attribute), sendMessage() ([Link] method), 67
118 sendPhoto() ([Link] method), 67
resize_keyboard ([Link] at- sendSticker() ([Link] method), 68
tribute), 259 sendVenue() ([Link] method), 69
restrict_chat_member() ([Link] method), 61 sendVideo() ([Link] method), 69
restrictChatMember() ([Link] method), 61 sendVideoNote() ([Link] method), 70
RESTRICTED ([Link] attribute), 97 sendVoice() ([Link] method), 71
result_id (ChosenInlineResult attribute), 149 set_chat_description() ([Link] method), 84
result_id ([Link] attribute), 219 set_chat_photo() ([Link] method), 84
RetryAfter, 100 set_chat_sticker_set() ([Link] method), 85
run() ([Link] method), 17 set_chat_title() ([Link] method), 85
run() ([Link] method), 12 set_game_score() ([Link] method), 85
run_async() ([Link] method), 7 set_name (Sticker attribute), 126
run_async_timeout (ConversationHandler attribute), 21 set_name ([Link] attribute), 260

Index 295
Python Telegram Bot Documentation, Release 9.0.0

set_sticker_position_in_set() ([Link] method), stop() ([Link] method), 16


86 stop() ([Link] method), 6
set_webhook() ([Link] method), 86 stop_message_live_location() ([Link] method),
setChatDescription() ([Link] method), 81 88
setChatPhoto() ([Link] method), 81 stopMessageLiveLocation() ([Link] method), 87
setChatStickerSet() ([Link] method), 81 street_line1 (ShippingAddress attribute), 151
setChatTitle() ([Link] method), 82 street_line1 ([Link] attribute), 270
setGameScore() ([Link] method), 82 street_line2 (ShippingAddress attribute), 151
setStickerPositionInSet() ([Link] method), 83 street_line2 ([Link] attribute), 270
setWebhook() ([Link] method), 83 strict (TypeHandler attribute), 33
shipping_address (OrderInfo attribute), 152 StringCommandHandler (class in [Link]), 31
shipping_address (ShippingQuery attribute), 153 StringRegexHandler (class in [Link]), 32
shipping_address ([Link] attribute), 271 successful_payment (Message attribute), 108
shipping_address ([Link] attribute), successful_payment ([Link] at-
272 tribute), 11
shipping_option_id (PreCheckoutQuery attribute), 155 successful_payment ([Link] attribute), 249
shipping_option_id (SuccessfulPayment attribute), 153 SuccessfulPayment (class in telegram), 152
shipping_option_id ([Link] at- SUPERGROUP ([Link] attribute), 94
tribute), 270 supergroup_chat_created (Message attribute), 108
shipping_option_id ([Link] at- supergroup_chat_created ([Link] attribute),
tribute), 269 249
shipping_query ([Link] attribute), 261 SUPPORTED_WEBHOOK_PORTS (in module tele-
shipping_query (Update attribute), 120 [Link]), 98
ShippingAddress (class in telegram), 151 switch_inline_query (InlineKeyboardButton attribute),
ShippingOption (class in telegram), 152 102
ShippingQuery (class in telegram), 153 switch_inline_query ([Link]
ShippingQueryHandler (class in [Link]), 30 attribute), 224
small_file_id (ChatPhoto attribute), 98 switch_inline_query_current_chat (InlineKeyboard-
small_file_id ([Link] attribute), 273 Button attribute), 102
start() ([Link] method), 8 switch_inline_query_current_chat (tele-
start() ([Link] method), 15 [Link] attribute),
start() ([Link] method), 16 224
start_parameter (Invoice attribute), 150
start_parameter ([Link] attribute), 272 T
start_polling() ([Link] method), 5 [Link] (module), 98
start_webhook() ([Link] method), 5 [Link] (module), 100
state (ShippingAddress attribute), 151 [Link] (module), 8
state ([Link] attribute), 270 [Link] (module), 3
states (ConversationHandler attribute), 21 telegram_payment_charge_id (SuccessfulPayment at-
status (ChatMember attribute), 96 tribute), 153
status ([Link] attribute), 217 telegram_payment_charge_id (tele-
status_update ([Link] attribute), 10 [Link] attribute), 269
Sticker (class in telegram), 125 TelegramError, 100
sticker (Message attribute), 107 TelegramObject (class in telegram), 119
sticker ([Link] attribute), 10 text (Game attribute), 156
sticker ([Link] attribute), 248 text (InlineKeyboardButton attribute), 102
sticker_file_id (InlineQueryResultCachedSticker text (KeyboardButton attribute), 105
attribute), 135 text (Message attribute), 107
sticker_file_id ([Link] ([Link] attribute), 11
attribute), 232 text ([Link] attribute), 266
sticker_set_name (Chat attribute), 93 text ([Link] attribute), 224
sticker_set_name ([Link] attribute), 215 text ([Link] attribute), 246
stickers (StickerSet attribute), 126 text ([Link] attribute), 248
stickers ([Link] attribute), 274 text_entities (Game attribute), 156
StickerSet (class in telegram), 126 text_entities ([Link] attribute), 266
stop() ([Link] method), 17 text_html ([Link] attribute), 115
stop() ([Link] method), 8 text_html_urled ([Link] attribute), 115
stop() ([Link] method), 15 TEXT_LINK ([Link] attribute), 117

296 Index
Python Telegram Bot Documentation, Release 9.0.0

text_markdown ([Link] attribute), 116 thumb_url ([Link] at-


text_markdown_urled ([Link] attribute), tribute), 242
116 thumb_width (InlineQueryResultArticle attribute), 129
TEXT_MENTION ([Link] attribute), thumb_width (InlineQueryResultContact attribute), 138
117 thumb_width (InlineQueryResultDocument attribute),
thumb (Animation attribute), 157 139
thumb (Document attribute), 99 thumb_width (InlineQueryResultLocation attribute),
thumb (Sticker attribute), 126 141
thumb ([Link] attribute), 265 thumb_width (InlineQueryResultVenue attribute), 145
thumb ([Link] attribute), 222 thumb_width ([Link] at-
thumb ([Link] attribute), 260 tribute), 227
thumb ([Link] attribute), 264 thumb_width ([Link] at-
thumb ([Link] attribute), 268 tribute), 235
thumb (Video attribute), 123 thumb_width ([Link]
thumb (VideoNote attribute), 124 attribute), 236
thumb_height (InlineQueryResultArticle attribute), 129 thumb_width ([Link] at-
thumb_height (InlineQueryResultContact attribute), tribute), 238
138 thumb_width ([Link]
thumb_height (InlineQueryResultDocument attribute), attribute), 241
139 tick() ([Link] method), 15
thumb_height (InlineQueryResultLocation attribute), time_limit (DelayQueue attribute), 16
141 timed_out_behavior (ConversationHandler attribute),
thumb_height (InlineQueryResultVenue attribute), 145 21
thumb_height ([Link] at- TimedOut, 100
tribute), 227 title (Audio attribute), 34
thumb_height ([Link] at- title (Chat attribute), 93
tribute), 235 title (Game attribute), 156
thumb_height ([Link] title (InlineQueryResultArticle attribute), 129
attribute), 236 title (InlineQueryResultAudio attribute), 130
thumb_height ([Link] at- title (InlineQueryResultCachedDocument attribute),
tribute), 238 132
thumb_height ([Link] at- title (InlineQueryResultCachedGif attribute), 133
tribute), 241 title (InlineQueryResultCachedMpeg4Gif attribute),
thumb_url (InlineQueryResultArticle attribute), 129 133
thumb_url (InlineQueryResultContact attribute), 138 title (InlineQueryResultCachedPhoto attribute), 134
thumb_url (InlineQueryResultDocument attribute), 139 title (InlineQueryResultCachedVideo attribute), 136
thumb_url (InlineQueryResultGif attribute), 140 title (InlineQueryResultCachedVoice attribute), 137
thumb_url (InlineQueryResultLocation attribute), 141 title (InlineQueryResultDocument attribute), 138
thumb_url (InlineQueryResultMpeg4Gif attribute), 142 title (InlineQueryResultGif attribute), 140
thumb_url (InlineQueryResultPhoto attribute), 143 title (InlineQueryResultLocation attribute), 141
thumb_url (InlineQueryResultVenue attribute), 145 title (InlineQueryResultMpeg4Gif attribute), 142
thumb_url (InlineQueryResultVideo attribute), 146 title (InlineQueryResultPhoto attribute), 143
thumb_url ([Link] at- title (InlineQueryResultVenue attribute), 144
tribute), 227 title (InlineQueryResultVideo attribute), 146
thumb_url ([Link] at- title (InlineQueryResultVoice attribute), 147
tribute), 235 title (InputVenueMessageContent attribute), 148
thumb_url ([Link] at- title (Invoice attribute), 150
tribute), 236 title (ShippingOption attribute), 152
thumb_url ([Link] attribute), title (StickerSet attribute), 126
237 title ([Link] attribute), 158
thumb_url ([Link] title ([Link] attribute), 214
attribute), 238 title ([Link] attribute), 266
thumb_url (telegram.InlineQueryResultMpeg4Gif at- title ([Link] attribute), 227
tribute), 239 title ([Link] attribute), 228
thumb_url ([Link] at- title ([Link] at-
tribute), 239 tribute), 229
thumb_url ([Link] at- title ([Link] attribute),
tribute), 241 230

Index 297
Python Telegram Bot Documentation, Release 9.0.0

title (telegram.InlineQueryResultCachedMpeg4Gif at- type (InlineQueryResultMpeg4Gif attribute), 142


tribute), 231 type (InlineQueryResultPhoto attribute), 143
title ([Link] at- type (InlineQueryResultVenue attribute), 144
tribute), 232 type (InlineQueryResultVideo attribute), 145
title ([Link] at- type (InlineQueryResultVoice attribute), 147
tribute), 233 type (InputMediaPhoto attribute), 104
title ([Link] at- type (InputMediaVideo attribute), 104
tribute), 234 type (MessageEntity attribute), 116
title ([Link] attribute), type ([Link] attribute), 214
235 type ([Link] attribute), 226
title ([Link] attribute), 237 type ([Link] attribute), 227
title ([Link] attribute), type ([Link] attribute), 228
237 type ([Link] at-
title (telegram.InlineQueryResultMpeg4Gif attribute), tribute), 229
239 type ([Link] at-
title ([Link] attribute), 240 tribute), 229
title ([Link] attribute), 241 type ([Link] attribute),
title ([Link] attribute), 242 230
title ([Link] attribute), 243 type (telegram.InlineQueryResultCachedMpeg4Gif at-
title ([Link] attribute), tribute), 231
246 type ([Link] at-
title ([Link] attribute), 272 tribute), 231
title ([Link] attribute), 269 type ([Link]
title ([Link] attribute), 274 attribute), 232
title ([Link] attribute), 263 type ([Link] at-
title (Venue attribute), 122 tribute), 233
to_form() ([Link] method), 103 type ([Link] at-
to_json() ([Link] method), 119 tribute), 234
to_timestamp() (in module [Link]), 3 type ([Link] attribute),
total_amount (Invoice attribute), 151 234
total_amount (PreCheckoutQuery attribute), 154 type ([Link] attribute),
total_amount (SuccessfulPayment attribute), 153 235
total_amount ([Link] attribute), 272 type ([Link] attribute), 243
total_amount ([Link] attribute), type ([Link] attribute), 236
270 type ([Link] attribute),
total_amount ([Link] attribute), 237
268 type (telegram.InlineQueryResultMpeg4Gif attribute),
total_count ([Link] attribute), 263 238
total_count (UserProfilePhotos attribute), 122 type ([Link] attribute), 239
type (Chat attribute), 92 type ([Link] attribute), 240
type (InlineQueryResult attribute), 129 type ([Link] attribute), 241
type (InlineQueryResultArticle attribute), 129 type ([Link] attribute), 243
type (InlineQueryResultAudio attribute), 130 type ([Link] attribute), 275
type (InlineQueryResultCachedAudio attribute), 131 type ([Link] attribute), 275
type (InlineQueryResultCachedDocument attribute), type ([Link] attribute), 257
132 type (TypeHandler attribute), 33
type (InlineQueryResultCachedGif attribute), 133 TypeHandler (class in [Link]), 33
type (InlineQueryResultCachedMpeg4Gif attribute), TYPING ([Link] attribute), 95
133
type (InlineQueryResultCachedPhoto attribute), 134 U
type (InlineQueryResultCachedSticker attribute), 135 Unauthorized, 100
type (InlineQueryResultCachedVideo attribute), 136 unban_chat_member() ([Link] method), 88
type (InlineQueryResultCachedVoice attribute), 136 unban_member() ([Link] method), 95
type (InlineQueryResultContact attribute), 137 unbanChatMember() ([Link] method), 88
type (InlineQueryResultDocument attribute), 138 unpin_chat_message() ([Link] method), 89
type (InlineQueryResultGame attribute), 139 unpinChatMessage() ([Link] method), 89
type (InlineQueryResultGif attribute), 140 until_date (ChatMember attribute), 96
type (InlineQueryResultLocation attribute), 141 until_date ([Link] attribute), 217

298 Index
Python Telegram Bot Documentation, Release 9.0.0

Update (class in telegram), 119 video_height (InlineQueryResultVideo attribute), 146


update_id ([Link] attribute), 261 video_height ([Link]
update_id (Update attribute), 120 attribute), 242
update_queue (Dispatcher attribute), 6 video_note (Message attribute), 107
update_queue (Updater attribute), 4 video_note ([Link] attribute), 248
Updater (class in [Link]), 4 video_url (InlineQueryResultVideo attribute), 145
UPLOAD_AUDIO ([Link] attribute), 95 video_url ([Link] attribute),
UPLOAD_DOCUMENT ([Link] at- 242
tribute), 95 video_width (InlineQueryResultVideo attribute), 146
UPLOAD_PHOTO ([Link] attribute), 95 video_width ([Link] at-
upload_sticker_file() ([Link] method), 90 tribute), 242
UPLOAD_VIDEO ([Link] attribute), 95 VideoNote (class in telegram), 124
UPLOAD_VIDEO_NOTE ([Link] at- Voice (class in telegram), 124
tribute), 95 voice (Message attribute), 107
uploadStickerFile() ([Link] method), 89 voice ([Link] attribute), 11
url (InlineKeyboardButton attribute), 102 voice ([Link] attribute), 248
url (InlineQueryResultArticle attribute), 129 voice_duration (InlineQueryResultVoice attribute), 147
url (MessageEntity attribute), 116 voice_duration ([Link] at-
url ([Link] attribute), 224 tribute), 243
url ([Link] attribute), 227 voice_file_id (InlineQueryResultCachedVoice at-
URL ([Link] attribute), 117 tribute), 137
url ([Link] attribute), 257 voice_file_id ([Link]
url ([Link] attribute), 265 attribute), 234
url (WebhookInfo attribute), 125 voice_url (InlineQueryResultVoice attribute), 147
user (ChatMember attribute), 96 voice_url ([Link] attribute),
User (class in telegram), 121 243
user (GameHighScore attribute), 158
user (MessageEntity attribute), 116 W
user ([Link] attribute), 217 WebhookInfo (class in telegram), 125
user ([Link] attribute), 267 width (InputMediaVideo attribute), 104
user ([Link] attribute), 257 width (PhotoSize attribute), 117
user_data ([Link] attribute), 8 width (Sticker attribute), 125
user_id (Contact attribute), 99 width ([Link] attribute), 275
user_id ([Link] attribute), 222 width ([Link] attribute), 258
user_sig_handler (Updater attribute), 4 width ([Link] attribute), 259
username (Chat attribute), 93 width ([Link] attribute), 264
username ([Link] attribute), 90 width (Video attribute), 123
username ([Link] attribute), 214 workers (Dispatcher attribute), 6
username ([Link] attribute), 262
username (User attribute), 121 X
UserProfilePhotos (class in telegram), 122 x_shift (MaskPosition attribute), 127
x_shift ([Link] attribute), 274
V
Venue (class in telegram), 122 Y
venue (Message attribute), 107 y_shift (MaskPosition attribute), 127
venue ([Link] attribute), 11 y_shift ([Link] attribute), 274
venue ([Link] attribute), 248
Video (class in telegram), 123
video (Message attribute), 107
video ([Link] attribute), 11
video ([Link] attribute), 248
video_duration (InlineQueryResultVideo attribute), 146
video_duration ([Link] at-
tribute), 242
video_file_id (InlineQueryResultCachedVideo at-
tribute), 136
video_file_id ([Link]
attribute), 233

Index 299

You might also like