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
—
User subscription management for tracking user relationships with rooms, including read status, notifications, and room-specific user settings.
def subscriptions_get(self, **kwargs):
"""
Get user's subscriptions to rooms.
Parameters:
- updatedSince (str, optional): ISO date string to get subscriptions updated since
Returns:
requests.Response: List of user's room subscriptions
"""
def subscriptions_get_one(self, room_id, **kwargs):
"""
Get subscription information for a specific room.
Parameters:
- room_id (str): Room ID
Returns:
requests.Response: Room subscription details
"""def subscriptions_read(self, rid, **kwargs):
"""
Mark a room as read.
Parameters:
- rid (str): Room ID
Returns:
requests.Response: Read status update result
"""
def subscriptions_unread(self, room_id, **kwargs):
"""
Mark a room as unread.
Parameters:
- room_id (str): Room ID
- firstUnreadMessage (str, optional): First unread message ID
Returns:
requests.Response: Unread status update result
"""SubscriptionObject = {
"_id": "str", # Subscription ID
"u": { # User info
"_id": "str",
"username": "str",
"name": "str"
},
"rid": "str", # Room ID
"name": "str", # Room name
"t": "str", # Room type (c, p, d, l)
"ts": "datetime", # Subscription timestamp
"ls": "datetime", # Last seen timestamp
"f": "bool", # Favorite status
"open": "bool", # Open for user
"alert": "bool", # Has alerts
"unread": "int", # Unread count
"userMentions": "int", # User mention count
"groupMentions": "int", # Group mention count
"roles": ["str"], # User roles in room
"disableNotifications": "bool", # Notifications disabled
"muteGroupMentions": "bool", # Group mentions muted
"hideUnreadStatus": "bool", # Hide unread status
"desktopNotifications": "str", # Desktop notification setting
"mobilePushNotifications": "str", # Mobile notification setting
"emailNotifications": "str", # Email notification setting
"audioNotifications": "str", # Audio notification setting
"_updatedAt": "datetime" # Last update timestamp
}# Get all user subscriptions
subs = rocket.subscriptions_get()
subscriptions = subs.json()['subscriptions']
print(f"User is subscribed to {len(subscriptions)} rooms")
# Find specific subscription
general_sub = None
for sub in subscriptions:
if sub['name'] == 'general':
general_sub = sub
break
if general_sub:
print(f"General channel has {general_sub['unread']} unread messages")
print(f"User mentions: {general_sub['userMentions']}")
# Get single subscription
room_id = 'GENERAL'
sub_info = rocket.subscriptions_get_one(room_id)
subscription = sub_info.json()['subscription']
# Mark room as read
rocket.subscriptions_read(room_id)
print(f"Marked room {room_id} as read")
# Mark room as unread
rocket.subscriptions_unread(room_id)
print(f"Marked room {room_id} as unread")
# Get recently updated subscriptions
from datetime import datetime, timedelta
yesterday = (datetime.now() - timedelta(days=1)).isoformat() + 'Z'
recent_subs = rocket.subscriptions_get(updatedSince=yesterday)
print(f"Subscriptions updated since yesterday: {len(recent_subs.json()['subscriptions'])}")Install with Tessl CLI
npx tessl i tessl/pypi-rocketchat-a-p-i