Types

Users & Chats

User This object represents a Telegram user or bot.
UserStatus This object represents a User status (Last Seen privacy).
Chat This object represents a chat.
ChatPhoto This object represents a chat photo.
ChatMember This object contains information about one member of a chat.
ChatMembers This object contains information about the members list of a chat.
Dialog This object represents a dialog.
Dialogs This object represents a user’s dialogs chunk

Messages & Media

Message This object represents a message.
Messages This object represents a chat’s messages.
MessageEntity This object represents one special entity in a text message.
Photo This object represents a Photo.
PhotoSize This object represents one size of a photo or a file/sticker thumbnail.
UserProfilePhotos This object represents a user’s profile pictures.
Audio This object represents an audio file to be treated as music by the Telegram clients.
Document This object represents a general file (as opposed to photos, voice messages, audio files, …).
Animation This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
Video This object represents a video file.
Voice This object represents a voice note.
VideoNote This object represents a video message (available in Telegram apps as of v.4.0).
Contact This object represents a phone contact.
Location This object represents a point on the map.
Venue This object represents a venue.
Sticker This object represents a sticker.

Bots

ReplyKeyboardMarkup This object represents a custom keyboard with reply options.
KeyboardButton This object represents one button of the reply keyboard.
ReplyKeyboardRemove Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard.
InlineKeyboardMarkup This object represents an inline keyboard that appears right next to the message it belongs to.
InlineKeyboardButton This object represents one button of an inline keyboard.
ForceReply 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’).
CallbackQuery This object represents an incoming callback query from a callback button in an inline keyboard.

Input Media

InputMediaPhoto This object represents a photo to be sent inside an album.
InputMediaVideo This object represents a video to be sent inside an album.
InputMediaAudio This object represents a video to be sent inside an album.
InputMediaAnimation This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
InputMediaDocument This object represents a general file to be sent.
InputPhoneContact This object represents a Phone Contact to be added in your Telegram address book.
class pyrogram.User(id: int, is_self: bool, is_contact: bool, is_mutual_contact: bool, is_deleted: bool, is_bot: bool, first_name: str, status=None, last_name: str = None, username: str = None, language_code: str = None, phone_number: str = None, photo=None, restriction_reason: str = None)

This object represents a Telegram user or bot.

Parameters:
  • id (int) – Unique identifier for this user or bot.
  • is_self (bool) – True, if this user is you yourself.
  • is_contact (bool) – True, if this user is in your contacts.
  • is_mutual_contact (bool) – True, if you both have each other’s contact.
  • is_deleted (bool) – True, if this user is deleted.
  • is_bot (bool) – True, if this user is a bot.
  • first_name (str) – User’s or bot’s first name.
  • status (UserStatus, optional) – User’s Last Seen status. Empty for bots.
  • 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.
  • phone_number (str, optional) – User’s phone number.
  • photo (ChatPhoto, optional) – User’s or bot’s current profile photo. Suitable for downloads only.
  • restriction_reason (str, optional) – The reason why this bot might be unavailable to some users.
class pyrogram.UserStatus(user_id: int = None, online: bool = None, offline: bool = None, date: int = None, recently: bool = None, within_week: bool = None, within_month: bool = None, long_time_ago: bool = None)

This object represents a User status (Last Seen privacy).

Note

You won’t see exact last seen timestamps for people with whom you don’t share your own. Instead, you get “recently”, “within_week”, “within_month” or “long_time_ago” fields set.

Parameters:
  • user_id (int, optional) – User’s id. Only available for incoming UserStatus updates.
  • online (bool, optional) – True if the user is online in this very moment, None otherwise. If True, the “date” field will be also set containing the online expiration date (i.e.: the date when a user will automatically go offline in case of no action by his client).
  • offline (bool, optional) – True if the user is offline in this moment and has the Last Seen privacy setting public, None otherwise. If True, the “date” field will be also set containing the last seen date (i.e.: the date when a user was online the last time).
  • date (int, optional) – Exact date in unix time. Available only in case “online” or “offline” equals to True.
  • recently (bool, optional) – True for users with hidden Last Seen privacy that have been online between 1 second and 2-3 days ago, None otherwise.
  • within_week (bool, optional) – True for users with hidden Last Seen privacy that have been online between 2-3 and seven days ago, None otherwise.
  • within_month (bool, optional) – True for users with hidden Last Seen privacy that have been online between 6-7 days and a month ago, None otherwise.
  • long_time_ago (bool, optional) – True for users with hidden Last Seen privacy that have been online more than a month ago (this is also always shown to blocked users), None otherwise.
class pyrogram.Chat(id: int, type: str, title: str = None, username: str = None, first_name: str = None, last_name: str = None, all_members_are_administrators: bool = None, photo=None, description: str = None, invite_link: str = None, pinned_message=None, sticker_set_name: str = None, can_set_sticker_set: bool = None, members_count: int = None, restriction_reason: str = None)

This object represents a chat.

Parameters:
  • id (int) – Unique identifier for this chat.
  • type (str) – Type of chat, can be either “private”, “group”, “supergroup” or “channel”.
  • title (str, optional) – Title, for supergroups, channels and basic 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 basic group has “All Members Are Admins” enabled.
  • photo (ChatPhoto, optional) – Chat photo. Suitable for downloads only.
  • description (str, optional) – Description, for supergroups and channel chats. Returned only in get_chat().
  • invite_link (str, optional) – Chat invite link, for supergroups and channel chats. Returned only in get_chat().
  • pinned_message (Message, optional) – Pinned message, for supergroups and channel chats. Returned only in get_chat().
  • 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 group sticker set can be changed by you. Returned only in get_chat().
  • members_count (int, optional) – Chat members count, for groups and channels only.
  • restriction_reason (str, optional) – The reason why this chat might be unavailable to some users.
class pyrogram.ChatPhoto(small_file_id: str, big_file_id: str)

This object represents a 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.
class pyrogram.ChatMember(user, status: str, until_date: int = None, can_be_edited: bool = None, can_change_info: bool = None, can_post_messages: bool = None, can_edit_messages: bool = None, can_delete_messages: bool = None, can_invite_users: bool = None, can_restrict_members: bool = None, can_pin_messages: bool = None, can_promote_members: bool = None, can_send_messages: bool = None, can_send_media_messages: bool = None, can_send_other_messages: bool = None, can_add_web_page_previews: bool = None)

This object contains information about one member of a chat.

Parameters:
  • user (User) – Information about the user.
  • status (str) – The member’s status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked”.
  • until_date (int, optional) – Restricted and kicked only. Date when restrictions will be lifted for this user, unix time.
  • 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 administrator can change the chat title, photo and other settings.
  • can_post_messages (bool, optional) – Administrators only. True, if the administrator can post in the channel, channels only.
  • can_edit_messages (bool, optional) – Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only.
  • can_delete_messages (bool, optional) – Administrators only. True, if the administrator can delete messages of other users.
  • can_invite_users (bool, optional) – Administrators only. True, if the administrator can invite new users to the chat.
  • can_restrict_members (bool, optional) – Administrators only. True, if the administrator can restrict, ban or unban chat members.
  • can_pin_messages (bool, optional) – Administrators only. True, if the administrator can pin messages, supergroups only.
  • can_promote_members (bool, optional) – Administrators only. 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 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.
class pyrogram.ChatMembers(total_count: int, chat_members: list)

This object contains information about the members list of a chat.

Parameters:
  • total_count (int) – Total number of members the chat has.
  • chat_members (List of ChatMember) – Requested chat members.
class pyrogram.Dialog(chat, top_message, unread_messages_count: int, unread_mentions_count: int, unread_mark: bool, is_pinned: bool)

This object represents a dialog.

Parameters:
  • chat (Chat) – Conversation the dialog belongs to.
  • top_message (Message) – The last message sent in the dialog at this time.
  • unread_messages_count (int) – Amount of unread messages in this dialogs.
  • unread_mentions_count (int) – Amount of unread messages containing a mention in this dialog.
  • unread_mark (bool) – True, if the dialog has the unread mark set.
  • is_pinned (bool) – True, if the dialog is pinned.
class pyrogram.Dialogs(total_count: int, dialogs: list)

This object represents a user’s dialogs chunk

Parameters:
  • total_count (int) – Total number of dialogs the user has.
  • dialogs (List of Dialog) – Requested dialogs.
class pyrogram.Message(message_id: int, client=None, date: int = None, chat=None, from_user=None, forward_from=None, forward_from_chat=None, forward_from_message_id: int = None, forward_signature: str = None, forward_date: int = None, reply_to_message=None, mentioned=None, empty=None, service=None, media=None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, text: str = None, entities: list = None, caption_entities: list = None, audio=None, document=None, photo=None, sticker=None, animation=None, video=None, voice=None, video_note=None, caption: str = None, contact=None, location=None, venue=None, new_chat_members: list = None, left_chat_member=None, new_chat_title: str = None, new_chat_photo=None, delete_chat_photo: bool = None, group_chat_created: bool = None, supergroup_chat_created: bool = None, channel_chat_created: bool = None, migrate_to_chat_id: int = None, migrate_from_chat_id: int = None, pinned_message=None, views: int = None, via_bot=None, outgoing: bool = None, matches: list = None, command: list = None, reply_markup=None)

This object represents a message.

Parameters:
  • message_id (int) – Unique message identifier inside this chat.
  • date (int, optional) – Date the message was sent in Unix time.
  • chat (Chat, optional) – Conversation the message belongs to.
  • from_user (User, optional) – Sender, empty for messages sent to channels.
  • forward_from (User, optional) – For forwarded messages, sender of the original message.
  • forward_from_chat (Chat, optional) – For messages forwarded from channels, information about the original channel.
  • forward_from_message_id (int, optional) – For messages forwarded from channels, identifier of the original message in the channel.
  • forward_signature (str, optional) – For messages forwarded from channels, signature of the post author if present.
  • forward_date (int, optional) – For forwarded messages, date the original message was sent in Unix time.
  • reply_to_message (Message, optional) – For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
  • mentioned (bool, optional) – The message contains a mention.
  • empty (bool, optional) – The message is empty. A message can be empty in case it was deleted or you tried to retrieve a message that doesn’t exist yet.
  • service (bool, optional) – The message is a service message. A service message has one and only one of these fields set: left_chat_member, new_chat_title, new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created, migrate_to_chat_id, migrate_from_chat_id, pinned_message.
  • media (bool optional) – The message is a media message. A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation, voice, video_note, contact, location, venue.
  • edit_date (int, optional) – Date the message was last edited in Unix time.
  • media_group_id (str, optional) – The unique identifier of a media message group this message belongs to.
  • author_signature (str, optional) – Signature of the post author for messages in channels.
  • text (str, optional) – For text messages, the actual UTF-8 text of the message, 0-4096 characters. If the message contains entities (bold, italic, …) you can access text.markdown or text.html to get the marked up message text. In case there is no entity, the fields will contain the same text as text.
  • entities (List of MessageEntity, optional) – For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text.
  • caption_entities (List of MessageEntity, optional) – For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption.
  • audio (Audio, optional) – Message is an audio file, information about the file.
  • document (Document, optional) – Message is a general file, information about the file.
  • photo (Photo, optional) – Message is a photo, information about the photo.
  • sticker (Sticker, optional) – Message is a sticker, information about the sticker.
  • animation (Animation, optional) – Message is an animation, information about the animation.
  • video (Video, optional) – Message is a video, information about the video.
  • voice (Voice, optional) – Message is a voice message, information about the file.
  • video_note (VideoNote, optional) – Message is a video note, information about the video message.
  • caption (str, optional) – Caption for the audio, document, photo, video or voice, 0-1024 characters. If the message contains caption entities (bold, italic, …) you can access caption.markdown or caption.html to get the marked up caption text. In case there is no caption entity, the fields will contain the same text as caption.
  • contact (Contact, optional) – Message is a shared contact, information about the contact.
  • location (Location, optional) – Message is a shared location, information about the location.
  • venue (Venue, optional) – Message is a venue, information about the venue.
  • new_chat_members (List of User, optional) – New members that were added to the group or supergroup and information about them (the bot itself may be one of these members).
  • left_chat_member (User, 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 (Photo, 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 supergroup 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, because bot can’t be a member of a channel when it is created. It can only be found in 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 supergroup 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 (Message, optional) – Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
  • views (int, optional) – Channel post views.
  • via_bot (User) – The information of the bot that generated the message from an inline query of a user.
  • outgoing (bool, optional) – Whether the message is incoming or outgoing. Messages received from other chats are incoming (outgoing is False). Messages sent from yourself to other chats are outgoing (outgoing is True). An exception is made for your own personal chat; messages sent there will be incoming.
  • matches (list, optional) – A list containing all Match Objects that match the text of this message. Only applicable when using Filters.regex.
  • command (list, optional) – A list containing the command and its arguments, if any. E.g.: “/start 1 2 3” would produce [“start”, “1”, “2”, “3”]. Only applicable when using Filters.command.
  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply, optional) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
reply(text: str, quote: bool = None, parse_mode: str = '', disable_web_page_preview: bool = None, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None)

Bound method reply of Message.

Use as a shortcut for:

client.send_message(
    chat_id=message.chat.id,
    text="hello",
    reply_to_message_id=message.message_id
)

Example

message.reply("hello", quote=True)
Parameters:
  • text (str) – Text of the message to be sent.
  • quote (bool, optional) – If True, the message will be sent as a reply to this message. If reply_to_message_id is passed, this parameter will be ignored. Defaults to True in group chats and False in private chats.
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your message. Defaults to Markdown.
  • 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 (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply, optional) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
Returns:

On success, the sent Message is returned.

Raises:

Error

edit(text: str, parse_mode: str = '', disable_web_page_preview: bool = None, reply_markup=None)

Bound method edit of Message

Use as a shortcut for:

client.edit_message_text(
    chat_id=message.chat.id,
    message_id=message.message_id,
    text="hello",
)

Example

message.edit("hello")
Parameters:
  • text (str) – New text of the message.
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your message. Defaults to Markdown.
  • disable_web_page_preview (bool, optional) – Disables link previews for links in this message.
  • reply_markup (InlineKeyboardMarkup, optional) – An InlineKeyboardMarkup object.
Returns:

On success, the edited Message is returned.

Raises:

Error in case of a Telegram RPC error.

forward(chat_id: int, disable_notification: bool = None)

Bound method forward of Message.

Use as a shortcut for:

client.forward_messages(
    chat_id=chat_id,
    from_chat_id=message.chat.id,
    message_ids=message.message_id,
)

Example

message.forward(chat_id)
Parameters:
  • chat_id (int | str) – Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use “me” or “self”. For a contact that exists in your Telegram address book you can use his phone number (str).
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
Returns:

On success, the forwarded Message is returned.

Raises:

Error

delete(revoke: bool = True)

Bound method delete of Message.

Use as a shortcut for:

client.delete_messages(
    chat_id=chat_id,
    message_ids=message.message_id
)

Example

message.delete()
Parameters:revoke (bool, optional) – Deletes messages on both parts. This is only for private cloud chats and normal groups, messages on channels and supergroups are always revoked (i.e.: deleted for everyone). Defaults to True.
Returns:True on success.
Raises:Error
click(x: int, y: int = None, quote: bool = None)

Bound method click of Message.

Use as a shortcut for clicking a button attached to the message instead of.

  • Clicking inline buttons:
client.request_callback_answer(
    chat_id=message.chat.id,
    message_id=message.message_id,
    callback_data=message.reply_markup[i][j].callback_data
)
  • Clicking normal buttons:
client.send_message(
    chat_id=message.chat.id,
    text=message.reply_markup[i][j].text
)

Example

This method can be used in three different ways:

  1. Pass one integer argument only (e.g.: .click(2), to click a button at index 2). Buttons are counted left to right, starting from the top.
  2. Pass two integer arguments (e.g.: .click(1, 0), to click a button at position (1, 0)). The origin (0, 0) is top-left.
  3. Pass one string argument only (e.g.: .click("Settings"), to click a button by using its label). Only the first matching button will be pressed.
Parameters:
  • x (int | str) – Used as integer index, integer abscissa (in pair with y) or as string label.
  • y (int, optional) – Used as ordinate only (in pair with x).
  • quote (bool, optional) – Useful for normal buttons only, where pressing it will result in a new message sent. If True, the message will be sent as a reply to this message. Defaults to True in group chats and False in private chats.
Returns:

  • The result of request_callback_answer() in case of inline callback button clicks.
  • The result of reply() in case of normal button clicks.
  • A string in case the inline button is an URL, switch_inline_query or switch_inline_query_current_chat button.

Raises:
  • Error
  • ValueError – If the provided index or position is out of range or the button label was not found
  • TimeoutError – If, after clicking an inline button, the bot fails to answer within 10 seconds
download(file_name: str = '', block: bool = True, progress: callable = None, progress_args: tuple = None)

Bound method download of Message.

Use as a shortcut for:

client.download_media(message)

Example

message.download()
Parameters:
  • file_name (str, optional) – A custom file_name to be used instead of the one provided by Telegram. By default, all files are downloaded in the downloads folder in your working directory. You can also specify a path for downloading files in a custom location: paths that end with “/” are considered directories. All non-existent folders will be created automatically.
  • block (bool, optional) – Blocks the code execution until the file has been downloaded. Defaults to True.
  • progress (callable) – Pass a callback function to view the download progress. The function must take (client, current, total, *args) as positional arguments (look at the section below for a detailed description).
  • progress_args (tuple) – Extra custom arguments for the progress callback function. Useful, for example, if you want to pass a chat_id and a message_id in order to edit a message with the updated progress.
Returns:

On success, the absolute path of the downloaded file as string is returned, None otherwise.

Raises:
  • Error
  • ValueError – If the message doesn’t contain any downloadable media
class pyrogram.Messages(total_count: int, messages: list)

This object represents a chat’s messages.

Parameters:
  • total_count (int) – Total number of messages the target chat has.
  • messages (List of Message) – Requested messages.
class pyrogram.MessageEntity(type: str, offset: int, length: int, url: str = None, user=None)

This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

Parameters:
  • type (str) – Type of the entity. Can be “mention” (@username), “hashtag”, “cashtag”, “bot_command”, “url”, “email”, “phone_number”, “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 user taps on the text.
  • user (User, optional) – For “text_mention” only, the mentioned user.
class pyrogram.Photo(id: str, date: int, sizes: list)

This object represents a Photo.

Parameters:
  • id (str) – Unique identifier for this photo.
  • date (int) – Date the photo was sent in Unix time.
  • sizes (List of PhotoSize) – Available sizes of this photo.
class pyrogram.PhotoSize(file_id: str, width: int, height: int, file_size: int)

This object represents one size of a photo or a file/sticker thumbnail.

Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Photo width.
  • height (int) – Photo height.
  • file_size (int) – File size.
class pyrogram.UserProfilePhotos(total_count: int, photos: list)

This object represents a user’s profile pictures.

Parameters:
  • total_count (int) – Total number of profile pictures the target user has.
  • photos (List of Photo) – Requested profile pictures.
class pyrogram.Audio(file_id: str, duration: int, thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None, performer: str = None, title: str = None)

This object represents an audio file to be treated as music by the Telegram clients.

Parameters:
  • file_id (str) – Unique identifier for this file.
  • duration (int) – Duration of the audio in seconds as defined by sender.
  • thumb (PhotoSize, optional) – Thumbnail of the music file album cover.
  • file_name (str, optional) – Audio file name.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the audio was sent in Unix time.
  • 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.
class pyrogram.Document(file_id: str, thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None)

This object represents a general file (as opposed to photos, voice messages, audio files, …).

Parameters:
  • file_id (str) – Unique file identifier.
  • thumb (PhotoSize, optional) – Document thumbnail as defined by sender.
  • file_name (str, optional) – Original filename as defined by sender.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the document was sent in Unix time.
class pyrogram.Animation(file_id: str, width: int, height: int, duration: int, thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None)

This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).

Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Animation width as defined by sender.
  • height (int) – Animation height as defined by sender.
  • duration (int) – Duration of the animation in seconds as defined by sender.
  • thumb (PhotoSize, optional) – Animation thumbnail.
  • file_name (str, optional) – Animation file name.
  • mime_type (str, optional) – Mime type of a file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the animation was sent in Unix time.
class pyrogram.Video(file_id: str, width: int, height: int, duration: int, thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None)

This object represents a video file.

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 (PhotoSize, optional) – Video thumbnail.
  • file_name (str, optional) – Video file name.
  • mime_type (str, optional) – Mime type of a file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the video was sent in Unix time.
class pyrogram.Voice(file_id: str, duration: int, waveform: bytes = None, mime_type: str = None, file_size: int = None, date: int = None)

This object represents a voice note.

Parameters:
  • file_id (str) – Unique identifier for this file.
  • duration (int) – Duration of the audio in seconds as defined by sender.
  • waveform (bytes, optional) – Voice waveform.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the voice was sent in Unix time.
class pyrogram.VideoNote(file_id: str, length: int, duration: int, thumb=None, mime_type: str = None, file_size: int = None, date: int = None)

This object represents a video message (available in Telegram apps as of v.4.0).

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 (PhotoSize, optional) – Video thumbnail.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the video note was sent in Unix time.
class pyrogram.Contact(phone_number: str, first_name: str, last_name: str = None, user_id: int = None, vcard: str = None)

This object represents a phone contact.

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.
  • vcard (str, optional) – Additional data about the contact in the form of a vCard.
class pyrogram.Location(longitude: float, latitude: float)

This object represents a point on the map.

Parameters:
  • longitude (float) – Longitude as defined by sender.
  • latitude (float) – Latitude as defined by sender.
class pyrogram.Venue(location, title: str, address: str, foursquare_id: str = None, foursquare_type: str = None)

This object represents a venue.

Parameters:
  • location (Location) – Venue location.
  • title (str) – Name of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (str, optional) – Foursquare identifier of the venue.
  • foursquare_type (str, optional) – Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
class pyrogram.Sticker(file_id: str, width: int, height: int, thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None, emoji: str = None, set_name: str = None, mask_position=None)

This object represents a sticker.

Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Sticker width.
  • height (int) – Sticker height.
  • thumb (PhotoSize, optional) – Sticker thumbnail in the .webp or .jpg format.
  • file_name (str, optional) – Sticker file name.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • date (int, optional) – Date the sticker was sent in Unix time.
  • emoji (str, optional) – Emoji associated with the sticker.
  • set_name (str, optional) – Name of the sticker set to which the sticker belongs.
class pyrogram.ReplyKeyboardMarkup(keyboard: list, resize_keyboard: bool = None, one_time_keyboard: bool = None, selective: bool = None)

This object represents a custom keyboard with reply options.

Parameters:
  • keyboard (List of List of KeyboardButton) – List of button rows, each represented by a List of KeyboardButton objects.
  • resize_keyboard (bool, optional) – Requests clients to resize the keyboard vertically 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.
  • 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 message. 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.
class pyrogram.KeyboardButton(text: str, request_contact: bool = None, request_location: bool = None)

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. Optional fields are mutually exclusive.

Parameters:
  • text (str) – Text of the button. If none of the optional fields are used, it will be sent 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.
class pyrogram.ReplyKeyboardRemove(selective: bool = None)

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

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 message. 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.
class pyrogram.InlineKeyboardMarkup(inline_keyboard: list)

This object represents an inline keyboard that appears right next to the message it belongs to.

Parameters:inline_keyboard (List of List of InlineKeyboardButton) – List of button rows, each represented by a List of InlineKeyboardButton objects.
class pyrogram.InlineKeyboardButton(text: str, callback_data: bytes = None, url: str = None, switch_inline_query: str = None, switch_inline_query_current_chat: str = None)

This object represents one button of an inline keyboard. You must use exactly one of the optional fields.

Parameters:
  • text (str) – Label text on the button.
  • callback_data (bytes, optional) – Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.
  • url (str, optional) – HTTP url to be opened when button is pressed.
  • 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.Note: 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.
class pyrogram.ForceReply(selective: bool = None)

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.

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 message.
class pyrogram.CallbackQuery(id: str, from_user, chat_instance: str, client=None, message=None, inline_message_id: str = None, data: str = None, game_short_name: str = None)

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. Exactly one of the fields data or game_short_name will be present.

Parameters:
  • id (str) – Unique identifier for this query.
  • from_user (User) – Sender.
  • chat_instance (str, 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.
  • message (Message, optional) – Identifier of the message sent via the bot in inline mode, that originated the query.
  • inline_message_id (str) – 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.
answer(text: str = None, show_alert: bool = None, url: str = None, cache_time: int = 0)

Bound method answer of CallbackQuery.

Use this method as a shortcut for:

client.answer_callback_query(
    callback_query.id,
    text="Hello",
    show_alert=True
)

Example

callback_query.answer("Hello", show_alert=True)
Parameters:
  • text (str) – Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.
  • show_alert (bool) – 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) – 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 t.me/your_bot?start=XXXX that open your bot with a parameter.
  • cache_time (int) – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
class pyrogram.InputMediaPhoto(media: str, caption: str = '', parse_mode: str = '')

This object represents a photo to be sent inside an album. It is intended to be used with send_media_group().

Parameters:
  • media (str) – Photo to send. Pass a file_id as string to send a photo that exists on the Telegram servers or pass a file path as string to upload a new photo that exists on your local machine. Sending photo by a URL is currently unsupported.
  • caption (str, optional) – Caption of the photo to be sent, 0-1024 characters
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown.
class pyrogram.InputMediaVideo(media: str, thumb: str = None, caption: str = '', parse_mode: str = '', width: int = 0, height: int = 0, duration: int = 0, supports_streaming: bool = True)

This object represents a video to be sent inside an album. It is intended to be used with send_media_group().

Parameters:
  • media (str) – Video to send. Pass a file_id as string to send a video that exists on the Telegram servers or pass a file path as string to upload a new video that exists on your local machine. Sending video by a URL is currently unsupported.
  • thumb (str) – Thumbnail of the video sent. The thumbnail should be in JPEG format and less than 200 KB in size. A thumbnail’s width and height should not exceed 90 pixels. Thumbnails can’t be reused and can be only uploaded as a new file.
  • caption (str, optional) – Caption of the video to be sent, 0-1024 characters
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown.
  • width (int, optional) – Video width.
  • height (int, optional) – Video height.
  • duration (int, optional) – Video duration.
  • supports_streaming (bool, optional) – Pass True, if the uploaded video is suitable for streaming.
class pyrogram.InputMediaAudio(media: str, thumb: str = None, caption: str = '', parse_mode: str = '', duration: int = 0, performer: int = '', title: str = '')

This object represents a video to be sent inside an album. It is intended to be used with send_media_group().

Parameters:
  • media (str) – Audio to send. Pass a file_id as string to send an audio that exists on the Telegram servers or pass a file path as string to upload a new audio that exists on your local machine.
  • thumb (str, optional) – Thumbnail of the music file album cover. The thumbnail should be in JPEG format and less than 200 KB in size. A thumbnail’s width and height should not exceed 90 pixels. Thumbnails can’t be reused and can be only uploaded as a new file.
  • caption (str, optional) – Caption of the audio to be sent, 0-1024 characters
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown.
  • duration (int, optional) – Duration of the audio in seconds
  • performer (int, optional) – Performer of the audio
  • title (int, optional) – Title of the audio
class pyrogram.InputMediaAnimation(media: str, thumb: str = None, caption: str = '', parse_mode: str = '', width: int = 0, height: int = 0, duration: int = 0)

This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.

Parameters:
  • media (str) – Animation to send. Pass a file_id as string to send a file that exists on the Telegram servers or pass a file path as string to upload a new file that exists on your local machine.
  • thumb (str, optional) – Thumbnail of the animation file sent. The thumbnail should be in JPEG format and less than 200 KB in size. A thumbnail’s width and height should not exceed 90 pixels. Thumbnails can’t be reused and can be only uploaded as a new file.
  • caption (str, optional) – Caption of the animation to be sent, 0-1024 characters
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown.
  • width (int, optional) – Animation width.
  • height (int, optional) – Animation height.
  • duration (int, optional) – Animation duration.
class pyrogram.InputMediaDocument(media: str, thumb: str = None, caption: str = '', parse_mode: str = '')

This object represents a general file to be sent.

Parameters:
  • media (str) – File to send. Pass a file_id as string to send a file that exists on the Telegram servers or pass a file path as string to upload a new file that exists on your local machine.
  • thumb (str) – Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 KB in size. A thumbnail’s width and height should not exceed 90 pixels. Thumbnails can’t be reused and can be only uploaded as a new file.
  • caption (str, optional) – Caption of the document to be sent, 0-1024 characters
  • parse_mode (str, optional) – Use MARKDOWN or HTML if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown.
class pyrogram.InputPhoneContact(phone: str, first_name: str, last_name: str = '')

This object represents a Phone Contact to be added in your Telegram address book. It is intended to be used with add_contacts()

Parameters:
  • phone (str) – Contact’s phone number
  • first_name (str) – Contact’s first name
  • last_name (str, optional) – Contact’s last name