### Install Pyrogram with Pip Source: https://telegramplayground.github.io/pyrogram/intro/quickstart Installs the Pyrogram library using pip. It first uninstalls any existing version before installing the specified fork. ```bash pip uninstall -y pyrogram && pip install pyrotgfork ``` -------------------------------- ### Install Pyrogram using Pip Source: https://telegramplayground.github.io/pyrogram/intro/install Installs the Pyrogram library using pip. It first uninstalls any existing version before installing the specified version. Dependencies like TgCrypto can be installed using extras. ```bash pip uninstall -y pyrogram && pip install pyrotgfork ``` ```bash pip install pyrotgfork[fast] ``` -------------------------------- ### Pyrogram Client.start() - Python Example Source: https://telegramplayground.github.io/pyrogram/api/methods/start This code snippet demonstrates how to use the Client.start() method in Pyrogram to connect to Telegram. It initializes a client, starts the connection, performs API operations, and then stops the client. This method handles the initial authorization process interactively if it's a new session. ```python from pyrogram import Client app = Client("my_account") async def main(): await app.start() ... # Invoke API methods await app.stop() app.run(main()) ``` -------------------------------- ### Basic Pyrogram Bot Example Source: https://telegramplayground.github.io/pyrogram/index This Python code snippet demonstrates how to create a simple Telegram bot using the Pyrogram framework. It initializes a client, sets up a message handler for private chats, and responds with a greeting. Ensure Pyrogram is installed (`pip install pyrogram`). ```python from pyrogram import Client, filters app = Client("my_account") @app.on_message(filters.private) async def hello(client, message): await message.reply("Hello from Pyrogram!") app.run() ``` -------------------------------- ### Verify Pyrogram Installation Source: https://telegramplayground.github.io/pyrogram/intro/install Verifies a successful Pyrogram installation by importing the library and accessing its version information within a Python shell. If no errors occur, the installation is considered successful. ```python from pyrogram import __version__ print(__version__) ``` -------------------------------- ### Pyrogram Message Reply Example Source: https://telegramplayground.github.io/pyrogram/api/bound-methods/index Demonstrates how to use a bound method to reply to a message. This example requires Pyrogram to be installed and configured. It defines a message handler that replies with 'hi' to any incoming message. ```python from pyrogram import Client app = Client("my_account") @app.on_message() def hello(client, message): message.reply("hi") app.run() ``` -------------------------------- ### Send a Message with Pyrogram Client Source: https://telegramplayground.github.io/pyrogram/api/client Demonstrates how to instantiate and use the Pyrogram Client to send a message to 'me' (the current user). This requires the pyrogram library to be installed. The example shows basic client initialization and message sending within a context manager. ```python from pyrogram import Client app = Client("my_account") with app: app.send_message(chat_id="me", text="Hi!") ``` -------------------------------- ### account.InstallTheme Source: https://telegramplayground.github.io/pyrogram/telegram/functions/account/install-theme Installs a theme for the Telegram client. This function supports installing both light and dark versions of themes, specifying the theme itself, its format, and its base theme. ```APIDOC ## POST /account/InstallTheme ### Description Installs a theme for the Telegram client. Supports specifying dark version, theme object, format, and base theme. ### Method POST ### Endpoint /account/InstallTheme ### Parameters #### Query Parameters - **dark** (bool) - Optional - Whether to install the dark version of the theme. - **theme** (InputTheme) - Optional - The theme object to install. - **format** (str) - Optional - The format of the theme, identifying supported theming engines. - **base_theme** (BaseTheme) - Optional - Indicates a basic theme provided by all clients. ### Request Example ```json { "dark": true, "theme": { "slug": "my_cool_theme" }, "format": "custom", "base_theme": "classic" } ``` ### Response #### Success Response (200) - **result** (bool) - True if the theme was installed successfully, false otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### messages.InstallStickerSet Source: https://telegramplayground.github.io/pyrogram/telegram/functions/messages/install-sticker-set Installs a sticker set for the user. It can optionally archive the sticker set after installation. ```APIDOC ## POST /messages.InstallStickerSet ### Description Installs a stickerset. The `archived` parameter can be used to archive the stickerset after installation. ### Method POST ### Endpoint /messages.InstallStickerSet ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stickerset** (InputStickerSet) - Required - The sticker set to install. - **archived** (bool) - Optional - Whether to archive the sticker set after installation. ### Request Example ```json { "stickerset": { "_வைத்": "inputStickerSetID", "id": 12345, "access_hash": "some_access_hash" }, "archived": false } ``` ### Response #### Success Response (200) - **result** (messages.StickerSetInstallResult) - The result of the sticker set installation. #### Response Example ```json { "result": { "_வைத்": "messages.stickerSetInstallResultArchive", "sets": [ { "_வைத்": "stickerSet", "id": 12345, "access_hash": "some_access_hash", "title": "Sticker Pack Title", "short_name": "pack_short_name", "thumbs": [], "count": 10, "hash": 0 } ] } } ``` ``` -------------------------------- ### Pyrogram Welcome Bot: Python Source: https://telegramplayground.github.io/pyrogram/start/examples/welcome_bot This Python script utilizes the Pyrogram library to automatically send a welcome message when a new member joins a specified Telegram chat. It leverages the 'emoji' module for enhanced message formatting and 'filters' to ensure the welcome message is triggered only by new chat members in the target chat. The script requires Pyrogram to be installed and configured with a Telegram client. ```python from pyrogram import Client, emoji, filters # Target chat. Can also be a list of multiple chat ids/usernames TARGET = -100123456789 # Welcome message template MESSAGE = "{} Welcome to [Pyrogram](https://telegramplayground.github.io/pyrogram/)'s group chat {}!" app = Client("my_account") # Filter in only new_chat_members updates generated in TARGET chat @app.on_chat_member_updated(filters.chat(TARGET)) async def welcome(client, chat_member_updated): if chat_member_updated.old_chat_member: return # it's not a new join # Build the new members list (with mentions) by using their first_name new_member = chat_member_updated.new_chat_member.user.mention added_by = message.from_user.id # is equal to new_member if user wasn't added # Build the welcome message by using an emoji and the list we built above text = MESSAGE.format(emoji.SPARKLES, new_member) # send a message to the chat await client.send_message( chat_id=chat_member_updated.chat.id, text=text ) app.run() # Automatically start() and idle() ``` -------------------------------- ### Client.start() Source: https://telegramplayground.github.io/pyrogram/api/methods/start Starts the Pyrogram client, connecting to Telegram and managing the authorization process for new sessions. It returns the client instance and can raise a ConnectionError if the client is already started. ```APIDOC ## Client.start() ### Description Starts the client, connecting to Telegram and automatically managing the authorization process for new sessions using an interactive prompt. ### Method `async def start(self)` ### Endpoint N/A (This is a client method, not a REST endpoint) ### Parameters None ### Request Example ```python from pyrogram import Client app = Client("my_account") async def main(): await app.start() # ... invoke API methods await app.stop() app.run(main()) ``` ### Response #### Success Response - **Client** (`Client`) – The started client instance. #### Response Example ```python # The method returns the client instance upon successful start. # Example of usage: # started_client = await app.start() ``` ### Raises - **ConnectionError** – Raised if you attempt to start an already started client. ``` -------------------------------- ### Send a Message with Pyrogram (Python) Source: https://telegramplayground.github.io/pyrogram/intro/quickstart A Python script demonstrating how to send a message to yourself using Pyrogram. It requires your Telegram API ID and API Hash. The script initializes a client, sends a message, and then closes the connection. ```python import asyncio from pyrogram import Client api_id = 12345 api_hash = "0123456789abcdef0123456789abcdef" async def main(): async with Client("my_account", api_id, api_hash) as app: await app.send_message(chat_id="me", text="Greetings from **Pyrogram**!") asyncio.run(main()) ``` -------------------------------- ### Pyrogram Client Context Manager for Async Operations Source: https://telegramplayground.github.io/pyrogram/start/invoking This example demonstrates using the `async with` statement as a context manager for the Pyrogram Client. This approach automatically handles the starting and stopping of the client, ensuring graceful termination even if errors occur. It's an alternative to manually calling `app.start()` and `app.stop()`. ```python from pyrogram import Client app = Client("my_account") async def main(): await app.start() await app.send_message(chat_id="me", text="Hi!") await app.stop() app.run(main()) ``` -------------------------------- ### Client.run() - Start, Idle, Stop Source: https://telegramplayground.github.io/pyrogram/api/methods/run This is a convenience method that calls start(), idle(), and stop() in sequence. It's useful for running a single client with less verbose code. ```APIDOC ## Client.run() ### Description Starts the client, idles the main script, and finally stops the client. When called without arguments, it acts as a convenience method that calls `start()`, `idle()`, and `stop()` in sequence, making it less verbose for running a single client. ### Method `run()` ### Endpoint N/A (This is a method of the Client class) ### Parameters None ### Request Example ```python from pyrogram import Client app = Client("my_account") # ... Set handlers up app.run() ``` ### Response #### Success Response (None explicit, but client lifecycle is managed) - N/A #### Response Example N/A ``` -------------------------------- ### Install uvloop for Pyrogram Source: https://telegramplayground.github.io/pyrogram/topics/speedups This snippet shows the command to install uvloop, a fast, drop-in replacement for Python's built-in asyncio event loop. ```bash pip3 install -U uvloop ``` -------------------------------- ### account.GetThemes API Source: https://telegramplayground.github.io/pyrogram/telegram/types/account/themes Retrieves the list of installed themes for the user. ```APIDOC ## account.GetThemes ### Description Get installed themes. ### Method GET ### Endpoint /account/GetThemes ### Parameters #### Path Parameters None #### Query Parameters - **hash** (int 64-bit) - Optional - Hash used for caching, for more info click here. #### Request Body None ### Request Example ``` GET /account/GetThemes?hash=1234567890 ``` ### Response #### Success Response (200) - **Themes** (account.Themes) - The themes object containing installed themes. #### Response Example ```json { "themes": { "hash": 1234567890, "themes": [ { "name": "Default", "color": "#0077fa", "emoji": "🎨" } ] } } ``` ``` -------------------------------- ### Get Chat History with Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/get_chat_history This Python code snippet demonstrates how to get the complete message history of a Telegram chat, starting from the most recent messages. It requires the Pyrogram library and an initialized Client instance. The function iterates through messages and prints each one. ```python from pyrogram import Client app = Client("my_account") async def main(): async with app: # "me" refers to your own chat (Saved Messages) async for message in app.get_chat_history("me"): print(message) app.run(main()) ``` -------------------------------- ### Send Basic Message with Pyrogram Client Source: https://telegramplayground.github.io/pyrogram/start/examples/hello_world This snippet shows how to create a Pyrogram Client instance and send a basic message to 'me' (the sender). It requires the 'pyrogram' library. The message text supports Markdown by default. ```python from pyrogram import Client # Create a new Client instance app = Client("my_account") async def main(): async with app: # Send a message, Markdown is enabled by default await app.send_message(chat_id="me", text="Hi there! I'm using **Pyrogram**") app.run(main()) ``` -------------------------------- ### account.InstallWallPaper API Source: https://telegramplayground.github.io/pyrogram/telegram/functions/account/install-wall-paper Installs a specified wallpaper for the user's account and applies the given settings. ```APIDOC ## POST /account/InstallWallPaper ### Description Installs a wallpaper for the user's account with specified settings. ### Method POST ### Endpoint /account/InstallWallPaper ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **wallpaper** (InputWallPaper) - Required - The wallpaper to be installed. - **settings** (WallPaperSettings) - Required - The settings for the wallpaper. ### Request Example ```json { "wallpaper": { ... }, "settings": { ... } } ``` ### Response #### Success Response (200) - **result** (bool) - True if the wallpaper was installed successfully, False otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### BotPreviewMedia Constructors Source: https://telegramplayground.github.io/pyrogram/telegram/base/bot-preview-media Details about the BotPreviewMedia constructor, which represents a main mini app preview media. ```APIDOC ## BotPreviewMedia Constructor ### Description Represents a Main Mini App preview media. Bots can offer users interactive HTML5 web apps to completely replace any website. ### Method N/A (Constructor) ### Endpoint N/A (Constructor) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Get Chat Members with Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/get_chat_members This snippet retrieves all members from a specified Telegram chat using the `get_chat_members` method of the Pyrogram client. It requires a Pyrogram client instance and the chat ID as input. The output is a stream of `Member` objects, which are then printed. ```python from pyrogram import Client # Target channel/supergroup TARGET = -100123456789 app = Client("my_account") async def main(): async with app: async for member in app.get_chat_members(TARGET): print(member) app.run(main()) ``` -------------------------------- ### Help API Source: https://telegramplayground.github.io/pyrogram/telegram/functions/index Endpoints for retrieving application configuration, terms of service, and user information. ```APIDOC ## Help API Endpoints This section provides access to help and configuration-related information. ### GetConfig **Description**: Retrieves the application configuration. **Method**: GET **Endpoint**: `/help/getConfig` ### GetTermsOfServiceUpdate **Description**: Fetches the latest terms of service update. **Method**: GET **Endpoint**: `/help/getTermsOfServiceUpdate` ### GetUserInfo **Description**: Retrieves information about the current user. **Method**: GET **Endpoint**: `/help/getUserInfo` ### AcceptTermsOfService **Description**: Accepts the terms of service. **Method**: POST **Endpoint**: `/help/acceptTermsOfService` ``` -------------------------------- ### Get Chat Information using Raw API Source: https://telegramplayground.github.io/pyrogram/topics/advanced-usage This example demonstrates retrieving detailed information about a Telegram channel using the raw `GetFullChannel` function. It requires the `Client` and `functions` from `pyrogram.raw`, and utilizes `app.resolve_peer()` to get the channel's input peer. ```python from pyrogram import Client from pyrogram.raw import functions, types async with Client("my_account") as app: r = await app.invoke( functions.channels.GetFullChannel( channel=app.resolve_peer("username") ) ) print(r) ``` -------------------------------- ### help.GetConfig Source: https://telegramplayground.github.io/pyrogram/telegram/functions/help/get-config Retrieves the current system configuration, including data center specific settings. This endpoint requires no parameters. ```APIDOC ## GET /help/GetConfig ### Description Retrieves the current configuration, including data center configuration. ### Method GET ### Endpoint /help/GetConfig ### Parameters #### Path Parameters No path parameters required. #### Query Parameters No query parameters required. #### Request Body No request body required. ### Request Example No request body example available. ### Response #### Success Response (200) - **config** (Config) - The configuration object containing data center details. #### Response Example ```json { "config": { "dc_options": [ { "ipv4_dc_options": [ { "ip_address": "149.154.175.51", "port": 443 } ], "ipv6_dc_options": [], "id": 2, "test_mode": false, "cdn_public_keys": [] } ], "chat_big_size": 4096, "chat_size_max": 100, "message_edit_time_limit": 600, "date": 1678888888 } } ``` ``` -------------------------------- ### Pyrogram Smart Plugins Setup and Usage Source: https://telegramplayground.github.io/pyrogram/topics/smart-plugins This Python code illustrates the use of Pyrogram's Smart Plugins system. It shows how to organize handlers in a 'plugins' folder and how to configure the client to automatically discover and register these plugins. This method simplifies handler registration and allows the use of decorators directly on handler functions. ```python myproject/ plugins/ handlers.py main.py ``` ```python from pyrogram import Client, filters @Client.on_message(filters.text & filters.private) async def echo(client, message): await message.reply(message.text) @Client.on_message(filters.text & filters.private, group=1) async def echo_reversed(client, message): await message.reply(message.text[::-1]) ``` ```python from pyrogram import Client plugins = dict(root="plugins") Client("my_account", plugins=plugins).run() ``` -------------------------------- ### Get Type of Pyrogram User Status Source: https://telegramplayground.github.io/pyrogram/topics/debugging Illustrates how to determine the type of an object's attribute, in this case, the 'status' attribute of a User object, using Python's built-in `type()` function. ```python status = me.status print(type(status)) ``` -------------------------------- ### Configure Pyrogram Client with API Credentials Source: https://telegramplayground.github.io/pyrogram/start/setup This snippet demonstrates how to initialize a Pyrogram Client instance using your Telegram API ID and API Hash. Ensure you have obtained these credentials from my.telegram.org. The client is initialized with a session name, api_id, and api_hash. ```python from pyrogram import Client api_id = 12345 api_hash = "0123456789abcdef0123456789abcdef" app = Client("my_account", api_id=api_id, api_hash=api_hash) ``` -------------------------------- ### Get Attach Menu Bots - Pyrogram Source: https://telegramplayground.github.io/pyrogram/telegram/functions/messages/get-attach-menu-bots This function retrieves a list of installed attachment menu bot mini-apps available in Telegram. It requires a `hash` parameter for caching purposes and returns an `AttachMenuBots` object. ```python from pyrogram.raw.functions.messages import GetAttachMenuBots # Example usage: # await client.send(GetAttachMenuBots(hash=0)) ``` -------------------------------- ### BusinessIntro Class Source: https://telegramplayground.github.io/pyrogram/telegram/base/business-intro Documentation for the BusinessIntro class, which represents the introduction of a Telegram Business account. It provides access to various business-specific features. ```APIDOC ## BusinessIntro Class ### Description Represents a Telegram Business introduction. Users can convert their Telegram account into a business account to access features like opening hours, location, quick replies, automated messages, custom start pages, and chatbot support. ### Constructors This base type has 1 constructor available: * **BusinessIntro** - Telegram Business introduction. ### Usage Example ```python # This is a conceptual example, actual implementation may vary. from pyrogram.raw.types import BusinessIntro # Example of how BusinessIntro might be used (illustrative) # business_intro = BusinessIntro() # print(business_intro) ``` ``` -------------------------------- ### Handle FloodWait Error in Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/errors Example of using a try-except block to catch FloodWait errors. It demonstrates accessing the 'value' attribute of the exception to get the required waiting time and using asyncio.sleep to pause execution. ```python import asyncio from pyrogram.errors import FloodWait ... try: ... # Your code except FloodWait as e: await asyncio.sleep(e.value) # Wait N seconds before continuing ... ``` -------------------------------- ### Get Dialogs List as User with Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/get_dialogs This snippet retrieves all dialogs for a user account. It requires the Pyrogram library and initializes a client. The code iterates through the dialogs using `app.get_dialogs()` and prints the chat title or first name. This functionality is usable by both users and bots. ```python from pyrogram import Client app = Client("my_account") async def main(): async with app: async for dialog in app.get_dialogs(): print(dialog.chat.title or dialog.chat.first_name) app.run(main()) ``` -------------------------------- ### Edit Message Media with Pyrogram Source: https://telegramplayground.github.io/pyrogram/api/methods/edit_message_media This snippet demonstrates how to use the Client.edit_message_media() method to replace the media of an existing message. It shows examples for updating with a local photo, video, or audio file. Ensure you have the Pyrogram library installed and an active client instance ('app'). ```python from pyrogram.types import InputMediaPhoto, InputMediaVideo, InputMediaAudio # Replace the current media with a local photo await app.edit_message_media(chat_id, message_id, InputMediaPhoto("new_photo.jpg")) # Replace the current media with a local video await app.edit_message_media(chat_id, message_id, InputMediaVideo("new_video.mp4")) # Replace the current media with a local audio await app.edit_message_media(chat_id, message_id, InputMediaAudio("new_audio.mp3")) ``` -------------------------------- ### InputTheme Constructor Source: https://telegramplayground.github.io/pyrogram/telegram/types/input-theme Describes the InputTheme constructor, its layer, ID, and required parameters. ```APIDOC ## InputTheme Constructor ### Description Represents a theme with an ID and access hash. This is a constructor for the InputTheme object. ### Method N/A (Constructor) ### Endpoint N/A (Class Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) None #### Response Example None ### Class Details - **Layer**: `214` - **ID**: `3C5693E9` ### Parameters - **id** (`int` 64-bit) - Required - The unique identifier for the theme. - **access_hash** (`int` 64-bit) - Required - The access hash for the theme. ``` -------------------------------- ### Get Archived Stories from Chat - Python Source: https://telegramplayground.github.io/pyrogram/api/methods/get_chat_archived_stories Retrieves all archived stories from a specified Telegram chat using the Pyrogram library. This function can be used by both users and bots. It takes the chat ID, an optional starting story ID, and an optional limit as input, returning a generator of Story objects. ```python from pyrogram import Client async def get_archived_stories(app: Client, chat_id: int | str, from_story_id: int = 0, limit: int = 0): """ Get all archived stories from a chat by using chat identifier. Parameters: chat_id (int | str): Unique identifier (int) or username (str) of the target chat. from_story_id (int, optional): Identifier of the story starting from which stories must be returned; use 0 to get results from the last story. limit (int, optional): The maximum number of stories to be returned. Returns: Generator: A generator yielding Story objects. """ return app.get_chat_archived_stories(chat_id=chat_id, from_story_id=from_story_id, limit=limit) # Example usage: # async def main(): # async with Client("my_account") as app: # async for story in app.get_chat_archived_stories(chat_id="me"): # print(story) # # asyncio.run(main()) ``` -------------------------------- ### InstallWallPaper Function Source: https://telegramplayground.github.io/pyrogram/telegram/functions/account/install-wall-paper The InstallWallPaper function from the pyrogram.raw.functions.account module is used to set a new wallpaper. It requires an InputWallPaper object and WallPaperSettings as input. The function returns a boolean value indicating whether the installation was successful. This is a raw function, implying direct interaction with the Telegram API. ```python from pyrogram.raw.functions.account import InstallWallPaper from pyrogram.raw.types import InputWallPaper, WallPaperSettings # Example usage (requires an active Pyrogram client instance 'app') # wallpaper_object = InputWallPaper(id=123, access_hash='...') # Replace with actual wallpaper object # settings_object = WallPaperSettings(blur=True, motion=False) # Replace with actual settings # result = await app.send(InstallWallPaper(wallpaper=wallpaper_object, settings=settings_object)) # print(f"Wallpaper installed: {result}") ``` -------------------------------- ### Block Script Execution with pyrogram.idle() Source: https://telegramplayground.github.io/pyrogram/api/methods/idle The `idle()` function from Pyrogram is used to keep the script running until a termination signal is received. It's essential for event-driven applications where background clients need to remain active. The example demonstrates starting multiple clients, awaiting `idle()`, and then stopping the clients. ```python import asyncio from pyrogram import Client, idle async def main(): apps = [ Client("account1"), Client("account2"), Client("account3") ] ... # Set up handlers for app in apps: await app.start() await idle() for app in apps: await app.stop() asyncio.run(main()) ``` -------------------------------- ### ThemeSettings Class Source: https://telegramplayground.github.io/pyrogram/telegram/base/theme-settings Provides information about theme settings, including available constructors. ```APIDOC ## ThemeSettings Class ### Description Represents theme settings in Pyrogram. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **ThemeSettings** (object) - Represents theme settings. #### Response Example ```json { "ThemeSettings": "Theme settings" } ``` ### Constructors This base type has 1 constructor available. * **`ThemeSettings`** - Theme settings ``` -------------------------------- ### Handle Raw Telegram Updates with Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/raw_updates This Python code snippet illustrates how to use Pyrogram to listen for and process raw, unprocessed updates directly from the Telegram API. It requires the Pyrogram library to be installed. The handler function receives the update object, along with associated user and chat data. ```python from pyrogram import Client app = Client("my_account") @app.on_raw_update() async def raw(client, update, users, chats): print(update) app.run() # Automatically start() and idle() ``` -------------------------------- ### BotVerifierSettings Class Documentation Source: https://telegramplayground.github.io/pyrogram/telegram/base/bot-verifier-settings Documentation for the BotVerifierSettings class, which holds information about the current verifier bot and its role in Telegram's transparency initiatives. ```APIDOC ## BotVerifierSettings ### Description Provides information about the current verifier bot. Official third-party services use this to assign extra verification icons to user accounts and chats, preventing scams and reducing misinformation. ### Method N/A (This is a class/data structure documentation) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) - **BotVerifierSettings** (type: object) - Contains information about the current verifier bot. #### Response Example N/A ### Constructors #### BotVerifierSettings - **Description**: Info about the current verifier bot. - **Usage**: This constructor is used to represent the BotVerifierSettings object. ``` -------------------------------- ### Send Audio as Voice Message using Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/send_voice This Python code snippet uses the Pyrogram library to listen for audio messages and re-upload them as Telegram voice messages. It requires the Pyrogram library to be installed. The function downloads the incoming audio and then sends it back as a voice message, including a waveform for playback. ```python from pyrogram import Client, filters app = Client("my_account") @app.on_message(filters.audio) async def re_upload_as_voice(client, message): # Downlaod the Voice o = await message.download() # Re Upload the Audio as Telegram Voice Message await message.reply_voice(o, waveform=b'\xff\xbf\xf7\xde\xff\xcf\xbd\xbd\xf7\xfb\xff\xff\xff\xde{\xff?\xf7\xf6\xde\xef\xff\xff\xff{\xef\xfd\xff\xdc\xdb{\xbf\xff\xff\xff\xef\xbd\xf7\xffso\xef\xfd\xfe\xff') app.run() # Automatically start() and idle() ``` -------------------------------- ### GET /get_chat_admin_invite_links Source: https://telegramplayground.github.io/pyrogram/api/methods/get_chat_admin_invite_links Retrieves invite links created by an administrator in a chat. As an administrator, you can only get your own links. As the chat or channel owner, you can get everyone's links. ```APIDOC ## GET /get_chat_admin_invite_links ### Description Retrieves invite links created by an administrator in a chat. This method can be used by both users and bots. ### Method GET ### Endpoint `/get_chat_admin_invite_links` ### Parameters #### Query Parameters - **chat_id** (integer | string) - Required - Unique identifier for the target chat or username of the target channel/supergroup (in the format @username). - **admin_id** (integer | string) - Required - Unique identifier (int) or username (str) of the target user. Use "me" or "self" for yourself. Use a phone number (str) for a contact. - **revoked** (boolean) - Optional - True to get revoked links instead. Defaults to False (get active links only). - **limit** (integer) - Optional - Limits the number of invite links to be retrieved. No limit applied by default. ### Request Example ```json { "chat_id": "@mychannel", "admin_id": "me", "revoked": false, "limit": 10 } ``` ### Response #### Success Response (200) - **invite_links** (array of objects) - A list of ChatInviteLink objects. ##### ChatInviteLink Object - **invite_link** (string) - The invite link. - **creator_id** (integer) - The ID of the user who created the link. - **is_primary** (boolean) - True, if this is the primary invite link. - **is_revoked** (boolean) - True, if the link was revoked. - **expire_date** (string) - The expiration date of the link, in ISO 8601 format. - **member_limit** (integer) - The maximum number of users that can be added using this link. #### Response Example ```json { "invite_links": [ { "invite_link": "https://t.me/+abcdef12345", "creator_id": 123456789, "is_primary": true, "is_revoked": false, "expire_date": "2024-12-31T23:59:59Z", "member_limit": 50 } ] } ``` ``` -------------------------------- ### ThemeSettings Constructor Source: https://telegramplayground.github.io/pyrogram/telegram/types/theme-settings Details the ThemeSettings constructor, which represents theme settings. ```APIDOC ## ThemeSettings ### Description Theme settings ### Method N/A (Type definition) ### Endpoint N/A ### Parameters This is a type definition and does not have direct parameters in the context of an API endpoint. ### Request Example N/A ### Response #### Success Response (N/A) This is a type definition, not an endpoint with a success response. #### Response Example N/A ``` -------------------------------- ### Echo Bot using Pyrogram Source: https://telegramplayground.github.io/pyrogram/start/examples/echo_bot This Python code defines a simple echo bot using the Pyrogram library. It utilizes the `@app.on_message` decorator with `filters.text` and `filters.private` to process only text messages sent in private chats. The bot then replies with the same text it received. The `Client` is initialized and run, automatically starting the client and keeping it running indefinitely. ```python from pyrogram import Client, filters app = Client("my_account") @app.on_message(filters.text & filters.private) async def echo(client, message): await message.reply(message.text) app.run() # Automatically start() and idle() ``` -------------------------------- ### Pyrogram Client Instantiation and Method Invocation Source: https://telegramplayground.github.io/pyrogram/start/invoking This section details the step-by-step process of using Pyrogram. It covers importing the Client class, creating a client instance with a session name, defining an asynchronous function to perform actions like sending messages, and finally executing this function. ```python from pyrogram import Client ``` ```python app = Client("my_account") ``` ```python async def main(): async with app: await app.send_message(chat_id="me", text="Hi!") ``` ```python app.run(main()) ``` -------------------------------- ### Send Markdown Formatted Message with Pyrogram Source: https://telegramplayground.github.io/pyrogram/topics/text-formatting Demonstrates how to send a message with various text formatting styles using Pyrogram's Markdown parse mode. It includes bold, italic, underline, strike, spoiler, URLs, inline code, code blocks, blockquotes, and expandable blockquotes. Ensure Pyrogram is installed and you have an active app instance. ```python from pyrogram.enums import ParseMode await app.send_message( chat_id="me", text=( "**bold**, " "__italic__, " "--underline--, " "~~strike~~, " "||spoiler||, " "[URL](https://telegramplayground.github.io/pyrogram/), " "`code`, " "```" "for i in range(10):\n" " print(i)" "```" ">blockquote\n" "|>escaped blockquote\n" ">Fist line of multi line blockquote\n" ">Block quotation continued\n" ">Block quotation continued\n" ">Block quotation continued\n" ">The last line of the block quotation" "**>\n" "The expandable block quotation started right after the previous block quotation\n" "It is separated from the previous block quotation by expandable syntax\n" "Expandable block quotation continued\n" "Hidden by default part of the expandable block quotation started\n" "Expandable block quotation continued\n" "The last line of the expandable block quotation with the expandability mark<**" ), parse_mode=ParseMode.MARKDOWN ) ``` -------------------------------- ### Get Chat Members using Chat Object in Pyrogram Source: https://telegramplayground.github.io/pyrogram/api/bound-methods/Chat.get_members This code example shows how to use the shortcut method `chat.get_members()` to retrieve members directly from a `Chat` object in Pyrogram. This method simplifies the process compared to using the client directly and allows for iterating over members with ease. It's a common pattern for accessing chat information when you already have a `Chat` object. ```python async for member in chat.get_members(): print(member) ``` -------------------------------- ### InputWallPaper Constructor Source: https://telegramplayground.github.io/pyrogram/telegram/types/input-wall-paper Provides details on how to construct an InputWallPaper object, including required parameters like ID and access hash. ```APIDOC ## InputWallPaper Constructor ### Description Constructs an `InputWallPaper` object used for representing wallpapers. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for constructor" } ``` ### Response #### Success Response (200) - **InputWallPaper** (object) - The constructed InputWallPaper object. #### Response Example ```json { "example": "Not applicable for constructor response" } ``` ## Class: InputWallPaper ### Description Represents a wallpaper in the Pyrogram library. ### Method Constructor ### Endpoint `pyrogram.raw.types.InputWallPaper` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Not applicable for constructor" } ``` ### Response #### Success Response (200) - **id** (int 64-bit) - Wallpaper ID. - **access_hash** (int 64-bit) - Access hash. #### Response Example ```json { "id": 1234567890123456789, "access_hash": 9876543210987654321 } ``` ``` -------------------------------- ### bots.AddPreviewMedia Source: https://telegramplayground.github.io/pyrogram/telegram/functions/bots/add-preview-media Adds a main mini app preview for a bot. This method can only be used by owners of bots with a configured Main Mini App. ```APIDOC ## bots.AddPreviewMedia ### Description Adds a main mini app preview for a bot. This method can only be used by owners of bots with a configured Main Mini App. ### Method POST ### Endpoint /bots/AddPreviewMedia ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **bot** (InputUser) - Required - The bot that owns the Main Mini App. - **lang_code** (str) - Required - ISO 639-1 language code, indicating the localization of the preview to add. - **media** (InputMedia) - Required - The photo/video preview, uploaded using messages.uploadMedia. ### Request Example ```json { "bot": {"InputUser" object}, "lang_code": "en", "media": {"InputMedia" object} } ``` ### Response #### Success Response (200) - **BotPreviewMedia** - The response object indicating the success of adding the preview. #### Response Example ```json { "BotPreviewMedia": { ... } } ``` ``` -------------------------------- ### Get Admined Bots API Source: https://telegramplayground.github.io/pyrogram/telegram/types/user Get a list of bots that are currently administered by the user. ```APIDOC ## GET /bots.GetAdminedBots ### Description Get a list of bots owned by the current user. ### Method GET ### Endpoint /bots.GetAdminedBots ### Response #### Success Response (200) - **bots** (array) - List of bot objects administered by the user. #### Response Example ```json { "bots": [ { "id": 98765, "username": "my_cool_bot" } ] } ``` ``` -------------------------------- ### POST /messages.RequestMainWebView Source: https://telegramplayground.github.io/pyrogram/telegram/functions/messages/request-main-web-view Opens a Main Mini App for a given bot and peer. Supports options for compact, fullscreen, start parameters, and theme parameters. ```APIDOC ## POST /messages.RequestMainWebView ### Description Opens a Main Mini App for a given bot and peer. This function allows specifying various parameters to control how the mini app is displayed and initiated. ### Method POST ### Endpoint /messages.RequestMainWebView ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **peer** (InputPeer) - Required - Currently open chat, may be inputPeerEmpty if no chat is currently open. - **bot** (InputUser) - Required - Bot that owns the main mini app. - **platform** (str) - Required - Short name of the application; 0-64 English letters, digits, and underscores. - **compact** (bool) - Optional - If set, requests to open the mini app in compact mode. - **fullscreen** (bool) - Optional - If set, requests to open the mini app in fullscreen mode. - **start_param** (str) - Optional - Start parameter, if opening from a Main Mini App link. - **theme_params** (DataJSON) - Optional - Theme parameters. ### Request Example ```json { "peer": {"_": "inputPeerEmpty"}, "bot": {"_": "inputUser", "user_id": 123456789, "access_hash": "some_access_hash"}, "platform": "android", "compact": true, "start_param": "startpayload123", "theme_params": {"_": "dataJSON", "data": "{\"theme\": \"dark\"}"} } ``` ### Response #### Success Response (200) - **result** (WebViewResult) - The result of opening the web view. #### Response Example ```json { "_": "webViewResult", "url": "https://example.com/mini_app" } ``` ``` -------------------------------- ### Pyrogram Client Initialization Source: https://telegramplayground.github.io/pyrogram/api/client This section covers the initialization of the Pyrogram Client, detailing all available parameters for configuring your Telegram session. ```APIDOC ## Pyrogram Client Initialization ### Description Initialize a new Pyrogram Client instance to connect to Telegram. This allows you to manage your Telegram account or bot. ### Method `Client(...)` ### Endpoint N/A (Class constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (Client Constructor) - **name** (`str`) - Required - A name for the client, e.g.: “my_account”. - **api_id** (`int` | `str`, _optional_) - The _api_id_ part of the Telegram API key. - **api_hash** (`str`, _optional_) - The _api_hash_ part of the Telegram API key. - **app_version** (`str`, _optional_) - Application version. Defaults to “Pyrogram x.y.z”. - **device_model** (`str`, _optional_) - Device model. Defaults to _platform.python_implementation() + “ “ + platform.python_version()_. - **system_version** (`str`, _optional_) - Operating System version. Defaults to _platform.system() + “ “ + platform.release()_. - **lang_pack** (`str`, _optional_) - Name of the language pack used on the client. Defaults to "". - **lang_code** (`str`, _optional_) - Code of the language used on the client, in ISO 639-1 standard. Defaults to "en". - **system_lang_code** (`str`, _optional_) - Code of the language used on the system, in ISO 639-1 standard. Defaults to "en". - **ipv6** (`bool`, _optional_) - Pass True to connect to Telegram using IPv6. Defaults to False. - **proxy** (`dict`, _optional_) - The Proxy settings as dict. E.g.: `dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")`. - **test_mode** (`bool`, _optional_) - Enable or disable login to the test servers. Defaults to False. - **bot_token** (`str`, _optional_) - Pass the Bot API token to create a bot session. Only applicable for new sessions. - **session_string** (`str`, _optional_) - Pass a session string to load the session in-memory. - **in_memory** (`bool`, _optional_) - Pass True to start an in-memory session. Defaults to False. - **phone_number** (`str`, _optional_) - Pass the phone number to avoid entering it manually. Only applicable for new sessions. - **phone_code** (`str`, _optional_) - Pass the phone code (for test numbers only) to avoid entering it manually. Only applicable for new sessions. - **password** (`str`, _optional_) - Pass the Two-Step Verification password if required. Only applicable for new sessions. - **workers** (`int`, _optional_) - Number of maximum concurrent workers for handling incoming updates. Defaults to `min(32, os.cpu_count() + 4)`. - **workdir** (`str`, _optional_) - Define a custom working directory for session files. Defaults to the parent directory of the main script. - **plugins** (`dict`, _optional_) - Smart Plugins settings as dict, e.g.: `dict(root="plugins")`. - **parse_mode** (`ParseMode`, _optional_) - Set the global parse mode of the client. - **no_updates** (`bool`, _optional_) - Pass True to disable incoming updates. Defaults to False. - **skip_updates** (`bool`, _optional_) - Pass True to skip pending updates that arrived while the client was offline. Defaults to True. - **takeout** (`bool`, _optional_) - Pass True to use a takeout session. Implies `no_updates=True`. Defaults to False. - **sleep_threshold** (`int`, _optional_) - Set a sleep threshold for flood wait exceptions. Defaults to 10 seconds. ### Request Example ```python from pyrogram import Client app = Client("my_account", api_id=1234567, api_hash="0123456789abcdef0123456789abcdef") ``` ### Response #### Success Response (200) N/A (Client initialization does not return a direct response in this context). #### Response Example N/A ``` -------------------------------- ### messages.StickerSetInstallResultArchive Source: https://telegramplayground.github.io/pyrogram/telegram/types/messages/sticker-set-install-result-archive Represents a sticker set that has been installed but archived due to exceeding the maximum number of installed sticker sets. ```APIDOC ## messages.StickerSetInstallResultArchive ### Description This object signifies that a sticker set was successfully installed, but due to exceeding the limit of installed sticker sets, it has been archived. It is a constructor of `StickerSetInstallResult`. ### Method (Not applicable, this is a data type) ### Endpoint (Not applicable, this is a data type) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example (Not applicable, this is a data type) ### Response #### Success Response (200) - **sets** (List of `StickerSetCovered`) – A list of sticker sets that have been archived. #### Response Example ```json { "sets": [ { "id": 1234567890, "access_hash": "some_access_hash", "title": "Archived Sticker Pack", "short_name": "archived_pack", "count": 50, "hash": 12345 } ] } ``` ``` -------------------------------- ### Run Pyrogram Client Sequentially Source: https://telegramplayground.github.io/pyrogram/api/methods/run This code demonstrates the basic usage of Client.run() without any arguments. It sequentially calls start(), idle(), and stop() for a Pyrogram client, making it a convenient way to run a single client instance with minimal verbosity. Ensure handlers are set up before calling run(). ```python from pyrogram import Client app = Client("my_account") ... # Set handlers up app.run() ```