Available Methods#

This page is about Pyrogram methods. All the methods listed here are bound to a Client instance, except for idle() and compose(), which are special functions that can be found in the main package directly.

from pyrogram import Client

app = Client("my_account")

with app:
    app.send_message(chat_id="me", text="hi")

Utilities#

run

Start the client, idle the main script and finally stop the client.

start

Start the client.

stop

Stop the Client.

restart

Restart the Client.

export_session_string

Export the current authorized session as a serialized string.

add_handler

Register an update handler.

remove_handler

Remove a previously-registered update handler.

stop_transmission

Stop downloading or uploading a file.

set_parse_mode

Set the parse mode to be used globally by the client.

idle

Block the main script execution until a signal is received.

compose

Run multiple clients at once.

Authorization#

initialize

Initialize the client by starting up workers.

sign_up

Register a new user in Telegram.

accept_terms_of_service

Accept the given terms of service.

sign_in

Authorize a user in Telegram with a valid confirmation code.

sign_in_bot

Authorize a bot using its bot token generated by BotFather.

connect

Connect the client to Telegram servers.

send_code

Send the confirmation code to the given phone number.

resend_code

Re-send the confirmation code using a different type.

recover_password

Recover your password with a recovery code and log in.

send_recovery_code

Send a code to your email to recover your password.

get_password_hint

Get your Two-Step Verification password hint.

check_password

Check your Two-Step Verification password and log in.

log_out

Log out from Telegram and delete the *.session file.

disconnect

Disconnect the client from Telegram servers.

terminate

Terminate the client by shutting down workers.

get_me

Get your own user identity.

get_active_sessions

Returns all active sessions of the current user.

terminate_session

Terminates a session of the current user.

terminate_all_other_sessions

Terminates all other sessions of the current user.

Messages#

send_message

Send text messages.

forward_messages

Forward messages of any kind.

copy_message

Copy messages of any kind.

send_photo

Send photos.

send_audio

Send audio files.

send_document

Send generic files.

send_video

Send video files.

send_animation

Send animation files (animation or H.264/MPEG-4 AVC video without sound).

send_voice

Send audio files.

send_video_note

Send video messages.

send_cached_media

Send any media stored on the Telegram servers using a file_id.

send_paid_media

Use this method to send paid media.

send_media_group

Send a group of photos or videos as an album.

get_media_group

Get the media group a message belongs to.

copy_media_group

Copy a media group by providing one of the message ids.

send_location

Send points on the map.

send_venue

Send information about a venue.

send_contact

Send phone contacts.

send_poll

Send a new poll.

send_dice

Send a dice with a random value from 1 to 6.

send_chat_action

Use this method when you need to tell the user that something is happening on the bot's side.

add_paid_message_reaction

Adds the paid message reaction to a message.

set_reaction

Use this method to change the chosen reactions on a message.

download_media

Download the media from a message.

stream_media

Stream the media from a message chunk by chunk.

edit_message_text

Edit the text of messages.

edit_inline_text

Edit the text of inline messages.

edit_message_caption

Edit the caption of media messages.

edit_inline_caption

Edit the caption of inline media messages.

edit_message_media

Edit animation, audio, document, photo or video messages.

edit_inline_media

Edit inline animation, audio, document, photo or video messages.

edit_message_reply_markup

Edit only the reply markup of messages sent by the bot.

edit_inline_reply_markup

Edit only the reply markup of inline messages sent via the bot (for inline bots).

edit_cached_media

Edit a media stored on the Telegram servers using a file_id.

stop_poll

Stop a poll which was sent by you.

delete_messages

Delete messages, including service messages, with the following limitations:

get_chat_sponsored_messages

Returns sponsored messages to be shown in a chat; for channel chats only.

get_chat_history

Get messages from a chat history.

get_chat_history_count

Get the total count of messages in a chat.

read_chat_history

Mark a chat's message history as read.

get_messages

Get one or more messages from a chat by using message identifiers.

view_messages

Informs the server that messages are being viewed by the current user.

get_discussion_message

Get the first discussion message of a channel post or a discussion thread in a group.

get_discussion_replies

Get the message replies of a discussion thread.

get_discussion_replies_count

Get the total count of replies in a discussion thread.

search_global

Search messages globally from all of your chats.

search_global_count

Get the count of messages resulting from a global search.

search_messages

Search for text and media messages inside a specific chat.

search_messages_count

Get the count of messages resulting from a search inside a chat.

search_public_messages_by_tag

Searches for public channel posts containing the given hashtag or cashtag.

count_public_messages_by_tag

Get the count of messages with the provided hashtag or cashtag.

vote_poll

Vote a poll.

retract_vote

Retract your vote in a poll.

translate_text

Translates a text to the given language.

translate_message_text

Extracts text or caption of the given message and translates it to the given language.

Chats#

ban_chat_member

Ban a user from a group, a supergroup or a channel.

unban_chat_member

Unban a previously banned user in a supergroup or channel.

restrict_chat_member

Restrict a user in a supergroup.

promote_chat_member

Promote or demote a user in a supergroup or a channel.

set_administrator_title

Set a custom title (rank) to an administrator of a supergroup.

set_chat_permissions

Set default chat permissions for all members.

set_chat_photo

Set a new chat photo or video (H.264/MPEG-4 AVC video, max 5 seconds).

delete_chat_photo

Delete a chat photo.

set_chat_title

Change the title of a chat.

set_chat_description

Change the description of a supergroup or a channel.

pin_chat_message

Pin a message in a group, channel or your own chat.

unpin_chat_message

Unpin a message in a group, channel or your own chat.

unpin_all_chat_messages

Use this method to clear the list of pinned messages in a chat.

search_chats

Searches for the specified query in the title and username of already known chats via request to the server.

join_chat

Join a group chat or channel.

leave_chat

Leave a group chat or channel.

get_chat

Get up to date information about a chat.

get_chat_members

Get the members list of a chat.

get_chat_members_count

Get the number of members in a chat.

get_chat_member

Get information about one member of a chat.

get_dialogs

Get a user's dialogs sequentially.

get_dialogs_count

Get the total count of your dialogs.

set_chat_username

Set a channel or a supergroup username.

get_nearby_chats

Get nearby chats.

archive_chats

Archive one or more chats.

unarchive_chats

Unarchive one or more chats.

add_chat_members

Add new chat members to a group, supergroup or channel

create_channel

Create a new broadcast channel.

create_group

Create a new basic group.

create_supergroup

Create a new supergroup.

delete_channel

Delete a channel.

delete_supergroup

Delete a supergroup.

delete_user_history

Delete all messages sent by a certain user in a supergroup.

set_slow_mode

Set the slow mode interval for a chat.

set_chat_message_auto_delete_time

Changes the message auto-delete or self-destruct (for secret chats) time in a chat.

mark_chat_unread

Mark a chat as unread.

get_chat_event_log

Get the actions taken by chat members and administrators in the last 48h.

get_chat_online_count

Get the number of members that are currently online in a chat.

get_send_as_chats

Get the list of "send_as" chats available.

set_send_as_chat

Set the default "send_as" chat for a chat.

set_chat_protected_content

Set the chat protected content setting.

get_created_chats

Get a list of chats of the specified type of the current user account

transfer_chat_ownership

Changes the owner of a chat.

Chat Forum Topics#

get_forum_topic_icon_stickers

Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.

create_forum_topic

Use this method to create a topic in a forum supergroup chat.

edit_forum_topic

Use this method to edit name and icon of a topic in a forum supergroup chat.

close_forum_topic

Use this method to close an open topic in a forum supergroup chat.

reopen_forum_topic

Use this method to reopen a closed topic in a forum supergroup chat.

delete_forum_topic

Use this method to delete a forum topic along with all its messages in a forum supergroup chat.

hide_forum_topic

Use this method to hide a topic in a forum supergroup chat.

unhide_forum_topic

Use this method to unhide a topic in a forum supergroup chat.

get_forum_topics

Get one or more topic from a chat.

get_forum_topic

Get one or more topic from a chat by using topic identifiers.

Users#

get_chat_photos

Get a chat or a user profile photos sequentially.

get_chat_photos_count

Get the total count of photos for a chat.

get_users

Get information about a user.

set_profile_photo

Set a new profile photo or video (H.264/MPEG-4 AVC video, max 5 seconds).

delete_profile_photos

Delete your own profile photos.

set_username

Set your own username.

update_profile

Update your profile details such as first name, last name and bio.

block_user

Block a user.

unblock_user

Unblock a user.

get_common_chats

Get the common chats you have with a user.

get_default_emoji_statuses

Get the default emoji statuses.

set_emoji_status

Set the emoji status.

set_birthdate

Changes the birthdate of the current user

set_personal_chat

Changes the personal chat of the current user

delete_account

Deletes the account of the current user, deleting all information associated with the user from the server.

update_status

Updates online user status.

Contacts#

add_contact

Add an existing Telegram user as contact, even without a phone number.

delete_contacts

Delete contacts from your Telegram address book.

import_contacts

Import contacts to your Telegram address book.

get_contacts

Get contacts from your Telegram address book.

get_contacts_count

Get the total count of contacts from your Telegram address book.

Password#

enable_cloud_password

Enable the Two-Step Verification security feature (Cloud Password) on your account.

change_cloud_password

Change your Two-Step Verification password (Cloud Password) with a new one.

remove_cloud_password

Turn off the Two-Step Verification security feature (Cloud Password) on your account.

Bots#

answer_callback_query

Send answers to callback queries sent from inline keyboards.

request_callback_answer

Request a callback answer from bots.

set_bot_commands

Set the list of the bot's commands.

delete_bot_commands

Delete the list of the bot's commands for the given scope and user language.

get_bot_commands

Get the current list of the bot's commands for the given scope and user language.

set_bot_name

Use this method to get the current / owned bot name for the given user language.

get_bot_name

Use this method to get the current / owned bot name for the given user language.

set_bot_info_description

Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.

get_bot_info_description

Use this method to get the current / owned bot description for the given user language.

set_bot_info_short_description

Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot.

get_bot_info_short_description

Use this method to get the current / owned bot short description for the given user language.

set_chat_menu_button

Change the bot's menu button in a private chat, or the default menu button.

get_chat_menu_button

Get the current value of the bot's menu button in a private chat, or the default menu button.

set_bot_default_privileges

Change the default privileges requested by the bot when it's added as an administrator to groups or channels.

get_bot_default_privileges

Get the current default privileges of the bot.

send_game

Send a game.

set_game_score

Set the score of the specified user in a game.

get_game_high_scores

Get data for high score tables.

answer_inline_query

Send answers to an inline query.

get_inline_bot_results

Get bot results via inline queries.

send_inline_bot_result

Send an inline bot result.

answer_web_app_query

Set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated.

send_web_app_custom_request

Sends a custom request from a Web App.

Stickers#

send_sticker

Send static .webp or animated .tgs stickers.

get_custom_emoji_stickers

Get information about custom emoji stickers by their identifiers.

get_message_effects

Returns information about all available message effects.

get_stickers

Get all stickers from set by short name.

Stories#

get_stories

Get one or more stories from a chat by using stories identifiers.

Payments#

send_invoice

Use this method to send invoices.

create_invoice_link

Use this method to create a link for an invoice.

answer_shipping_query

If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the API sends the confirmation in the form of an ShippingQueryHandler.

answer_pre_checkout_query

Once the user has confirmed their payment and shipping details, the API sends the final confirmation in the form of an PreCheckoutQueryHandler.

refund_star_payment

Refunds a successful payment in Telegram Stars.

get_business_connection

Use this method to get information about the connection of the bot with a business account.

get_collectible_item_info

Returns information about a given collectible item that was purchased at https://fragment.com

get_payment_form

Get information about a invoice or paid media.

send_payment_form

Pay an invoice.

Phone#

create_video_chat

Creates a video chat (a group call bound to a chat).

discard_group_call

Terminate a group/channel call or livestream

get_video_chat_rtmp_url

Returns RTMP URL for streaming to the chat; requires owner privileges.

invite_group_call_participants

Invites users to an active group call.

load_group_call_participants

Loads participants list in a group call of a chat.

Advanced#

Methods used only when dealing with the raw Telegram API. Learn more about how to use the raw API at Advanced Usage.

invoke

Invoke raw Telegram functions.

resolve_peer

Get the InputPeer of a known peer id.

get_file

save_file

Upload a file onto Telegram servers, without actually sending the message to anyone.