### Quick Start: Basic Rubika Bot with Pyrubi Source: https://github.com/aliganji1/pyrubi/blob/main/README.md A simple example demonstrating how to initialize a Rubika client, set up a message listener for 'hello' messages, and reply using the pyrubi library. This requires the pyrubi library to be installed. ```python from pyrubi import Client from pyrubi.types import Message client = Client("mySelf") @client.on_message(regexp="hello") def send_hello(message: Message): message.reply("**hello** __from__ ##pyrubi##") client.run() ``` -------------------------------- ### Quick Start: Rubika Bot with Manual Session Data Source: https://github.com/aliganji1/pyrubi/blob/main/README.md This example shows how to initialize a Rubika client with manually provided authentication and private keys. It includes setting up a message listener and replying to 'hello' messages. Ensure your auth_key and private_key are correctly formatted. ```python from pyrubi import Client from pyrubi.types import Message auth_key = "abcdefghijklnopkrstuvwxyzazxcqwe" private_key = "-----BEGIN RSA PRIVATE KEY-----\n..." client = Client(auth=auth_key, private=private_key) @client.on_message(regexp="hello") def send_hello(message: Message): message.reply("**hello** __from__ ##pyrubi##") client.run() ``` -------------------------------- ### Install Pyrubi Library Source: https://github.com/aliganji1/pyrubi/blob/main/README.md Installs or updates the pyrubi library using pip. Ensure you have Python and pip installed. ```bash pip install -U pyrubi ``` -------------------------------- ### Handle Incoming Messages and Run Pyrubi Bot Source: https://context7.com/aliganji1/pyrubi/llms.txt Shows how to register message handlers using decorators with filters like regular expressions or by checking message properties. It includes examples for simple text replies, checking message details, and downloading media files. The snippet concludes with starting the bot's execution. ```python from pyrubi import Client from pyrubi.types import Message client = Client("myBot") # Simple text-based handler @client.on_message(regexp="hello") def send_hello(message: Message): message.reply("**hello** __from__ ##pyrubi##") message.seen() # Handler with multiple conditions @client.on_message(regexp="status") def check_status(message: Message): if message.is_mine: return # Ignore own messages response = f""" Chat Type: {message.chat_type} Author: {message.author_title} Message ID: {message.message_id} Time: {message.time_string} """ message.reply(response) # Media file handler @client.on_message() def handle_media(message: Message): if message.message_type == "Image": file_data = message.download(save=True, save_as="received_image.jpg") message.reply("Image received and saved!") elif message.message_type == "Voice": message.reply("Voice message received") # Start the bot (blocking call) client.run() ``` -------------------------------- ### Message Handler and Bot Execution Source: https://context7.com/aliganji1/pyrubi/llms.txt Explains how to register message handlers using decorators with filters and regular expressions. It covers simple text-based responses, handling multiple conditions, and processing media files. Finally, it shows how to start the bot's execution. ```APIDOC ## Message Handler and Bot Execution ### Description Registering message handlers with filters and regular expressions for automated responses. ### Method N/A (Library Usage) ### Endpoint N/A (Library Usage) ### Parameters N/A (Library Usage) ### Request Example ```python from pyrubi import Client from pyrubi.types import Message client = Client("myBot") # Simple text-based handler @client.on_message(regexp="hello") def send_hello(message: Message): message.reply("**hello** __from__ ##pyrubi##") message.seen() # Handler with multiple conditions @client.on_message(regexp="status") def check_status(message: Message): if message.is_mine: return # Ignore own messages response = f""" Chat Type: {message.chat_type} Author: {message.author_title} Message ID: {message.message_id} Time: {message.time_string} """ message.reply(response) # Media file handler @client.on_message() def handle_media(message: Message): if message.message_type == "Image": file_data = message.download(save=True, save_as="received_image.jpg") message.reply("Image received and saved!") elif message.message_type == "Voice": message.reply("Voice message received") # Start the bot (blocking call) client.run() ``` ### Response #### Success Response (N/A - Bot Execution) N/A #### Response Example N/A ``` -------------------------------- ### Stickers and GIFs Management (Python) Source: https://context7.com/aliganji1/pyrubi/llms.txt Handles sending stickers by emoji or sticker data, retrieving stickers by emoji, managing sticker sets (getting own, trending, searching, adding, removing), and managing saved GIFs (getting own, adding, removing). Also supports sending GIFs with optional text and thumbnail. Requires chat GUID, sticker data, or GIF file paths. ```python from pyrubi import Client client = Client("mySelf") chat_guid = "u0123456789ABCDEF0123456789ABCDEF" # Send sticker by emoji (random from available) client.send_sticker( object_guid=chat_guid, emoji="😂" ) # Get stickers by emoji stickers = client.get_stickers_by_emoji(emoji="❤️") sticker_data = stickers["stickers"][0] # First sticker # Send specific sticker client.send_sticker( object_guid=chat_guid, sticker_data=sticker_data ) # Get my sticker sets my_stickers = client.get_my_sticker_sets() for sticker_set in my_stickers["sticker_sets"]: print(f"Set: {sticker_set['name']}") # Get trending sticker sets trending = client.get_trend_sticker_sets(start_id=None) # Search sticker sets search_results = client.search_stickers( search_text="funny", start_id=None ) # Add sticker set client.add_sticker(sticker_set_id="sticker_set_123456") # Remove sticker set client.remove_sticker(sticker_set_id="sticker_set_123456") # Get my saved GIFs my_gifs = client.get_my_gif_set() # Add GIF to saved collection client.add_gif( object_guid=chat_guid, message_id="12345678901234567890" ) # Remove GIF from collection client.remove_gif(file_id="file_123456") # Send GIF client.send_gif( object_guid=chat_guid, file="./animation.gif", text="Check this out!", thumbnail="./gif_thumb.jpg" ) ``` -------------------------------- ### Send Various Media and Text Messages with Pyrubi Source: https://context7.com/aliganji1/pyrubi/llms.txt Provides examples for sending different types of content via the Rubika API using Pyrubi. This includes text messages with formatting, images with captions and spoilers, videos with custom thumbnails, audio files, voice messages, locations, and contact information. It also demonstrates how to reply to specific messages. ```python from pyrubi import Client client = Client("mySelf") # Send text message chat_guid = "u0123456789ABCDEF0123456789ABCDEF" response = client.send_text( object_guid=chat_guid, text="Hello from **Pyrubi**! Visit @pyrubika for more info." ) # Send image with caption and spoiler client.send_image( object_guid=chat_guid, file="./photo.jpg", text="Check out this image!", is_spoil=True, # Blur the image thumbnail="./thumb.jpg" ) # Send video with custom thumbnail client.send_video( object_guid=chat_guid, file="./video.mp4", text="My video", thumbnail="./video_thumb.jpg" ) # Send audio/music file client.send_music( object_guid=chat_guid, file="./song.mp3", text="Great song!", performer="Artist Name" ) # Send voice message client.send_voice( object_guid=chat_guid, file="./voice.ogg", time=45 # Duration in seconds ) # Send location client.send_location( object_guid=chat_guid, latitude=35.6892, longitude=51.3890 ) # Send contact client.send_contact( object_guid=chat_guid, first_name="John", last_name="Doe", phone_number="989123456789", user_guid="u0123456789ABCDEF0123456789ABCDEF" ) # Reply to a specific message client.send_text( object_guid=chat_guid, text="This is a reply", message_id="12345678901234567890" ) ``` -------------------------------- ### Handle All Messages in Pyrubi Source: https://context7.com/aliganji1/pyrubi/llms.txt Demonstrates how to handle all incoming messages in Pyrubi, accessing message properties like GUID, text, author, chat type, and file information. It also shows how to use message methods such as replying, reacting, downloading files, forwarding, pinning, deleting, banning, and checking membership. This requires the pyrubi library and its Message types. ```python from pyrubi import Client from pyrubi.types import Message client = Client("myBot") @client.on_message() def handle_all_messages(message: Message): # Message properties print(f"Object GUID: {message.object_guid}") print(f"Message ID: {message.message_id}") print(f"Text: {message.text}") print(f"Author GUID: {message.author_guid}") print(f"Author Title: {message.author_title}") print(f"Is mine: {message.is_mine}") print(f"Chat type: {message.chat_type}" ) # User, Group, Channel print(f"Message type: {message.message_type}") # Text, Image, Video, etc. print(f"Time: {message.time_string}") print(f"Is edited: {message.is_edited}") # Check message type if message.is_group: print("Message from group") elif message.is_user: print("Private message") # Check for links if message.has_link: print("Message contains a link") # Forward information if message.is_forward: print(f"Forwarded from: {message.forward_from}") print(f"Original GUID: {message.forward_object_guid}") print(f"Original message ID: {message.forward_message_id}") # Event information (e.g., member joined, pinned message) if message.is_event: print(f"Event type: {message.event_type}") print(f"Event performer: {message.event_object_guid}") # File information if message.file_inline: file = message.file_inline print(f"File type: {file['type']}") print(f"File name: {file['file_name']}") print(f"File size: {file['size']}") # Reply information if message.reply_message_id: reply_info = message.reply_info print(f"Replying to: {reply_info.text}") print(f"Reply author: {reply_info.author_guid}") # Message methods message.seen() # Mark as seen message.reply("Thanks for your message!") message.reaction(1) # Add thumbs up reaction # Download file if present if message.file_inline: message.download(save=True, save_as="./downloads/file.dat") # Forward to another chat message.forward(to_object_guid="g0987654321FEDCBA9876543210FEDCBA") # Pin message message.pin() # Delete message message.delete(delete_for_all=True) # Ban author (if in group) if message.is_group and not message.is_mine: message.ban() # Check if author is member of another chat is_member = message.check_join(object_guid="g0123456789ABCDEF0123456789ABCDEF") client.run() ``` -------------------------------- ### PyRubi: Create, Edit, Manage Group and Channel Info Source: https://context7.com/aliganji1/pyrubi/llms.txt This snippet demonstrates how to manage groups and channels using the PyRubi client. It covers creating new groups and channels, editing their information (including title, description, slow mode, and reaction settings), adding members, and setting or removing administrative permissions. It also includes functionality to ban/unban members, retrieve member lists (all, admin, banned), and set default access permissions for group members. Requires a connected PyRubi client instance and valid GUIDs. ```python from pyrubi import Client from pyrubi.enums import SetAdminAccessList, SetGroupDefaultAccessList client = Client("mySelf") # Create a new group response = client.add_group( title="My Python Group", member_guids=["u0111111111111111111111111111111", "u0222222222222222222222222222222"] ) group_guid = response["group"]["group_guid"] # Create a new channel response = client.add_channel( title="My Channel", description="A channel about Python programming", member_guids=["u0111111111111111111111111111111"], private=False # Public channel ) channel_guid = response["channel"]["channel_guid"] # Edit group information client.edit_group_info( object_guid=group_guid, title="Updated Group Name", description="New group description", slow_mode=10, # 10 seconds between messages event_messages=True, chat_history_for_new_members=True, reaction_type="Selected", selected_reactions=[1, 2, 3] # Allowed reactions ) # Edit channel information client.edit_channel_info( object_guid=channel_guid, title="Updated Channel", description="New channel description", username="mychannel", private=False, sign_message=True, reaction_type="All" ) # Add members to group/channel client.add_member( object_guid=group_guid, member_guids=["u0333333333333333333333333333333", "u0444444444444444444444444444444"] ) # Set admin with permissions client.set_admin( object_guid=group_guid, member_guid="u0111111111111111111111111111111", access_list=[ SetAdminAccessList.ban_member, SetAdminAccessList.delete_messages, SetAdminAccessList.pin_messages, SetAdminAccessList.change_info ], custom_title="Moderator" ) # Remove admin permissions client.unset_admin( object_guid=group_guid, member_guid="u0111111111111111111111111111111" ) # Ban member client.ban_member( object_guid=group_guid, member_guid="u0555555555555555555555555555555" ) # Unban member client.unban_member( object_guid=group_guid, member_guid="u0555555555555555555555555555555" ) # Get all members members = client.get_all_members( object_guid=group_guid, search_text="john", just_get_guids=False # Set True to get only GUIDs list ) # Get admin members only admins = client.get_admin_members( object_guid=group_guid, just_get_guids=False ) # Get banned members banned = client.get_banned_members(object_guid=group_guid) # Set group default access permissions client.set_group_default_access( object_guid=group_guid, access_list=[ SetGroupDefaultAccessList.send_messages, SetGroupDefaultAccessList.view_members ] ) ``` -------------------------------- ### Download Files and Transcribe Voice Messages with PyRubi Source: https://context7.com/aliganji1/pyrubi/llms.txt This snippet demonstrates how to download files from messages and manage file operations using the PyRubi client. It includes getting download links, downloading files to disk or memory, and downloading directly from file inline data. It also shows how to transcribe voice messages to text. Requires a PyRubi Client instance and chat/message identifiers. ```python from pyrubi import Client client = Client("mySelf") chat_guid = "g0123456789ABCDEF0123456789ABCDEF" message_id = "12345678901234567890" # Get download link for file download_url = client.get_download_link( object_guid=chat_guid, message_id=message_id ) print(f"Download URL: {download_url}") # Download file and save to disk file_data = client.download( object_guid=chat_guid, message_id=message_id, save=True, save_as="./downloads/myfile.pdf" ) print(f"Downloaded: {file_data['file_name']}") print(f"Size: {file_data['size']} bytes") # Download file to memory (no save) file_data = client.download( object_guid=chat_guid, message_id=message_id, save=False ) file_bytes = file_data['file'] # Raw bytes # Process file_bytes as needed # Download from file_inline directly (without message_id) file_inline = { "file_id": "123456789", "access_hash_rec": "abcdefgh", "dc_id": "1", "size": 1024000, "file_name": "document.pdf" } file_data = client.download(file_inline=file_inline, save=True) # Transcribe voice message to text transcription = client.transcribe_voice( object_guid=chat_guid, message_id=message_id ) if transcription["status"] == "OK": print(f"Transcription: {transcription['text']}") ``` -------------------------------- ### PyRubi: Edit, Delete, Forward, Pin, React to Messages Source: https://context7.com/aliganji1/pyrubi/llms.txt This snippet demonstrates how to perform various message operations using the PyRubi client. It includes editing, deleting (for all participants), forwarding messages to other chats, pinning/unpinning messages, and managing reactions (adding/removing). It also shows how to mark messages as seen, retrieve messages by various filters (including by ID), and search for messages within a chat. Requires a connected PyRubi client instance and valid chat/message GUIDs. ```python from pyrubi import Client client = Client("mySelf") chat_guid = "g0123456789ABCDEF0123456789ABCDEF" message_id = "12345678901234567890" # Edit message client.edit_message( object_guid=chat_guid, message_id=message_id, text="Updated message content with **formatting**" ) # Delete messages (for everyone) client.delete_messages( object_guid=chat_guid, message_ids=[message_id, "09876543210987654321"], delete_for_all=True ) # Forward messages to another chat target_chat = "g0987654321FEDCBA9876543210FEDCBA" client.forward_messages( object_guid=chat_guid, message_ids=[message_id], to_object_guid=target_chat ) # Pin message client.pin_message(object_guid=chat_guid, message_id=message_id) # Unpin message client.unpin_message(object_guid=chat_guid, message_id=message_id) # Add reaction to message (reaction IDs: 1-5) client.reaction_message( object_guid=chat_guid, message_id=message_id, reaction=1 # 👍 ) # Remove reaction client.unreaction_message( object_guid=chat_guid, message_id=message_id, reaction=1 ) # Mark messages as seen client.seen_messages( object_guid=chat_guid, min_id="12345678901234567890", max_id="12345678901234567899" ) # Get messages messages = client.get_messages( object_guid=chat_guid, max_message_id=None, filter_type="Image", # Filter: Image, Video, Voice, File, etc. limit=50 ) # Get specific messages by ID messages = client.get_messages_by_id( object_guid=chat_guid, message_ids=[message_id, "09876543210987654321"] ) # Search messages in chat results = client.search_chat_messages( object_guid=chat_guid, search_text="#python" ) ``` -------------------------------- ### Manage Chats and Retrieve Information with PyRubi Source: https://context7.com/aliganji1/pyrubi/llms.txt This section covers various chat management operations using the PyRubi client. It includes retrieving chats, getting chat information by GUID or username, joining, leaving, removing, and pinning/unpinning chats. It also details muting/unmuting, sending activity, marking chats as seen, deleting history, uploading avatars, getting avatars, reporting chats, and sending typing indicators. Requires a PyRubi Client instance. ```python from pyrubi import Client client = Client("mySelf") # Get all chats chats = client.get_chats(start_id=None) for chat in chats["chats"]: print(f"{chat['object_guid']}: {chat.get('title', 'Private Chat')}") # Get chat information by GUID chat_info = client.get_chat_info(object_guid="g0123456789ABCDEF0123456789ABCDEF") print(f"Title: {chat_info['chat']['title']}") print(f"Members: {chat_info['chat']['count_members']}") # Get chat information by username chat_info = client.get_chat_info_by_username(username="@mychannel") # Join chat by link or GUID client.join_chat(guid_or_link="https://rubika.ir/joing/XXXXXXXX") # Leave chat client.leave_chat(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Remove/delete chat client.remove_chat(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Get/set chat invite link link = client.get_link(object_guid="g0123456789ABCDEF0123456789ABCDEF") print(f"Invite link: {link['join_link']}") # Generate new invite link new_link = client.set_link(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Pin chat to top client.pin_chat(object_guid="u0123456789ABCDEF0123456789ABCDEF") # Unpin chat client.unpin_chat(object_guid="u0123456789ABCDEF0123456789ABCDEF") # Mute chat client.mute_chat(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Unmute chat client.unmute_chat(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Send typing activity client.send_chat_activity( object_guid="u0123456789ABCDEF0123456789ABCDEF", activity="Typing" # Options: Typing, Recording, Uploading ) # Mark multiple chats as seen client.seen_chats(seen_list={ "g0123456789ABCDEF0123456789ABCDEF": "12345678901234567890", "u0987654321FEDCBA9876543210FEDCBA": "09876543210987654321" }) # Delete chat history client.delete_history( object_guid="u0123456789ABCDEF0123456789ABCDEF", last_message_id="12345678901234567890" ) # Upload avatar/profile picture client.upload_avatar( object_guid="g0123456789ABCDEF0123456789ABCDEF", main_file="./avatar.jpg", thumbnail_file="./avatar_thumb.jpg" ) # Get avatars avatars = client.getAvatars(object_guid="g0123456789ABCDEF0123456789ABCDEF") # Report chat/user client.report_chat( object_guid="u0123456789ABCDEF0123456789ABCDEF", description="Spam or inappropriate content" ) ``` -------------------------------- ### Initialize Pyrubi Client with Authentication Options Source: https://context7.com/aliganji1/pyrubi/llms.txt Demonstrates how to initialize the Pyrubi client using automatic session management or manual authentication with provided keys. It also shows advanced configuration options like proxy and API version, and how to retrieve current user information. ```python from pyrubi import Client from pyrubi.types import Message # Automatic session management - creates/loads session file client = Client("mySelf") # Manual authentication with auth key and private key auth_key = "abcdefghijklmnopqrstuvwxyzabcdefgh" private_key = "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQC...\n-----END RSA PRIVATE KEY-----" client = Client(auth=auth_key, private=private_key) # Advanced configuration with proxy and custom settings client = Client( session="myBot", platform="web", # Options: web, android, rubx api_version=6, proxy="http://proxy.example.com:8080", time_out=10, show_progress_bar=True ) # Get current user information me = client.get_me() print(f"Logged in as: {me['user']['first_name']}") print(f"User GUID: {me['user']['user_guid']}") print(f"Auth: {me['auth']}") ``` -------------------------------- ### Client Initialization and Authentication Source: https://context7.com/aliganji1/pyrubi/llms.txt Demonstrates how to create a Pyrubi client instance with automatic session management or manual authentication. It also shows advanced configuration options and how to retrieve current user information. ```APIDOC ## Client Initialization and Authentication ### Description Creating a Pyrubi client with automatic session management or manual authentication credentials. ### Method N/A (Library Usage) ### Endpoint N/A (Library Usage) ### Parameters N/A (Library Usage) ### Request Example ```python from pyrubi import Client from pyrubi.types import Message # Automatic session management - creates/loads session file client = Client("mySelf") # Manual authentication with auth key and private key auth_key = "abcdefghijklmnopqrstuvwxyzabcdefgh" private_key = """-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQC...\n-----END RSA PRIVATE KEY-----""" client = Client(auth=auth_key, private=private_key) # Advanced configuration with proxy and custom settings client = Client( session="myBot", platform="web", # Options: web, android, rubx api_version=6, proxy="http://proxy.example.com:8080", time_out=10, show_progress_bar=True ) # Get current user information me = client.get_me() print(f"Logged in as: {me['user']['first_name']}") print(f"User GUID: {me['user']['user_guid']}") print(f"Auth: {me['auth']}") ``` ### Response #### Success Response (N/A - Client Initialization) N/A #### Response Example ```json { "user": { "first_name": "ExampleUser", "user_guid": "u0123456789ABCDEF0123456789ABCDEF" }, "auth": "..." } ``` ``` -------------------------------- ### Advanced Search and Global Operations with PyRubi Client Source: https://context7.com/aliganji1/pyrubi/llms.txt This snippet covers advanced search functionalities including global message search, global object search (users, channels, groups), retrieving absolute objects by GUIDs, getting server time, checking user membership in a chat, obtaining profile link items, resolving links from app URLs, and resetting contacts. It utilizes the Filters enum for search refinement and requires an initialized PyRubi client. ```python from pyrubi import Client from pyrubi.enums import Filters client = Client("mySelf") # Search global messages results = client.search_global_messages(search_text="python tutorial") for message in results.get("messages", []): print(f"From: {message.get('chat_title')}") print(f"Text: {message.get('text')}") # Search global objects (users, channels, groups) results = client.search_global_objects( search_text="programming", filters=[Filters.channel, Filters.group] ) # Get absolute objects by GUIDs objects = client.get_abs_objects( object_guids=[ "g0123456789ABCDEF0123456789ABCDEF", "u0987654321FEDCBA9876543210FEDCBA", "c0111111111111111111111111111111" ] ) for obj in objects["objects"]: print(f"Type: {obj['type']}") print(f"Title: {obj.get('title', obj.get('first_name'))}") # Get server time time_info = client.get_time() print(f"Server time: {time_info['time_ms']}") # Check if user is member of chat is_member = client.check_join( object_guid="g0123456789ABCDEF0123456789ABCDEF", user_guid="u0123456789ABCDEF0123456789ABCDEF" ) print(f"Is member: {is_member}") # Get profile link items (bio links) links = client.get_profile_link_items( object_guid="u0123456789ABCDEF0123456789ABCDEF" ) # Get link from app URL link_info = client.get_link_from_app_url( url="rubika://profile/username/johndoe" ) # Reset/refresh contacts client.reset_contacts() ``` -------------------------------- ### Get Poll Status and Voters (Python) Source: https://context7.com/aliganji1/pyrubi/llms.txt Retrieves the status of a poll, including total votes and vote counts per option, and fetches voters for a specific poll option. Requires a poll ID and optionally a selection index for voters. Outputs are dictionaries containing poll and voter information. ```python from pyrubi import Client client = Client("mySelf") poll_id = "your_poll_id" # Get poll status and results status = client.get_poll_status(poll_id=poll_id) print(f"Total votes: {status['poll']['total_votes']}") for option in status['poll']['options']: print(f"{option['text']}: {option['vote_count']} votes") # Get voters for specific option voters = client.get_poll_option_voters( poll_id=poll_id, selection_index=0, # Get voters for first option start_id=None ) for voter in voters['voters']: print(f"Voter: {voter['user']['first_name']}") ``` -------------------------------- ### Create and Manage Polls with PyRubi Source: https://context7.com/aliganji1/pyrubi/llms.txt This section illustrates how to create polls and quizzes, vote in them, and retrieve poll results using the PyRubi client. It shows the creation of both simple anonymous polls and interactive quizzes with a defined correct answer. It also demonstrates how to cast a vote in an existing poll. Requires a PyRubi Client instance and chat identifiers. ```python from pyrubi import Client client = Client("mySelf") chat_guid = "g0123456789ABCDEF0123456789ABCDEF" # Create a simple poll poll = client.send_poll( object_guid=chat_guid, question="What is your favorite programming language?", options=["Python", "JavaScript", "Java", "C++"], multiple_answers=False, anonymous=True, quiz=False ) poll_id = poll["message"]["poll"]["poll_id"] # Create a quiz (with correct answer) quiz = client.send_poll( object_guid=chat_guid, question="What is 2 + 2?", options=["3", "4", "5", "6"], quiz=True, anonymous=False ) # Vote in a poll (index starts at 0) client.vote_poll( poll_id=poll_id, selection_index=0 # Vote for first option ) ``` -------------------------------- ### Manage Two-Step Verification and Password with PyRubi Source: https://context7.com/aliganji1/pyrubi/llms.txt This snippet demonstrates how to check the status of two-step verification, verify a two-step passcode, change the account password, set up and verify a recovery email, and turn off two-step verification using the PyRubi client. It requires the client object to be initialized. ```python from pyrubi import Client client = Client("mySelf") # Check two-step passcode status status = client.get_two_passcode_status() print(f"2FA enabled: {status.get('has_password', False)}") # Verify two-step password result = client.check_two_step_passcode(password="MySecurePassword123") # Change password client.change_password( password="OldPassword123", new_password="NewSecurePassword456", new_hint="New hint" ) # Setup recovery email client.request_recovery_email( password="MySecurePassword123", recovery_email="newemail@example.com" ) # Verify recovery email with code client.verify_recovery_email( password="MySecurePassword123", code="123456" ) # Turn off two-step verification client.turn_off_two_step(password="MySecurePassword123") # Logout from current session client.logout() ``` -------------------------------- ### Group and Channel Management Source: https://context7.com/aliganji1/pyrubi/llms.txt APIs for creating, editing, and managing groups and channels, including member management, administrative permissions, and banning. ```APIDOC ## POST /api/groups/add ### Description Creates a new group with specified title and initial members. ### Method POST ### Endpoint `/api/groups/add` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **title** (string) - Required - The title of the new group. - **member_guids** (array of strings) - Optional - A list of user GUIDs to add as initial members. ### Request Example ```json { "title": "My Python Group", "member_guids": ["u0111111111111111111111111111111", "u0222222222222222222222222222222"] } ``` ### Response #### Success Response (200) Returns information about the newly created group. - **group** (object) - Contains details of the created group, including `group_guid`. #### Response Example ```json { "group": { "group_guid": "g0abcdef1234567890abcdef1234567890" } } ``` ## POST /api/channels/add ### Description Creates a new channel with a title, description, and initial members. ### Method POST ### Endpoint `/api/channels/add` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **title** (string) - Required - The title of the new channel. - **description** (string) - Optional - A description for the channel. - **member_guids** (array of strings) - Optional - A list of user GUIDs to add as initial members. - **private** (boolean) - Optional - Whether the channel is private. Defaults to false (public). ### Request Example ```json { "title": "My Channel", "description": "A channel about Python programming", "member_guids": ["u0111111111111111111111111111111"], "private": false } ``` ### Response #### Success Response (200) Returns information about the newly created channel. - **channel** (object) - Contains details of the created channel, including `channel_guid`. #### Response Example ```json { "channel": { "channel_guid": "c0abcdef1234567890abcdef1234567890" } } ``` ## POST /api/groups/edit_info ### Description Edits the information of an existing group. ### Method POST ### Endpoint `/api/groups/edit_info` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group. - **title** (string) - Optional - The new title for the group. - **description** (string) - Optional - The new description for the group. - **slow_mode** (integer) - Optional - The slow mode interval in seconds. - **event_messages** (boolean) - Optional - Whether to show event messages. - **chat_history_for_new_members** (boolean) - Optional - Whether new members can see chat history. - **reaction_type** (string) - Optional - Type of reactions allowed (e.g., "Selected", "All"). - **selected_reactions** (array of integers) - Optional - List of allowed reaction IDs if `reaction_type` is "Selected". ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "title": "Updated Group Name", "slow_mode": 10, "selected_reactions": [1, 2, 3] } ``` ### Response #### Success Response (200) Returns a success status indicating the group info was updated. #### Response Example ```json { "status": "success" } ``` ## POST /api/channels/edit_info ### Description Edits the information of an existing channel. ### Method POST ### Endpoint `/api/channels/edit_info` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the channel. - **title** (string) - Optional - The new title for the channel. - **description** (string) - Optional - The new description for the channel. - **username** (string) - Optional - The new username for the channel. - **private** (boolean) - Optional - Whether the channel is private. - **sign_message** (boolean) - Optional - Whether messages should be signed. - **reaction_type** (string) - Optional - Type of reactions allowed (e.g., "All"). ### Request Example ```json { "object_guid": "c0abcdef1234567890abcdef1234567890", "title": "Updated Channel", "username": "mychannel" } ``` ### Response #### Success Response (200) Returns a success status indicating the channel info was updated. #### Response Example ```json { "status": "success" } ``` ## POST /api/groups/add_member ### Description Adds one or more members to a group or channel. ### Method POST ### Endpoint `/api/groups/add_member` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group or channel. - **member_guids** (array of strings) - Required - A list of user GUIDs to add. ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "member_guids": ["u0333333333333333333333333333333", "u0444444444444444444444444444444"] } ``` ### Response #### Success Response (200) Returns a success status indicating the members were added. #### Response Example ```json { "status": "success" } ``` ## POST /api/groups/set_admin ### Description Sets administrative permissions for a member in a group or channel. ### Method POST ### Endpoint `/api/groups/set_admin` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group or channel. - **member_guid** (string) - Required - The GUID of the member to set as admin. - **access_list** (array of strings) - Required - A list of permissions to grant (e.g., "ban_member", "delete_messages"). - **custom_title** (string) - Optional - A custom title for the admin. ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "member_guid": "u0111111111111111111111111111111", "access_list": ["ban_member", "delete_messages", "pin_messages", "change_info"], "custom_title": "Moderator" } ``` ### Response #### Success Response (200) Returns a success status indicating the admin permissions were set. #### Response Example ```json { "status": "success" } ``` ## POST /api/groups/unset_admin ### Description Removes administrative permissions from a member in a group or channel. ### Method POST ### Endpoint `/api/groups/unset_admin` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group or channel. - **member_guid** (string) - Required - The GUID of the member to remove admin permissions from. ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "member_guid": "u0111111111111111111111111111111" } ``` ### Response #### Success Response (200) Returns a success status indicating admin permissions were removed. #### Response Example ```json { "status": "success" } ``` ## POST /api/groups/ban_member ### Description Bans a member from a group or channel. ### Method POST ### Endpoint `/api/groups/ban_member` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group or channel. - **member_guid** (string) - Required - The GUID of the member to ban. ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "member_guid": "u0555555555555555555555555555555" } ``` ### Response #### Success Response (200) Returns a success status indicating the member was banned. #### Response Example ```json { "status": "success" } ``` ## POST /api/groups/unban_member ### Description Unbans a member from a group or channel. ### Method POST ### Endpoint `/api/groups/unban_member` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group or channel. - **member_guid** (string) - Required - The GUID of the member to unban. ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "member_guid": "u0555555555555555555555555555555" } ``` ### Response #### Success Response (200) Returns a success status indicating the member was unbanned. #### Response Example ```json { "status": "success" } ``` ## GET /api/groups/get_all_members ### Description Retrieves a list of all members in a group or channel, with optional search and GUID-only retrieval. ### Method GET ### Endpoint `/api/groups/get_all_members` ### Parameters #### Path Parameters None #### Query Parameters - **object_guid** (string) - Required - The unique identifier of the group or channel. - **search_text** (string) - Optional - Text to search for among member names. - **just_get_guids** (boolean) - Optional - If true, only returns a list of member GUIDs. Defaults to false. ### Request Example ``` GET /api/groups/get_all_members?object_guid=g0abcdef1234567890abcdef1234567890&search_text=john&just_get_guids=false ``` ### Response #### Success Response (200) Returns a list of members or their GUIDs. - **members** (array of objects or strings) - A list of member objects or GUID strings. #### Response Example ```json { "members": [ { "user_guid": "u0111111111111111111111111111111", "name": "John Doe" } ] } ``` ## GET /api/groups/get_admin_members ### Description Retrieves a list of admin members in a group or channel. ### Method GET ### Endpoint `/api/groups/get_admin_members` ### Parameters #### Path Parameters None #### Query Parameters - **object_guid** (string) - Required - The unique identifier of the group or channel. - **just_get_guids** (boolean) - Optional - If true, only returns a list of admin GUIDs. Defaults to false. ### Request Example ``` GET /api/groups/get_admin_members?object_guid=g0abcdef1234567890abcdef1234567890&just_get_guids=false ``` ### Response #### Success Response (200) Returns a list of admin members or their GUIDs. - **admins** (array of objects or strings) - A list of admin member objects or GUID strings. #### Response Example ```json { "admins": [ { "user_guid": "u0111111111111111111111111111111", "name": "Admin User" } ] } ``` ## GET /api/groups/get_banned_members ### Description Retrieves a list of banned members from a group or channel. ### Method GET ### Endpoint `/api/groups/get_banned_members` ### Parameters #### Path Parameters None #### Query Parameters - **object_guid** (string) - Required - The unique identifier of the group or channel. ### Request Example ``` GET /api/groups/get_banned_members?object_guid=g0abcdef1234567890abcdef1234567890 ``` ### Response #### Success Response (200) Returns a list of banned members. - **banned_members** (array of objects) - A list of banned member objects. #### Response Example ```json { "banned_members": [ { "user_guid": "u0555555555555555555555555555555", "name": "Banned User" } ] } ``` ## POST /api/groups/set_default_access ### Description Sets default access permissions for new members joining a group. ### Method POST ### Endpoint `/api/groups/set_default_access` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object_guid** (string) - Required - The unique identifier of the group. - **access_list** (array of strings) - Required - A list of default permissions to grant (e.g., "send_messages", "view_members"). ### Request Example ```json { "object_guid": "g0abcdef1234567890abcdef1234567890", "access_list": ["send_messages", "view_members"] } ``` ### Response #### Success Response (200) Returns a success status indicating the default access permissions were set. #### Response Example ```json { "status": "success" } ``` ```