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
—
Comprehensive channel lifecycle management for public Rocket.Chat channels. Provides complete functionality for creating, configuring, administering, and managing channel membership, permissions, and content.
Create new public channels and retrieve channel information and metadata.
def channels_create(self, name, **kwargs):
"""
Create a new public channel.
Parameters:
- name (str): Channel name (required)
- members (list, optional): List of usernames to add as members
- readonly (bool, optional): Create as read-only channel
- customFields (dict, optional): Custom fields for the channel
Returns:
requests.Response: Channel creation result
"""
def channels_info(self, room_id=None, channel=None, **kwargs):
"""
Get channel information.
Parameters:
- room_id (str, optional): Channel ID
- channel (str, optional): Channel name
Returns:
requests.Response: Channel information
"""
def channels_delete(self, room_id=None, channel=None, **kwargs):
"""
Delete a public channel.
Parameters:
- room_id (str, optional): Channel ID
- channel (str, optional): Channel name
Returns:
requests.Response: Deletion result
"""List and discover channels based on user access and criteria.
def channels_list(self, **kwargs):
"""
List all channels the user has access to.
Parameters:
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
- sort (dict, optional): Sort criteria
- query (dict, optional): Search query
Returns:
requests.Response: List of channels
"""
def channels_list_joined(self, **kwargs):
"""
List channels the user has joined.
Parameters:
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of joined channels
"""
def channels_online(self, _id=None, query=None):
"""
List online users in channels.
Parameters:
- _id (str, optional): Channel ID
- query (dict, optional): Query parameters
Returns:
requests.Response: Online users information
"""Manage channel membership including invitations, removals, and access control.
def channels_invite(self, room_id, user_id, **kwargs):
"""
Invite a user to the channel.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to invite
Returns:
requests.Response: Invitation result
"""
def channels_kick(self, room_id, user_id, **kwargs):
"""
Remove a user from the channel.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to remove
Returns:
requests.Response: Removal result
"""
def channels_join(self, room_id, join_code, **kwargs):
"""
Join a channel.
Parameters:
- room_id (str): Channel ID
- join_code (str): Join code if required
Returns:
requests.Response: Join result
"""
def channels_leave(self, room_id, **kwargs):
"""
Leave a channel.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Leave result
"""
def channels_members(self, room_id=None, channel=None, **kwargs):
"""
List channel members.
Parameters:
- room_id (str, optional): Channel ID
- channel (str, optional): Channel name
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of members
"""Configure channel settings including name, description, topic, and behavior.
def channels_rename(self, room_id, name, **kwargs):
"""
Rename a channel.
Parameters:
- room_id (str): Channel ID
- name (str): New channel name
Returns:
requests.Response: Rename result
"""
def channels_set_description(self, room_id, description, **kwargs):
"""
Set channel description.
Parameters:
- room_id (str): Channel ID
- description (str): Channel description
Returns:
requests.Response: Update result
"""
def channels_set_topic(self, room_id, topic, **kwargs):
"""
Set channel topic.
Parameters:
- room_id (str): Channel ID
- topic (str): Channel topic
Returns:
requests.Response: Update result
"""
def channels_set_announcement(self, room_id, announcement, **kwargs):
"""
Set channel announcement.
Parameters:
- room_id (str): Channel ID
- announcement (str): Channel announcement
Returns:
requests.Response: Update result
"""
def channels_set_read_only(self, room_id, read_only, **kwargs):
"""
Set channel read-only status.
Parameters:
- room_id (str): Channel ID
- read_only (bool): Read-only status
Returns:
requests.Response: Update result
"""
def channels_set_type(self, room_id, a_type, **kwargs):
"""
Set channel type.
Parameters:
- room_id (str): Channel ID
- a_type (str): Channel type ('c' for channel, 'p' for private)
Returns:
requests.Response: Update result
"""
def channels_set_custom_fields(self, rid, custom_fields):
"""
Set custom fields for channel.
Parameters:
- rid (str): Channel ID
- custom_fields (dict): Custom fields dictionary
Returns:
requests.Response: Update result
"""Administrative functions for channel management including archiving, defaults, and access control.
def channels_archive(self, room_id, **kwargs):
"""
Archive a channel.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Archive result
"""
def channels_unarchive(self, room_id, **kwargs):
"""
Unarchive a channel.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Unarchive result
"""
def channels_set_default(self, room_id, default, **kwargs):
"""
Set channel as default.
Parameters:
- room_id (str): Channel ID
- default (bool): Default channel status
Returns:
requests.Response: Update result
"""
def channels_set_join_code(self, room_id, join_code, **kwargs):
"""
Set join code for channel.
Parameters:
- room_id (str): Channel ID
- join_code (str): Join code required to join channel
Returns:
requests.Response: Update result
"""
def channels_close(self, room_id, **kwargs):
"""
Close channel for user.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Close result
"""
def channels_open(self, room_id, **kwargs):
"""
Open channel for user.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Open result
"""Manage user roles within channels including moderators, owners, and leaders.
def channels_add_moderator(self, room_id, user_id, **kwargs):
"""
Add channel moderator.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to make moderator
Returns:
requests.Response: Role assignment result
"""
def channels_remove_moderator(self, room_id, user_id, **kwargs):
"""
Remove channel moderator.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to remove moderator role
Returns:
requests.Response: Role removal result
"""
def channels_moderators(self, room_id=None, channel=None, **kwargs):
"""
List channel moderators.
Parameters:
- room_id (str, optional): Channel ID
- channel (str, optional): Channel name
Returns:
requests.Response: List of moderators
"""
def channels_add_owner(self, room_id, user_id=None, username=None, **kwargs):
"""
Add channel owner.
Parameters:
- room_id (str): Channel ID
- user_id (str, optional): User ID
- username (str, optional): Username
Returns:
requests.Response: Role assignment result
"""
def channels_remove_owner(self, room_id, user_id, **kwargs):
"""
Remove channel owner.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to remove owner role
Returns:
requests.Response: Role removal result
"""
def channels_add_leader(self, room_id, user_id, **kwargs):
"""
Add channel leader.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to make leader
Returns:
requests.Response: Role assignment result
"""
def channels_remove_leader(self, room_id, user_id, **kwargs):
"""
Remove channel leader.
Parameters:
- room_id (str): Channel ID
- user_id (str): User ID to remove leader role
Returns:
requests.Response: Role removal result
"""
def channels_roles(self, room_id=None, room_name=None, **kwargs):
"""
List user roles in channel.
Parameters:
- room_id (str, optional): Channel ID
- room_name (str, optional): Channel name
Returns:
requests.Response: List of user roles
"""Access channel content including message history, files, and statistics.
def channels_history(self, room_id, **kwargs):
"""
Get channel message history.
Parameters:
- room_id (str): Channel ID
- latest (str, optional): Latest message timestamp
- oldest (str, optional): Oldest message timestamp
- inclusive (bool, optional): Include boundaries
- count (int, optional): Number of messages
- unreads (bool, optional): Include unread count
Returns:
requests.Response: Message history
"""
def channels_files(self, room_id=None, room_name=None, **kwargs):
"""
List files in channel.
Parameters:
- room_id (str, optional): Channel ID
- room_name (str, optional): Channel name
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of files
"""
def channels_counters(self, room_id=None, room_name=None, **kwargs):
"""
Get channel counters.
Parameters:
- room_id (str, optional): Channel ID
- room_name (str, optional): Channel name
Returns:
requests.Response: Channel statistics
"""
def channels_get_all_user_mentions_by_channel(self, room_id, **kwargs):
"""
Get all user mentions in channel.
Parameters:
- room_id (str): Channel ID
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of mentions
"""Manage channel integrations and webhooks.
def channels_get_integrations(self, room_id, **kwargs):
"""
Get channel integrations.
Parameters:
- room_id (str): Channel ID
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of integrations
"""
def channels_add_all(self, room_id, **kwargs):
"""
Add all server users to channel.
Parameters:
- room_id (str): Channel ID
Returns:
requests.Response: Addition result
"""# Create a new channel
response = rocket.channels_create(
name='project-alpha',
members=['john.doe', 'jane.smith'],
readonly=False
)
channel_id = response.json()['channel']['_id']
# Configure the channel
rocket.channels_set_description(channel_id, 'Project Alpha discussion channel')
rocket.channels_set_topic(channel_id, 'Daily updates and collaboration')
rocket.channels_set_announcement(channel_id, 'Welcome to Project Alpha!')
# Add moderators
rocket.channels_add_moderator(channel_id, 'manager_user_id')# Invite users to channel
rocket.channels_invite(channel_id, 'new_user_id')
# List current members
members = rocket.channels_members(room_id=channel_id, count=50)
print(f"Channel has {len(members.json()['members'])} members")
# Remove inactive user
rocket.channels_kick(channel_id, 'inactive_user_id')Install with Tessl CLI
npx tessl i tessl/pypi-rocketchat-a-p-i