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

chat.mddocs/

Chat Operations

Core messaging functionality for sending, managing, and interacting with messages in Rocket.Chat. Provides comprehensive support for message lifecycle, reactions, threading, and advanced message features.

Capabilities

Message Sending

Send messages to channels, groups, and direct messages with various formatting options and attachments.

def chat_post_message(self, text, room_id=None, channel=None, **kwargs):
    """
    Send a message to a room.
    
    Parameters:
    - text (str): Message text content
    - room_id (str, optional): Room ID to send message to
    - channel (str, optional): Channel name to send message to
    - alias (str, optional): Display name override
    - emoji (str, optional): Emoji for avatar
    - avatar (str, optional): Avatar URL
    - attachments (list, optional): Message attachments
    - parseUrls (bool, optional): Parse URLs in message
    - bot (dict, optional): Bot information
    - groupable (bool, optional): Allow message grouping
    - customFields (dict, optional): Custom message fields
    
    Returns:
    requests.Response: Message sending result
    """

def chat_send_message(self, message):
    """
    Send a message object (requires message.rid).
    
    Parameters:
    - message (dict): Complete message object with rid
    
    Returns:
    requests.Response: Message sending result
    """

Message Retrieval and Information

Get message details, history, and metadata.

def chat_get_message(self, msg_id, **kwargs):
    """
    Get a message by ID.
    
    Parameters:
    - msg_id (str): Message ID
    
    Returns:
    requests.Response: Message details
    """

def chat_get_starred_messages(self, room_id, **kwargs):
    """
    Get starred messages in a room.
    
    Parameters:
    - room_id (str): Room ID
    - offset (int, optional): Number of items to skip
    - count (int, optional): Number of items to return
    
    Returns:
    requests.Response: List of starred messages
    """

def chat_get_mentioned_messages(self, room_id, **kwargs):
    """
    Get messages where user is mentioned.
    
    Parameters:
    - room_id (str): Room ID
    - offset (int, optional): Number of items to skip
    - count (int, optional): Number of items to return
    
    Returns:
    requests.Response: List of mentioned messages
    """

def chat_get_message_read_receipts(self, message_id, **kwargs):
    """
    Get message read receipts.
    
    Parameters:
    - message_id (str): Message ID
    
    Returns:
    requests.Response: Read receipt information
    """

Message Management

Edit, delete, and manage existing messages.

def chat_update(self, room_id, msg_id, text, **kwargs):
    """
    Update/edit a message.
    
    Parameters:
    - room_id (str): Room ID containing the message
    - msg_id (str): Message ID to update
    - text (str): New message text
    - attachments (list, optional): Updated attachments
    - parseUrls (bool, optional): Parse URLs in updated message
    
    Returns:
    requests.Response: Update result
    """

def chat_delete(self, room_id, msg_id, **kwargs):
    """
    Delete a message.
    
    Parameters:
    - room_id (str): Room ID containing the message
    - msg_id (str): Message ID to delete
    - asUser (bool, optional): Delete as user vs system
    
    Returns:
    requests.Response: Deletion result
    """

Message Interactions

React to messages, pin, star, and manage message interactions.

def chat_react(self, msg_id, emoji="smile", **kwargs):
    """
    Add or remove reaction to a message.
    
    Parameters:
    - msg_id (str): Message ID
    - emoji (str): Emoji reaction (default: "smile")
    - shouldReact (bool, optional): Add (true) or remove (false) reaction
    
    Returns:
    requests.Response: Reaction result
    """

def chat_pin_message(self, msg_id, **kwargs):
    """
    Pin a message.
    
    Parameters:
    - msg_id (str): Message ID to pin
    
    Returns:
    requests.Response: Pin result
    """

def chat_unpin_message(self, msg_id, **kwargs):
    """
    Unpin a message.
    
    Parameters:
    - msg_id (str): Message ID to unpin
    
    Returns:
    requests.Response: Unpin result
    """

def chat_star_message(self, msg_id, **kwargs):
    """
    Star a message.
    
    Parameters:
    - msg_id (str): Message ID to star
    
    Returns:
    requests.Response: Star result
    """

def chat_unstar_message(self, msg_id, **kwargs):
    """
    Unstar a message.
    
    Parameters:
    - msg_id (str): Message ID to unstar
    
    Returns:
    requests.Response: Unstar result
    """

Message Search and Discovery

Search for messages and content within rooms.

def chat_search(self, room_id, search_text, **kwargs):
    """
    Search messages in a room.
    
    Parameters:
    - room_id (str): Room ID to search in
    - search_text (str): Text to search for
    - regex (bool, optional): Use regex search
    - caseSensitive (bool, optional): Case sensitive search
    - count (int, optional): Number of results to return
    - offset (int, optional): Number of results to skip
    
    Returns:
    requests.Response: Search results
    """

Thread Management

Manage message threads and threaded conversations.

def chat_get_thread_messages(self, thread_msg_id, **kwargs):
    """
    Get messages in a thread.
    
    Parameters:
    - thread_msg_id (str): Thread parent message ID
    - offset (int, optional): Number of items to skip
    - count (int, optional): Number of items to return
    - sort (dict, optional): Sort criteria
    - query (dict, optional): Query filters
    
    Returns:
    requests.Response: Thread messages
    """

def chat_follow_message(self, mid, **kwargs):
    """
    Follow a message thread.
    
    Parameters:
    - mid (str): Message ID to follow
    
    Returns:
    requests.Response: Follow result
    """

Message Reporting and Moderation

Report messages and handle moderation actions.

def chat_report_message(self, message_id, description, **kwargs):
    """
    Report a message for moderation.
    
    Parameters:
    - message_id (str): Message ID to report
    - description (str): Report description/reason
    
    Returns:
    requests.Response: Report submission result
    """

Message Format Types

Basic Message Structure

MessageObject = {
    "_id": "str",  # Message ID
    "rid": "str",  # Room ID
    "msg": "str",  # Message text
    "ts": "datetime",  # Timestamp
    "u": {  # User object
        "_id": "str",
        "username": "str",
        "name": "str"
    },
    "mentions": ["UserObject"],  # Mentioned users
    "channels": ["ChannelObject"],  # Mentioned channels
    "_updatedAt": "datetime",
    "editedAt": "datetime",  # If edited
    "editedBy": "UserObject",  # Editor info
    "urls": ["UrlObject"],  # Parsed URLs
    "attachments": ["AttachmentObject"],  # File attachments
    "reactions": "dict",  # Emoji reactions
    "starred": ["UserObject"],  # Users who starred
    "pinned": "bool",  # Pin status
    "pinnedAt": "datetime",  # Pin timestamp
    "pinnedBy": "UserObject"  # Who pinned
}

Attachment Structure

AttachmentObject = {
    "title": "str",
    "title_link": "str",
    "text": "str",
    "color": "str",
    "thumb_url": "str",
    "image_url": "str",
    "author_name": "str",
    "author_link": "str",
    "author_icon": "str",
    "fields": [{
        "title": "str",
        "value": "str",
        "short": "bool"
    }],
    "ts": "datetime"
}

Usage Examples

Sending Messages with Formatting

# Send a simple message
response = rocket.chat_post_message(
    text="Hello, World!",
    channel="general"
)

# Send a message with formatting and attachments
response = rocket.chat_post_message(
    text="Important update:",
    room_id="ROOM_ID",
    alias="System Bot",
    emoji=":bell:",
    attachments=[{
        "title": "Server Status",
        "text": "All systems operational",
        "color": "good",
        "fields": [{
            "title": "Uptime",
            "value": "99.9%",
            "short": True
        }]
    }]
)

Message Management Workflow

# Send a message
response = rocket.chat_post_message(text="Original message", channel="general")
msg_id = response.json()['message']['_id']
room_id = response.json()['message']['rid']

# Edit the message
rocket.chat_update(room_id, msg_id, "Updated message content")

# Add reaction
rocket.chat_react(msg_id, "thumbsup")

# Pin the message
rocket.chat_pin_message(msg_id)

# Star the message
rocket.chat_star_message(msg_id)

Message Search and Discovery

# Search for messages containing specific text
results = rocket.chat_search(
    room_id="ROOM_ID",
    search_text="important announcement",
    count=10
)

# Get messages where user is mentioned
mentions = rocket.chat_get_mentioned_messages(
    room_id="ROOM_ID",
    count=20
)

# Get starred messages
starred = rocket.chat_get_starred_messages(
    room_id="ROOM_ID"
)

Thread Management

# Get thread messages
thread_messages = rocket.chat_get_thread_messages(
    thread_msg_id="PARENT_MESSAGE_ID",
    count=50
)

# Follow a thread for notifications
rocket.chat_follow_message("PARENT_MESSAGE_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