CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rocketchat-a-p-i

Python API wrapper for Rocket.Chat's REST API, enabling developers to programmatically interact with Rocket.Chat servers for chat automation, bot development, and integration purposes

Pending
Overview
Eval results
Files

rooms.mddocs/

Rooms

Advanced room operations and management functionality that works across all room types (channels, groups, direct messages). Provides file upload, history management, favorites, and administrative functions.

Capabilities

Room Information

def rooms_get(self, **kwargs):
    """
    Get all opened rooms for the current user.
    
    Parameters:
    - updatedSince (str, optional): ISO date string to get rooms updated since
    
    Returns:
    requests.Response: List of user's opened rooms
    """

def rooms_info(self, room_id=None, room_name=None):
    """
    Get information about a specific room.
    
    Parameters:
    - room_id (str, optional): Room ID
    - room_name (str, optional): Room name
    
    Returns:
    requests.Response: Room information
    """

def rooms_admin_rooms(self, **kwargs):
    """
    Get all rooms (requires view-room-administration permission).
    
    Parameters:
    - offset (int, optional): Number of items to skip
    - count (int, optional): Number of items to return
    - sort (dict, optional): Sort criteria
    - filter (str, optional): Filter rooms by name
    - types (list, optional): Room types to include
    
    Returns:
    requests.Response: List of all rooms
    """

File Operations

def rooms_upload(self, rid, file, **kwargs):
    """
    Upload a file to a room.
    
    Parameters:
    - rid (str): Room ID
    - file (str): File path to upload
    - description (str, optional): File description
    - msg (str, optional): Message to accompany the file
    
    Returns:
    requests.Response: File upload result
    """

Room Management

def rooms_favorite(self, room_id=None, room_name=None, favorite=True):
    """
    Mark a room as favorite or unfavorite.
    
    Parameters:
    - room_id (str, optional): Room ID
    - room_name (str, optional): Room name
    - favorite (bool): True to favorite, False to unfavorite
    
    Returns:
    requests.Response: Favorite operation result
    """

def rooms_leave(self, room_id):
    """
    Leave a room.
    
    Parameters:
    - room_id (str): Room ID to leave
    
    Returns:
    requests.Response: Leave operation result
    """

History Management

def rooms_clean_history(self, room_id, latest, oldest, **kwargs):
    """
    Clean room history by removing messages from a time range.
    
    Parameters:
    - room_id (str): Room ID
    - latest (str): Latest date (ISO string or timestamp)
    - oldest (str): Oldest date (ISO string or timestamp)
    - exclusive (bool, optional): Exclude boundary messages
    - ignoreDiscussion (bool, optional): Ignore discussion messages
    - filesOnly (bool, optional): Delete only files
    - users (list, optional): Only delete messages from specific users
    
    Returns:
    requests.Response: History cleaning result
    """

Discussion Management

def rooms_create_discussion(self, prid, t_name, **kwargs):
    """
    Create a new discussion for a room.
    
    Parameters:
    - prid (str): Parent room ID
    - t_name (str): Discussion name
    - reply (str, optional): Message ID to start discussion from
    - users (list, optional): Users to add to discussion
    - encrypted (bool, optional): Create encrypted discussion
    
    Returns:
    requests.Response: Discussion creation result
    """

Room Object Structure

RoomObject = {
    "_id": "str",           # Room ID
    "name": "str",          # Room name
    "t": "str",             # Room type (c=channel, p=group, d=direct)
    "u": {                  # Creator user info
        "_id": "str",
        "username": "str"
    },
    "topic": "str",         # Room topic
    "description": "str",   # Room description
    "announcement": "str",  # Room announcement
    "msgs": "int",          # Message count
    "usersCount": "int",    # User count
    "lastMessage": "dict",  # Last message info
    "ts": "datetime",       # Creation timestamp
    "_updatedAt": "datetime", # Last update timestamp
    "ro": "bool",           # Read-only status
    "sysMes": "bool",       # System messages enabled
    "default": "bool",      # Default channel
    "featured": "bool",     # Featured status
    "favorite": "bool",     # User's favorite status
    "open": "bool",         # Open for user
    "alert": "bool",        # Has unread messages
    "unread": "int",        # Unread message count
    "userMentions": "int",  # User mention count
    "groupMentions": "int"  # Group mention count
}

Usage Examples

# Get all user's rooms
rooms = rocket.rooms_get()
print(f"User has {len(rooms.json()['rooms'])} rooms")

# Get room information
room_info = rocket.rooms_info(room_name='general')
room_id = room_info.json()['room']['_id']

# Upload file to room
upload_result = rocket.rooms_upload(
    rid=room_id,
    file='/path/to/document.pdf',
    description='Important document',
    msg='Please review this document'
)

# Favorite a room
rocket.rooms_favorite(room_id=room_id, favorite=True)

# Clean room history (remove messages from last 7 days)
from datetime import datetime, timedelta
now = datetime.now()
week_ago = now - timedelta(days=7)

rocket.rooms_clean_history(
    room_id=room_id,
    latest=now.isoformat(),
    oldest=week_ago.isoformat(),
    filesOnly=False
)

# Create discussion
discussion = rocket.rooms_create_discussion(
    prid=room_id,
    t_name='Project Planning Discussion',
    users=['john.doe', 'jane.smith']
)

# Leave room
rocket.rooms_leave(room_id)

Install with Tessl CLI

npx tessl i tessl/pypi-rocketchat-a-p-i

docs

administration.md

assets.md

channels.md

chat.md

direct-messages.md

groups.md

index.md

integrations.md

livechat.md

miscellaneous.md

permissions.md

roles.md

rooms.md

settings.md

statistics.md

subscriptions.md

teams.md

users.md

tile.json